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 android_xml.py.""" | |
7 | |
8 import os | |
9 import StringIO | |
10 import sys | |
11 import unittest | |
12 | |
13 if __name__ == '__main__': | |
14 sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) | |
15 | |
16 from grit import util | |
17 from grit.format import android_xml | |
18 from grit.node import message | |
19 from grit.tool import build | |
20 | |
21 | |
22 class AndroidXmlUnittest(unittest.TestCase): | |
23 | |
24 def testMessages(self): | |
25 root = util.ParseGrdForUnittest(ur""" | |
26 <messages> | |
27 <message name="IDS_SIMPLE" desc="A vanilla string"> | |
28 Martha | |
29 </message> | |
30 <message name="IDS_ONE_LINE" desc="On one line">sat and wondered</mess
age> | |
31 <message name="IDS_QUOTES" desc="A string with quotation marks"> | |
32 out loud, "Why don't I build a flying car?" | |
33 </message> | |
34 <message name="IDS_MULTILINE" desc="A string split over several lines"
> | |
35 She gathered | |
36 wood, charcoal, and | |
37 a sledge hammer. | |
38 </message> | |
39 <message name="IDS_WHITESPACE" desc="A string with extra whitespace."> | |
40 ''' How old fashioned -- she thought. ''' | |
41 </message> | |
42 <message name="IDS_PLACEHOLDERS" desc="A string with placeholders"> | |
43 I'll buy a <ph name="WAVELENGTH">%d<ex>200</ex></ph> nm laser at <ph
name="STORE_NAME">%s<ex>the grocery store</ex></ph>. | |
44 </message> | |
45 <message name="IDS_PLURALS" desc="A string using the ICU plural format
"> | |
46 {NUM_THINGS, plural, | |
47 =1 {Maybe I'll get one laser.} | |
48 other {Maybe I'll get # lasers.}} | |
49 </message> | |
50 </messages> | |
51 """) | |
52 | |
53 buf = StringIO.StringIO() | |
54 build.RcBuilder.ProcessNode(root, DummyOutput('android', 'en'), buf) | |
55 output = buf.getvalue() | |
56 expected = ur""" | |
57 <?xml version="1.0" encoding="utf-8"?> | |
58 <resources xmlns:android="http://schemas.android.com/apk/res/android"> | |
59 <string name="simple">"Martha"</string> | |
60 <string name="one_line">"sat and wondered"</string> | |
61 <string name="quotes">"out loud, \"Why don\'t I build a flying car?\""</string> | |
62 <string name="multiline">"She gathered | |
63 wood, charcoal, and | |
64 a sledge hammer."</string> | |
65 <string name="whitespace">" How old fashioned -- she thought. "</string> | |
66 <string name="placeholders">"I\'ll buy a %d nm laser at %s."</string> | |
67 <plurals name="plurals"> | |
68 <item quantity="one">"Maybe I\'ll get one laser."</item> | |
69 <item quantity="other">"Maybe I\'ll get %d lasers."</item> | |
70 </plurals> | |
71 </resources> | |
72 """ | |
73 self.assertEqual(output.strip(), expected.strip()) | |
74 | |
75 def testTaggedOnly(self): | |
76 root = util.ParseGrdForUnittest(ur""" | |
77 <messages> | |
78 <message name="IDS_HELLO" desc="" formatter_data="android_java"> | |
79 Hello | |
80 </message> | |
81 <message name="IDS_WORLD" desc=""> | |
82 world | |
83 </message> | |
84 </messages> | |
85 """) | |
86 | |
87 msg_hello, msg_world = root.GetChildrenOfType(message.MessageNode) | |
88 self.assertTrue(android_xml.ShouldOutputNode(msg_hello, tagged_only=True)) | |
89 self.assertFalse(android_xml.ShouldOutputNode(msg_world, tagged_only=True)) | |
90 self.assertTrue(android_xml.ShouldOutputNode(msg_hello, tagged_only=False)) | |
91 self.assertTrue(android_xml.ShouldOutputNode(msg_world, tagged_only=False)) | |
92 | |
93 | |
94 class DummyOutput(object): | |
95 | |
96 def __init__(self, type, language): | |
97 self.type = type | |
98 self.language = language | |
99 | |
100 def GetType(self): | |
101 return self.type | |
102 | |
103 def GetLanguage(self): | |
104 return self.language | |
105 | |
106 def GetOutputFilename(self): | |
107 return 'hello.gif' | |
108 | |
109 if __name__ == '__main__': | |
110 unittest.main() | |
OLD | NEW |