Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: tools/grit/grit/format/rc_header_unittest.py

Issue 2690263004: Add option to GRIT to provide a resource ordering input file. (Closed)
Patch Set: Reverse dict using 1-liner-ish. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/grit/grit/format/rc_header.py ('k') | tools/grit/grit/grd_reader.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/format/rc_header_unittest.py
diff --git a/tools/grit/grit/format/rc_header_unittest.py b/tools/grit/grit/format/rc_header_unittest.py
index 5d780e3e44a44c5f7f37c813b0f27f84a6152cb5..22c5f38f9e86a39c0111b90cc0fe98b713ac4982 100755
--- a/tools/grit/grit/format/rc_header_unittest.py
+++ b/tools/grit/grit/format/rc_header_unittest.py
@@ -10,6 +10,7 @@
import os
import sys
+import tempfile
if __name__ == '__main__':
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
@@ -27,6 +28,13 @@ class RcHeaderFormatterUnittest(unittest.TestCase):
output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines())
return ''.join(output).replace(' ', '')
+ def _MakeTempPredeterminedIdsFile(self, content):
+ tmp_dir = tempfile.gettempdir()
+ predetermined_ids_file = tmp_dir + "/predetermined_ids.txt"
+ with open(predetermined_ids_file, 'w') as f:
+ f.write(content)
+ return predetermined_ids_file
+
def testFormatter(self):
grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="2" source_lang_id="en" current_release="3" base_dir=".">
@@ -189,5 +197,53 @@ class RcHeaderFormatterUnittest(unittest.TestCase):
'#define IDS_BONGO _Pragma("IDS_BONGO") 10001\n'),
''.join(output))
+ def testPredeterminedIds(self):
+ predetermined_ids_file = self._MakeTempPredeterminedIdsFile(
+ 'IDS_BONGO 101\nID_LOGO 102\n')
+ grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+ <grit latest_public_release="2" source_lang_id="en" current_release="3" base_dir=".">
+ <release seq="3">
+ <includes first_id="300" comment="bingo">
+ <include type="gif" name="ID_LOGO" file="images/logo.gif" />
+ </includes>
+ <messages first_id="10000">
+ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user">
+ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today?
+ </message>
+ <message name="IDS_BONGO">
+ Bongo!
+ </message>
+ </messages>
+ </release>
+ </grit>'''), '.', predetermined_ids_file=predetermined_ids_file)
+ output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
+ grd.GetRcHeaderFormat())
+ self.assertEqual(('#define ID_LOGO 102\n'
+ '#define IDS_GREETING 10000\n'
+ '#define IDS_BONGO 101\n'), ''.join(output))
+
+ def testPredeterminedIdsOverlap(self):
+ predetermined_ids_file = self._MakeTempPredeterminedIdsFile(
+ 'ID_LOGO 10000\n')
+ grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+ <grit latest_public_release="2" source_lang_id="en" current_release="3" base_dir=".">
+ <release seq="3">
+ <includes first_id="300" comment="bingo">
+ <include type="gif" name="ID_LOGO" file="images/logo.gif" />
+ </includes>
+ <messages first_id="10000">
+ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user">
+ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today?
+ </message>
+ <message name="IDS_BONGO">
+ Bongo!
+ </message>
+ </messages>
+ </release>
+ </grit>'''), '.', predetermined_ids_file=predetermined_ids_file)
+ output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
+ grd.GetRcHeaderFormat())
+ self.assertRaises(exception.IdRangeOverlap, self.FormatAll, grd)
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « tools/grit/grit/format/rc_header.py ('k') | tools/grit/grit/grd_reader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698