diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-28 20:36:59 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-28 20:36:59 +0000 |
commit | 9dcd3e08a3e777be291f7c62d5f82b5b975c17ed (patch) | |
tree | 760c04dd8081ee86dd5c16abddbabdc9c53bd719 /tools/json_schema_compiler | |
parent | 326013b86f8d5bd19a031fa5c6ee529c736e7907 (diff) | |
download | chromium_src-9dcd3e08a3e777be291f7c62d5f82b5b975c17ed.zip chromium_src-9dcd3e08a3e777be291f7c62d5f82b5b975c17ed.tar.gz chromium_src-9dcd3e08a3e777be291f7c62d5f82b5b975c17ed.tar.bz2 |
Fixes to json_schema_compiler unit tests
These are necessary after the changes that went in with
crrev.com/129042 (http://codereview.chromium.org/9836078)
Update: also fix some fallout from crrev.com/129251
BUG=120481
TEST=(this is a test)
Review URL: https://chromiumcodereview.appspot.com/9866050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129482 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator.py | 4 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator_test.py | 64 |
2 files changed, 38 insertions, 30 deletions
diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py index 9609f35..04e0080 100644 --- a/tools/json_schema_compiler/cpp_type_generator.py +++ b/tools/json_schema_compiler/cpp_type_generator.py @@ -32,7 +32,7 @@ class CppTypeGenerator(object): if qualified_name in self._type_namespaces: raise ValueError('Type %s is declared in both %s and %s' % (qualified_name, namespace.name, - self._type_namespaces[qualified_type].name)) + self._type_namespaces[qualified_name].name)) self._type_namespaces[qualified_name] = namespace self._cpp_namespaces[namespace] = cpp_namespace @@ -213,7 +213,7 @@ class CppTypeGenerator(object): if type_name == self._QualifyName(namespace, ref_type): return namespace - raise ValueError('Cannot resolve %s to a type in any namespace.' % ref_type) + return None def _NamespaceTypeDependencies(self): """Returns a dict containing a mapping of model.Namespace to the C++ type diff --git a/tools/json_schema_compiler/cpp_type_generator_test.py b/tools/json_schema_compiler/cpp_type_generator_test.py index ca40815..bc1144d 100644 --- a/tools/json_schema_compiler/cpp_type_generator_test.py +++ b/tools/json_schema_compiler/cpp_type_generator_test.py @@ -24,21 +24,26 @@ class CppTypeGeneratorTest(unittest.TestCase): self.tabs = self.model.namespaces.get('tabs') def testGenerateIncludesAndForwardDeclarations(self): - manager = CppTypeGenerator('', self.windows, 'windows_api') - manager.AddNamespace(self.tabs, 'tabs_api') - self.assertEquals('#include "path/to/tabs_api.h"', + manager = CppTypeGenerator('', self.windows, self.windows.unix_name) + manager.AddNamespace(self.tabs, self.tabs.unix_name) + self.assertEquals('#include "path/to/tabs.h"', manager.GenerateIncludes().Render()) self.assertEquals( 'namespace tabs {\n' 'struct Tab;\n' - '}', + '}\n' + 'namespace windows {\n' + 'struct Window;\n' + '} // windows', manager.GenerateForwardDeclarations().Render()) - manager = CppTypeGenerator('', self.permissions, 'permissions_api') - manager.AddNamespace(self.permissions, 'permissions_api') + manager = CppTypeGenerator('', self.permissions, self.permissions.unix_name) self.assertEquals('', manager.GenerateIncludes().Render()) - self.assertEquals('', manager.GenerateForwardDeclarations().Render()) + self.assertEquals('namespace permissions {\n' + 'struct Permissions;\n' + '} // permissions', + manager.GenerateForwardDeclarations().Render()) - def testGenerateIncludesAndForwardDeclaratiosnMultipleTypes(self): + def testGenerateIncludesAndForwardDeclarationsMultipleTypes(self): m = model.Model() self.tabs_json[0]['types'].append(self.permissions_json[0]['types'][0]) tabs_namespace = m.AddNamespace(self.tabs_json[0], @@ -47,19 +52,22 @@ class CppTypeGeneratorTest(unittest.TestCase): self.permissions_json[0]['functions'][1]) windows = m.AddNamespace(self.windows_json[0], 'path/to/windows.json') - manager = CppTypeGenerator('', windows, 'windows_api') - manager.AddNamespace(tabs_namespace, 'tabs_api') - self.assertEquals('#include "path/to/tabs_api.h"', + manager = CppTypeGenerator('', windows, self.windows.unix_name) + manager.AddNamespace(tabs_namespace, self.tabs.unix_name) + self.assertEquals('#include "path/to/tabs.h"', manager.GenerateIncludes().Render()) self.assertEquals( 'namespace tabs {\n' 'struct Tab;\n' 'struct Permissions;\n' - '}', + '}\n' + 'namespace windows {\n' + 'struct Window;\n' + '} // windows', manager.GenerateForwardDeclarations().Render()) def testChoicesEnum(self): - manager = CppTypeGenerator('', self.tabs, 'tabs_api') + manager = CppTypeGenerator('', self.tabs, self.tabs.unix_name) prop = self.tabs.functions['move'].params[0] self.assertEquals('TAB_IDS_ARRAY', manager.GetEnumValue(prop, model.PropertyType.ARRAY.name)) @@ -69,7 +77,7 @@ class CppTypeGeneratorTest(unittest.TestCase): manager.GetChoicesEnumType(prop)) def testGetTypeSimple(self): - manager = CppTypeGenerator('', self.tabs, 'tabs_api') + manager = CppTypeGenerator('', self.tabs, self.tabs.unix_name) self.assertEquals('int', manager.GetType( self.tabs.types['Tab'].properties['id'])) @@ -81,42 +89,42 @@ class CppTypeGeneratorTest(unittest.TestCase): self.tabs.types['Tab'].properties['selected'])) def testGetTypeArray(self): - manager = CppTypeGenerator('', self.windows, 'windows_api') + manager = CppTypeGenerator('', self.windows, self.windows.unix_name) self.assertEquals('std::vector<linked_ptr<Window> >', manager.GetType( self.windows.functions['getAll'].callback.params[0])) - manager = CppTypeGenerator('', self.permissions, 'permissions_api') + manager = CppTypeGenerator('', self.permissions, self.permissions.unix_name) self.assertEquals('std::vector<std::string>', manager.GetType( self.permissions.types['Permissions'].properties['origins'])) def testGetTypeLocalRef(self): - manager = CppTypeGenerator('', self.tabs, 'tabs_api') + manager = CppTypeGenerator('', self.tabs, self.tabs.unix_name) self.assertEquals('Tab', manager.GetType( self.tabs.functions['get'].callback.params[0])) def testGetTypeIncludedRef(self): - manager = CppTypeGenerator('', self.windows, 'windows_api') - manager.AddNamespace(self.tabs, 'tabs_api') - self.assertEquals('std::vector<linked_ptr<tabs_api::Tab> >', + manager = CppTypeGenerator('', self.windows, self.windows.unix_name) + manager.AddNamespace(self.tabs, self.tabs.unix_name) + self.assertEquals('std::vector<linked_ptr<tabs::Tab> >', manager.GetType( self.windows.types['Window'].properties['tabs'])) def testGetTypeNotfound(self): prop = self.windows.types['Window'].properties['tabs'].item_type prop.ref_type = 'Something' - manager = CppTypeGenerator('', self.windows, 'windows_api') + manager = CppTypeGenerator('', self.windows, self.windows.unix_name) self.assertRaises(KeyError, manager.GetType, prop) def testGetTypeNotimplemented(self): prop = self.windows.types['Window'].properties['tabs'].item_type prop.type_ = 10 - manager = CppTypeGenerator('', self.windows, 'windows_api') + manager = CppTypeGenerator('', self.windows, self.windows.unix_name) self.assertRaises(NotImplementedError, manager.GetType, prop) def testGetTypeWithPadForGeneric(self): - manager = CppTypeGenerator('', self.permissions, 'permissions_api') + manager = CppTypeGenerator('', self.permissions, self.permissions.unix_name) self.assertEquals('std::vector<std::string> ', manager.GetType( self.permissions.types['Permissions'].properties['origins'], @@ -128,16 +136,16 @@ class CppTypeGeneratorTest(unittest.TestCase): def testNamespaceDeclaration(self): manager = CppTypeGenerator('extensions', self.permissions, - 'permissions_api') + self.permissions.unix_name) self.assertEquals( 'namespace extensions {', manager.GetRootNamespaceStart().Render()) manager = CppTypeGenerator('extensions::gen::api', self.permissions, - 'permissions_api') - self.assertEquals('namespace permissions_api {', + self.permissions.unix_name) + self.assertEquals('namespace permissions {', manager.GetNamespaceStart().Render()) - self.assertEquals('} // permissions_api', + self.assertEquals('} // permissions', manager.GetNamespaceEnd().Render()) self.assertEquals( 'namespace extensions {\n' @@ -152,7 +160,7 @@ class CppTypeGeneratorTest(unittest.TestCase): def testExpandChoicesInParams(self): manager = CppTypeGenerator('extensions', self.tabs, - 'tabs_api') + self.tabs.unix_name) props = self.tabs.functions['move'].params self.assertEquals(2, len(props)) self.assertEquals(3, len(manager.GetExpandedChoicesInParams(props))) |