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 grit.tool.rc2grd''' |
| 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 re |
| 14 import StringIO |
| 15 import unittest |
| 16 |
| 17 from grit.node import base |
| 18 from grit.tool import rc2grd |
| 19 from grit.gather import rc |
| 20 from grit import grd_reader |
| 21 |
| 22 |
| 23 class Rc2GrdUnittest(unittest.TestCase): |
| 24 def testPlaceholderize(self): |
| 25 tool = rc2grd.Rc2Grd() |
| 26 original = "Hello %s, how are you? I'm $1 years old!" |
| 27 msg = tool.Placeholderize(original) |
| 28 self.failUnless(msg.GetPresentableContent() == "Hello TODO_0001, how are you
? I'm TODO_0002 years old!") |
| 29 self.failUnless(msg.GetRealContent() == original) |
| 30 |
| 31 def testHtmlPlaceholderize(self): |
| 32 tool = rc2grd.Rc2Grd() |
| 33 original = "Hello <b>[USERNAME]</b>, how are you? I'm [AGE] years old!" |
| 34 msg = tool.Placeholderize(original) |
| 35 self.failUnless(msg.GetPresentableContent() == |
| 36 "Hello BEGIN_BOLDX_USERNAME_XEND_BOLD, how are you? I'm X_AG
E_X years old!") |
| 37 self.failUnless(msg.GetRealContent() == original) |
| 38 |
| 39 def testMenuWithoutWhitespaceRegression(self): |
| 40 # There was a problem in the original regular expression for parsing out |
| 41 # menu sections, that would parse the following block of text as a single |
| 42 # menu instead of two. |
| 43 two_menus = ''' |
| 44 // Hyper context menus |
| 45 IDR_HYPERMENU_FOLDER MENU |
| 46 BEGIN |
| 47 POPUP "HyperFolder" |
| 48 BEGIN |
| 49 MENUITEM "Open Containing Folder", IDM_OPENFOLDER |
| 50 END |
| 51 END |
| 52 |
| 53 IDR_HYPERMENU_FILE MENU |
| 54 BEGIN |
| 55 POPUP "HyperFile" |
| 56 BEGIN |
| 57 MENUITEM "Open Folder", IDM_OPENFOLDER |
| 58 END |
| 59 END |
| 60 |
| 61 ''' |
| 62 self.failUnless(len(rc2grd._MENU.findall(two_menus)) == 2) |
| 63 |
| 64 def testRegressionScriptWithTranslateable(self): |
| 65 tool = rc2grd.Rc2Grd() |
| 66 |
| 67 # test rig |
| 68 class DummyNode(base.Node): |
| 69 def AddChild(self, item): |
| 70 self.node = item |
| 71 verbose = False |
| 72 extra_verbose = False |
| 73 tool.not_localizable_re = re.compile('') |
| 74 tool.o = DummyNode() |
| 75 |
| 76 rc_text = '''STRINGTABLE\nBEGIN\nID_BINGO "<SPAN id=hp style='BEHAVIOR: url(
#default#homepage)'></SPAN><script>if (!hp.isHomePage('[$~HOMEPAGE~$]')) {docume
nt.write(""<a href=\\""[$~SETHOMEPAGEURL~$]\\"" >Set As Homepage</a> - "");}</sc
ript>"\nEND\n''' |
| 77 tool.AddMessages(rc_text, tool.o) |
| 78 self.failUnless(tool.o.node.GetCdata().find('Set As Homepage') != -1) |
| 79 |
| 80 # TODO(joi) Improve the HTML parser to support translateables inside |
| 81 # <script> blocks? |
| 82 self.failUnless(tool.o.node.attrs['translateable'] == 'false') |
| 83 |
| 84 def testRoleModel(self): |
| 85 rc_text = ('STRINGTABLE\n' |
| 86 'BEGIN\n' |
| 87 ' // This should not show up\n' |
| 88 ' IDS_BINGO "Hello %s, how are you?"\n' |
| 89 ' // The first description\n' |
| 90 ' IDS_BONGO "Hello %s, my name is %s, and yours?"\n' |
| 91 ' IDS_PROGRAMS_SHUTDOWN_TEXT "Google Desktop Search needs t
o close the following programs:\\n\\n$1\\nThe installation will not proceed if y
ou choose to cancel."\n' |
| 92 'END\n') |
| 93 tool = rc2grd.Rc2Grd() |
| 94 tool.role_model = grd_reader.Parse(StringIO.StringIO( |
| 95 '''<?xml version="1.0" encoding="UTF-8"?> |
| 96 <grit latest_public_release="2" source_lang_id="en-US" current_release="3"
base_dir="."> |
| 97 <release seq="3"> |
| 98 <messages> |
| 99 <message name="IDS_BINGO"> |
| 100 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you? |
| 101 </message> |
| 102 <message name="IDS_BONGO" desc="The other description"> |
| 103 Hello <ph name="USERNAME">%s<ex>Jakob</ex></ph>, my name is <ph na
me="ADMINNAME">%s<ex>Joi</ex></ph>, and yours? |
| 104 </message> |
| 105 <message name="IDS_PROGRAMS_SHUTDOWN_TEXT" desc="LIST_OF_PROGRAMS is
replaced by a bulleted list of program names."> |
| 106 Google Desktop Search needs to close the following programs: |
| 107 |
| 108 <ph name="LIST_OF_PROGRAMS">$1<ex>Program 1, Program 2</ex></ph> |
| 109 The installation will not proceed if you choose to cancel. |
| 110 </message> |
| 111 </messages> |
| 112 </release> |
| 113 </grit>'''), dir='.') |
| 114 |
| 115 # test rig |
| 116 class DummyOpts(object): |
| 117 verbose = False |
| 118 extra_verbose = False |
| 119 tool.o = DummyOpts() |
| 120 result = tool.Process(rc_text, '.\resource.rc') |
| 121 self.failUnless( |
| 122 result.children[2].children[2].children[0].attrs['desc'] == '') |
| 123 self.failUnless( |
| 124 result.children[2].children[2].children[0].children[0].attrs['name'] == 'U
SERNAME') |
| 125 self.failUnless( |
| 126 result.children[2].children[2].children[1].attrs['desc'] == 'The other des
cription') |
| 127 self.failUnless( |
| 128 result.children[2].children[2].children[1].attrs['meaning'] == '') |
| 129 self.failUnless( |
| 130 result.children[2].children[2].children[1].children[0].attrs['name'] == 'U
SERNAME') |
| 131 self.failUnless( |
| 132 result.children[2].children[2].children[1].children[1].attrs['name'] == 'A
DMINNAME') |
| 133 self.failUnless( |
| 134 result.children[2].children[2].children[2].children[0].attrs['name'] == 'L
IST_OF_PROGRAMS') |
| 135 |
| 136 if __name__ == '__main__': |
| 137 unittest.main() |
| 138 |
OLD | NEW |