Add WebRtc logging in IpcPacketSocket when the socket is blocked or unblocked.
[chromium-blink-merge.git] / tools / json_schema_compiler / ppapi_generator_test.py
blob4d396ffa91eb54376bbd38119bdf34d02e3919f1
1 #!/usr/bin/env python
2 # Copyright 2013 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.
6 import os
7 import unittest
9 from model import Model
10 import ppapi_generator
11 from schema_loader import SchemaLoader
14 def _LoadNamespace(filename):
15 filename = os.path.join(os.path.dirname(__file__), filename)
16 schema_loader = SchemaLoader(
17 os.path.dirname(os.path.relpath(os.path.normpath(filename),
18 os.path.dirname(filename))),
19 os.path.dirname(filename))
20 schema = os.path.normpath(filename)
21 api_def = schema_loader.LoadSchema(os.path.split(schema)[1])[0]
23 api_model = Model()
24 relpath = os.path.relpath(os.path.normpath(filename),
25 os.path.dirname(filename))
26 namespace = api_model.AddNamespace(api_def, relpath)
27 generator = ppapi_generator._PpapiGeneratorBase(namespace)
28 return namespace, generator
31 class PpapiGeneratorIdlStructsTest(unittest.TestCase):
32 def setUp(self):
33 self.namespace, self.generator = _LoadNamespace(
34 os.path.join('test', 'idl_pepper.idl'))
36 def testTypesOrder(self):
37 typename_to_index = dict(
38 (type_.name, i) for i, type_ in enumerate(self.generator._types))
39 self.assertLess(typename_to_index['MyType1'], typename_to_index['MyType2'])
40 self.assertLess(typename_to_index['MyType1'], typename_to_index['MyType3'])
41 self.assertLess(typename_to_index['MyType1'], typename_to_index['MyType4'])
42 self.assertLess(typename_to_index['MyType1'], typename_to_index['MyType5'])
43 self.assertLess(typename_to_index['MyType3'], typename_to_index['MyType5'])
44 self.assertLess(typename_to_index['MyType4'], typename_to_index['MyType5'])
45 self.assertLess(typename_to_index['MyType5'], typename_to_index['MyType6'])
47 def testNeedsArray(self):
48 self.assertFalse(self.generator.NeedsArray(self.namespace.types['MyType1']))
49 self.assertTrue(self.generator.NeedsArray(self.namespace.types['MyType2']))
50 self.assertTrue(self.generator.NeedsArray(self.namespace.types['MyType3']))
51 self.assertFalse(self.generator.NeedsArray(self.namespace.types['MyType4']))
52 self.assertFalse(self.generator.NeedsArray(self.namespace.types['MyType5']))
53 self.assertTrue(self.generator.NeedsArray(self.namespace.types['EnumType']))
55 def testNeedsOptional(self):
56 self.assertFalse(
57 self.generator.NeedsOptional(self.namespace.types['MyType1']))
58 self.assertFalse(
59 self.generator.NeedsOptional(self.namespace.types['MyType2']))
60 self.assertTrue(
61 self.generator.NeedsOptional(self.namespace.types['MyType3']))
62 self.assertTrue(
63 self.generator.NeedsOptional(self.namespace.types['MyType4']))
64 self.assertFalse(
65 self.generator.NeedsOptional(self.namespace.types['MyType5']))
66 self.assertTrue(
67 self.generator.NeedsOptional(self.namespace.types['EnumType']))
69 def testNeedsOptionalArray(self):
70 self.assertFalse(
71 self.generator.NeedsOptionalArray(self.namespace.types['MyType1']))
72 self.assertTrue(
73 self.generator.NeedsOptionalArray(self.namespace.types['MyType2']))
74 self.assertFalse(
75 self.generator.NeedsOptionalArray(self.namespace.types['MyType3']))
76 self.assertFalse(
77 self.generator.NeedsOptionalArray(self.namespace.types['MyType4']))
78 self.assertFalse(
79 self.generator.NeedsOptionalArray(self.namespace.types['MyType5']))
80 self.assertTrue(
81 self.generator.NeedsOptionalArray(self.namespace.types['EnumType']))
83 def testFormatParamTypePrimitive(self):
84 self.assertEqual('int32_t', self.generator.FormatParamType(
85 self.namespace.types['MyType'].properties['int_single']))
86 self.assertEqual('PP_Int32_Array', self.generator.FormatParamType(
87 self.namespace.types['MyType'].properties['int_array']))
88 self.assertEqual('PP_Optional_Int32', self.generator.FormatParamType(
89 self.namespace.types['MyType'].properties['optional_int']))
90 self.assertEqual('PP_Optional_Int32_Array', self.generator.FormatParamType(
91 self.namespace.types['MyType'].properties['optional_int_array']))
92 self.assertEqual('double_t', self.generator.FormatParamType(
93 self.namespace.types['MyType'].properties['double_single']))
94 self.assertEqual('PP_Double_Array', self.generator.FormatParamType(
95 self.namespace.types['MyType'].properties['double_array']))
96 self.assertEqual('PP_Optional_Double', self.generator.FormatParamType(
97 self.namespace.types['MyType'].properties['optional_double']))
98 self.assertEqual('PP_Optional_Double_Array', self.generator.FormatParamType(
99 self.namespace.types['MyType'].properties['optional_double_array']))
100 self.assertEqual('PP_Var', self.generator.FormatParamType(
101 self.namespace.types['MyType'].properties['string']))
102 self.assertEqual('PP_String_Array', self.generator.FormatParamType(
103 self.namespace.types['MyType'].properties['string_array']))
104 self.assertEqual('PP_Var', self.generator.FormatParamType(
105 self.namespace.types['MyType'].properties['optional_string']))
106 self.assertEqual('PP_Optional_String_Array', self.generator.FormatParamType(
107 self.namespace.types['MyType'].properties['optional_string_array']))
109 def testFormatParamTypeStruct(self):
110 self.assertEqual('PP_IdlPepper_MyType0', self.generator.FormatParamType(
111 self.namespace.types['MyType'].properties['struct_single']))
112 self.assertEqual(
113 'PP_IdlPepper_MyType0_Array', self.generator.FormatParamType(
114 self.namespace.types['MyType'].properties['struct_array']))
115 self.assertEqual(
116 'PP_IdlPepper_Optional_MyType0', self.generator.FormatParamType(
117 self.namespace.types['MyType'].properties['optional_struct']))
118 self.assertEqual(
119 'PP_IdlPepper_Optional_MyType0_Array', self.generator.FormatParamType(
120 self.namespace.types['MyType'].properties[
121 'optional_struct_array']))
123 def testFormatParamTypeEnum(self):
124 self.assertEqual('PP_IdlPepper_EnumType', self.generator.FormatParamType(
125 self.namespace.types['MyType'].properties['enum_single']))
126 self.assertEqual(
127 'PP_IdlPepper_EnumType_Array', self.generator.FormatParamType(
128 self.namespace.types['MyType'].properties['enum_array']))
129 self.assertEqual(
130 'PP_IdlPepper_Optional_EnumType', self.generator.FormatParamType(
131 self.namespace.types['MyType'].properties['optional_enum']))
132 self.assertEqual(
133 'PP_IdlPepper_Optional_EnumType_Array', self.generator.FormatParamType(
134 self.namespace.types['MyType'].properties['optional_enum_array']))
136 def testEnumValueName(self):
137 enum_type = self.namespace.types['EnumType']
138 self.assertEqual('PP_IDLPEPPER_ENUMTYPE_NAME1',
139 self.generator.EnumValueName(enum_type.enum_values[0],
140 enum_type))
141 self.assertEqual('PP_IDLPEPPER_ENUMTYPE_NAME2',
142 self.generator.EnumValueName(enum_type.enum_values[1],
143 enum_type))
144 enum_type = self.namespace.types['AnotherEnumType']
145 self.assertEqual('PP_IDLPEPPER_ANOTHERENUMTYPE_NAME1',
146 self.generator.EnumValueName(enum_type.enum_values[0],
147 enum_type))
148 self.assertEqual('PP_IDLPEPPER_ANOTHERENUMTYPE_NAME2',
149 self.generator.EnumValueName(enum_type.enum_values[1],
150 enum_type))
152 def testReturnTypes(self):
153 self.assertEqual('void', self.generator.GetFunctionReturnType(
154 self.namespace.functions['function1']))
155 self.assertEqual('void', self.generator.GetFunctionReturnType(
156 self.namespace.functions['function2']))
157 self.assertEqual('int32_t', self.generator.GetFunctionReturnType(
158 self.namespace.functions['function3']))
159 self.assertEqual('int32_t', self.generator.GetFunctionReturnType(
160 self.namespace.functions['function4']))
161 self.assertEqual('int32_t', self.generator.GetFunctionReturnType(
162 self.namespace.functions['function5']))
163 self.assertEqual('int32_t', self.generator.GetFunctionReturnType(
164 self.namespace.functions['function6']))
166 def testHasOutArray(self):
167 self.assertFalse(self.generator.HasArrayOuts(
168 self.namespace.functions['function1']))
169 self.assertFalse(self.generator.HasArrayOuts(
170 self.namespace.functions['function2']))
171 self.assertTrue(self.generator.HasArrayOuts(
172 self.namespace.functions['function3']))
173 self.assertFalse(self.generator.HasArrayOuts(
174 self.namespace.functions['function4']))
175 self.assertFalse(self.generator.HasArrayOuts(
176 self.namespace.functions['function5']))
177 self.assertTrue(self.generator.HasArrayOuts(
178 self.namespace.functions['function6']))
179 self.assertTrue(self.generator.HasArrayOuts(
180 self.namespace.functions['function7']))
181 self.assertTrue(self.generator.HasArrayOuts(
182 self.namespace.functions['function8']))
183 self.assertFalse(self.generator.HasArrayOuts(
184 self.namespace.functions['function9']))
185 self.assertTrue(self.generator.HasArrayOuts(
186 self.namespace.functions['function10']))
187 self.assertTrue(self.generator.HasArrayOuts(
188 self.namespace.functions['function11']))
189 self.assertFalse(self.generator.HasArrayOuts(
190 self.namespace.functions['function12']))
192 if __name__ == '__main__':
193 unittest.main()