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 | 6 |
7 """Unittests for writers.adml_writer.""" | 7 """Unittests for writers.adml_writer.""" |
8 | 8 |
9 | 9 |
10 import os | 10 import os |
11 import sys | 11 import sys |
12 import unittest | 12 import unittest |
13 if __name__ == '__main__': | 13 if __name__ == '__main__': |
14 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) | 14 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) |
15 | 15 |
16 | 16 |
17 from writers import adml_writer | 17 from writers import adml_writer |
18 from writers import xml_writer_base_unittest | 18 from writers import xml_writer_base_unittest |
19 | 19 |
20 | 20 |
21 class AdmlWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest): | 21 class AdmlWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest): |
22 | 22 |
23 def setUp(self): | 23 def setUp(self): |
24 config = { | 24 config = { |
25 'app_name': 'test', | 25 'app_name': 'test', |
26 'build': 'test', | 26 'build': 'test', |
27 'win_supported_os': 'SUPPORTED_TESTOS', | 27 'win_supported_os': 'SUPPORTED_TESTOS', |
28 'win_mandatory_category_path': ['test_category'], | 28 |
29 'win_recommended_category_path': ['test_recommended_category'], | 29 'win_config' : { |
30 'win_category_path_strings': { | 30 'win' : { |
31 'test_category': 'TestCategory', | 31 'mandatory_category_path': ['test_category'], |
32 'test_recommended_category': 'TestCategory - recommended' | 32 'recommended_category_path': ['test_category_recommended'], |
| 33 'category_path_strings': { |
| 34 'test_category': 'TestCategory', |
| 35 'test_category_recommended': 'TestCategory - recommended', |
| 36 }, |
| 37 }, |
| 38 'chrome_os' : { |
| 39 'mandatory_category_path': ['cros_test_category'], |
| 40 'recommended_category_path': ['cros_test_category_recommended'], |
| 41 'category_path_strings': { |
| 42 'cros_test_category': 'CrOSTestCategory', |
| 43 'cros_test_category_recommended': 'CrOSTestCategory - recommended', |
| 44 }, |
| 45 }, |
33 }, | 46 }, |
34 } | 47 } |
35 self.writer = adml_writer.GetWriter(config) | 48 self.writer = self._GetWriter(config) |
36 self.writer.messages = { | 49 self.writer.messages = { |
37 'win_supported_winxpsp2': { | 50 'win_supported_winxpsp2': { |
38 'text': 'Supported on Test OS or higher', | 51 'text': 'Supported on Test OS or higher', |
39 'desc': 'blah' | 52 'desc': 'blah' |
40 }, | 53 }, |
41 'doc_recommended': { | 54 'doc_recommended': { |
42 'text': 'Recommended', | 55 'text': 'Recommended', |
43 'desc': 'bleh' | 56 'desc': 'bleh' |
44 }, | 57 }, |
45 } | 58 } |
46 self.writer.Init() | 59 self.writer.Init() |
47 | 60 |
| 61 def _GetWriter(self, config): |
| 62 return adml_writer.GetWriter(config) |
| 63 |
| 64 def GetCategory(self): |
| 65 return "test_category"; |
| 66 |
| 67 def GetCategoryString(self): |
| 68 return "TestCategory"; |
| 69 |
48 def _InitWriterForAddingPolicyGroups(self, writer): | 70 def _InitWriterForAddingPolicyGroups(self, writer): |
49 '''Initialize the writer for adding policy groups. This method must be | 71 '''Initialize the writer for adding policy groups. This method must be |
50 called before the method "BeginPolicyGroup" can be called. It initializes | 72 called before the method "BeginPolicyGroup" can be called. It initializes |
51 attributes of the writer. | 73 attributes of the writer. |
52 ''' | 74 ''' |
53 writer.BeginTemplate() | 75 writer.BeginTemplate() |
54 | 76 |
55 def _InitWriterForAddingPolicies(self, writer, policy): | 77 def _InitWriterForAddingPolicies(self, writer, policy): |
56 '''Initialize the writer for adding policies. This method must be | 78 '''Initialize the writer for adding policies. This method must be |
57 called before the method "WritePolicy" can be called. It initializes | 79 called before the method "WritePolicy" can be called. It initializes |
(...skipping 14 matching lines...) Expand all Loading... |
72 self.writer._string_table_elem.removeChild(elem) | 94 self.writer._string_table_elem.removeChild(elem) |
73 | 95 |
74 def testEmpty(self): | 96 def testEmpty(self): |
75 self.writer.BeginTemplate() | 97 self.writer.BeginTemplate() |
76 self.writer.EndTemplate() | 98 self.writer.EndTemplate() |
77 output = self.writer.GetTemplateText() | 99 output = self.writer.GetTemplateText() |
78 expected_output = ( | 100 expected_output = ( |
79 '<?xml version="1.0" ?><policyDefinitionResources' | 101 '<?xml version="1.0" ?><policyDefinitionResources' |
80 ' revision="1.0" schemaVersion="1.0"><displayName/><description/>' | 102 ' revision="1.0" schemaVersion="1.0"><displayName/><description/>' |
81 '<resources><stringTable><string id="SUPPORTED_TESTOS">Supported on' | 103 '<resources><stringTable><string id="SUPPORTED_TESTOS">Supported on' |
82 ' Test OS or higher</string><string id="test_category">TestCategory' | 104 ' Test OS or higher</string>' |
83 '</string><string id="test_recommended_category">' | 105 '<string id="' + self.GetCategory() + '">' + \ |
84 'TestCategory - recommended</string></stringTable><presentationTable/>' | 106 self.GetCategoryString() + '</string>' |
| 107 '<string id="' + self.GetCategory() + '_recommended">' + \ |
| 108 self.GetCategoryString() + ' - recommended</string>' |
| 109 '</stringTable><presentationTable/>' |
85 '</resources></policyDefinitionResources>') | 110 '</resources></policyDefinitionResources>') |
86 self.AssertXMLEquals(output, expected_output) | 111 self.AssertXMLEquals(output, expected_output) |
87 | 112 |
88 def testVersionAnnotation(self): | 113 def testVersionAnnotation(self): |
89 self.writer.config['version'] = '39.0.0.0' | 114 self.writer.config['version'] = '39.0.0.0' |
90 self.writer.BeginTemplate() | 115 self.writer.BeginTemplate() |
91 self.writer.EndTemplate() | 116 self.writer.EndTemplate() |
92 output = self.writer.GetTemplateText() | 117 output = self.writer.GetTemplateText() |
93 expected_output = ( | 118 expected_output = ( |
94 '<?xml version="1.0" ?><policyDefinitionResources' | 119 '<?xml version="1.0" ?><policyDefinitionResources' |
95 ' revision="1.0" schemaVersion="1.0"><!--test version: 39.0.0.0-->' | 120 ' revision="1.0" schemaVersion="1.0"><!--test version: 39.0.0.0-->' |
96 '<displayName/><description/><resources><stringTable>' | 121 '<displayName/><description/><resources><stringTable>' |
97 '<string id="SUPPORTED_TESTOS">Supported on' | 122 '<string id="SUPPORTED_TESTOS">Supported on' |
98 ' Test OS or higher</string><string id="test_category">TestCategory' | 123 ' Test OS or higher</string>' |
99 '</string><string id="test_recommended_category">' | 124 '<string id="' + self.GetCategory() + '">' + \ |
100 'TestCategory - recommended</string></stringTable><presentationTable/>' | 125 self.GetCategoryString() + '</string>' |
| 126 '<string id="' + self.GetCategory() + '_recommended">' + \ |
| 127 self.GetCategoryString() + ' - recommended</string>' |
| 128 '</stringTable><presentationTable/>' |
101 '</resources></policyDefinitionResources>') | 129 '</resources></policyDefinitionResources>') |
102 self.AssertXMLEquals(output, expected_output) | 130 self.AssertXMLEquals(output, expected_output) |
103 | 131 |
104 def testPolicyGroup(self): | 132 def testPolicyGroup(self): |
105 empty_policy_group = { | 133 empty_policy_group = { |
106 'name': 'PolicyGroup', | 134 'name': 'PolicyGroup', |
107 'caption': 'Test Group Caption', | 135 'caption': 'Test Group Caption', |
108 'desc': 'This is the test description of the test policy group.', | 136 'desc': 'This is the test description of the test policy group.', |
109 'policies': [ | 137 'policies': [ |
110 {'name': 'PolicyStub2', | 138 {'name': 'PolicyStub2', |
111 'type': 'main'}, | 139 'type': 'main'}, |
112 {'name': 'PolicyStub1', | 140 {'name': 'PolicyStub1', |
113 'type': 'main'}, | 141 'type': 'main'}, |
114 ], | 142 ], |
115 } | 143 } |
116 self._InitWriterForAddingPolicyGroups(self.writer) | 144 self._InitWriterForAddingPolicyGroups(self.writer) |
117 self.writer.BeginPolicyGroup(empty_policy_group) | 145 self.writer.BeginPolicyGroup(empty_policy_group) |
118 self.writer.EndPolicyGroup | 146 self.writer.EndPolicyGroup |
119 # Assert generated string elements. | 147 # Assert generated string elements. |
120 output = self.GetXMLOfChildren(self.writer._string_table_elem) | 148 output = self.GetXMLOfChildren(self.writer._string_table_elem) |
121 expected_output = ( | 149 expected_output = ( |
122 '<string id="SUPPORTED_TESTOS">' | 150 '<string id="SUPPORTED_TESTOS">' |
123 'Supported on Test OS or higher</string>\n' | 151 'Supported on Test OS or higher</string>\n' |
124 '<string id="test_category">TestCategory</string>\n' | 152 '<string id="' + self.GetCategory() + '">' + \ |
125 '<string id="test_recommended_category">' | 153 self.GetCategoryString() + '</string>\n' |
126 'TestCategory - recommended</string>\n' | 154 '<string id="' + self.GetCategory() + '_recommended">' + \ |
| 155 self.GetCategoryString() + ' - recommended</string>\n' |
127 '<string id="PolicyGroup_group">Test Group Caption</string>') | 156 '<string id="PolicyGroup_group">Test Group Caption</string>') |
128 self.AssertXMLEquals(output, expected_output) | 157 self.AssertXMLEquals(output, expected_output) |
129 # Assert generated presentation elements. | 158 # Assert generated presentation elements. |
130 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) | 159 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) |
131 expected_output = '' | 160 expected_output = '' |
132 self.AssertXMLEquals(output, expected_output) | 161 self.AssertXMLEquals(output, expected_output) |
133 | 162 |
134 def testMainPolicy(self): | 163 def testMainPolicy(self): |
135 main_policy = { | 164 main_policy = { |
136 'name': 'DummyMainPolicy', | 165 'name': 'DummyMainPolicy', |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 ], | 255 ], |
227 } | 256 } |
228 self. _InitWriterForAddingPolicies(self.writer, enum_policy) | 257 self. _InitWriterForAddingPolicies(self.writer, enum_policy) |
229 self.writer.WritePolicy(enum_policy) | 258 self.writer.WritePolicy(enum_policy) |
230 # Assert generated string elements. | 259 # Assert generated string elements. |
231 output = self.GetXMLOfChildren(self.writer._string_table_elem) | 260 output = self.GetXMLOfChildren(self.writer._string_table_elem) |
232 expected_output = ( | 261 expected_output = ( |
233 '<string id="EnumPolicyStub">Enum policy caption</string>\n' | 262 '<string id="EnumPolicyStub">Enum policy caption</string>\n' |
234 '<string id="EnumPolicyStub_Explain">' | 263 '<string id="EnumPolicyStub_Explain">' |
235 'This is a test description.</string>\n' | 264 'This is a test description.</string>\n' |
236 '<string id="item 1">Caption Item 1</string>\n' | 265 '<string id="EnumPolicyStub_item 1">Caption Item 1</string>\n' |
237 '<string id="item 2">Caption Item 2</string>') | 266 '<string id="EnumPolicyStub_item 2">Caption Item 2</string>') |
238 self.AssertXMLEquals(output, expected_output) | 267 self.AssertXMLEquals(output, expected_output) |
239 # Assert generated presentation elements. | 268 # Assert generated presentation elements. |
240 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) | 269 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) |
241 expected_output = ( | 270 expected_output = ( |
242 '<presentation id="EnumPolicyStub">\n' | 271 '<presentation id="EnumPolicyStub">\n' |
243 ' <dropdownList refId="EnumPolicyStub">' | 272 ' <dropdownList refId="EnumPolicyStub">' |
244 'Enum policy label</dropdownList>\n' | 273 'Enum policy label</dropdownList>\n' |
245 '</presentation>') | 274 '</presentation>') |
246 self.AssertXMLEquals(output, expected_output) | 275 self.AssertXMLEquals(output, expected_output) |
247 | 276 |
(...skipping 18 matching lines...) Expand all Loading... |
266 ], | 295 ], |
267 } | 296 } |
268 self. _InitWriterForAddingPolicies(self.writer, enum_policy) | 297 self. _InitWriterForAddingPolicies(self.writer, enum_policy) |
269 self.writer.WritePolicy(enum_policy) | 298 self.writer.WritePolicy(enum_policy) |
270 # Assert generated string elements. | 299 # Assert generated string elements. |
271 output = self.GetXMLOfChildren(self.writer._string_table_elem) | 300 output = self.GetXMLOfChildren(self.writer._string_table_elem) |
272 expected_output = ( | 301 expected_output = ( |
273 '<string id="EnumPolicyStub">Enum policy caption</string>\n' | 302 '<string id="EnumPolicyStub">Enum policy caption</string>\n' |
274 '<string id="EnumPolicyStub_Explain">' | 303 '<string id="EnumPolicyStub_Explain">' |
275 'This is a test description.</string>\n' | 304 'This is a test description.</string>\n' |
276 '<string id="item 1">Caption Item 1</string>\n' | 305 '<string id="EnumPolicyStub_item 1">Caption Item 1</string>\n' |
277 '<string id="item 2">Caption Item 2</string>') | 306 '<string id="EnumPolicyStub_item 2">Caption Item 2</string>') |
278 self.AssertXMLEquals(output, expected_output) | 307 self.AssertXMLEquals(output, expected_output) |
279 # Assert generated presentation elements. | 308 # Assert generated presentation elements. |
280 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) | 309 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) |
281 expected_output = ( | 310 expected_output = ( |
282 '<presentation id="EnumPolicyStub">\n' | 311 '<presentation id="EnumPolicyStub">\n' |
283 ' <dropdownList refId="EnumPolicyStub">' | 312 ' <dropdownList refId="EnumPolicyStub">' |
284 'Enum policy label</dropdownList>\n' | 313 'Enum policy label</dropdownList>\n' |
285 '</presentation>') | 314 '</presentation>') |
286 self.AssertXMLEquals(output, expected_output) | 315 self.AssertXMLEquals(output, expected_output) |
287 | 316 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 420 |
392 def testStringEncodings(self): | 421 def testStringEncodings(self): |
393 enum_policy_a = { | 422 enum_policy_a = { |
394 'name': 'EnumPolicy.A', | 423 'name': 'EnumPolicy.A', |
395 'type': 'string-enum', | 424 'type': 'string-enum', |
396 'caption': 'Enum policy A caption', | 425 'caption': 'Enum policy A caption', |
397 'label': 'Enum policy A label', | 426 'label': 'Enum policy A label', |
398 'desc': 'This is a test description.', | 427 'desc': 'This is a test description.', |
399 'items': [ | 428 'items': [ |
400 { | 429 { |
401 'name': 'tls1.2', | 430 'name': 'same_item', |
402 'value': 'tls1.2', | 431 'value': '1', |
403 'caption': 'tls1.2', | 432 'caption': 'caption_a', |
404 } | 433 } |
405 ], | 434 ], |
406 } | 435 } |
407 enum_policy_b = { | 436 enum_policy_b = { |
408 'name': 'EnumPolicy.B', | 437 'name': 'EnumPolicy.B', |
409 'type': 'string-enum', | 438 'type': 'string-enum', |
410 'caption': 'Enum policy B caption', | 439 'caption': 'Enum policy B caption', |
411 'label': 'Enum policy B label', | 440 'label': 'Enum policy B label', |
412 'desc': 'This is a test description.', | 441 'desc': 'This is a test description.', |
413 'items': [ | 442 'items': [ |
414 { | 443 { |
415 'name': 'tls1.2', | 444 'name': 'same_item', |
416 'value': 'tls1.2', | 445 'value': '2', |
417 'caption': 'tls1.2', | 446 'caption': 'caption_b', |
418 } | 447 } |
419 ], | 448 ], |
420 } | 449 } |
421 self. _InitWriterForAddingPolicies(self.writer, enum_policy_a) | 450 self. _InitWriterForAddingPolicies(self.writer, enum_policy_a) |
422 self.writer.WritePolicy(enum_policy_a) | 451 self.writer.WritePolicy(enum_policy_a) |
423 self.writer.WritePolicy(enum_policy_b) | 452 self.writer.WritePolicy(enum_policy_b) |
424 # Assert generated string elements. | 453 # Assert generated string elements. |
425 output = self.GetXMLOfChildren(self.writer._string_table_elem) | 454 output = self.GetXMLOfChildren(self.writer._string_table_elem) |
426 expected_output = ( | 455 expected_output = ( |
427 '<string id="EnumPolicy_A">Enum policy A caption</string>\n' | 456 '<string id="EnumPolicy_A">Enum policy A caption</string>\n' |
428 '<string id="EnumPolicy_A_Explain">' | 457 '<string id="EnumPolicy_A_Explain">' |
429 'This is a test description.</string>\n' | 458 'This is a test description.</string>\n' |
430 '<string id="tls1_2">tls1.2</string>\n' | 459 '<string id="EnumPolicy_A_same_item">caption_a</string>\n' |
431 '<string id="EnumPolicy_B">Enum policy B caption</string>\n' | 460 '<string id="EnumPolicy_B">Enum policy B caption</string>\n' |
432 '<string id="EnumPolicy_B_Explain">' | 461 '<string id="EnumPolicy_B_Explain">' |
433 'This is a test description.</string>\n') | 462 'This is a test description.</string>\n' |
| 463 '<string id="EnumPolicy_B_same_item">caption_b</string>\n') |
434 self.AssertXMLEquals(output, expected_output) | 464 self.AssertXMLEquals(output, expected_output) |
435 # Assert generated presentation elements. | 465 # Assert generated presentation elements. |
436 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) | 466 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) |
437 expected_output = ( | 467 expected_output = ( |
438 '<presentation id="EnumPolicy.A">\n' | 468 '<presentation id="EnumPolicy.A">\n' |
439 ' <dropdownList refId="EnumPolicy.A">' | 469 ' <dropdownList refId="EnumPolicy.A">' |
440 'Enum policy A label</dropdownList>\n' | 470 'Enum policy A label</dropdownList>\n' |
441 '</presentation>\n' | 471 '</presentation>\n' |
442 '<presentation id="EnumPolicy.B">\n' | 472 '<presentation id="EnumPolicy.B">\n' |
443 ' <dropdownList refId="EnumPolicy.B">' | 473 ' <dropdownList refId="EnumPolicy.B">' |
444 'Enum policy B label</dropdownList>\n' | 474 'Enum policy B label</dropdownList>\n' |
445 '</presentation>') | 475 '</presentation>') |
446 self.AssertXMLEquals(output, expected_output) | 476 self.AssertXMLEquals(output, expected_output) |
447 | 477 |
448 | 478 |
449 if __name__ == '__main__': | 479 if __name__ == '__main__': |
450 unittest.main() | 480 unittest.main() |
OLD | NEW |