| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 '''Unit tests for the admin template gatherer.''' | 6 '''Unit tests for the admin template gatherer.''' |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 if __name__ == '__main__': | 10 if __name__ == '__main__': |
| 11 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../..')) | 11 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 12 | 12 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 42 pseudofile = StringIO.StringIO( | 42 pseudofile = StringIO.StringIO( |
| 43 'bingo bongo\n' | 43 'bingo bongo\n' |
| 44 'ding dong\n' | 44 'ding dong\n' |
| 45 'whatcha="bingo bongo"\n' | 45 'whatcha="bingo bongo"\n' |
| 46 'gotcha = "bingolabongola "the wise" fingulafongula" \n') | 46 'gotcha = "bingolabongola "the wise" fingulafongula" \n') |
| 47 gatherer = admin_template.AdmGatherer.FromFile(pseudofile) | 47 gatherer = admin_template.AdmGatherer.FromFile(pseudofile) |
| 48 self.assertRaises(admin_template.MalformedAdminTemplateException, | 48 self.assertRaises(admin_template.MalformedAdminTemplateException, |
| 49 gatherer.Parse) | 49 gatherer.Parse) |
| 50 | 50 |
| 51 _TRANSLATABLES_FROM_FILE = ( | 51 _TRANSLATABLES_FROM_FILE = ( |
| 52 'Google', 'Google Desktop', 'Preferences', | 52 'Google', 'Google Desktop Search', 'Preferences', |
| 53 'Controls Google Desktop preferences', | 53 'Controls Google Deskop Search preferences', |
| 54 'Indexing and Capture Control', | 54 'Indexing and Capture Control', |
| 55 'Controls what files, web pages, and other content will be indexed by Google
Desktop.', | 55 'Controls what files, web pages, and other content will be indexed by Google
Desktop Search.', |
| 56 'Prevent indexing of email', | 56 'Prevent indexing of e-mail', |
| 57 # there are lots more but we don't check any further | 57 # there are lots more but we don't check any further |
| 58 ) | 58 ) |
| 59 | 59 |
| 60 def VerifyCliquesFromAdmFile(self, cliques): | 60 def VerifyCliquesFromAdmFile(self, cliques): |
| 61 self.failUnless(len(cliques) > 20) | 61 self.failUnless(len(cliques) > 20) |
| 62 for ix in range(len(self._TRANSLATABLES_FROM_FILE)): | 62 for ix in range(len(self._TRANSLATABLES_FROM_FILE)): |
| 63 text = cliques[ix].GetMessage().GetRealContent() | 63 text = cliques[ix].GetMessage().GetRealContent() |
| 64 self.failUnless(text == self._TRANSLATABLES_FROM_FILE[ix]) | 64 self.failUnless(text == self._TRANSLATABLES_FROM_FILE[ix]) |
| 65 | 65 |
| 66 def testFromFile(self): | 66 def testFromFile(self): |
| 67 fname = util.PathFromRoot('grit/testdata/GoogleDesktop.adm') | 67 fname = util.PathFromRoot('grit/test/data/GoogleDesktopSearch.adm') |
| 68 gatherer = admin_template.AdmGatherer.FromFile(fname) | 68 gatherer = admin_template.AdmGatherer.FromFile(fname) |
| 69 gatherer.Parse() | 69 gatherer.Parse() |
| 70 cliques = gatherer.GetCliques() | 70 cliques = gatherer.GetCliques() |
| 71 self.VerifyCliquesFromAdmFile(cliques) | 71 self.VerifyCliquesFromAdmFile(cliques) |
| 72 | 72 |
| 73 def MakeGrd(self): | 73 def MakeGrd(self): |
| 74 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT
F-8"?> | 74 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT
F-8"?> |
| 75 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
> | 75 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
> |
| 76 <release seq="3"> | 76 <release seq="3"> |
| 77 <structures> | 77 <structures> |
| 78 <structure type="admin_template" name="IDAT_GOOGLE_DESKTOP_SEARCH" | 78 <structure type="admin_template" name="IDAT_GOOGLE_DESKTOP_SEARCH" |
| 79 file="GoogleDesktop.adm" exclude_from_rc="true" /> | 79 file="GoogleDesktopSearch.adm" exclude_from_rc="true" /> |
| 80 <structure type="txt" name="BINGOBONGO" | 80 <structure type="txt" name="BINGOBONGO" |
| 81 file="README.txt" exclude_from_rc="true" /> | 81 file="README.txt" exclude_from_rc="true" /> |
| 82 </structures> | 82 </structures> |
| 83 </release> | 83 </release> |
| 84 <outputs> | 84 <outputs> |
| 85 <output filename="de_res.rc" type="rc_all" lang="de" /> | 85 <output filename="de_res.rc" type="rc_all" lang="de" /> |
| 86 </outputs> | 86 </outputs> |
| 87 </grit>'''), util.PathFromRoot('grit/testdata')) | 87 </grit>'''), util.PathFromRoot('grit/test/data')) |
| 88 grd.RunGatherers(recursive=True) | 88 grd.RunGatherers(recursive=True) |
| 89 return grd | 89 return grd |
| 90 | 90 |
| 91 def testInGrd(self): | 91 def testInGrd(self): |
| 92 grd = self.MakeGrd() | 92 grd = self.MakeGrd() |
| 93 cliques = grd.children[0].children[0].children[0].GetCliques() | 93 cliques = grd.children[0].children[0].children[0].GetCliques() |
| 94 self.VerifyCliquesFromAdmFile(cliques) | 94 self.VerifyCliquesFromAdmFile(cliques) |
| 95 | 95 |
| 96 def testFileIsOutput(self): | 96 def testFileIsOutput(self): |
| 97 grd = self.MakeGrd() | 97 grd = self.MakeGrd() |
| 98 dirname = tempfile.mkdtemp() | 98 dirname = tempfile.mkdtemp() |
| 99 try: | 99 try: |
| 100 tool = build.RcBuilder() | 100 tool = build.RcBuilder() |
| 101 tool.o = grit_runner.Options() | 101 tool.o = grit_runner.Options() |
| 102 tool.output_directory = dirname | 102 tool.output_directory = dirname |
| 103 tool.res = grd | 103 tool.res = grd |
| 104 tool.Process() | 104 tool.Process() |
| 105 | 105 |
| 106 self.failUnless(os.path.isfile( | 106 self.failUnless(os.path.isfile( |
| 107 os.path.join(dirname, 'de_GoogleDesktop.adm'))) | 107 os.path.join(dirname, 'de_GoogleDesktopSearch.adm'))) |
| 108 self.failUnless(os.path.isfile( | 108 self.failUnless(os.path.isfile( |
| 109 os.path.join(dirname, 'de_README.txt'))) | 109 os.path.join(dirname, 'de_README.txt'))) |
| 110 finally: | 110 finally: |
| 111 for f in os.listdir(dirname): | 111 for f in os.listdir(dirname): |
| 112 os.unlink(os.path.join(dirname, f)) | 112 os.unlink(os.path.join(dirname, f)) |
| 113 os.rmdir(dirname) | 113 os.rmdir(dirname) |
| 114 | 114 |
| 115 if __name__ == '__main__': | 115 if __name__ == '__main__': |
| 116 unittest.main() | 116 unittest.main() |
| 117 |
| OLD | NEW |