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 import idl_schema | 6 import idl_schema |
7 import unittest | 7 import unittest |
8 | 8 |
9 def getFunction(schema, name): | 9 def getFunction(schema, name): |
10 for item in schema['functions']: | 10 for item in schema['functions']: |
(...skipping 20 matching lines...) Expand all Loading... |
31 def testSimpleCallbacks(self): | 31 def testSimpleCallbacks(self): |
32 schema = self.idl_basics | 32 schema = self.idl_basics |
33 expected = [{'type':'function', 'name':'cb', 'parameters':[]}] | 33 expected = [{'type':'function', 'name':'cb', 'parameters':[]}] |
34 self.assertEquals(expected, getParams(schema, 'function4')) | 34 self.assertEquals(expected, getParams(schema, 'function4')) |
35 | 35 |
36 expected = [{'type':'function', 'name':'cb', | 36 expected = [{'type':'function', 'name':'cb', |
37 'parameters':[{'name':'x', 'type':'integer'}]}] | 37 'parameters':[{'name':'x', 'type':'integer'}]}] |
38 self.assertEquals(expected, getParams(schema, 'function5')) | 38 self.assertEquals(expected, getParams(schema, 'function5')) |
39 | 39 |
40 expected = [{'type':'function', 'name':'cb', | 40 expected = [{'type':'function', 'name':'cb', |
41 'parameters':[{'name':'arg', '$ref':'idl_basics.MyType1'}]}] | 41 'parameters':[{'name':'arg', '$ref':'MyType1'}]}] |
42 self.assertEquals(expected, getParams(schema, 'function6')) | 42 self.assertEquals(expected, getParams(schema, 'function6')) |
43 | 43 |
44 def testCallbackWithArrayArgument(self): | 44 def testCallbackWithArrayArgument(self): |
45 schema = self.idl_basics | 45 schema = self.idl_basics |
46 expected = [{'type':'function', 'name':'cb', | 46 expected = [{'type':'function', 'name':'cb', |
47 'parameters':[{'name':'arg', 'type':'array', | 47 'parameters':[{'name':'arg', 'type':'array', |
48 'items':{'$ref':'idl_basics.MyType2'}}]}] | 48 'items':{'$ref':'MyType2'}}]}] |
49 self.assertEquals(expected, getParams(schema, 'function12')) | 49 self.assertEquals(expected, getParams(schema, 'function12')) |
50 | 50 |
51 | 51 |
52 def testArrayOfCallbacks(self): | 52 def testArrayOfCallbacks(self): |
53 schema = idl_schema.Load('test/idl_callback_arrays.idl')[0] | 53 schema = idl_schema.Load('test/idl_callback_arrays.idl')[0] |
54 expected = [{'type':'array', 'name':'callbacks', | 54 expected = [{'type':'array', 'name':'callbacks', |
55 'items':{'type':'function', 'name':'MyCallback', | 55 'items':{'type':'function', 'name':'MyCallback', |
56 'parameters':[{'type':'integer', 'name':'x'}]}}] | 56 'parameters':[{'type':'integer', 'name':'x'}]}}] |
57 self.assertEquals(expected, getParams(schema, 'whatever')) | 57 self.assertEquals(expected, getParams(schema, 'whatever')) |
58 | 58 |
59 def testLegalValues(self): | 59 def testLegalValues(self): |
60 self.assertEquals({ | 60 self.assertEquals({ |
61 'x': {'name': 'x', 'type': 'integer', 'enum': [1,2], | 61 'x': {'name': 'x', 'type': 'integer', 'enum': [1,2], |
62 'description': 'This comment tests "double-quotes".'}, | 62 'description': 'This comment tests "double-quotes".'}, |
63 'y': {'name': 'y', 'type': 'string'}}, | 63 'y': {'name': 'y', 'type': 'string'}}, |
64 getType(self.idl_basics, 'idl_basics.MyType1')['properties']) | 64 getType(self.idl_basics, 'MyType1')['properties']) |
65 | 65 |
66 def testEnum(self): | 66 def testEnum(self): |
67 schema = self.idl_basics | 67 schema = self.idl_basics |
68 expected = {'enum': ['name1', 'name2'], 'description': 'Enum description', | 68 expected = {'enum': ['name1', 'name2'], 'description': 'Enum description', |
69 'type': 'string', 'id': 'idl_basics.EnumType'} | 69 'type': 'string', 'id': 'EnumType'} |
70 self.assertEquals(expected, getType(schema, expected['id'])) | 70 self.assertEquals(expected, getType(schema, expected['id'])) |
71 | 71 |
72 expected = [{'name':'type', '$ref':'idl_basics.EnumType'}, | 72 expected = [{'name':'type', '$ref':'EnumType'}, |
73 {'type':'function', 'name':'cb', | 73 {'type':'function', 'name':'cb', |
74 'parameters':[{'name':'type', '$ref':'idl_basics.EnumType'}]}] | 74 'parameters':[{'name':'type', '$ref':'EnumType'}]}] |
75 self.assertEquals(expected, getParams(schema, 'function13')) | 75 self.assertEquals(expected, getParams(schema, 'function13')) |
76 | 76 |
77 expected = [{'items': {'$ref': 'idl_basics.EnumType'}, 'name': 'types', | 77 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types', |
78 'type': 'array'}] | 78 'type': 'array'}] |
79 self.assertEquals(expected, getParams(schema, 'function14')) | 79 self.assertEquals(expected, getParams(schema, 'function14')) |
80 | 80 |
81 def testNoCompile(self): | 81 def testNoCompile(self): |
82 schema = self.idl_basics | 82 schema = self.idl_basics |
83 func = getFunction(schema, 'function15') | 83 func = getFunction(schema, 'function15') |
84 self.assertTrue(func is not None) | 84 self.assertTrue(func is not None) |
85 self.assertTrue(func['nocompile']) | 85 self.assertTrue(func['nocompile']) |
86 | 86 |
87 def testInternalNamespace(self): | 87 def testInternalNamespace(self): |
(...skipping 19 matching lines...) Expand all Loading... |
107 def testFunctionComment(self): | 107 def testFunctionComment(self): |
108 schema = self.idl_basics | 108 schema = self.idl_basics |
109 func = getFunction(schema, 'function3') | 109 func = getFunction(schema, 'function3') |
110 self.assertEquals(('This comment should appear in the documentation, ' | 110 self.assertEquals(('This comment should appear in the documentation, ' |
111 'despite occupying multiple lines.'), | 111 'despite occupying multiple lines.'), |
112 func['description']) | 112 func['description']) |
113 self.assertEquals( | 113 self.assertEquals( |
114 [{'description': ('So should this comment about the argument. ' | 114 [{'description': ('So should this comment about the argument. ' |
115 '<em>HTML</em> is fine too.'), | 115 '<em>HTML</em> is fine too.'), |
116 'name': 'arg', | 116 'name': 'arg', |
117 '$ref': 'idl_basics.MyType1'}], | 117 '$ref': 'MyType1'}], |
118 func['parameters']) | 118 func['parameters']) |
119 func = getFunction(schema, 'function4') | 119 func = getFunction(schema, 'function4') |
120 self.assertEquals(('This tests if "double-quotes" are escaped correctly.' | 120 self.assertEquals(('This tests if "double-quotes" are escaped correctly.' |
121 '<br/><br/> It also tests a comment with two newlines.'), | 121 '<br/><br/> It also tests a comment with two newlines.'), |
122 func['description']) | 122 func['description']) |
123 | 123 |
124 def testReservedWords(self): | 124 def testReservedWords(self): |
125 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] | 125 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] |
126 | 126 |
127 foo_type = getType(schema, 'reserved_words.Foo') | 127 foo_type = getType(schema, 'Foo') |
128 self.assertEquals(['float', 'DOMString'], foo_type['enum']) | 128 self.assertEquals(['float', 'DOMString'], foo_type['enum']) |
129 | 129 |
130 enum_type = getType(schema, 'reserved_words.enum') | 130 enum_type = getType(schema, 'enum') |
131 self.assertEquals(['callback', 'namespace'], enum_type['enum']) | 131 self.assertEquals(['callback', 'namespace'], enum_type['enum']) |
132 | 132 |
133 dictionary = getType(schema, 'reserved_words.dictionary'); | 133 dictionary = getType(schema, 'dictionary'); |
134 self.assertEquals('integer', dictionary['properties']['long']['type']) | 134 self.assertEquals('integer', dictionary['properties']['long']['type']) |
135 | 135 |
136 mytype = getType(schema, 'reserved_words.MyType') | 136 mytype = getType(schema, 'MyType') |
137 self.assertEquals('string', mytype['properties']['interface']['type']) | 137 self.assertEquals('string', mytype['properties']['interface']['type']) |
138 | 138 |
139 params = getParams(schema, 'static') | 139 params = getParams(schema, 'static') |
140 self.assertEquals('reserved_words.Foo', params[0]['$ref']) | 140 self.assertEquals('Foo', params[0]['$ref']) |
141 self.assertEquals('reserved_words.enum', params[1]['$ref']) | 141 self.assertEquals('enum', params[1]['$ref']) |
142 | 142 |
143 if __name__ == '__main__': | 143 if __name__ == '__main__': |
144 unittest.main() | 144 unittest.main() |
OLD | NEW |