3 # Copyright (c) 2011 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """ Unit tests for the easy_xml.py file. """
9 import gyp.easy_xml as easy_xml
14 class TestSequenceFunctions(unittest.TestCase):
17 self.stderr = StringIO.StringIO()
19 def test_EasyXml_simple(self):
21 easy_xml.XmlToString(['test']),
22 '<?xml version="1.0" encoding="utf-8"?><test/>')
25 easy_xml.XmlToString(['test'], encoding='Windows-1252'),
26 '<?xml version="1.0" encoding="Windows-1252"?><test/>')
28 def test_EasyXml_simple_with_attributes(self):
30 easy_xml.XmlToString(['test2', {'a': 'value1', 'b': 'value2'}]),
31 '<?xml version="1.0" encoding="utf-8"?><test2 a="value1" b="value2"/>')
33 def test_EasyXml_escaping(self):
34 original = '<test>\'"\r&\nfoo'
35 converted = '<test>\'"
&
foo'
36 converted_apos = converted.replace("'", ''')
38 easy_xml.XmlToString(['test3', {'a': original}, original]),
39 '<?xml version="1.0" encoding="utf-8"?><test3 a="%s">%s</test3>' %
40 (converted, converted_apos))
42 def test_EasyXml_pretty(self):
54 '<?xml version="1.0" encoding="utf-8"?>\n'
65 def test_EasyXml_complex(self):
68 '<?xml version="1.0" encoding="utf-8"?>'
70 '<PropertyGroup Label="Globals">'
71 '<ProjectGuid>{D2250C20-3A94-4FB9-AF73-11BC5B73884B}</ProjectGuid>'
72 '<Keyword>Win32Proj</Keyword>'
73 '<RootNamespace>automated_ui_tests</RootNamespace>'
75 '<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props"/>'
77 'Condition="\'$(Configuration)|$(Platform)\'=='
78 '\'Debug|Win32\'" Label="Configuration">'
79 '<ConfigurationType>Application</ConfigurationType>'
80 '<CharacterSet>Unicode</CharacterSet>'
84 xml = easy_xml.XmlToString(
86 ['PropertyGroup', {'Label': 'Globals'},
87 ['ProjectGuid', '{D2250C20-3A94-4FB9-AF73-11BC5B73884B}'],
88 ['Keyword', 'Win32Proj'],
89 ['RootNamespace', 'automated_ui_tests']
91 ['Import', {'Project': '$(VCTargetsPath)\\Microsoft.Cpp.props'}],
93 {'Condition': "'$(Configuration)|$(Platform)'=='Debug|Win32'",
94 'Label': 'Configuration'},
95 ['ConfigurationType', 'Application'],
96 ['CharacterSet', 'Unicode']
99 self.assertEqual(xml, target)
102 if __name__ == '__main__':