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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 rc_header formatter''' 6 '''Unit tests for the rc_header formatter'''
7 7
8 # GRD samples exceed the 80 character limit. 8 # GRD samples exceed the 80 character limit.
9 # pylint: disable-msg=C6310 9 # pylint: disable-msg=C6310
10 10
11 import os 11 import os
12 import sys 12 import sys
13 import tempfile
13 if __name__ == '__main__': 14 if __name__ == '__main__':
14 sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) 15 sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
15 16
16 import StringIO 17 import StringIO
17 import unittest 18 import unittest
18 19
19 from grit import exception 20 from grit import exception
20 from grit import grd_reader 21 from grit import grd_reader
21 from grit import util 22 from grit import util
22 from grit.format import rc_header 23 from grit.format import rc_header
23 24
24 25
25 class RcHeaderFormatterUnittest(unittest.TestCase): 26 class RcHeaderFormatterUnittest(unittest.TestCase):
26 def FormatAll(self, grd): 27 def FormatAll(self, grd):
27 output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines()) 28 output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines())
28 return ''.join(output).replace(' ', '') 29 return ''.join(output).replace(' ', '')
29 30
31 def _MakeTempPredeterminedIdsFile(self, content):
32 tmp_dir = tempfile.gettempdir()
33 predetermined_ids_file = tmp_dir + "/predetermined_ids.txt"
34 with open(predetermined_ids_file, 'w') as f:
35 f.write(content)
36 return predetermined_ids_file
37
30 def testFormatter(self): 38 def testFormatter(self):
31 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT F-8"?> 39 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT F-8"?>
32 <grit latest_public_release="2" source_lang_id="en" current_release="3" ba se_dir="."> 40 <grit latest_public_release="2" source_lang_id="en" current_release="3" ba se_dir=".">
33 <release seq="3"> 41 <release seq="3">
34 <includes first_id="300" comment="bingo"> 42 <includes first_id="300" comment="bingo">
35 <include type="gif" name="ID_LOGO" file="images/logo.gif" /> 43 <include type="gif" name="ID_LOGO" file="images/logo.gif" />
36 </includes> 44 </includes>
37 <messages first_id="10000"> 45 <messages first_id="10000">
38 <message name="IDS_GREETING" desc="Printed to greet the currently lo gged in user"> 46 <message name="IDS_GREETING" desc="Printed to greet the currently lo gged in user">
39 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing t oday? 47 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing t oday?
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 # Using a custom rc_header format string. 190 # Using a custom rc_header format string.
183 grd.AssignRcHeaderFormat( 191 grd.AssignRcHeaderFormat(
184 '#define {textual_id} _Pragma("{textual_id}") {numeric_id}') 192 '#define {textual_id} _Pragma("{textual_id}") {numeric_id}')
185 output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(), 193 output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
186 grd.GetRcHeaderFormat()) 194 grd.GetRcHeaderFormat())
187 self.assertEqual(('#define IDR_LOGO _Pragma("IDR_LOGO") 300\n' 195 self.assertEqual(('#define IDR_LOGO _Pragma("IDR_LOGO") 300\n'
188 '#define IDS_GREETING _Pragma("IDS_GREETING") 10000\n' 196 '#define IDS_GREETING _Pragma("IDS_GREETING") 10000\n'
189 '#define IDS_BONGO _Pragma("IDS_BONGO") 10001\n'), 197 '#define IDS_BONGO _Pragma("IDS_BONGO") 10001\n'),
190 ''.join(output)) 198 ''.join(output))
191 199
200 def testPredeterminedIds(self):
201 predetermined_ids_file = self._MakeTempPredeterminedIdsFile(
202 'IDS_BONGO 101\nID_LOGO 102\n')
203 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT F-8"?>
204 <grit latest_public_release="2" source_lang_id="en" current_release="3" ba se_dir=".">
205 <release seq="3">
206 <includes first_id="300" comment="bingo">
207 <include type="gif" name="ID_LOGO" file="images/logo.gif" />
208 </includes>
209 <messages first_id="10000">
210 <message name="IDS_GREETING" desc="Printed to greet the currently lo gged in user">
211 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing t oday?
212 </message>
213 <message name="IDS_BONGO">
214 Bongo!
215 </message>
216 </messages>
217 </release>
218 </grit>'''), '.', predetermined_ids_file=predetermined_ids_file)
219 output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
220 grd.GetRcHeaderFormat())
221 self.assertEqual(('#define ID_LOGO 102\n'
222 '#define IDS_GREETING 10000\n'
223 '#define IDS_BONGO 101\n'), ''.join(output))
224
225 def testPredeterminedIdsOverlap(self):
226 predetermined_ids_file = self._MakeTempPredeterminedIdsFile(
227 'ID_LOGO 10000\n')
228 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT F-8"?>
229 <grit latest_public_release="2" source_lang_id="en" current_release="3" ba se_dir=".">
230 <release seq="3">
231 <includes first_id="300" comment="bingo">
232 <include type="gif" name="ID_LOGO" file="images/logo.gif" />
233 </includes>
234 <messages first_id="10000">
235 <message name="IDS_GREETING" desc="Printed to greet the currently lo gged in user">
236 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing t oday?
237 </message>
238 <message name="IDS_BONGO">
239 Bongo!
240 </message>
241 </messages>
242 </release>
243 </grit>'''), '.', predetermined_ids_file=predetermined_ids_file)
244 output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
245 grd.GetRcHeaderFormat())
246 self.assertRaises(exception.IdRangeOverlap, self.FormatAll, grd)
247
192 if __name__ == '__main__': 248 if __name__ == '__main__':
193 unittest.main() 249 unittest.main()
OLDNEW
« 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