OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 """Unittest for c_format.py. | |
7 """ | |
8 | |
9 import os | |
10 import sys | |
11 if __name__ == '__main__': | |
12 sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) | |
13 | |
14 import unittest | |
15 import StringIO | |
16 | |
17 from grit import util | |
18 from grit.tool import build | |
19 | |
20 | |
21 class CFormatUnittest(unittest.TestCase): | |
22 | |
23 def testMessages(self): | |
24 root = util.ParseGrdForUnittest(""" | |
25 <messages> | |
26 <message name="IDS_QUESTIONS">Do you want to play questions?</message> | |
27 <message name="IDS_QUOTES"> | |
28 "What's in a name, <ph name="NAME">%s<ex>Brandon</ex></ph>?" | |
29 </message> | |
30 <message name="IDS_LINE_BREAKS"> | |
31 Was that rhetoric? | |
32 No. | |
33 Statement. Two all. Game point. | |
34 </message> | |
35 <message name="IDS_NON_ASCII"> | |
36 \xc3\xb5\\xc2\\xa4\\\xc2\xa4\\\\xc3\\xb5\xe4\xa4\xa4 | |
37 </message> | |
38 </messages> | |
39 """) | |
40 | |
41 buf = StringIO.StringIO() | |
42 build.RcBuilder.ProcessNode(root, DummyOutput('c_format', 'en'), buf) | |
43 output = util.StripBlankLinesAndComments(buf.getvalue()) | |
44 self.assertEqual(u"""\ | |
45 #include "resource.h" | |
46 const char* GetString(int id) { | |
47 switch (id) { | |
48 case IDS_QUESTIONS: | |
49 return "Do you want to play questions?"; | |
50 case IDS_QUOTES: | |
51 return "\\"What\\'s in a name, %s?\\""; | |
52 case IDS_LINE_BREAKS: | |
53 return "Was that rhetoric?\\nNo.\\nStatement. Two all. Game point."; | |
54 case IDS_NON_ASCII: | |
55 return "\\303\\265\\xc2\\xa4\\\\302\\244\\\\xc3\\xb5\\344\\244\\244"; | |
56 default: | |
57 return 0; | |
58 } | |
59 }""", output) | |
60 | |
61 | |
62 class DummyOutput(object): | |
63 | |
64 def __init__(self, type, language): | |
65 self.type = type | |
66 self.language = language | |
67 | |
68 def GetType(self): | |
69 return self.type | |
70 | |
71 def GetLanguage(self): | |
72 return self.language | |
73 | |
74 def GetOutputFilename(self): | |
75 return 'hello.gif' | |
76 | |
77 if __name__ == '__main__': | |
78 unittest.main() | |
OLD | NEW |