OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 '''Unit tests for the rc_header formatter''' |
| 7 |
| 8 import os |
| 9 import sys |
| 10 if __name__ == '__main__': |
| 11 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../..')) |
| 12 |
| 13 import StringIO |
| 14 import unittest |
| 15 |
| 16 from grit.format import rc_header |
| 17 from grit.node import message |
| 18 from grit.node import structure |
| 19 from grit.node import include |
| 20 from grit.node import misc |
| 21 from grit import grd_reader |
| 22 from grit import exception |
| 23 |
| 24 |
| 25 class RcHeaderFormatterUnittest(unittest.TestCase): |
| 26 def setUp(self): |
| 27 self.formatter = rc_header.Item() |
| 28 self.formatter.ids_ = {} # need to reset this between tests |
| 29 |
| 30 def FormatAll(self, grd): |
| 31 output = [] |
| 32 for node in grd: |
| 33 if isinstance(node, (message.MessageNode, structure.StructureNode, |
| 34 include.IncludeNode, misc.IdentifierNode)): |
| 35 output.append(self.formatter.Format(node)) |
| 36 output = ''.join(output) |
| 37 return output.replace(' ', '') |
| 38 |
| 39 def testFormatter(self): |
| 40 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT
F-8"?> |
| 41 <grit latest_public_release="2" source_lang_id="en" current_release="3" ba
se_dir="."> |
| 42 <release seq="3"> |
| 43 <includes first_id="300" comment="bingo"> |
| 44 <include type="gif" name="ID_LOGO" file="images/logo.gif" /> |
| 45 </includes> |
| 46 <messages first_id="10000"> |
| 47 <message name="IDS_GREETING" desc="Printed to greet the currently lo
gged in user"> |
| 48 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing t
oday? |
| 49 </message> |
| 50 <message name="IDS_BONGO"> |
| 51 Bongo! |
| 52 </message> |
| 53 </messages> |
| 54 <structures> |
| 55 <structure type="dialog" name="IDD_NARROW_DIALOG" file="rc_files/dia
logs.rc" /> |
| 56 <structure type="version" name="VS_VERSION_INFO" file="rc_files/vers
ion.rc" /> |
| 57 </structures> |
| 58 </release> |
| 59 </grit>'''), '.') |
| 60 output = self.FormatAll(grd) |
| 61 self.failUnless(output.count('IDS_GREETING10000')) |
| 62 self.failUnless(output.count('ID_LOGO300')) |
| 63 |
| 64 def testExplicitFirstIdOverlaps(self): |
| 65 # second first_id will overlap preexisting range |
| 66 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT
F-8"?> |
| 67 <grit latest_public_release="2" source_lang_id="en" current_release="3" ba
se_dir="."> |
| 68 <release seq="3"> |
| 69 <includes first_id="300" comment="bingo"> |
| 70 <include type="gif" name="ID_LOGO" file="images/logo.gif" /> |
| 71 <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> |
| 72 </includes> |
| 73 <messages first_id="301"> |
| 74 <message name="IDS_GREETING" desc="Printed to greet the currently lo
gged in user"> |
| 75 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing t
oday? |
| 76 </message> |
| 77 <message name="IDS_SMURFGEBURF">Frubegfrums</message> |
| 78 </messages> |
| 79 </release> |
| 80 </grit>'''), '.') |
| 81 self.assertRaises(exception.IdRangeOverlap, self.FormatAll, grd) |
| 82 |
| 83 def testImplicitOverlapsPreexisting(self): |
| 84 # second message in <messages> will overlap preexisting range |
| 85 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UT
F-8"?> |
| 86 <grit latest_public_release="2" source_lang_id="en" current_release="3" ba
se_dir="."> |
| 87 <release seq="3"> |
| 88 <includes first_id="301" comment="bingo"> |
| 89 <include type="gif" name="ID_LOGO" file="images/logo.gif" /> |
| 90 <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> |
| 91 </includes> |
| 92 <messages first_id="300"> |
| 93 <message name="IDS_GREETING" desc="Printed to greet the currently lo
gged in user"> |
| 94 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing t
oday? |
| 95 </message> |
| 96 <message name="IDS_SMURFGEBURF">Frubegfrums</message> |
| 97 </messages> |
| 98 </release> |
| 99 </grit>'''), '.') |
| 100 self.assertRaises(exception.IdRangeOverlap, self.FormatAll, grd) |
| 101 |
| 102 |
| 103 if __name__ == '__main__': |
| 104 unittest.main() |
OLD | NEW |