OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # pylint: disable=import-error,print-statement,relative-import,protected-access | 5 # pylint: disable=import-error,print-statement,relative-import,protected-access |
6 | 6 |
7 """Unit tests for code_generator_web_module.py.""" | 7 """Unit tests for code_generator_web_agent_api.py.""" |
8 | 8 |
9 import unittest | 9 import unittest |
10 | 10 |
11 from code_generator_web_module import InterfaceContextBuilder | 11 from code_generator_web_agent_api import InterfaceContextBuilder |
12 from code_generator_web_module import STRING_INCLUDE_PATH | 12 from code_generator_web_agent_api import STRING_INCLUDE_PATH |
13 from code_generator_web_module import TypeResolver | 13 from code_generator_web_agent_api import TypeResolver |
14 from idl_definitions import IdlAttribute | 14 from idl_definitions import IdlAttribute |
15 from idl_definitions import IdlOperation | 15 from idl_definitions import IdlOperation |
16 from idl_types import IdlType | 16 from idl_types import IdlType |
17 from idl_types import PRIMITIVE_TYPES | 17 from idl_types import PRIMITIVE_TYPES |
18 from idl_types import STRING_TYPES | 18 from idl_types import STRING_TYPES |
19 | 19 |
20 | 20 |
21 # TODO(dglazkov): Convert to use actual objects, not stubs. | 21 # TODO(dglazkov): Convert to use actual objects, not stubs. |
22 # See http://crbug.com/673214 for more details. | 22 # See http://crbug.com/673214 for more details. |
23 class IdlTestingHelper(object): | 23 class IdlTestingHelper(object): |
(...skipping 14 matching lines...) Expand all Loading... |
38 | 38 |
39 def make_stub_idl_type(self, base_type): | 39 def make_stub_idl_type(self, base_type): |
40 return IdlType(base_type) | 40 return IdlType(base_type) |
41 | 41 |
42 def make_stub_interfaces_info(self, classes_to_paths): | 42 def make_stub_interfaces_info(self, classes_to_paths): |
43 result = {} | 43 result = {} |
44 for class_name, path in classes_to_paths.iteritems(): | 44 for class_name, path in classes_to_paths.iteritems(): |
45 result[class_name] = {'include_path': path} | 45 result[class_name] = {'include_path': path} |
46 return result | 46 return result |
47 | 47 |
| 48 |
48 class TypeResolverTest(unittest.TestCase): | 49 class TypeResolverTest(unittest.TestCase): |
49 | 50 |
50 def test_includes_from_type_should_filter_primitive_types(self): | 51 def test_includes_from_type_should_filter_primitive_types(self): |
51 helper = IdlTestingHelper() | 52 helper = IdlTestingHelper() |
52 type_resolver = TypeResolver({}) | 53 type_resolver = TypeResolver({}) |
53 for primitive_type in PRIMITIVE_TYPES: | 54 for primitive_type in PRIMITIVE_TYPES: |
54 idl_type = helper.make_stub_idl_type(primitive_type) | 55 idl_type = helper.make_stub_idl_type(primitive_type) |
55 self.assertEqual( | 56 self.assertEqual( |
56 type_resolver._includes_from_type(idl_type), set()) | 57 type_resolver._includes_from_type(idl_type), set()) |
57 | 58 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 'header_includes': set(['path_to_foo']), | 111 'header_includes': set(['path_to_foo']), |
111 }, builder.build()) | 112 }, builder.build()) |
112 | 113 |
113 builder = InterfaceContextBuilder('test', TypeResolver({})) | 114 builder = InterfaceContextBuilder('test', TypeResolver({})) |
114 builder.set_inheritance(None) | 115 builder.set_inheritance(None) |
115 self.assertEqual({ | 116 self.assertEqual({ |
116 'code_generator': 'test', | 117 'code_generator': 'test', |
117 'header_includes': set(['platform/heap/Handle.h']), | 118 'header_includes': set(['platform/heap/Handle.h']), |
118 }, builder.build()) | 119 }, builder.build()) |
119 | 120 |
120 | |
121 def test_add_attribute(self): | 121 def test_add_attribute(self): |
122 helper = IdlTestingHelper() | 122 helper = IdlTestingHelper() |
123 builder = InterfaceContextBuilder( | 123 builder = InterfaceContextBuilder( |
124 'test', TypeResolver(helper.make_stub_interfaces_info({ | 124 'test', TypeResolver(helper.make_stub_interfaces_info({ |
125 'foo': 'path_to_foo', | 125 'foo': 'path_to_foo', |
126 'bar': 'path_to_bar' | 126 'bar': 'path_to_bar' |
127 }))) | 127 }))) |
128 | 128 |
129 attribute = helper.make_stub_idl_attribute('foo', 'bar') | 129 attribute = helper.make_stub_idl_attribute('foo', 'bar') |
130 builder.add_attribute(attribute) | 130 builder.add_attribute(attribute) |
(...skipping 11 matching lines...) Expand all Loading... |
142 'bar': 'path_to_bar' | 142 'bar': 'path_to_bar' |
143 }))) | 143 }))) |
144 | 144 |
145 operation = helper.make_stub_idl_operation('foo', 'bar') | 145 operation = helper.make_stub_idl_operation('foo', 'bar') |
146 builder.add_operation(operation) | 146 builder.add_operation(operation) |
147 self.assertEqual({ | 147 self.assertEqual({ |
148 'code_generator': 'test', | 148 'code_generator': 'test', |
149 'cpp_includes': set(['path_to_bar']), | 149 'cpp_includes': set(['path_to_bar']), |
150 'methods': [{'name': 'foo', 'return_type': 'bar'}], | 150 'methods': [{'name': 'foo', 'return_type': 'bar'}], |
151 }, builder.build()) | 151 }, builder.build()) |
OLD | NEW |