OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 grit.format.rc''' | 6 '''Unit tests for grit.format.rc''' |
7 | 7 |
8 import os | 8 import os |
9 import re | 9 import re |
10 import sys | 10 import sys |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 output = buf.getvalue().strip() | 80 output = buf.getvalue().strip() |
81 expected = u''' | 81 expected = u''' |
82 IDC_KLONKMENU MENU | 82 IDC_KLONKMENU MENU |
83 BEGIN | 83 BEGIN |
84 POPUP "&File" | 84 POPUP "&File" |
85 BEGIN | 85 BEGIN |
86 MENUITEM "E&xit", IDM_EXIT | 86 MENUITEM "E&xit", IDM_EXIT |
87 MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE | 87 MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE |
88 POPUP "gonk" | 88 POPUP "gonk" |
89 BEGIN | 89 BEGIN |
90 MENUITEM "Klonk && is ""good""", ID_GONK_KLONKIS | 90 MENUITEM "Klonk && is [good]", ID_GONK_KLONKIS |
91 END | 91 END |
92 END | 92 END |
93 POPUP "&Help" | 93 POPUP "&Help" |
94 BEGIN | 94 BEGIN |
95 MENUITEM "&About ...", IDM_ABOUT | 95 MENUITEM "&About ...", IDM_ABOUT |
96 END | 96 END |
97 END | 97 END |
98 | 98 |
99 IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 | 99 IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 |
100 STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU | 100 STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 self.failUnless(fr_file == os.path.join(output_dir, 'fr_simple.html')) | 239 self.failUnless(fr_file == os.path.join(output_dir, 'fr_simple.html')) |
240 | 240 |
241 fo = file(fr_file) | 241 fo = file(fr_file) |
242 contents = fo.read() | 242 contents = fo.read() |
243 fo.close() | 243 fo.close() |
244 | 244 |
245 self.failUnless(contents.find('<p>') != -1) # should contain the markup | 245 self.failUnless(contents.find('<p>') != -1) # should contain the markup |
246 self.failUnless(contents.find('Hello!') == -1) # should be translated | 246 self.failUnless(contents.find('Hello!') == -1) # should be translated |
247 | 247 |
248 | 248 |
| 249 def testSubstitutionHtml(self): |
| 250 input_file = util.PathFromRoot('grit/testdata/toolbar_about.html') |
| 251 root = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="U
TF-8"?> |
| 252 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> |
| 253 <release seq="1" allow_pseudo="False"> |
| 254 <structures fallback_to_english="True"> |
| 255 <structure type="tr_html" name="IDR_HTML" file="%s" expand_variables
="true"/> |
| 256 </structures> |
| 257 </release> |
| 258 </grit> |
| 259 ''' % input_file), util.PathFromRoot('.')) |
| 260 util.FixRootForUnittest(root, '.') |
| 261 root.SetOutputContext('ar', {}) |
| 262 # We must run the gatherers since we'll be wanting the translation of the |
| 263 # file. The file exists in the location pointed to. |
| 264 root.RunGatherers(recursive=True) |
| 265 |
| 266 output_dir = tempfile.gettempdir() |
| 267 import grit.node.structure |
| 268 structure = root.GetChildrenOfType(grit.node.structure.StructureNode)[0] |
| 269 ar_file = structure.FileForLanguage('ar', output_dir) |
| 270 self.failUnless(ar_file == os.path.join(output_dir, |
| 271 'ar_toolbar_about.html')) |
| 272 |
| 273 fo = file(ar_file) |
| 274 contents = fo.read() |
| 275 fo.close() |
| 276 |
| 277 self.failUnless(contents.find('dir="RTL"') != -1) |
| 278 |
| 279 |
249 def testFallbackToEnglish(self): | 280 def testFallbackToEnglish(self): |
250 root = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="U
TF-8"?> | 281 root = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="U
TF-8"?> |
251 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> | 282 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> |
252 <release seq="1" allow_pseudo="False"> | 283 <release seq="1" allow_pseudo="False"> |
253 <structures fallback_to_english="True"> | 284 <structures fallback_to_english="True"> |
254 <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\kl
onk.rc" encoding="utf-16" /> | 285 <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\kl
onk.rc" encoding="utf-16" /> |
255 </structures> | 286 </structures> |
256 </release> | 287 </release> |
257 </grit>'''), util.PathFromRoot('.')) | 288 </grit>'''), util.PathFromRoot('.')) |
258 util.FixRootForUnittest(root) | 289 util.FixRootForUnittest(root) |
| 290 root.SetOutputContext('en', {}) |
259 root.RunGatherers(recursive = True) | 291 root.RunGatherers(recursive = True) |
260 | 292 |
261 node = root.GetNodeById("IDD_ABOUTBOX") | 293 node = root.GetNodeById("IDD_ABOUTBOX") |
262 formatter = node.ItemFormatter('rc_all') | 294 formatter = node.ItemFormatter('rc_all') |
263 output = formatter.Format(node, 'bingobongo') | 295 output = formatter.Format(node, 'bingobongo') |
264 self.failUnless(output.strip() == '''IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 | 296 self.failUnless(output.strip() == '''IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 |
265 STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU | 297 STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU |
266 CAPTION "About" | 298 CAPTION "About" |
267 FONT 8, "System", 0, 0, 0x0 | 299 FONT 8, "System", 0, 0, 0x0 |
268 BEGIN | 300 BEGIN |
269 ICON IDI_KLONK,IDC_MYICON,14,9,20,20 | 301 ICON IDI_KLONK,IDC_MYICON,14,9,20,20 |
270 LTEXT "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8, | 302 LTEXT "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8, |
271 SS_NOPREFIX | 303 SS_NOPREFIX |
272 LTEXT "Copyright (C) 2005",IDC_STATIC,49,20,119,8 | 304 LTEXT "Copyright (C) 2005",IDC_STATIC,49,20,119,8 |
273 DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP | 305 DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP |
274 CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", | 306 CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", |
275 BS_AUTORADIOBUTTON,46,51,84,10 | 307 BS_AUTORADIOBUTTON,46,51,84,10 |
276 END''') | 308 END''') |
277 | 309 |
278 | 310 |
| 311 def testSubstitutionRc(self): |
| 312 root = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="U
TF-8"?> |
| 313 <grit latest_public_release="2" source_lang_id="en-US" current_release="3" |
| 314 base_dir="."> |
| 315 <outputs> |
| 316 <output lang="en" type="rc_all" filename="grit\\testdata\klonk_resourc
es.rc"/> |
| 317 </outputs> |
| 318 |
| 319 <release seq="1" allow_pseudo="False"> |
| 320 <structures> |
| 321 <structure type="menu" name="IDC_KLONKMENU" |
| 322 file="grit\\testdata\klonk.rc" encoding="utf-16" |
| 323 expand_variables="true" /> |
| 324 </structures> |
| 325 <messages> |
| 326 <message name="good" sub_variable="true"> |
| 327 excellent |
| 328 </message> |
| 329 </messages> |
| 330 </release> |
| 331 </grit> |
| 332 '''), util.PathFromRoot('.')) |
| 333 util.FixRootForUnittest(root) |
| 334 root.SetOutputContext('en', {}) |
| 335 root.RunGatherers(recursive=True) |
| 336 |
| 337 buf = StringIO.StringIO() |
| 338 build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf) |
| 339 output = buf.getvalue() |
| 340 self.failUnless(output.strip() == ''' |
| 341 // Copyright (c) Google Inc. 2012 |
| 342 // All rights reserved. |
| 343 // This file is automatically generated by GRIT. Do not edit. |
| 344 |
| 345 #include "resource.h" |
| 346 #include <winresrc.h> |
| 347 #ifdef IDC_STATIC |
| 348 #undef IDC_STATIC |
| 349 #endif |
| 350 #define IDC_STATIC (-1) |
| 351 |
| 352 LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL |
| 353 |
| 354 |
| 355 IDC_KLONKMENU MENU |
| 356 BEGIN |
| 357 POPUP "&File" |
| 358 BEGIN |
| 359 MENUITEM "E&xit", IDM_EXIT |
| 360 MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE |
| 361 POPUP "gonk" |
| 362 BEGIN |
| 363 MENUITEM "Klonk && is excellent", ID_GONK_KLONKIS |
| 364 END |
| 365 END |
| 366 POPUP "&Help" |
| 367 BEGIN |
| 368 MENUITEM "&About ...", IDM_ABOUT |
| 369 END |
| 370 END |
| 371 |
| 372 STRINGTABLE |
| 373 BEGIN |
| 374 good "excellent" |
| 375 END |
| 376 '''.strip()) |
| 377 |
| 378 |
279 if __name__ == '__main__': | 379 if __name__ == '__main__': |
280 unittest.main() | 380 unittest.main() |
OLD | NEW |