| Index: third_party/WebKit/Source/bindings/scripts/code_generator_web_agent_api_test.py
|
| diff --git a/third_party/WebKit/Source/bindings/scripts/code_generator_web_agent_api_test.py b/third_party/WebKit/Source/bindings/scripts/code_generator_web_agent_api_test.py
|
| index 9baed1816761a8dd00144c9db21b816c48fd3874..1520eb647d561b34a37ae0166ae558c2a7b303db 100644
|
| --- a/third_party/WebKit/Source/bindings/scripts/code_generator_web_agent_api_test.py
|
| +++ b/third_party/WebKit/Source/bindings/scripts/code_generator_web_agent_api_test.py
|
| @@ -9,11 +9,15 @@
|
| import unittest
|
|
|
| from code_generator_web_agent_api import InterfaceContextBuilder
|
| +from code_generator_web_agent_api import MethodOverloadSplitter
|
| from code_generator_web_agent_api import STRING_INCLUDE_PATH
|
| from code_generator_web_agent_api import TypeResolver
|
| +from idl_definitions import IdlArgument
|
| from idl_definitions import IdlAttribute
|
| from idl_definitions import IdlOperation
|
| from idl_types import IdlType
|
| +from idl_types import IdlNullableType
|
| +from idl_types import IdlUnionType
|
| from idl_types import PRIMITIVE_TYPES
|
| from idl_types import STRING_TYPES
|
|
|
| @@ -24,6 +28,13 @@ class IdlTestingHelper(object):
|
| """A collection of stub makers and helper utils to make testing code
|
| generation easy."""
|
|
|
| + def make_stub_idl_argument(self, name, idl_type, is_optional=False):
|
| + idl_argument = IdlArgument()
|
| + idl_argument.name = name
|
| + idl_argument.idl_type = idl_type
|
| + idl_argument.is_optional = is_optional
|
| + return idl_argument
|
| +
|
| def make_stub_idl_attribute(self, name, return_type):
|
| idl_attribute_stub = IdlAttribute()
|
| idl_attribute_stub.name = name
|
| @@ -73,6 +84,121 @@ class TypeResolverTest(unittest.TestCase):
|
| set([STRING_INCLUDE_PATH]))
|
|
|
|
|
| +class MethodOverloadSplitterTest(unittest.TestCase):
|
| +
|
| + def test_enumerate_argument_types(self):
|
| + splitter = MethodOverloadSplitter(IdlOperation())
|
| + nullable_and_primitive = IdlArgument()
|
| + nullable_and_primitive.idl_type = IdlNullableType(IdlType('double'))
|
| + with self.assertRaises(ValueError):
|
| + splitter._enumerate_argument_types(nullable_and_primitive)
|
| +
|
| + argument = IdlArgument()
|
| + foo_type = IdlType('Foo')
|
| + bar_type = IdlType('Bar')
|
| +
|
| + argument.idl_type = foo_type
|
| + self.assertEqual(
|
| + splitter._enumerate_argument_types(argument), [foo_type])
|
| +
|
| + argument.is_optional = True
|
| + self.assertEqual(
|
| + splitter._enumerate_argument_types(argument), [None, foo_type])
|
| +
|
| + argument.is_optional = False
|
| + argument.idl_type = IdlUnionType([foo_type, bar_type])
|
| + self.assertEqual(
|
| + splitter._enumerate_argument_types(argument), [foo_type, bar_type])
|
| +
|
| + argument.is_optional = True
|
| + self.assertEqual(
|
| + splitter._enumerate_argument_types(argument),
|
| + [None, foo_type, bar_type])
|
| +
|
| + def test_update_argument_lists(self):
|
| + splitter = MethodOverloadSplitter(IdlOperation())
|
| + foo_type = IdlType('Foo')
|
| + bar_type = IdlType('Bar')
|
| + baz_type = IdlType('Baz')
|
| + qux_type = IdlType('Qux')
|
| +
|
| + result = splitter._update_argument_lists([[]], [foo_type])
|
| + self.assertEqual(result, [[foo_type]])
|
| +
|
| + result = splitter._update_argument_lists([[]], [foo_type, bar_type])
|
| + self.assertEqual(result, [[foo_type], [bar_type]])
|
| +
|
| + existing_list = [[foo_type]]
|
| + result = splitter._update_argument_lists(existing_list, [bar_type])
|
| + self.assertEqual(result, [[foo_type, bar_type]])
|
| +
|
| + existing_list = [[foo_type]]
|
| + result = splitter._update_argument_lists(existing_list,
|
| + [None, bar_type])
|
| + self.assertEqual(result, [[foo_type], [foo_type, bar_type]])
|
| +
|
| + existing_list = [[foo_type]]
|
| + result = splitter._update_argument_lists(existing_list,
|
| + [bar_type, baz_type])
|
| + self.assertEqual(result, [[foo_type, bar_type], [foo_type, baz_type]])
|
| +
|
| + existing_list = [[foo_type], [qux_type]]
|
| + result = splitter._update_argument_lists(existing_list,
|
| + [bar_type, baz_type])
|
| + self.assertEqual(result, [
|
| + [foo_type, bar_type],
|
| + [foo_type, baz_type],
|
| + [qux_type, bar_type],
|
| + [qux_type, baz_type],
|
| + ])
|
| +
|
| + existing_list = [[foo_type], [qux_type]]
|
| + result = splitter._update_argument_lists(existing_list,
|
| + [None, bar_type, baz_type])
|
| + self.assertEqual(result, [
|
| + [foo_type],
|
| + [foo_type, bar_type],
|
| + [foo_type, baz_type],
|
| + [qux_type],
|
| + [qux_type, bar_type],
|
| + [qux_type, baz_type],
|
| + ])
|
| +
|
| + existing_list = [[foo_type, qux_type]]
|
| + result = splitter._update_argument_lists(existing_list,
|
| + [bar_type, baz_type])
|
| + self.assertEqual(result, [
|
| + [foo_type, qux_type, bar_type],
|
| + [foo_type, qux_type, baz_type],
|
| + ])
|
| +
|
| + def test_split_into_overloads(self):
|
| + helper = IdlTestingHelper()
|
| + type_double = IdlType('double')
|
| + type_foo = IdlType('foo')
|
| + type_double_or_foo = IdlUnionType([type_double, type_foo])
|
| + idl_operation = IdlOperation()
|
| +
|
| + idl_operation.arguments = []
|
| + splitter = MethodOverloadSplitter(idl_operation)
|
| + result = splitter.split_into_overloads()
|
| + self.assertEqual(result, [[]])
|
| +
|
| + idl_operation.arguments = [
|
| + helper.make_stub_idl_argument(None, type_double, True)
|
| + ]
|
| + splitter = MethodOverloadSplitter(idl_operation)
|
| + result = splitter.split_into_overloads()
|
| + self.assertEqual(result, [[], [type_double]])
|
| +
|
| + idl_operation.arguments = [
|
| + helper.make_stub_idl_argument(None, type_double_or_foo)
|
| + ]
|
| + splitter = MethodOverloadSplitter(idl_operation)
|
| + result = splitter.split_into_overloads()
|
| + self.assertEqual(result, [[type_double], [type_foo]])
|
| +
|
| +
|
| class InterfaceContextBuilderTest(unittest.TestCase):
|
|
|
| def test_empty(self):
|
| @@ -131,7 +257,7 @@ class InterfaceContextBuilderTest(unittest.TestCase):
|
| self.assertEqual({
|
| 'code_generator': 'test',
|
| 'cpp_includes': set(['path_to_bar']),
|
| - 'attributes': [{'name': 'foo', 'return_type': 'bar'}],
|
| + 'attributes': [{'name': 'foo', 'type': 'bar'}],
|
| }, builder.build())
|
|
|
| def test_add_method(self):
|
| @@ -139,7 +265,8 @@ class InterfaceContextBuilderTest(unittest.TestCase):
|
| builder = InterfaceContextBuilder(
|
| 'test', TypeResolver(helper.make_stub_interfaces_info({
|
| 'foo': 'path_to_foo',
|
| - 'bar': 'path_to_bar'
|
| + 'bar': 'path_to_bar',
|
| + 'garply': 'path_to_garply',
|
| })))
|
|
|
| operation = helper.make_stub_idl_operation('foo', 'bar')
|
| @@ -147,5 +274,33 @@ class InterfaceContextBuilderTest(unittest.TestCase):
|
| self.assertEqual({
|
| 'code_generator': 'test',
|
| 'cpp_includes': set(['path_to_bar']),
|
| - 'methods': [{'name': 'foo', 'return_type': 'bar'}],
|
| + 'methods': [{
|
| + 'arguments': [],
|
| + 'name': 'Foo',
|
| + 'type': 'bar'
|
| + }],
|
| + }, builder.build())
|
| +
|
| + operation = helper.make_stub_idl_operation('quux', 'garply')
|
| + operation.arguments = [
|
| + helper.make_stub_idl_argument('barBaz', IdlType('qux'))
|
| + ]
|
| + builder.add_operation(operation)
|
| + self.assertEqual({
|
| + 'code_generator': 'test',
|
| + 'cpp_includes': set(['path_to_bar', 'path_to_garply']),
|
| + 'methods': [
|
| + {
|
| + 'arguments': [],
|
| + 'name': 'Foo',
|
| + 'type': 'bar'
|
| + },
|
| + {
|
| + 'arguments': [
|
| + {'name': 'bar_baz', 'type': 'qux'}
|
| + ],
|
| + 'name': 'Quux',
|
| + 'type': 'garply'
|
| + }
|
| + ],
|
| }, builder.build())
|
|
|