diff options
author | rdevlin.cronin <rdevlin.cronin@chromium.org> | 2015-04-06 10:19:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-06 17:35:43 +0000 |
commit | 00f1fc22bfcc653b47d62778170af3eee9855720 (patch) | |
tree | 2386d4a7e984d7db6f9cfa0c07409a715832993e /tools/json_schema_compiler | |
parent | 86b507da14efeb641795641b24c49f57a07ae879 (diff) | |
download | chromium_src-00f1fc22bfcc653b47d62778170af3eee9855720.zip chromium_src-00f1fc22bfcc653b47d62778170af3eee9855720.tar.gz chromium_src-00f1fc22bfcc653b47d62778170af3eee9855720.tar.bz2 |
[Extensions API] Remove inline enums
Remove all inlined enums from extension APIs.
BUG=472279
TBR=derat@chromium.org (mechanical changes to chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc and chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc)
Review URL: https://codereview.chromium.org/1055673002
Cr-Commit-Position: refs/heads/master@{#323912}
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r-- | tools/json_schema_compiler/cc_generator.py | 23 | ||||
-rwxr-xr-x | tools/json_schema_compiler/compiler.py | 2 | ||||
-rw-r--r-- | tools/json_schema_compiler/model.py | 15 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/arrays.json | 23 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/arrays_unittest.cc | 58 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/callbacks.json | 14 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/callbacks_unittest.cc | 4 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/enums.json | 50 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/enums_unittest.cc | 87 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/objects.json | 31 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/objects_unittest.cc | 4 |
11 files changed, 127 insertions, 184 deletions
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py index 3e2a1be..73413ef 100644 --- a/tools/json_schema_compiler/cc_generator.py +++ b/tools/json_schema_compiler/cc_generator.py @@ -148,9 +148,12 @@ class _Generator(object): real_t = self._type_helper.FollowRef(t) if real_t.property_type == PropertyType.ENUM: - items.append('%s(%s)' % ( - prop.unix_name, - self._type_helper.GetEnumNoneValue(t))) + namespace_prefix = ('%s::' % real_t.namespace.unix_name + if real_t.namespace != self._namespace + else '') + items.append('%s(%s%s)' % (prop.unix_name, + namespace_prefix, + self._type_helper.GetEnumNoneValue(t))) elif prop.optional: continue elif t.property_type == PropertyType.INTEGER: @@ -289,9 +292,13 @@ class _Generator(object): prop, value_var, dst, 'false'))) underlying_type = self._type_helper.FollowRef(prop.type_) if underlying_type.property_type == PropertyType.ENUM: + namespace_prefix = ('%s::' % underlying_type.namespace.unix_name + if underlying_type.namespace != self._namespace + else '') (c.Append('} else {') - .Append('%%(dst)s->%%(name)s = %s;' % - self._type_helper.GetEnumNoneValue(prop.type_))) + .Append('%%(dst)s->%%(name)s = %s%s;' % + (namespace_prefix, + self._type_helper.GetEnumNoneValue(prop.type_)))) c.Eblock('}') else: (c.Sblock( @@ -1027,9 +1034,13 @@ class _Generator(object): underlying_type = self._type_helper.FollowRef(prop.type_) if (underlying_type.property_type == PropertyType.ENUM and prop.optional): - c.Append('%s->%s = %s;' % ( + namespace_prefix = ('%s::' % underlying_type.namespace.unix_name + if underlying_type.namespace != self._namespace + else '') + c.Append('%s->%s = %s%s;' % ( dst, prop.unix_name, + namespace_prefix, self._type_helper.GetEnumNoneValue(prop.type_))) return c diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py index e09366b2..f3c4009 100755 --- a/tools/json_schema_compiler/compiler.py +++ b/tools/json_schema_compiler/compiler.py @@ -57,7 +57,7 @@ def GenerateSchema(generator_name, api_def = json_schema.DeleteNodes(api_def, 'nocompile') api_defs.extend(api_def) - api_model = Model() + api_model = Model(allow_inline_enums=False) # For single-schema compilation make sure that the first (i.e. only) schema # is the default one. diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py index 3f7b2fe..642e818 100644 --- a/tools/json_schema_compiler/model.py +++ b/tools/json_schema_compiler/model.py @@ -24,7 +24,8 @@ class Model(object): Properties: - |namespaces| a map of a namespace name to its model.Namespace """ - def __init__(self): + def __init__(self, allow_inline_enums=True): + self._allow_inline_enums = allow_inline_enums self.namespaces = {} def AddNamespace(self, @@ -37,7 +38,8 @@ class Model(object): namespace = Namespace(json, source_file, include_compiler_options=include_compiler_options, - environment=environment) + environment=environment, + allow_inline_enums=self._allow_inline_enums) self.namespaces[namespace.name] = namespace return namespace @@ -104,7 +106,8 @@ class Namespace(object): json, source_file, include_compiler_options=False, - environment=None): + environment=None, + allow_inline_enums=True): self.name = json['namespace'] if 'description' not in json: # TODO(kalman): Go back to throwing an error here. @@ -118,6 +121,7 @@ class Namespace(object): self.source_file_dir, self.source_file_filename = os.path.split(source_file) self.short_filename = os.path.basename(source_file).split('.')[0] self.parent = None + self.allow_inline_enums = allow_inline_enums self.platforms = _GetPlatforms(json) toplevel_origin = Origin(from_client=True, from_json=True) self.types = _GetTypes(self, json, self, toplevel_origin) @@ -198,6 +202,11 @@ class Type(object): self.property_type = PropertyType.REF self.ref_type = json['$ref'] elif 'enum' in json and json_type == 'string': + if not namespace.allow_inline_enums and not isinstance(parent, Namespace): + raise ParseException( + self, + 'Inline enum "%s" found in namespace "%s". These are not allowed. ' + 'See crbug.com/472279' % (name, namespace.name)) self.property_type = PropertyType.ENUM self.enum_values = [EnumValue(value) for value in json['enum']] self.cpp_enum_prefix_override = json.get('cpp_enum_prefix_override', None) diff --git a/tools/json_schema_compiler/test/arrays.json b/tools/json_schema_compiler/test/arrays.json index 23314e9..3dfeeb8 100644 --- a/tools/json_schema_compiler/test/arrays.json +++ b/tools/json_schema_compiler/test/arrays.json @@ -4,19 +4,6 @@ "description": "The arrays API.", "types": [ { - "id": "EnumArrayType", - "type": "object", - "properties": { - "types": { - "type": "array", - "items": { - "type": "string", - "enum": ["one", "two", "three"] - } - } - } - }, - { "id": "Enumeration", "type": "string", "enum": ["one", "two", "three"] @@ -37,13 +24,6 @@ "id": "EnumArrayMixed", "type": "object", "properties": { - "inline_enums": { - "type": "array", - "items": { - "type": "string", - "enum": ["one", "two", "three"] - } - }, "infile_enums": { "type": "array", "items": { @@ -65,8 +45,7 @@ "types": { "type": "array", "items": { - "type": "string", - "enum": ["one", "two", "three"] + "$ref": "Enumeration" }, "optional": true } diff --git a/tools/json_schema_compiler/test/arrays_unittest.cc b/tools/json_schema_compiler/test/arrays_unittest.cc index 79ebfb2..f0d3ab1 100644 --- a/tools/json_schema_compiler/test/arrays_unittest.cc +++ b/tools/json_schema_compiler/test/arrays_unittest.cc @@ -52,35 +52,6 @@ TEST(JsonSchemaCompilerArrayTest, BasicArrayType) { } } -TEST(JsonSchemaCompilerArrayTest, EnumArrayType) { - // { "types": ["one", "two", "three"] } - base::ListValue* types = new base::ListValue(); - types->AppendString("one"); - types->AppendString("two"); - types->AppendString("three"); - base::DictionaryValue value; - value.Set("types", types); - - EnumArrayType enum_array_type; - - // Test Populate. - ASSERT_TRUE(EnumArrayType::Populate(value, &enum_array_type)); - { - EnumArrayType::TypesType enums[] = { - EnumArrayType::TYPES_TYPE_ONE, - EnumArrayType::TYPES_TYPE_TWO, - EnumArrayType::TYPES_TYPE_THREE, - }; - std::vector<EnumArrayType::TypesType> enums_vector( - enums, enums + arraysize(enums)); - EXPECT_EQ(enums_vector, enum_array_type.types); - } - - // Test ToValue. - scoped_ptr<base::Value> as_value(enum_array_type.ToValue()); - EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; -} - TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) { // { "types": ["one", "two", "three"] } base::ListValue* types = new base::ListValue(); @@ -108,11 +79,6 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) { TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) { // { "types": ["one", "two", "three"] } - base::ListValue* inline_enums = new base::ListValue(); - inline_enums->AppendString("one"); - inline_enums->AppendString("two"); - inline_enums->AppendString("three"); - base::ListValue* infile_enums = new base::ListValue(); infile_enums->AppendString("one"); infile_enums->AppendString("two"); @@ -124,7 +90,6 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) { external_enums->AppendString("three"); base::DictionaryValue value; - value.Set("inline_enums", inline_enums); value.Set("infile_enums", infile_enums); value.Set("external_enums", external_enums); @@ -133,15 +98,6 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) { // Test Populate. ASSERT_TRUE(EnumArrayMixed::Populate(value, &enum_array_mixed)); - EnumArrayMixed::Inline_enumsType expected_inline_types[] = { - EnumArrayMixed::INLINE_ENUMS_TYPE_ONE, - EnumArrayMixed::INLINE_ENUMS_TYPE_TWO, - EnumArrayMixed::INLINE_ENUMS_TYPE_THREE}; - EXPECT_EQ(std::vector<EnumArrayMixed::Inline_enumsType>( - expected_inline_types, - expected_inline_types + arraysize(expected_inline_types)), - enum_array_mixed.inline_enums); - Enumeration expected_infile_types[] = {ENUMERATION_ONE, ENUMERATION_TWO, ENUMERATION_THREE}; EXPECT_EQ(std::vector<Enumeration>( @@ -164,16 +120,14 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) { TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { { - std::vector<OptionalEnumArrayType::TypesType> enums; - enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE); - enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO); - enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE); + std::vector<Enumeration> enums; + enums.push_back(ENUMERATION_ONE); + enums.push_back(ENUMERATION_TWO); + enums.push_back(ENUMERATION_THREE); scoped_ptr<base::ListValue> types(new base::ListValue()); - for (size_t i = 0; i < enums.size(); ++i) { - types->Append(new base::StringValue( - OptionalEnumArrayType::ToString(enums[i]))); - } + for (size_t i = 0; i < enums.size(); ++i) + types->Append(new base::StringValue(ToString(enums[i]))); base::DictionaryValue value; value.Set("types", types.release()); diff --git a/tools/json_schema_compiler/test/callbacks.json b/tools/json_schema_compiler/test/callbacks.json index 2f86c26..dbd03c3 100644 --- a/tools/json_schema_compiler/test/callbacks.json +++ b/tools/json_schema_compiler/test/callbacks.json @@ -2,7 +2,13 @@ { "namespace": "callbacks", "description": "The callbacks API.", - "types": [], + "types": [ + { + "id": "Enumeration", + "type": "string", + "enum": ["foo", "bar", "baz"] + } + ], "functions": [ { "name": "returnsNothing", @@ -30,8 +36,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "Enumeration" } } } @@ -57,8 +62,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "Enumeration" } } } diff --git a/tools/json_schema_compiler/test/callbacks_unittest.cc b/tools/json_schema_compiler/test/callbacks_unittest.cc index 001e977..a12584d 100644 --- a/tools/json_schema_compiler/test/callbacks_unittest.cc +++ b/tools/json_schema_compiler/test/callbacks_unittest.cc @@ -10,7 +10,7 @@ using namespace test::api::callbacks; TEST(JsonSchemaCompilerCallbacksTest, ReturnsObjectResultCreate) { ReturnsObject::Results::SomeObject some_object; - some_object.state = ReturnsObject::Results::SomeObject::STATE_FOO; + some_object.state = ENUMERATION_FOO; scoped_ptr<base::ListValue> results = ReturnsObject::Results::Create(some_object); @@ -23,7 +23,7 @@ TEST(JsonSchemaCompilerCallbacksTest, ReturnsObjectResultCreate) { TEST(JsonSchemaCompilerCallbacksTest, ReturnsMultipleResultCreate) { ReturnsMultiple::Results::SomeObject some_object; - some_object.state = ReturnsMultiple::Results::SomeObject::STATE_FOO; + some_object.state = ENUMERATION_FOO; scoped_ptr<base::ListValue> results = ReturnsMultiple::Results::Create(5, some_object); diff --git a/tools/json_schema_compiler/test/enums.json b/tools/json_schema_compiler/test/enums.json index c776313..9723767 100644 --- a/tools/json_schema_compiler/test/enums.json +++ b/tools/json_schema_compiler/test/enums.json @@ -9,12 +9,16 @@ "enum": ["one", "two", "three"] }, { + "id": "OtherEnumeration", + "type": "string", + "enum": ["spam", "ham", "eggs"] + }, + { "id": "EnumType", "type": "object", "properties": { "type": { - "type": "string", - "enum": ["one", "two", "three"] + "$ref": "Enumeration" } } }, @@ -32,13 +36,9 @@ } }, { - "id": "InlineAndReferenceEnum", + "id": "ReferenceEnum", "type": "object", "properties": { - "inline_enum": { - "type": "string", - "enum": ["test1", "test2", "test3"] - }, "reference_enum": { "$ref": "Enumeration" } @@ -49,8 +49,7 @@ "type": "object", "properties": { "type": { - "type": "string", - "enum": ["one", "two", "three"], + "$ref": "Enumeration", "optional": true } } @@ -64,8 +63,7 @@ "parameters": [ { "name": "state", - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "Enumeration" }, { "name": "callback", @@ -83,8 +81,7 @@ "name": "values", "type": "array", "items": { - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "Enumeration" } }, { @@ -140,8 +137,7 @@ "parameters": [ { "name": "state", - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "Enumeration" } ] } @@ -175,13 +171,11 @@ "parameters": [ { "name": "firstState", - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "Enumeration" }, { "name": "secondState", - "type": "string", - "enum": ["spam", "ham", "eggs"] + "$ref": "OtherEnumeration" } ] } @@ -194,8 +188,7 @@ "parameters": [ { "name": "state", - "type": "string", - "enum": ["foo", "bar", "baz"], + "$ref": "Enumeration", "optional": true }, { @@ -212,14 +205,12 @@ "parameters": [ { "name": "state", - "type": "string", - "enum": ["foo", "bar", "baz"], + "$ref": "Enumeration", "optional": true }, { "name": "type", - "type": "string", - "enum": ["foo", "ding", "dong"], + "$ref": "OtherEnumeration", "optional": true }, { @@ -238,8 +229,7 @@ "parameters": [ { "name": "someEnum", - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "Enumeration" } ] }, @@ -250,13 +240,11 @@ "parameters": [ { "name": "firstEnum", - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "Enumeration" }, { "name": "secondEnum", - "type": "string", - "enum": ["spam", "ham", "eggs"] + "$ref": "OtherEnumeration" } ] } diff --git a/tools/json_schema_compiler/test/enums_unittest.cc b/tools/json_schema_compiler/test/enums_unittest.cc index 7f1addb..2eee096 100644 --- a/tools/json_schema_compiler/test/enums_unittest.cc +++ b/tools/json_schema_compiler/test/enums_unittest.cc @@ -16,7 +16,7 @@ TEST(JsonSchemaCompilerEnumsTest, EnumTypePopulate) { base::DictionaryValue value; value.Set("type", new base::StringValue("one")); EXPECT_TRUE(EnumType::Populate(value, &enum_type)); - EXPECT_EQ(EnumType::TYPE_ONE, enum_type.type); + EXPECT_EQ(ENUMERATION_ONE, enum_type.type); EXPECT_TRUE(value.Equals(enum_type.ToValue().get())); } { @@ -59,15 +59,12 @@ TEST(JsonSchemaCompilerEnumsTest, EnumsAsTypes) { EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); } { - InlineAndReferenceEnum enumeration; + ReferenceEnum enumeration; base::DictionaryValue value; - ASSERT_FALSE(InlineAndReferenceEnum::Populate(value, &enumeration)); - - value.Set("inline_enum", new base::StringValue("test2")); - ASSERT_FALSE(InlineAndReferenceEnum::Populate(value, &enumeration)); + ASSERT_FALSE(ReferenceEnum::Populate(value, &enumeration)); value.Set("reference_enum", new base::StringValue("one")); - ASSERT_TRUE(InlineAndReferenceEnum::Populate(value, &enumeration)); + ASSERT_TRUE(ReferenceEnum::Populate(value, &enumeration)); EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); } } @@ -95,17 +92,16 @@ TEST(JsonSchemaCompilerEnumsTest, EnumsArrayAsType) { TEST(JsonSchemaCompilerEnumsTest, ReturnsEnumCreate) { { - ReturnsEnum::Results::State state = ReturnsEnum::Results::STATE_FOO; - scoped_ptr<base::Value> result( - new base::StringValue(ReturnsEnum::Results::ToString(state))); - scoped_ptr<base::Value> expected(new base::StringValue("foo")); + Enumeration state = ENUMERATION_ONE; + scoped_ptr<base::Value> result(new base::StringValue(ToString(state))); + scoped_ptr<base::Value> expected(new base::StringValue("one")); EXPECT_TRUE(result->Equals(expected.get())); } { - ReturnsEnum::Results::State state = ReturnsEnum::Results::STATE_FOO; + Enumeration state = ENUMERATION_ONE; scoped_ptr<base::ListValue> results = ReturnsEnum::Results::Create(state); base::ListValue expected; - expected.Append(new base::StringValue("foo")); + expected.Append(new base::StringValue("one")); EXPECT_TRUE(results->Equals(&expected)); } } @@ -113,10 +109,9 @@ TEST(JsonSchemaCompilerEnumsTest, ReturnsEnumCreate) { TEST(JsonSchemaCompilerEnumsTest, ReturnsTwoEnumsCreate) { { scoped_ptr<base::ListValue> results = ReturnsTwoEnums::Results::Create( - ReturnsTwoEnums::Results::FIRST_STATE_FOO, - ReturnsTwoEnums::Results::SECOND_STATE_HAM); + ENUMERATION_ONE, OTHER_ENUMERATION_HAM); base::ListValue expected; - expected.Append(new base::StringValue("foo")); + expected.Append(new base::StringValue("one")); expected.Append(new base::StringValue("ham")); EXPECT_TRUE(results->Equals(&expected)); } @@ -128,14 +123,14 @@ TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) { base::DictionaryValue value; value.Set("type", new base::StringValue("two")); EXPECT_TRUE(OptionalEnumType::Populate(value, &enum_type)); - EXPECT_EQ(OptionalEnumType::TYPE_TWO, enum_type.type); + EXPECT_EQ(ENUMERATION_TWO, enum_type.type); EXPECT_TRUE(value.Equals(enum_type.ToValue().get())); } { OptionalEnumType enum_type; base::DictionaryValue value; EXPECT_TRUE(OptionalEnumType::Populate(value, &enum_type)); - EXPECT_EQ(OptionalEnumType::TYPE_NONE, enum_type.type); + EXPECT_EQ(ENUMERATION_NONE, enum_type.type); EXPECT_TRUE(value.Equals(enum_type.ToValue().get())); } { @@ -149,11 +144,11 @@ TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) { TEST(JsonSchemaCompilerEnumsTest, TakesEnumParamsCreate) { { base::ListValue params_value; - params_value.Append(new base::StringValue("baz")); + params_value.Append(new base::StringValue("two")); scoped_ptr<TakesEnum::Params> params( TakesEnum::Params::Create(params_value)); EXPECT_TRUE(params.get()); - EXPECT_EQ(TakesEnum::Params::STATE_BAZ, params->state); + EXPECT_EQ(ENUMERATION_TWO, params->state); } { base::ListValue params_value; @@ -167,14 +162,14 @@ TEST(JsonSchemaCompilerEnumsTest, TakesEnumParamsCreate) { TEST(JsonSchemaCompilerEnumsTest, TakesEnumArrayParamsCreate) { { base::ListValue params_value; - params_value.Append(List(new base::StringValue("foo"), - new base::StringValue("bar")).release()); + params_value.Append(List(new base::StringValue("one"), + new base::StringValue("two")).release()); scoped_ptr<TakesEnumArray::Params> params( TakesEnumArray::Params::Create(params_value)); ASSERT_TRUE(params); EXPECT_EQ(2U, params->values.size()); - EXPECT_EQ(TakesEnumArray::Params::VALUES_TYPE_FOO, params->values[0]); - EXPECT_EQ(TakesEnumArray::Params::VALUES_TYPE_BAR, params->values[1]); + EXPECT_EQ(ENUMERATION_ONE, params->values[0]); + EXPECT_EQ(ENUMERATION_TWO, params->values[1]); } { base::ListValue params_value; @@ -188,18 +183,18 @@ TEST(JsonSchemaCompilerEnumsTest, TakesEnumArrayParamsCreate) { TEST(JsonSchemaCompilerEnumsTest, TakesOptionalEnumParamsCreate) { { base::ListValue params_value; - params_value.Append(new base::StringValue("baz")); + params_value.Append(new base::StringValue("three")); scoped_ptr<TakesOptionalEnum::Params> params( TakesOptionalEnum::Params::Create(params_value)); EXPECT_TRUE(params.get()); - EXPECT_EQ(TakesOptionalEnum::Params::STATE_BAZ, params->state); + EXPECT_EQ(ENUMERATION_THREE, params->state); } { base::ListValue params_value; scoped_ptr<TakesOptionalEnum::Params> params( TakesOptionalEnum::Params::Create(params_value)); EXPECT_TRUE(params.get()); - EXPECT_EQ(TakesOptionalEnum::Params::STATE_NONE, params->state); + EXPECT_EQ(ENUMERATION_NONE, params->state); } { base::ListValue params_value; @@ -213,34 +208,34 @@ TEST(JsonSchemaCompilerEnumsTest, TakesOptionalEnumParamsCreate) { TEST(JsonSchemaCompilerEnumsTest, TakesMultipleOptionalEnumsParamsCreate) { { base::ListValue params_value; - params_value.Append(new base::StringValue("foo")); - params_value.Append(new base::StringValue("foo")); + params_value.Append(new base::StringValue("one")); + params_value.Append(new base::StringValue("ham")); scoped_ptr<TakesMultipleOptionalEnums::Params> params( TakesMultipleOptionalEnums::Params::Create(params_value)); EXPECT_TRUE(params.get()); - EXPECT_EQ(TakesMultipleOptionalEnums::Params::STATE_FOO, params->state); - EXPECT_EQ(TakesMultipleOptionalEnums::Params::TYPE_FOO, params->type); + EXPECT_EQ(ENUMERATION_ONE, params->state); + EXPECT_EQ(OTHER_ENUMERATION_HAM, params->type); } { base::ListValue params_value; - params_value.Append(new base::StringValue("foo")); + params_value.Append(new base::StringValue("one")); scoped_ptr<TakesMultipleOptionalEnums::Params> params( TakesMultipleOptionalEnums::Params::Create(params_value)); EXPECT_TRUE(params.get()); - EXPECT_EQ(TakesMultipleOptionalEnums::Params::STATE_FOO, params->state); - EXPECT_EQ(TakesMultipleOptionalEnums::Params::TYPE_NONE, params->type); + EXPECT_EQ(ENUMERATION_ONE, params->state); + EXPECT_EQ(OTHER_ENUMERATION_NONE, params->type); } { base::ListValue params_value; scoped_ptr<TakesMultipleOptionalEnums::Params> params( TakesMultipleOptionalEnums::Params::Create(params_value)); EXPECT_TRUE(params.get()); - EXPECT_EQ(TakesMultipleOptionalEnums::Params::STATE_NONE, params->state); - EXPECT_EQ(TakesMultipleOptionalEnums::Params::TYPE_NONE, params->type); + EXPECT_EQ(ENUMERATION_NONE, params->state); + EXPECT_EQ(OTHER_ENUMERATION_NONE, params->type); } { base::ListValue params_value; - params_value.Append(new base::StringValue("baz")); + params_value.Append(new base::StringValue("three")); params_value.Append(new base::StringValue("invalid")); scoped_ptr<TakesMultipleOptionalEnums::Params> params( TakesMultipleOptionalEnums::Params::Create(params_value)); @@ -250,28 +245,26 @@ TEST(JsonSchemaCompilerEnumsTest, TakesMultipleOptionalEnumsParamsCreate) { TEST(JsonSchemaCompilerEnumsTest, OnEnumFiredCreate) { { - OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; - scoped_ptr<base::Value> result( - new base::StringValue(OnEnumFired::ToString(some_enum))); - scoped_ptr<base::Value> expected(new base::StringValue("foo")); + Enumeration some_enum = ENUMERATION_ONE; + scoped_ptr<base::Value> result(new base::StringValue(ToString(some_enum))); + scoped_ptr<base::Value> expected(new base::StringValue("one")); EXPECT_TRUE(result->Equals(expected.get())); } { - OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; + Enumeration some_enum = ENUMERATION_ONE; scoped_ptr<base::ListValue> results(OnEnumFired::Create(some_enum)); base::ListValue expected; - expected.Append(new base::StringValue("foo")); + expected.Append(new base::StringValue("one")); EXPECT_TRUE(results->Equals(&expected)); } } TEST(JsonSchemaCompilerEnumsTest, OnTwoEnumsFiredCreate) { { - scoped_ptr<base::Value> results(OnTwoEnumsFired::Create( - OnTwoEnumsFired::FIRST_ENUM_FOO, - OnTwoEnumsFired::SECOND_ENUM_HAM)); + scoped_ptr<base::Value> results( + OnTwoEnumsFired::Create(ENUMERATION_ONE, OTHER_ENUMERATION_HAM)); base::ListValue expected; - expected.Append(new base::StringValue("foo")); + expected.Append(new base::StringValue("one")); expected.Append(new base::StringValue("ham")); EXPECT_TRUE(results->Equals(&expected)); } diff --git a/tools/json_schema_compiler/test/objects.json b/tools/json_schema_compiler/test/objects.json index e76e229..dd0bb20 100644 --- a/tools/json_schema_compiler/test/objects.json +++ b/tools/json_schema_compiler/test/objects.json @@ -2,7 +2,18 @@ { "namespace": "objects", "description": "The objects API.", - "types": [], + "types": [ + { + "id": "firstState", + "type": "string", + "enum": ["foo", "bar", "baz"] + }, + { + "id": "secondState", + "type": "string", + "enum": ["spam", "ham", "eggs"] + } + ], "functions": [ { "name": "objectParam", @@ -46,8 +57,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "firstState" } } } @@ -69,8 +79,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "firstState" } } }, @@ -79,8 +88,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "enum": ["spam", "ham", "eggs"] + "$ref": "secondState" } } } @@ -100,8 +108,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "firstState" } } } @@ -117,8 +124,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "enum": ["foo", "bar", "baz"] + "$ref": "firstState" } } }, @@ -127,8 +133,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "enum": ["spam", "ham", "eggs"] + "$ref": "secondState" } } } diff --git a/tools/json_schema_compiler/test/objects_unittest.cc b/tools/json_schema_compiler/test/objects_unittest.cc index 6dc2c45..f57300f 100644 --- a/tools/json_schema_compiler/test/objects_unittest.cc +++ b/tools/json_schema_compiler/test/objects_unittest.cc @@ -48,7 +48,7 @@ TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) { TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) { ReturnsObject::Results::Info info; - info.state = ReturnsObject::Results::Info::STATE_FOO; + info.state = FIRST_STATE_FOO; scoped_ptr<base::ListValue> results = ReturnsObject::Results::Create(info); base::DictionaryValue expected; @@ -60,7 +60,7 @@ TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) { TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) { OnObjectFired::SomeObject object; - object.state = OnObjectFired::SomeObject::STATE_BAR; + object.state = FIRST_STATE_BAR; scoped_ptr<base::ListValue> results(OnObjectFired::Create(object)); base::DictionaryValue expected; |