| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 'z': {'name': 'z', 'type': 'string'}, |
| 65 'a': {'name': 'a', 'type': 'string'}, |
| 66 'b': {'name': 'b', 'type': 'string'}, |
| 67 'c': {'name': 'c', 'type': 'string'}}, |
| 64 getType(self.idl_basics, 'MyType1')['properties']) | 68 getType(self.idl_basics, 'MyType1')['properties']) |
| 65 | 69 |
| 70 def testMemberOrdering(self): |
| 71 self.assertEquals( |
| 72 ['x', 'y', 'z', 'a', 'b', 'c'], |
| 73 getType(self.idl_basics, 'MyType1')['properties'].keys()) |
| 74 |
| 66 def testEnum(self): | 75 def testEnum(self): |
| 67 schema = self.idl_basics | 76 schema = self.idl_basics |
| 68 expected = {'enum': ['name1', 'name2'], 'description': 'Enum description', | 77 expected = {'enum': ['name1', 'name2'], 'description': 'Enum description', |
| 69 'type': 'string', 'id': 'EnumType'} | 78 'type': 'string', 'id': 'EnumType'} |
| 70 self.assertEquals(expected, getType(schema, expected['id'])) | 79 self.assertEquals(expected, getType(schema, expected['id'])) |
| 71 | 80 |
| 72 expected = [{'name':'type', '$ref':'EnumType'}, | 81 expected = [{'name':'type', '$ref':'EnumType'}, |
| 73 {'type':'function', 'name':'cb', | 82 {'type':'function', 'name':'cb', |
| 74 'parameters':[{'name':'type', '$ref':'EnumType'}]}] | 83 'parameters':[{'name':'type', '$ref':'EnumType'}]}] |
| 75 self.assertEquals(expected, getParams(schema, 'function13')) | 84 self.assertEquals(expected, getParams(schema, 'function13')) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 144 |
| 136 mytype = getType(schema, 'MyType') | 145 mytype = getType(schema, 'MyType') |
| 137 self.assertEquals('string', mytype['properties']['interface']['type']) | 146 self.assertEquals('string', mytype['properties']['interface']['type']) |
| 138 | 147 |
| 139 params = getParams(schema, 'static') | 148 params = getParams(schema, 'static') |
| 140 self.assertEquals('Foo', params[0]['$ref']) | 149 self.assertEquals('Foo', params[0]['$ref']) |
| 141 self.assertEquals('enum', params[1]['$ref']) | 150 self.assertEquals('enum', params[1]['$ref']) |
| 142 | 151 |
| 143 if __name__ == '__main__': | 152 if __name__ == '__main__': |
| 144 unittest.main() | 153 unittest.main() |
| OLD | NEW |