diff options
author | gfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 15:19:08 +0000 |
---|---|---|
committer | gfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 15:19:08 +0000 |
commit | 50cecd9dd668ec929df6289a40fdb33c810bc776 (patch) | |
tree | 553cffd0cc885fcd72a68b70a735b4a266571db6 /tools/grit | |
parent | 412cee3c0ae3867d64a0c240c8d5e7c8d2fb7a61 (diff) | |
download | chromium_src-50cecd9dd668ec929df6289a40fdb33c810bc776.zip chromium_src-50cecd9dd668ec929df6289a40fdb33c810bc776.tar.gz chromium_src-50cecd9dd668ec929df6289a40fdb33c810bc776.tar.bz2 |
Add unit tests to adm_writer
Add unit tests to adm_writer, clean up other writer unit tests and fix list policies generated by adm_writer. (Move KEYNAME into the PART structure.)
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3284006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57995 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
6 files changed, 375 insertions, 119 deletions
diff --git a/tools/grit/grit/format/policy_templates/writers/adm_writer.py b/tools/grit/grit/format/policy_templates/writers/adm_writer.py index 76b8b60..d0639f6 100644 --- a/tools/grit/grit/format/policy_templates/writers/adm_writer.py +++ b/tools/grit/grit/format/policy_templates/writers/adm_writer.py @@ -41,7 +41,10 @@ class AdmWriter(template_writer.TemplateWriter): indent_diff *= 2 if indent_diff < 0: self.indent = self.indent[(-indent_diff):] - self.policy_list.append(self.indent + string) + if string != '': + self.policy_list.append(self.indent + string) + else: + self.policy_list.append('') if indent_diff > 0: self.indent += ''.ljust(indent_diff) @@ -63,13 +66,14 @@ class AdmWriter(template_writer.TemplateWriter): self._AddGuiString(policy_part_name, policy['caption']) self._PrintLine() - if policy_type == 'list': - self._PrintLine('KEYNAME "%s\\%s"' % (self._key_name, policy_name)) # Print the PART ... END PART section: self._PrintLine( 'PART !!%s %s' % (policy_part_name, self.TYPE_TO_INPUT[policy_type]), 1) if policy_type == 'list': + # Note that the following line causes FullArmor ADMX Migrator to create + # corrupt ADMX files. Please use admx_writer to get ADMX files. + self._PrintLine('KEYNAME "%s\\%s"' % (self._key_name, policy_name)) self._PrintLine('VALUEPREFIX ""') else: self._PrintLine('VALUENAME "%s"' % policy_name) diff --git a/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py new file mode 100644 index 0000000..ed2b684 --- /dev/null +++ b/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py @@ -0,0 +1,280 @@ +#!/usr/bin/python2.4 +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +'''Unit tests for grit.format.policy_templates.writers.adm_writer''' + + +import os +import sys +if __name__ == '__main__': + sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../..')) + +import tempfile +import unittest +import StringIO + +from grit.format.policy_templates.writers import writer_unittest_common +from grit import grd_reader +from grit import util +from grit.tool import build + + +class AdmWriterUnittest(writer_unittest_common.WriterUnittestCommon): + '''Unit tests for AdmWriter.''' + + def CompareOutputs(self, output, expected_output): + '''Compares the output of the adm_writer with its expected output. + + Args: + output: The output of the adm writer as returned by grit. + expected_output: The expected output. + + Raises: + AssertionError: if the two strings are not equivalent. + ''' + self.assertEquals( + output.strip(), + expected_output.strip().replace('\n', '\r\n')) + + def testEmpty(self): + # Test PListWriter in case of empty polices. + grd = self.PrepareTest(''' + { + 'policy_groups': [], + 'placeholders': [], + }''', ''' + <messages> + <message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least "Windows 3.11</message> + </messages> + ''' ) + output = self.GetOutput(grd, 'fr', {'_chromium': '1',}, 'adm', 'en') + expected_output = '''CLASS MACHINE + CATEGORY !!chromium + KEYNAME "Software\\Policies\\Chromium" + + END CATEGORY + +[Strings] +SUPPORTED_WINXPSP2="At least "Windows 3.11" +chromium="Chromium"''' + self.CompareOutputs(output, expected_output) + + def testMainPolicy(self): + # Tests a policy group with a single policy of type 'main'. + grd = self.PrepareTest(''' + { + 'policy_groups': [ + { + 'name': 'MainGroup', + 'policies': [{ + 'name': 'MainPolicy', + 'type': 'main', + }], + }, + ], + 'placeholders': [], + }''', ''' + <messages> + <message name="IDS_POLICY_GROUP_MAINGROUP_CAPTION">Caption of main.</message> + <message name="IDS_POLICY_GROUP_MAINGROUP_DESC">Description of main.</message> + <message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.12</message> + </messages> + ''' ) + output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'adm', 'en') + expected_output = '''CLASS MACHINE + CATEGORY !!google + CATEGORY !!googlechrome + KEYNAME "Software\\Policies\\Google\\Google Chrome" + + POLICY !!MainGroup_Policy + #if version >= 4 + SUPPORTED !!SUPPORTED_WINXPSP2 + #endif + EXPLAIN !!MainGroup_Explain + VALUENAME "MainPolicy" + VALUEON NUMERIC 1 + VALUEOFF NUMERIC 0 + END POLICY + + END CATEGORY + END CATEGORY + +[Strings] +SUPPORTED_WINXPSP2="At least Windows 3.12" +google="Google" +googlechrome="Google Chrome" +MainGroup_Policy="Caption of main." +MainGroup_Explain="Description of main."''' + self.CompareOutputs(output, expected_output) + + def testStringPolicy(self): + # Tests a policy group with a single policy of type 'string'. + grd = self.PrepareTest(''' + { + 'policy_groups': [ + { + 'name': 'StringGroup', + 'policies': [{ + 'name': 'StringPolicy', + 'type': 'string', + }], + }, + ], + 'placeholders': [], + }''', ''' + <messages> + <message name="IDS_POLICY_GROUP_STRINGGROUP_CAPTION">Caption of group.</message> + <message name="IDS_POLICY_GROUP_STRINGGROUP_DESC">Description of group. +With a newline.</message> + <message name="IDS_POLICY_STRINGPOLICY_CAPTION">Caption of policy.</message> + <message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.13</message> + </messages> + ''' ) + output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en') + expected_output = '''CLASS MACHINE + CATEGORY !!chromium + KEYNAME "Software\\Policies\\Chromium" + + POLICY !!StringGroup_Policy + #if version >= 4 + SUPPORTED !!SUPPORTED_WINXPSP2 + #endif + EXPLAIN !!StringGroup_Explain + + PART !!StringPolicy_Part EDITTEXT + VALUENAME "StringPolicy" + END PART + END POLICY + + END CATEGORY + +[Strings] +SUPPORTED_WINXPSP2="At least Windows 3.13" +chromium="Chromium" +StringGroup_Policy="Caption of group." +StringGroup_Explain="Description of group.\\nWith a newline." +StringPolicy_Part="Caption of policy." +''' + self.CompareOutputs(output, expected_output) + + def testEnumPolicy(self): + # Tests a policy group with a single policy of type 'enum'. + grd = self.PrepareTest(''' + { + 'policy_groups': [ + { + 'name': 'EnumGroup', + 'policies': [{ + 'name': 'EnumPolicy', + 'type': 'enum', + 'items': [ + {'name': 'ProxyServerDisabled', 'value': '0'}, + {'name': 'ProxyServerAutoDetect', 'value': '1'}, + ] + }], + }, + ], + 'placeholders': [], + }''', ''' + <messages> + <message name="IDS_POLICY_GROUP_ENUMGROUP_CAPTION">Caption of group.</message> + <message name="IDS_POLICY_GROUP_ENUMGROUP_DESC">Description of group.</message> + <message name="IDS_POLICY_ENUMPOLICY_CAPTION">Caption of policy.</message> + <message name="IDS_POLICY_ENUMPOLICY_DESC">Description of policy.</message> + <message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">Option1</message> + <message name="IDS_POLICY_ENUM_PROXYSERVERAUTODETECT_CAPTION">Option2</message> + <message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.14</message> + </messages> + ''' ) + output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en') + expected_output = '''CLASS MACHINE + CATEGORY !!google + CATEGORY !!googlechrome + KEYNAME "Software\\Policies\\Google\\Google Chrome" + + POLICY !!EnumGroup_Policy + #if version >= 4 + SUPPORTED !!SUPPORTED_WINXPSP2 + #endif + EXPLAIN !!EnumGroup_Explain + + PART !!EnumPolicy_Part DROPDOWNLIST + VALUENAME "EnumPolicy" + ITEMLIST + NAME !!ProxyServerDisabled_DropDown VALUE NUMERIC 0 + NAME !!ProxyServerAutoDetect_DropDown VALUE NUMERIC 1 + END ITEMLIST + END PART + END POLICY + + END CATEGORY + END CATEGORY + +[Strings] +SUPPORTED_WINXPSP2="At least Windows 3.14" +google="Google" +googlechrome="Google Chrome" +EnumGroup_Policy="Caption of group." +EnumGroup_Explain="Description of group." +EnumPolicy_Part="Caption of policy." +ProxyServerDisabled_DropDown="Option1" +ProxyServerAutoDetect_DropDown="Option2" +''' + self.CompareOutputs(output, expected_output) + + def testListPolicy(self): + # Tests a policy group with a single policy of type 'list'. + grd = self.PrepareTest(''' + { + 'policy_groups': [ + { + 'name': 'ListGroup', + 'policies': [{ + 'name': 'ListPolicy', + 'type': 'list', + }], + }, + ], + 'placeholders': [], + }''', ''' + <messages> + <message name="IDS_POLICY_GROUP_LISTGROUP_CAPTION">Caption of list group.</message> + <message name="IDS_POLICY_GROUP_LISTGROUP_DESC">Description of list group. +With a newline.</message> + <message name="IDS_POLICY_LISTPOLICY_CAPTION">Caption of list policy.</message> + <message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.15</message> + </messages> + ''') + output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en') + expected_output = '''CLASS MACHINE + CATEGORY !!chromium + KEYNAME "Software\\Policies\\Chromium" + + POLICY !!ListGroup_Policy + #if version >= 4 + SUPPORTED !!SUPPORTED_WINXPSP2 + #endif + EXPLAIN !!ListGroup_Explain + + PART !!ListPolicy_Part LISTBOX + KEYNAME "Software\\Policies\\Chromium\\ListPolicy" + VALUEPREFIX "" + END PART + END POLICY + + END CATEGORY + +[Strings] +SUPPORTED_WINXPSP2="At least Windows 3.15" +chromium="Chromium" +ListGroup_Policy="Caption of list group." +ListGroup_Explain="Description of list group.\\nWith a newline." +ListPolicy_Part="Caption of list policy." +''' + self.CompareOutputs(output, expected_output) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py index 635b55f..d8b3506 100644 --- a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py @@ -22,40 +22,34 @@ from grit.tool import build class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon): - '''Unit tests for PListWriter.''' + '''Unit tests for PListStringsWriter.''' def testEmpty(self): - # Test PListWriter in case of empty polices. - grd = self.prepareTest(''' + # Test PListStringsWriter in case of empty polices. + grd = self.PrepareTest(''' { 'policy_groups': [], 'placeholders': [], }''', ''' - <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> - <release seq="1"> - <structures> - <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> - </structures> <messages> <message name="IDS_POLICY_MAC_CHROME_PREFERENCES">$1 preferen"ces</message> </messages> - </release> - </grit> ''' ) - - self.CompareResult( + output = self.GetOutput( grd, 'fr', {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'}, 'plist_strings', - 'en', - '''Chromium.pfm_title = "Chromium"; + 'en') + expected_output = \ +'''Chromium.pfm_title = "Chromium"; Chromium.pfm_description = "Chromium preferen\\"ces"; - ''') +''' + self.assertEquals(output.strip(), expected_output.strip()) def testMainPolicy(self): # Tests a policy group with a single policy of type 'main'. - grd = self.prepareTest(''' + grd = self.PrepareTest(''' { 'policy_groups': [ { @@ -68,35 +62,30 @@ Chromium.pfm_description = "Chromium preferen\\"ces"; ], 'placeholders': [], }''', ''' - <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> - <release seq="1"> - <structures> - <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> - </structures> <messages> <message name="IDS_POLICY_GROUP_MAINGROUP_CAPTION">Caption of main.</message> <message name="IDS_POLICY_GROUP_MAINGROUP_DESC">Title of main.</message> <message name="IDS_POLICY_MAC_CHROME_PREFERENCES">Preferences of $1</message> </messages> - </release> - </grit> ''' ) - self.CompareResult( + output = self.GetOutput( grd, 'fr', {'_google_chrome' : '1', 'mac_bundle_id': 'com.example.Test'}, 'plist_strings', - 'en', - '''Google Chrome.pfm_title = "Google Chrome"; + 'en') + expected_output = \ +'''Google Chrome.pfm_title = "Google Chrome"; Google Chrome.pfm_description = "Preferences of Google Chrome"; MainPolicy.pfm_title = "Caption of main."; MainPolicy.pfm_description = "Title of main."; -''') +''' + self.assertEquals(output.strip(), expected_output.strip()) def testStringPolicy(self): # Tests a policy group with a single policy of type 'string'. Also test # inheriting group description to policy description. - grd = self.prepareTest(''' + grd = self.PrepareTest(''' { 'policy_groups': [ { @@ -109,11 +98,6 @@ MainPolicy.pfm_description = "Title of main."; ], 'placeholders': [], }''', ''' - <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> - <release seq="1"> - <structures> - <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> - </structures> <messages> <message name="IDS_POLICY_GROUP_STRINGGROUP_CAPTION">Caption of group.</message> <message name="IDS_POLICY_GROUP_STRINGGROUP_DESC">Description of group. @@ -121,24 +105,24 @@ With a newline.</message> <message name="IDS_POLICY_STRINGPOLICY_CAPTION">Caption of policy.</message> <message name="IDS_POLICY_MAC_CHROME_PREFERENCES">Preferences Of $1</message> </messages> - </release> - </grit> ''' ) - self.CompareResult( + output = self.GetOutput( grd, 'fr', {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, 'plist_strings', - 'en', - '''Chromium.pfm_title = "Chromium"; + 'en') + expected_output = \ +'''Chromium.pfm_title = "Chromium"; Chromium.pfm_description = "Preferences Of Chromium"; StringPolicy.pfm_title = "Caption of policy."; StringPolicy.pfm_description = "Description of group.\\nWith a newline."; - ''') + ''' + self.assertEquals(output.strip(), expected_output.strip()) def testEnumPolicy(self): # Tests a policy group with a single policy of type 'enum'. - grd = self.prepareTest(''' + grd = self.PrepareTest(''' { 'policy_groups': [ { @@ -155,11 +139,6 @@ StringPolicy.pfm_description = "Description of group.\\nWith a newline."; ], 'placeholders': [], }''', ''' - <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> - <release seq="1"> - <structures> - <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> - </structures> <messages> <message name="IDS_POLICY_GROUP_ENUMGROUP_CAPTION">Caption of group.</message> <message name="IDS_POLICY_GROUP_ENUMGROUP_DESC">Description of group.</message> @@ -169,22 +148,21 @@ StringPolicy.pfm_description = "Description of group.\\nWith a newline."; <message name="IDS_POLICY_ENUM_PROXYSERVERAUTODETECT_CAPTION">Option2</message> <message name="IDS_POLICY_MAC_CHROME_PREFERENCES">$1 preferences</message> </messages> - </release> - </grit> ''' ) - self.CompareResult( + output = self.GetOutput( grd, 'fr', {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, 'plist_strings', - 'en', - '''Google Chrome.pfm_title = "Google Chrome"; + 'en') + expected_output = \ +'''Google Chrome.pfm_title = "Google Chrome"; Google Chrome.pfm_description = "Google Chrome preferences"; EnumPolicy.pfm_title = "Caption of policy."; EnumPolicy.pfm_description = "0 - Option1\\n1 - Option2\\nDescription of policy."; - ''') + ''' + self.assertEquals(output.strip(), expected_output.strip()) if __name__ == '__main__': unittest.main() - diff --git a/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py index c3a701a..35af4a6 100644 --- a/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py +++ b/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py @@ -26,7 +26,7 @@ from grit.tool import build class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): '''Unit tests for PListWriter.''' - def _GetExpectedResults(self, product_name, bundle_id, policies): + def _GetExpectedOutputs(self, product_name, bundle_id, policies): '''Substitutes the variable parts into a plist template. The result of this function can be used as an expected result to test the output of PListWriter. @@ -61,32 +61,25 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): def testEmpty(self): # Test PListWriter in case of empty polices. - grd = self.prepareTest(''' + grd = self.PrepareTest(''' { 'policy_groups': [], 'placeholders': [], - }''', ''' - <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> - <release seq="1"> - <structures> - <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> - </structures> - <messages /> - </release> - </grit> - ''' ) + }''', '''<messages />''' ) - self.CompareResult( + output = self.GetOutput( grd, 'fr', {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'}, 'plist', - 'en', - self._GetExpectedResults('Chromium', 'com.example.Test', '<array/>')) + 'en') + expected_output = \ + self._GetExpectedOutputs('Chromium', 'com.example.Test', '<array/>') + self.assertEquals(output.strip(), expected_output.strip()) def testMainPolicy(self): # Tests a policy group with a single policy of type 'main'. - grd = self.prepareTest(''' + grd = self.PrepareTest(''' { 'policy_groups': [ { @@ -99,25 +92,19 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): ], 'placeholders': [], }''', ''' - <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> - <release seq="1"> - <structures> - <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> - </structures> <messages> <message name="IDS_POLICY_GROUP_MAINGROUP_CAPTION">This is not tested here.</message> <message name="IDS_POLICY_GROUP_MAINGROUP_DESC">This is not tested here.</message> </messages> - </release> - </grit> ''' ) - self.CompareResult( + output = self.GetOutput( grd, 'fr', {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, 'plist', - 'en', - self._GetExpectedResults('Chromium', 'com.example.Test', '''<array> + 'en') + expected_output = \ + self._GetExpectedOutputs('Chromium', 'com.example.Test', '''<array> <dict> <key>pfm_name</key> <string>MainPolicy</string> @@ -132,11 +119,12 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): <key>pfm_type</key> <string>boolean</string> </dict> - </array>''')) + </array>''') + self.assertEquals(output.strip(), expected_output.strip()) def testStringPolicy(self): # Tests a policy group with a single policy of type 'string'. - grd = self.prepareTest(''' + grd = self.PrepareTest(''' { 'policy_groups': [ { @@ -149,27 +137,21 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): ], 'placeholders': [], }''', ''' - <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> - <release seq="1"> - <structures> - <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> - </structures> <messages> <message name="IDS_POLICY_GROUP_STRINGGROUP_CAPTION">This is not tested here.</message> <message name="IDS_POLICY_GROUP_STRINGGROUP_DESC">This is not tested here.</message> <message name="IDS_POLICY_STRINGPOLICY_CAPTION">This is not tested here.</message> <message name="IDS_POLICY_STRINGPOLICY_DESC">This is not tested here.</message> </messages> - </release> - </grit> ''' ) - self.CompareResult( + output = self.GetOutput( grd, 'fr', {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, 'plist', - 'en', - self._GetExpectedResults('Chromium', 'com.example.Test', '''<array> + 'en') + expected_output = \ + self._GetExpectedOutputs('Chromium', 'com.example.Test', '''<array> <dict> <key>pfm_name</key> <string>StringPolicy</string> @@ -184,11 +166,12 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): <key>pfm_type</key> <string>string</string> </dict> - </array>''')) + </array>''') + self.assertEquals(output.strip(), expected_output.strip()) def testEnumPolicy(self): # Tests a policy group with a single policy of type 'enum'. - grd = self.prepareTest(''' + grd = self.PrepareTest(''' { 'policy_groups': [ { @@ -205,11 +188,6 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): ], 'placeholders': [], }''', ''' - <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> - <release seq="1"> - <structures> - <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> - </structures> <messages> <message name="IDS_POLICY_GROUP_ENUMGROUP_CAPTION">This is not tested here.</message> <message name="IDS_POLICY_GROUP_ENUMGROUP_DESC">This is not tested here.</message> @@ -218,16 +196,15 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): <message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">This is not tested here.</message> <message name="IDS_POLICY_ENUM_PROXYSERVERAUTODETECT_CAPTION">This is not tested here.</message> </messages> - </release> - </grit> ''' ) - self.CompareResult( + output = self.GetOutput( grd, 'fr', {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, 'plist', - 'en', - self._GetExpectedResults('Google Chrome', 'com.example.Test2', '''<array> + 'en') + expected_output = \ + self._GetExpectedOutputs('Google Chrome', 'com.example.Test2', '''<array> <dict> <key>pfm_name</key> <string>EnumPolicy</string> @@ -247,9 +224,9 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): <integer>1</integer> </array> </dict> - </array>''')) + </array>''') + self.assertEquals(output.strip(), expected_output.strip()) if __name__ == '__main__': unittest.main() - diff --git a/tools/grit/grit/format/policy_templates/writers/writer_unittest_common.py b/tools/grit/grit/format/policy_templates/writers/writer_unittest_common.py index ff7d8f5..0970772 100644 --- a/tools/grit/grit/format/policy_templates/writers/writer_unittest_common.py +++ b/tools/grit/grit/format/policy_templates/writers/writer_unittest_common.py @@ -35,40 +35,54 @@ class DummyOutput(object): class WriterUnittestCommon(unittest.TestCase): '''Common class for unittesting writers.''' - def prepareTest(self, policy_json, grd_text): - '''Parses a grit tree along with a data structure of policies. + def PrepareTest(self, policy_json, grd_messages_text): + '''Prepares and parses a grit tree along with a data structure of policies. Args: policy_json: The policy data structure in JSON format. - grd_text: The grit tree in text form. + grd_messages_text: The messages node of the grit tree in text form. ''' + # First create a temporary file that contains the JSON policy list. tmp_file_name = 'test.json' tmp_dir_name = tempfile.gettempdir() json_file_path = tmp_dir_name + '/' + tmp_file_name f = open(json_file_path, 'w') f.write(policy_json.strip()) f.close() - grd = grd_reader.Parse( - StringIO.StringIO(grd_text % json_file_path), dir=tmp_dir_name) + # Then assemble the grit tree. + grd_begin_text = ''' + <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> + <release seq="1"> + <structures> + <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> + </structures>''' % json_file_path + grd_end_text = ''' + </release> + </grit>''' + grd_text = grd_begin_text + grd_messages_text + grd_end_text + grd_string_io = StringIO.StringIO(grd_text) + # Parse the grit tree and load the policies' JSON with a gatherer. + grd = grd_reader.Parse(grd_string_io, dir=tmp_dir_name) grd.RunGatherers(recursive=True) + # Remove the policies' JSON. os.unlink(json_file_path) return grd - def CompareResult(self, grd, env_lang, env_defs, out_type, out_lang, - expected_output): - '''Generates an output of the writer and compares it with the expected - result. Fails if they differ. + def GetOutput(self, grd, env_lang, env_defs, out_type, out_lang): + '''Generates an output of a writer. Args: grd: The root of the grit tree. env_lang: The environment language. env_defs: Environment definitions. out_type: Type of the output node for which output will be generated. + This selects the writer. out_lang: Language of the output node for which output will be generated. - expected_output: The expected output of the writer. + + Returns: + The string of the tamplete created by the writer. ''' grd.SetOutputContext(env_lang, env_defs) buf = StringIO.StringIO() build.RcBuilder.ProcessNode(grd, DummyOutput(out_type, out_lang), buf) - output = buf.getvalue() - self.assertEquals(output.strip(), expected_output.strip()) + return buf.getvalue() diff --git a/tools/grit/grit/test_suite_all.py b/tools/grit/grit/test_suite_all.py index 0a427a2..584eed3 100644 --- a/tools/grit/grit/test_suite_all.py +++ b/tools/grit/grit/test_suite_all.py @@ -50,6 +50,8 @@ class TestSuiteAll(unittest.TestSuite): from grit.format.policy_templates.writers import plist_writer_unittest from grit.format.policy_templates.writers \ import plist_strings_writer_unittest + from grit.format.policy_templates.writers \ + import adm_writer_unittest test_classes = [ base_unittest.NodeUnittest, @@ -82,6 +84,7 @@ class TestSuiteAll(unittest.TestSuite): policy_template_generator_unittest.PolicyTemplateGeneratorUnittest, plist_writer_unittest.PListWriterUnittest, plist_strings_writer_unittest.PListStringsWriterUnittest, + adm_writer_unittest.AdmWriterUnittest, # add test classes here... ] |