OLD | NEW |
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 misc.GritNode''' | 6 '''Unit tests for misc.GritNode''' |
7 | 7 |
8 | 8 |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 self.failUnless(hello_message not in active) | 94 self.failUnless(hello_message not in active) |
95 self.failUnless(french_message not in active) | 95 self.failUnless(french_message not in active) |
96 | 96 |
97 grd.SetOutputLanguage('en') | 97 grd.SetOutputLanguage('en') |
98 grd.SetDefines({'FORCE_FRENCH': '1', 'bingo': '1'}) | 98 grd.SetDefines({'FORCE_FRENCH': '1', 'bingo': '1'}) |
99 active = set(grd.ActiveDescendants()) | 99 active = set(grd.ActiveDescendants()) |
100 self.failUnless(bingo_message in active) | 100 self.failUnless(bingo_message in active) |
101 self.failUnless(hello_message not in active) | 101 self.failUnless(hello_message not in active) |
102 self.failUnless(french_message in active) | 102 self.failUnless(french_message in active) |
103 | 103 |
| 104 def testElsiness(self): |
| 105 grd = util.ParseGrdForUnittest(''' |
| 106 <messages> |
| 107 <if expr="True"> |
| 108 <then> <message name="IDS_YES1"></message> </then> |
| 109 <else> <message name="IDS_NO1"></message> </else> |
| 110 </if> |
| 111 <if expr="True"> |
| 112 <then> <message name="IDS_YES2"></message> </then> |
| 113 <else> </else> |
| 114 </if> |
| 115 <if expr="True"> |
| 116 <then> </then> |
| 117 <else> <message name="IDS_NO2"></message> </else> |
| 118 </if> |
| 119 <if expr="True"> |
| 120 <then> </then> |
| 121 <else> </else> |
| 122 </if> |
| 123 <if expr="False"> |
| 124 <then> <message name="IDS_NO3"></message> </then> |
| 125 <else> <message name="IDS_YES3"></message> </else> |
| 126 </if> |
| 127 <if expr="False"> |
| 128 <then> <message name="IDS_NO4"></message> </then> |
| 129 <else> </else> |
| 130 </if> |
| 131 <if expr="False"> |
| 132 <then> </then> |
| 133 <else> <message name="IDS_YES4"></message> </else> |
| 134 </if> |
| 135 <if expr="False"> |
| 136 <then> </then> |
| 137 <else> </else> |
| 138 </if> |
| 139 </messages>''') |
| 140 included = [msg.attrs['name'] for msg in grd.ActiveDescendants() |
| 141 if msg.name == 'message'] |
| 142 self.assertEqual(['IDS_YES1', 'IDS_YES2', 'IDS_YES3', 'IDS_YES4'], included) |
| 143 |
104 def testIffynessWithOutputNodes(self): | 144 def testIffynessWithOutputNodes(self): |
105 grd = grd_reader.Parse(StringIO.StringIO(''' | 145 grd = grd_reader.Parse(StringIO.StringIO(''' |
106 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> | 146 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> |
107 <outputs> | 147 <outputs> |
108 <output filename="uncond1.rc" type="rc_data" /> | 148 <output filename="uncond1.rc" type="rc_data" /> |
109 <if expr="lang == 'fr' or 'hello' in defs"> | 149 <if expr="lang == 'fr' or 'hello' in defs"> |
110 <output filename="only_fr.adm" type="adm" /> | 150 <output filename="only_fr.adm" type="adm" /> |
111 <output filename="only_fr.plist" type="plist" /> | 151 <output filename="only_fr.plist" type="plist" /> |
112 </if> | 152 </if> |
113 <if expr="lang == 'ru'"> | 153 <if expr="lang == 'ru'"> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 grd.SetOutputLanguage('en') | 198 grd.SetOutputLanguage('en') |
159 grd.SetDefines({'bingo': '1'}) | 199 grd.SetDefines({'bingo': '1'}) |
160 outputs = [output.GetFilename() for output in grd.GetOutputFiles()] | 200 outputs = [output.GetFilename() for output in grd.GetOutputFiles()] |
161 self.assertEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) | 201 self.assertEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) |
162 | 202 |
163 grd.SetOutputLanguage('fr') | 203 grd.SetOutputLanguage('fr') |
164 grd.SetDefines({'bingo': '1'}) | 204 grd.SetDefines({'bingo': '1'}) |
165 outputs = [output.GetFilename() for output in grd.GetOutputFiles()] | 205 outputs = [output.GetFilename() for output in grd.GetOutputFiles()] |
166 self.assertNotEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) | 206 self.assertNotEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) |
167 | 207 |
168 | |
169 class IfNodeChildrenUnittest(unittest.TestCase): | |
170 def testChildrenAccepted(self): | 208 def testChildrenAccepted(self): |
171 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0"?> | 209 grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0"?> |
172 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> | 210 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> |
173 <release seq="3"> | 211 <release seq="3"> |
174 <includes> | 212 <includes> |
175 <if expr="'bingo' in defs"> | 213 <if expr="'bingo' in defs"> |
176 <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> | 214 <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> |
177 </if> | 215 </if> |
178 <if expr="'bingo' in defs"> | 216 <if expr="'bingo' in defs"> |
179 <if expr="'hello' in defs"> | 217 <if expr="'hello' in defs"> |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 # a pseudo language should fail, but they do not fail and the test was | 395 # a pseudo language should fail, but they do not fail and the test was |
358 # broken and failed to catch it. Fix this. | 396 # broken and failed to catch it. Fix this. |
359 | 397 |
360 # Should not raise an exception since pseudo is allowed | 398 # Should not raise an exception since pseudo is allowed |
361 rc.FormatMessage(bingo, 'xyz-pseudo') | 399 rc.FormatMessage(bingo, 'xyz-pseudo') |
362 rc.FormatStructure(menu, 'xyz-pseudo', '.') | 400 rc.FormatStructure(menu, 'xyz-pseudo', '.') |
363 | 401 |
364 | 402 |
365 if __name__ == '__main__': | 403 if __name__ == '__main__': |
366 unittest.main() | 404 unittest.main() |
OLD | NEW |