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

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: Created 6 years, 9 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 def getFunction(schema, name): 9 def getFunction(schema, name):
10 for item in schema['functions']: 10 for item in schema['functions']:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 expected = [{'name':'type', '$ref':'EnumType'}, 91 expected = [{'name':'type', '$ref':'EnumType'},
92 {'type':'function', 'name':'cb', 92 {'type':'function', 'name':'cb',
93 'parameters':[{'name':'type', '$ref':'EnumType'}]}] 93 'parameters':[{'name':'type', '$ref':'EnumType'}]}]
94 self.assertEquals(expected, getParams(schema, 'function13')) 94 self.assertEquals(expected, getParams(schema, 'function13'))
95 95
96 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types', 96 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types',
97 'type': 'array'}] 97 'type': 'array'}]
98 self.assertEquals(expected, getParams(schema, 'function14')) 98 self.assertEquals(expected, getParams(schema, 'function14'))
99 99
100 def testScopedArguments(self):
101 schema = self.idl_basics
102 expected = [{'name':'value', '$ref':'other_namespace.SomeType'}]
103 self.assertEquals(expected, getParams(schema, 'function20'))
104
105 expected = [{'items': {'$ref': 'other_namespace.SomeType'},
106 'name': 'values',
107 'type': 'array'}]
108 self.assertEquals(expected, getParams(schema, 'function21'))
109
100 def testNoCompile(self): 110 def testNoCompile(self):
101 schema = self.idl_basics 111 schema = self.idl_basics
102 func = getFunction(schema, 'function15') 112 func = getFunction(schema, 'function15')
103 self.assertTrue(func is not None) 113 self.assertTrue(func is not None)
104 self.assertTrue(func['nocompile']) 114 self.assertTrue(func['nocompile'])
105 115
106 def testNoDocOnEnum(self): 116 def testNoDocOnEnum(self):
107 schema = self.idl_basics 117 schema = self.idl_basics
108 enum_with_nodoc = getType(schema, 'EnumTypeWithNoDoc') 118 enum_with_nodoc = getType(schema, 'EnumTypeWithNoDoc')
109 self.assertTrue(enum_with_nodoc is not None) 119 self.assertTrue(enum_with_nodoc is not None)
110 self.assertTrue(enum_with_nodoc['nodoc']) 120 self.assertTrue(enum_with_nodoc['nodoc'])
111 121
112 def testInternalNamespace(self): 122 def testInternalNamespace(self):
113 idl_basics = self.idl_basics 123 idl_basics = self.idl_basics
114 self.assertEquals('idl_basics', idl_basics['namespace']) 124 self.assertEquals('idl_basics', idl_basics['namespace'])
115 self.assertTrue(idl_basics['internal']) 125 self.assertTrue(idl_basics['internal'])
116 self.assertFalse(idl_basics['nodoc']) 126 self.assertFalse(idl_basics['nodoc'])
117 127
118 def testReturnTypes(self): 128 def testReturnTypes(self):
119 schema = self.idl_basics 129 schema = self.idl_basics
120 self.assertEquals({'name': 'function19', 'type': 'integer'}, 130 self.assertEquals({'name': 'function22', 'type': 'integer'},
121 getReturns(schema, 'function19')) 131 getReturns(schema, 'function22'))
122 self.assertEquals({'name': 'function20', '$ref': 'MyType1', 132 self.assertEquals({'name': 'function23', '$ref': 'MyType1',
123 'optional': True}, 133 'optional': True},
124 getReturns(schema, 'function20')) 134 getReturns(schema, 'function23'))
125 self.assertEquals({'name': 'function21', 'type': 'array', 135 self.assertEquals({'name': 'function24', 'type': 'array',
126 'items': {'$ref': 'MyType1'}}, 136 'items': {'$ref': 'MyType1'}},
127 getReturns(schema, 'function21')) 137 getReturns(schema, 'function24'))
128 self.assertEquals({'name': 'function22', '$ref': 'EnumType', 138 self.assertEquals({'name': 'function25', '$ref': 'EnumType',
129 'optional': True}, 139 'optional': True},
130 getReturns(schema, 'function22')) 140 getReturns(schema, 'function25'))
131 self.assertEquals({'name': 'function23', 'type': 'array', 141 self.assertEquals({'name': 'function26', 'type': 'array',
132 'items': {'$ref': 'EnumType'}}, 142 'items': {'$ref': 'EnumType'}},
133 getReturns(schema, 'function23')) 143 getReturns(schema, 'function26'))
144 self.assertEquals({'name': 'function27', '$ref': 'other_namespace.SomeType',
145 'optional': True},
146 getReturns(schema, 'function27'))
147 self.assertEquals({'name': 'function28', 'type': 'array',
148 'items': {'$ref': 'other_namespace.SomeType'}},
149 getReturns(schema, 'function28'))
134 150
135 def testChromeOSPlatformsNamespace(self): 151 def testChromeOSPlatformsNamespace(self):
136 schema = idl_schema.Load('test/idl_namespace_chromeos.idl')[0] 152 schema = idl_schema.Load('test/idl_namespace_chromeos.idl')[0]
137 self.assertEquals('idl_namespace_chromeos', schema['namespace']) 153 self.assertEquals('idl_namespace_chromeos', schema['namespace'])
138 expected = ['chromeos'] 154 expected = ['chromeos']
139 self.assertEquals(expected, schema['platforms']) 155 self.assertEquals(expected, schema['platforms'])
140 156
141 def testAllPlatformsNamespace(self): 157 def testAllPlatformsNamespace(self):
142 schema = idl_schema.Load('test/idl_namespace_all_platforms.idl')[0] 158 schema = idl_schema.Load('test/idl_namespace_all_platforms.idl')[0]
143 self.assertEquals('idl_namespace_all_platforms', schema['namespace']) 159 self.assertEquals('idl_namespace_all_platforms', schema['namespace'])
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 273
258 baz_type = getType(schema, 'BazType') 274 baz_type = getType(schema, 'BazType')
259 self.assertEquals(True, baz_type['properties']['x']['optional']) 275 self.assertEquals(True, baz_type['properties']['x']['optional'])
260 self.assertEquals('integer', baz_type['properties']['x']['type']) 276 self.assertEquals('integer', baz_type['properties']['x']['type'])
261 self.assertEquals(True, baz_type['properties']['foo']['optional']) 277 self.assertEquals(True, baz_type['properties']['foo']['optional'])
262 self.assertEquals('FooType', baz_type['properties']['foo']['$ref']) 278 self.assertEquals('FooType', baz_type['properties']['foo']['$ref'])
263 279
264 280
265 if __name__ == '__main__': 281 if __name__ == '__main__':
266 unittest.main() 282 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698