Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: tools/json_schema_compiler/idl_schema_test.py

Issue 197873009: Support scoped types in PPAPI IDL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed tests. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 from json_parse import OrderedDict 9 from json_parse import OrderedDict
10 10
(...skipping 23 matching lines...) Expand all
34 class IdlSchemaTest(unittest.TestCase): 34 class IdlSchemaTest(unittest.TestCase):
35 def setUp(self): 35 def setUp(self):
36 loaded = idl_schema.Load('test/idl_basics.idl') 36 loaded = idl_schema.Load('test/idl_basics.idl')
37 self.assertEquals(1, len(loaded)) 37 self.assertEquals(1, len(loaded))
38 self.assertEquals('idl_basics', loaded[0]['namespace']) 38 self.assertEquals('idl_basics', loaded[0]['namespace'])
39 self.idl_basics = loaded[0] 39 self.idl_basics = loaded[0]
40 self.maxDiff = None 40 self.maxDiff = None
41 41
42 def testSimpleCallbacks(self): 42 def testSimpleCallbacks(self):
43 schema = self.idl_basics 43 schema = self.idl_basics
44 expected = [{'type':'function', 'name':'cb', 'parameters':[]}] 44 expected = [{'type': 'function', 'name': 'cb', 'parameters':[]}]
45 self.assertEquals(expected, getParams(schema, 'function4')) 45 self.assertEquals(expected, getParams(schema, 'function4'))
46 46
47 expected = [{'type':'function', 'name':'cb', 47 expected = [{'type': 'function', 'name': 'cb',
48 'parameters':[{'name':'x', 'type':'integer'}]}] 48 'parameters':[{'name': 'x', 'type': 'integer'}]}]
49 self.assertEquals(expected, getParams(schema, 'function5')) 49 self.assertEquals(expected, getParams(schema, 'function5'))
50 50
51 expected = [{'type':'function', 'name':'cb', 51 expected = [{'type': 'function', 'name': 'cb',
52 'parameters':[{'name':'arg', '$ref':'MyType1'}]}] 52 'parameters':[{'name': 'arg', '$ref': 'MyType1'}]}]
53 self.assertEquals(expected, getParams(schema, 'function6')) 53 self.assertEquals(expected, getParams(schema, 'function6'))
54 54
55 def testCallbackWithArrayArgument(self): 55 def testCallbackWithArrayArgument(self):
56 schema = self.idl_basics 56 schema = self.idl_basics
57 expected = [{'type':'function', 'name':'cb', 57 expected = [{'type': 'function', 'name': 'cb',
58 'parameters':[{'name':'arg', 'type':'array', 58 'parameters':[{'name': 'arg', 'type': 'array',
59 'items':{'$ref':'MyType2'}}]}] 59 'items':{'$ref': 'MyType2'}}]}]
60 self.assertEquals(expected, getParams(schema, 'function12')) 60 self.assertEquals(expected, getParams(schema, 'function12'))
61 61
62 62
63 def testArrayOfCallbacks(self): 63 def testArrayOfCallbacks(self):
64 schema = idl_schema.Load('test/idl_function_types.idl')[0] 64 schema = idl_schema.Load('test/idl_function_types.idl')[0]
65 expected = [{'type':'array', 'name':'callbacks', 65 expected = [{'type': 'array', 'name': 'callbacks',
66 'items':{'type':'function', 'name':'MyCallback', 66 'items':{'type': 'function', 'name': 'MyCallback',
67 'parameters':[{'type':'integer', 'name':'x'}]}}] 67 'parameters':[{'type': 'integer', 'name': 'x'}]}}]
68 self.assertEquals(expected, getParams(schema, 'whatever')) 68 self.assertEquals(expected, getParams(schema, 'whatever'))
69 69
70 def testLegalValues(self): 70 def testLegalValues(self):
71 self.assertEquals({ 71 self.assertEquals({
72 'x': {'name': 'x', 'type': 'integer', 'enum': [1,2], 72 'x': {'name': 'x', 'type': 'integer', 'enum': [1,2],
73 'description': 'This comment tests "double-quotes".'}, 73 'description': 'This comment tests "double-quotes".'},
74 'y': {'name': 'y', 'type': 'string'}, 74 'y': {'name': 'y', 'type': 'string'},
75 'z': {'name': 'z', 'type': 'string'}, 75 'z': {'name': 'z', 'type': 'string'},
76 'a': {'name': 'a', 'type': 'string'}, 76 'a': {'name': 'a', 'type': 'string'},
77 'b': {'name': 'b', 'type': 'string'}, 77 'b': {'name': 'b', 'type': 'string'},
78 'c': {'name': 'c', 'type': 'string'}}, 78 'c': {'name': 'c', 'type': 'string'}},
79 getType(self.idl_basics, 'MyType1')['properties']) 79 getType(self.idl_basics, 'MyType1')['properties'])
80 80
81 def testMemberOrdering(self): 81 def testMemberOrdering(self):
82 self.assertEquals( 82 self.assertEquals(
83 ['x', 'y', 'z', 'a', 'b', 'c'], 83 ['x', 'y', 'z', 'a', 'b', 'c'],
84 getType(self.idl_basics, 'MyType1')['properties'].keys()) 84 getType(self.idl_basics, 'MyType1')['properties'].keys())
85 85
86 def testEnum(self): 86 def testEnum(self):
87 schema = self.idl_basics 87 schema = self.idl_basics
88 expected = {'enum': [{'name': 'name1', 'description': 'comment1'}, 88 expected = {'enum': [{'name': 'name1', 'description': 'comment1'},
89 {'name': 'name2'}], 89 {'name': 'name2'}],
90 'description': 'Enum description', 90 'description': 'Enum description',
91 'type': 'string', 'id': 'EnumType'} 91 'type': 'string', 'id': 'EnumType'}
92 self.assertEquals(expected, getType(schema, expected['id'])) 92 self.assertEquals(expected, getType(schema, expected['id']))
93 93
94 expected = [{'name':'type', '$ref':'EnumType'}, 94 expected = [{'name': 'type', '$ref': 'EnumType'},
95 {'type':'function', 'name':'cb', 95 {'type': 'function', 'name': 'cb',
96 'parameters':[{'name':'type', '$ref':'EnumType'}]}] 96 'parameters':[{'name': 'type', '$ref': 'EnumType'}]}]
97 self.assertEquals(expected, getParams(schema, 'function13')) 97 self.assertEquals(expected, getParams(schema, 'function13'))
98 98
99 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types', 99 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types',
100 'type': 'array'}] 100 'type': 'array'}]
101 self.assertEquals(expected, getParams(schema, 'function14')) 101 self.assertEquals(expected, getParams(schema, 'function14'))
102 102
103 def testScopedArguments(self):
104 schema = self.idl_basics
105 expected = [{'name': 'value', '$ref': 'idl_other_namespace.SomeType'}]
106 self.assertEquals(expected, getParams(schema, 'function20'))
107
108 expected = [{'items': {'$ref': 'idl_other_namespace.SomeType'},
109 'name': 'values',
110 'type': 'array'}]
111 self.assertEquals(expected, getParams(schema, 'function21'))
112
113 expected = [{'name': 'value',
114 '$ref': 'idl_other_namespace.sub_namespace.AnotherType'}]
115 self.assertEquals(expected, getParams(schema, 'function22'))
116
117 expected = [{'items': {'$ref': 'idl_other_namespace.sub_namespace.'
118 'AnotherType'},
119 'name': 'values',
120 'type': 'array'}]
121 self.assertEquals(expected, getParams(schema, 'function23'))
122
103 def testNoCompile(self): 123 def testNoCompile(self):
104 schema = self.idl_basics 124 schema = self.idl_basics
105 func = getFunction(schema, 'function15') 125 func = getFunction(schema, 'function15')
106 self.assertTrue(func is not None) 126 self.assertTrue(func is not None)
107 self.assertTrue(func['nocompile']) 127 self.assertTrue(func['nocompile'])
108 128
109 def testNoDocOnEnum(self): 129 def testNoDocOnEnum(self):
110 schema = self.idl_basics 130 schema = self.idl_basics
111 enum_with_nodoc = getType(schema, 'EnumTypeWithNoDoc') 131 enum_with_nodoc = getType(schema, 'EnumTypeWithNoDoc')
112 self.assertTrue(enum_with_nodoc is not None) 132 self.assertTrue(enum_with_nodoc is not None)
113 self.assertTrue(enum_with_nodoc['nodoc']) 133 self.assertTrue(enum_with_nodoc['nodoc'])
114 134
115 def testInternalNamespace(self): 135 def testInternalNamespace(self):
116 idl_basics = self.idl_basics 136 idl_basics = self.idl_basics
117 self.assertEquals('idl_basics', idl_basics['namespace']) 137 self.assertEquals('idl_basics', idl_basics['namespace'])
118 self.assertTrue(idl_basics['internal']) 138 self.assertTrue(idl_basics['internal'])
119 self.assertFalse(idl_basics['nodoc']) 139 self.assertFalse(idl_basics['nodoc'])
120 140
121 def testReturnTypes(self): 141 def testReturnTypes(self):
122 schema = self.idl_basics 142 schema = self.idl_basics
123 self.assertEquals({'name': 'function19', 'type': 'integer'}, 143 self.assertEquals({'name': 'function24', 'type': 'integer'},
124 getReturns(schema, 'function19')) 144 getReturns(schema, 'function24'))
125 self.assertEquals({'name': 'function20', '$ref': 'MyType1', 145 self.assertEquals({'name': 'function25', '$ref': 'MyType1',
126 'optional': True}, 146 'optional': True},
127 getReturns(schema, 'function20')) 147 getReturns(schema, 'function25'))
128 self.assertEquals({'name': 'function21', 'type': 'array', 148 self.assertEquals({'name': 'function26', 'type': 'array',
129 'items': {'$ref': 'MyType1'}}, 149 'items': {'$ref': 'MyType1'}},
130 getReturns(schema, 'function21')) 150 getReturns(schema, 'function26'))
131 self.assertEquals({'name': 'function22', '$ref': 'EnumType', 151 self.assertEquals({'name': 'function27', '$ref': 'EnumType',
132 'optional': True}, 152 'optional': True},
133 getReturns(schema, 'function22')) 153 getReturns(schema, 'function27'))
134 self.assertEquals({'name': 'function23', 'type': 'array', 154 self.assertEquals({'name': 'function28', 'type': 'array',
135 'items': {'$ref': 'EnumType'}}, 155 'items': {'$ref': 'EnumType'}},
136 getReturns(schema, 'function23')) 156 getReturns(schema, 'function28'))
157 self.assertEquals({'name': 'function29', '$ref':
158 'idl_other_namespace.SomeType',
159 'optional': True},
160 getReturns(schema, 'function29'))
161 self.assertEquals({'name': 'function30', 'type': 'array',
162 'items': {'$ref': 'idl_other_namespace.SomeType'}},
163 getReturns(schema, 'function30'))
137 164
138 def testChromeOSPlatformsNamespace(self): 165 def testChromeOSPlatformsNamespace(self):
139 schema = idl_schema.Load('test/idl_namespace_chromeos.idl')[0] 166 schema = idl_schema.Load('test/idl_namespace_chromeos.idl')[0]
140 self.assertEquals('idl_namespace_chromeos', schema['namespace']) 167 self.assertEquals('idl_namespace_chromeos', schema['namespace'])
141 expected = ['chromeos'] 168 expected = ['chromeos']
142 self.assertEquals(expected, schema['platforms']) 169 self.assertEquals(expected, schema['platforms'])
143 170
144 def testAllPlatformsNamespace(self): 171 def testAllPlatformsNamespace(self):
145 schema = idl_schema.Load('test/idl_namespace_all_platforms.idl')[0] 172 schema = idl_schema.Load('test/idl_namespace_all_platforms.idl')[0]
146 self.assertEquals('idl_namespace_all_platforms', schema['namespace']) 173 self.assertEquals('idl_namespace_all_platforms', schema['namespace'])
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 {'type': 'string'} 386 {'type': 'string'}
360 ] 387 ]
361 }] 388 }]
362 }] 389 }]
363 390
364 self.assertEquals(expected, badabish_params) 391 self.assertEquals(expected, badabish_params)
365 392
366 393
367 if __name__ == '__main__': 394 if __name__ == '__main__':
368 unittest.main() 395 unittest.main()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cpp_type_generator.py ('k') | tools/json_schema_compiler/schema_loader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698