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

Side by Side Diff: third_party/chrome/tools/idl_schema_test.py

Issue 12261015: Import chrome idl into third_party (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
« no previous file with comments | « third_party/chrome/tools/idl_schema.py ('k') | third_party/chrome/tools/json_parse.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 import idl_schema
7 import unittest
8
9 def getFunction(schema, name):
10 for item in schema['functions']:
11 if item['name'] == name:
12 return item
13 raise KeyError('Missing function %s' % name)
14
15 def getParams(schema, name):
16 function = getFunction(schema, name)
17 return function['parameters']
18
19 def getType(schema, id):
20 for item in schema['types']:
21 if item['id'] == id:
22 return item
23
24 class IdlSchemaTest(unittest.TestCase):
25 def setUp(self):
26 loaded = idl_schema.Load('test/idl_basics.idl')
27 self.assertEquals(1, len(loaded))
28 self.assertEquals('idl_basics', loaded[0]['namespace'])
29 self.idl_basics = loaded[0]
30
31 def testSimpleCallbacks(self):
32 schema = self.idl_basics
33 expected = [{'type':'function', 'name':'cb', 'parameters':[]}]
34 self.assertEquals(expected, getParams(schema, 'function4'))
35
36 expected = [{'type':'function', 'name':'cb',
37 'parameters':[{'name':'x', 'type':'integer'}]}]
38 self.assertEquals(expected, getParams(schema, 'function5'))
39
40 expected = [{'type':'function', 'name':'cb',
41 'parameters':[{'name':'arg', '$ref':'MyType1'}]}]
42 self.assertEquals(expected, getParams(schema, 'function6'))
43
44 def testCallbackWithArrayArgument(self):
45 schema = self.idl_basics
46 expected = [{'type':'function', 'name':'cb',
47 'parameters':[{'name':'arg', 'type':'array',
48 'items':{'$ref':'MyType2'}}]}]
49 self.assertEquals(expected, getParams(schema, 'function12'))
50
51
52 def testArrayOfCallbacks(self):
53 schema = idl_schema.Load('test/idl_callback_arrays.idl')[0]
54 expected = [{'type':'array', 'name':'callbacks',
55 'items':{'type':'function', 'name':'MyCallback',
56 'parameters':[{'type':'integer', 'name':'x'}]}}]
57 self.assertEquals(expected, getParams(schema, 'whatever'))
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 'z': {'name': 'z', 'type': 'string'},
65 'a': {'name': 'a', 'type': 'string'},
66 'b': {'name': 'b', 'type': 'string'},
67 'c': {'name': 'c', 'type': 'string'}},
68 getType(self.idl_basics, 'MyType1')['properties'])
69
70 def testMemberOrdering(self):
71 self.assertEquals(
72 ['x', 'y', 'z', 'a', 'b', 'c'],
73 getType(self.idl_basics, 'MyType1')['properties'].keys())
74
75 def testEnum(self):
76 schema = self.idl_basics
77 expected = {'enum': ['name1', 'name2'], 'description': 'Enum description',
78 'type': 'string', 'id': 'EnumType'}
79 self.assertEquals(expected, getType(schema, expected['id']))
80
81 expected = [{'name':'type', '$ref':'EnumType'},
82 {'type':'function', 'name':'cb',
83 'parameters':[{'name':'type', '$ref':'EnumType'}]}]
84 self.assertEquals(expected, getParams(schema, 'function13'))
85
86 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types',
87 'type': 'array'}]
88 self.assertEquals(expected, getParams(schema, 'function14'))
89
90 def testNoCompile(self):
91 schema = self.idl_basics
92 func = getFunction(schema, 'function15')
93 self.assertTrue(func is not None)
94 self.assertTrue(func['nocompile'])
95
96 def testInternalNamespace(self):
97 idl_basics = self.idl_basics
98 self.assertEquals('idl_basics', idl_basics['namespace'])
99 self.assertTrue(idl_basics['internal'])
100 self.assertFalse(idl_basics['nodoc'])
101
102 def testCallbackComment(self):
103 schema = self.idl_basics
104 self.assertEquals('A comment on a callback.',
105 getParams(schema, 'function16')[0]['description'])
106 self.assertEquals(
107 'A parameter.',
108 getParams(schema, 'function16')[0]['parameters'][0]['description'])
109 self.assertEquals(
110 'Just a parameter comment, with no comment on the callback.',
111 getParams(schema, 'function17')[0]['parameters'][0]['description'])
112 self.assertEquals(
113 'Override callback comment.',
114 getParams(schema, 'function18')[0]['description'])
115
116 def testFunctionComment(self):
117 schema = self.idl_basics
118 func = getFunction(schema, 'function3')
119 self.assertEquals(('This comment should appear in the documentation, '
120 'despite occupying multiple lines.'),
121 func['description'])
122 self.assertEquals(
123 [{'description': ('So should this comment about the argument. '
124 '<em>HTML</em> is fine too.'),
125 'name': 'arg',
126 '$ref': 'MyType1'}],
127 func['parameters'])
128 func = getFunction(schema, 'function4')
129 self.assertEquals(('This tests if "double-quotes" are escaped correctly.'
130 '<br/><br/> It also tests a comment with two newlines.'),
131 func['description'])
132
133 def testReservedWords(self):
134 schema = idl_schema.Load('test/idl_reserved_words.idl')[0]
135
136 foo_type = getType(schema, 'Foo')
137 self.assertEquals(['float', 'DOMString'], foo_type['enum'])
138
139 enum_type = getType(schema, 'enum')
140 self.assertEquals(['callback', 'namespace'], enum_type['enum'])
141
142 dictionary = getType(schema, 'dictionary');
143 self.assertEquals('integer', dictionary['properties']['long']['type'])
144
145 mytype = getType(schema, 'MyType')
146 self.assertEquals('string', mytype['properties']['interface']['type'])
147
148 params = getParams(schema, 'static')
149 self.assertEquals('Foo', params[0]['$ref'])
150 self.assertEquals('enum', params[1]['$ref'])
151
152 if __name__ == '__main__':
153 unittest.main()
OLDNEW
« no previous file with comments | « third_party/chrome/tools/idl_schema.py ('k') | third_party/chrome/tools/json_parse.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698