| Index: grit/tool/build_unittest.py
|
| diff --git a/grit/tool/build_unittest.py b/grit/tool/build_unittest.py
|
| index debe4d4c5312c043a29fd6cb8d2818354c26db8a..d94b30e78ca071931f2b1e26fd3c8eb6f6c2f1b9 100644
|
| --- a/grit/tool/build_unittest.py
|
| +++ b/grit/tool/build_unittest.py
|
| @@ -6,6 +6,7 @@
|
| '''Unit tests for the 'grit build' tool.
|
| '''
|
|
|
| +import codecs
|
| import os
|
| import sys
|
| import tempfile
|
| @@ -85,5 +86,98 @@ class BuildUnittest(unittest.TestCase):
|
| '-a', os.path.abspath(
|
| os.path.join(output_dir, 'resource.h'))]))
|
|
|
| + def _verifyWhitelistedOutput(self,
|
| + filename,
|
| + whitelisted_ids,
|
| + non_whitelisted_ids,
|
| + encoding='utf8'):
|
| + self.failUnless(os.path.exists(filename))
|
| + whitelisted_ids_found = []
|
| + non_whitelisted_ids_found = []
|
| + with codecs.open(filename, encoding=encoding) as f:
|
| + for line in f.readlines():
|
| + for whitelisted_id in whitelisted_ids:
|
| + if whitelisted_id in line:
|
| + whitelisted_ids_found.append(whitelisted_id)
|
| + for non_whitelisted_id in non_whitelisted_ids:
|
| + if non_whitelisted_id in line:
|
| + non_whitelisted_ids_found.append(non_whitelisted_id)
|
| + self.longMessage = True
|
| + self.assertEqual(whitelisted_ids,
|
| + whitelisted_ids_found,
|
| + '\nin file {}'.format(os.path.basename(filename)))
|
| + non_whitelisted_msg = ('Non-Whitelisted IDs {} found in {}'
|
| + .format(non_whitelisted_ids_found, os.path.basename(filename)))
|
| + self.assertFalse(non_whitelisted_ids_found, non_whitelisted_msg)
|
| +
|
| + def testWhitelistStrings(self):
|
| + output_dir = tempfile.mkdtemp()
|
| + builder = build.RcBuilder()
|
| + class DummyOpts(object):
|
| + def __init__(self):
|
| + self.input = util.PathFromRoot('grit/testdata/whitelist_strings.grd')
|
| + self.verbose = False
|
| + self.extra_verbose = False
|
| + whitelist_file = util.PathFromRoot('grit/testdata/whitelist.txt')
|
| + builder.Run(DummyOpts(), ['-o', output_dir,
|
| + '-w', whitelist_file])
|
| + header = os.path.join(output_dir, 'whitelist_test_resources.h')
|
| + rc = os.path.join(output_dir, 'en_whitelist_test_strings.rc')
|
| +
|
| + whitelisted_ids = ['IDS_MESSAGE_WHITELISTED']
|
| + non_whitelisted_ids = ['IDS_MESSAGE_NOT_WHITELISTED']
|
| + self._verifyWhitelistedOutput(
|
| + header,
|
| + whitelisted_ids,
|
| + non_whitelisted_ids,
|
| + )
|
| + self._verifyWhitelistedOutput(
|
| + rc,
|
| + whitelisted_ids,
|
| + non_whitelisted_ids,
|
| + encoding='utf16'
|
| + )
|
| +
|
| + def testWhitelistResources(self):
|
| + output_dir = tempfile.mkdtemp()
|
| + builder = build.RcBuilder()
|
| + class DummyOpts(object):
|
| + def __init__(self):
|
| + self.input = util.PathFromRoot('grit/testdata/whitelist_resources.grd')
|
| + self.verbose = False
|
| + self.extra_verbose = False
|
| + whitelist_file = util.PathFromRoot('grit/testdata/whitelist.txt')
|
| + builder.Run(DummyOpts(), ['-o', output_dir,
|
| + '-w', whitelist_file])
|
| + header = os.path.join(output_dir, 'whitelist_test_resources.h')
|
| + map_cc = os.path.join(output_dir, 'whitelist_test_resources_map.cc')
|
| + map_h = os.path.join(output_dir, 'whitelist_test_resources_map.h')
|
| + pak = os.path.join(output_dir, 'whitelist_test_resources.pak')
|
| +
|
| + # Ensure the resource map header and .pak files exist, but don't verify
|
| + # their content.
|
| + self.failUnless(os.path.exists(map_h))
|
| + self.failUnless(os.path.exists(pak))
|
| +
|
| + whitelisted_ids = [
|
| + 'IDR_STRUCTURE_WHITELISTED',
|
| + 'IDR_STRUCTURE_IN_TRUE_IF_WHITELISTED',
|
| + 'IDR_INCLUDE_WHITELISTED',
|
| + ]
|
| + non_whitelisted_ids = [
|
| + 'IDR_STRUCTURE_NOT_WHITELISTED',
|
| + 'IDR_STRUCTURE_IN_TRUE_IF_NOT_WHITELISTED',
|
| + 'IDR_STRUCTURE_IN_FALSE_IF_WHITELISTED',
|
| + 'IDR_STRUCTURE_IN_FALSE_IF_NOT_WHITELISTED',
|
| + 'IDR_INCLUDE_NOT_WHITELISTED',
|
| + ]
|
| + for output_file in (header, map_cc):
|
| + self._verifyWhitelistedOutput(
|
| + output_file,
|
| + whitelisted_ids,
|
| + non_whitelisted_ids,
|
| + )
|
| +
|
| +
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|