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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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): |
| 60 self.assertEquals({ |
| 61 'x': {'name': 'x', 'type': 'integer', 'enum': [1,2], |
| 62 'description': 'This comment tests \\\"double-quotes\\\".'}, |
| 63 'y': {'name': 'y', 'type': 'string'}}, |
| 64 getType(self.idl_basics, 'idl_basics.MyType1')['properties']) |
| 65 |
59 def testEnum(self): | 66 def testEnum(self): |
60 schema = self.idl_basics | 67 schema = self.idl_basics |
61 expected = {'enum': ['name1', 'name2'], | 68 expected = {'enum': ['name1', 'name2'], 'description': 'Enum description', |
62 'type': 'string', 'id': 'idl_basics.EnumType'} | 69 'type': 'string', 'id': 'idl_basics.EnumType'} |
63 self.assertEquals(expected, getType(schema, 'idl_basics.EnumType')) | 70 self.assertEquals(expected, getType(schema, expected['id'])) |
64 | 71 |
65 expected = [{'name':'type', '$ref':'idl_basics.EnumType'}, | 72 expected = [{'name':'type', '$ref':'idl_basics.EnumType'}, |
66 {'type':'function', 'name':'Callback5', | 73 {'type':'function', 'name':'Callback5', |
67 'parameters':[{'name':'type', '$ref':'idl_basics.EnumType'}]}] | 74 'parameters':[{'name':'type', '$ref':'idl_basics.EnumType'}]}] |
68 self.assertEquals(expected, getParams(schema, 'function13')) | 75 self.assertEquals(expected, getParams(schema, 'function13')) |
69 | 76 |
70 expected = [{'items': {'$ref': 'idl_basics.EnumType'}, 'name': 'types', | 77 expected = [{'items': {'$ref': 'idl_basics.EnumType'}, 'name': 'types', |
71 'type': 'array'}] | 78 'type': 'array'}] |
72 self.assertEquals(expected, getParams(schema, 'function14')) | 79 self.assertEquals(expected, getParams(schema, 'function14')) |
73 | 80 |
(...skipping 15 matching lines...) Expand all Loading... |
89 'name': 'arg', | 96 'name': 'arg', |
90 '$ref': 'idl_basics.MyType1'}], | 97 '$ref': 'idl_basics.MyType1'}], |
91 func['parameters']) | 98 func['parameters']) |
92 func = getFunction(schema, 'function4') | 99 func = getFunction(schema, 'function4') |
93 self.assertEquals(('This tests if \\\"double-quotes\\\" are escaped ' | 100 self.assertEquals(('This tests if \\\"double-quotes\\\" are escaped ' |
94 'correctly.'), | 101 'correctly.'), |
95 func['description']) | 102 func['description']) |
96 | 103 |
97 if __name__ == '__main__': | 104 if __name__ == '__main__': |
98 unittest.main() | 105 unittest.main() |
OLD | NEW |