Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: tools/json_schema_compiler/test/crossref_unittest.cc

Issue 1100333006: Make the JSON Schema compiler handle enums declared in other namespaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "tools/json_schema_compiler/test/simple_api.h" 5 #include "tools/json_schema_compiler/test/simple_api.h"
6 #include "tools/json_schema_compiler/test/crossref.h" 6 #include "tools/json_schema_compiler/test/crossref.h"
7 7
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 using namespace test::api::crossref; 10 using namespace test::api;
11 11
12 namespace { 12 namespace {
13 13
14 static scoped_ptr<base::DictionaryValue> CreateTestTypeDictionary() { 14 scoped_ptr<base::DictionaryValue> CreateTestTypeValue() {
15 base::DictionaryValue* value(new base::DictionaryValue()); 15 base::DictionaryValue* value(new base::DictionaryValue());
16 value->SetWithoutPathExpansion("number", new base::FundamentalValue(1.1)); 16 value->Set("number", new base::FundamentalValue(1.1));
17 value->SetWithoutPathExpansion("integer", new base::FundamentalValue(4)); 17 value->Set("integer", new base::FundamentalValue(4));
18 value->SetWithoutPathExpansion("string", new base::StringValue("bling")); 18 value->Set("string", new base::StringValue("bling"));
19 value->SetWithoutPathExpansion("boolean", new base::FundamentalValue(true)); 19 value->Set("boolean", new base::FundamentalValue(true));
20 return scoped_ptr<base::DictionaryValue>(value); 20 return scoped_ptr<base::DictionaryValue>(value);
21 } 21 }
22 22
23 } // namespace 23 } // namespace
24 24
25 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulate) { 25 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) {
not at google - send to devlin 2015/04/23 22:59:50 This is the only test I'm going to touch. The rest
26 scoped_ptr<CrossrefType> crossref_type(new CrossrefType()); 26 base::DictionaryValue crossref_orig;
27 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 27 crossref_orig.Set("testType", CreateTestTypeValue().release());
28 value->Set("testType", CreateTestTypeDictionary().release()); 28 crossref_orig.Set("testEnumRequired", new base::StringValue("one"));
29 EXPECT_TRUE(CrossrefType::Populate(*value, crossref_type.get())); 29 crossref_orig.Set("testEnumOptional", new base::StringValue("two"));
30 EXPECT_TRUE(crossref_type->test_type.get()); 30
31 EXPECT_TRUE(CreateTestTypeDictionary()->Equals( 31 // Test Populate of the value --> compiled type.
32 crossref_type->test_type->ToValue().get())); 32 crossref::CrossrefType crossref_type;
33 EXPECT_TRUE(value->Equals(crossref_type->ToValue().get())); 33 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type));
34 EXPECT_EQ(1.1, crossref_type.test_type.number);
35 EXPECT_EQ(4, crossref_type.test_type.integer);
36 EXPECT_EQ("bling", crossref_type.test_type.string);
37 EXPECT_EQ(true, crossref_type.test_type.boolean);
38 EXPECT_EQ(simple_api::TEST_ENUM_ONE, crossref_type.test_enum_required);
39 EXPECT_EQ(simple_api::TEST_ENUM_TWO, crossref_type.test_enum_optional);
40 EXPECT_EQ(simple_api::TEST_ENUM_NONE, crossref_type.test_enum_optional_extra);
41
42 // Test ToValue of the compiled type --> value.
43 scoped_ptr<base::DictionaryValue> crossref_value = crossref_type.ToValue();
44 ASSERT_TRUE(crossref_value);
45 EXPECT_TRUE(crossref_orig.Equals(crossref_value.get()));
34 } 46 }
35 47
36 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { 48 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) {
37 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 49 scoped_ptr<base::ListValue> params_value(new base::ListValue());
38 params_value->Append(CreateTestTypeDictionary().release()); 50 params_value->Append(CreateTestTypeValue().release());
39 scoped_ptr<TestTypeOptionalParam::Params> params( 51 scoped_ptr<crossref::TestTypeOptionalParam::Params> params(
40 TestTypeOptionalParam::Params::Create(*params_value)); 52 crossref::TestTypeOptionalParam::Params::Create(*params_value));
41 EXPECT_TRUE(params.get()); 53 EXPECT_TRUE(params.get());
42 EXPECT_TRUE(params->test_type.get()); 54 EXPECT_TRUE(params->test_type.get());
43 EXPECT_TRUE( 55 EXPECT_TRUE(
44 CreateTestTypeDictionary()->Equals(params->test_type->ToValue().get())); 56 CreateTestTypeValue()->Equals(params->test_type->ToValue().get()));
45 } 57 }
46 58
47 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) { 59 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) {
48 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 60 scoped_ptr<base::ListValue> params_value(new base::ListValue());
49 scoped_ptr<base::DictionaryValue> test_type_value = 61 scoped_ptr<base::DictionaryValue> test_type_value = CreateTestTypeValue();
50 CreateTestTypeDictionary();
51 test_type_value->RemoveWithoutPathExpansion("number", NULL); 62 test_type_value->RemoveWithoutPathExpansion("number", NULL);
52 params_value->Append(test_type_value.release()); 63 params_value->Append(test_type_value.release());
53 scoped_ptr<TestTypeOptionalParam::Params> params( 64 scoped_ptr<crossref::TestTypeOptionalParam::Params> params(
54 TestTypeOptionalParam::Params::Create(*params_value)); 65 crossref::TestTypeOptionalParam::Params::Create(*params_value));
55 EXPECT_FALSE(params.get()); 66 EXPECT_FALSE(params.get());
56 } 67 }
57 68
58 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) { 69 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) {
59 scoped_ptr<base::DictionaryValue> value = CreateTestTypeDictionary(); 70 scoped_ptr<base::DictionaryValue> value = CreateTestTypeValue();
60 scoped_ptr<test::api::simple_api::TestType> test_type( 71 scoped_ptr<simple_api::TestType> test_type(new simple_api::TestType());
61 new test::api::simple_api::TestType()); 72 EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get()));
62 EXPECT_TRUE(
63 test::api::simple_api::TestType::Populate(*value, test_type.get()));
64 73
65 scoped_ptr<base::ListValue> results = 74 scoped_ptr<base::ListValue> results =
66 GetTestType::Results::Create(*test_type); 75 crossref::GetTestType::Results::Create(*test_type);
67 base::DictionaryValue* result_dict = NULL; 76 base::DictionaryValue* result_dict = NULL;
68 results->GetDictionary(0, &result_dict); 77 results->GetDictionary(0, &result_dict);
69 EXPECT_TRUE(value->Equals(result_dict)); 78 EXPECT_TRUE(value->Equals(result_dict));
70 } 79 }
71 80
72 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) { 81 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) {
73 { 82 {
74 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 83 scoped_ptr<base::ListValue> params_value(new base::ListValue());
75 scoped_ptr<base::DictionaryValue> param_object_value( 84 scoped_ptr<base::DictionaryValue> param_object_value(
76 new base::DictionaryValue()); 85 new base::DictionaryValue());
77 param_object_value->Set("testType", CreateTestTypeDictionary().release()); 86 param_object_value->Set("testType", CreateTestTypeValue().release());
78 param_object_value->Set("boolean", new base::FundamentalValue(true)); 87 param_object_value->Set("boolean", new base::FundamentalValue(true));
79 params_value->Append(param_object_value.release()); 88 params_value->Append(param_object_value.release());
80 scoped_ptr<TestTypeInObject::Params> params( 89 scoped_ptr<crossref::TestTypeInObject::Params> params(
81 TestTypeInObject::Params::Create(*params_value)); 90 crossref::TestTypeInObject::Params::Create(*params_value));
82 EXPECT_TRUE(params.get()); 91 EXPECT_TRUE(params.get());
83 EXPECT_TRUE(params->param_object.test_type.get()); 92 EXPECT_TRUE(params->param_object.test_type.get());
84 EXPECT_TRUE(params->param_object.boolean); 93 EXPECT_TRUE(params->param_object.boolean);
85 EXPECT_TRUE(CreateTestTypeDictionary()->Equals( 94 EXPECT_TRUE(CreateTestTypeValue()->Equals(
86 params->param_object.test_type->ToValue().get())); 95 params->param_object.test_type->ToValue().get()));
87 } 96 }
88 { 97 {
89 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 98 scoped_ptr<base::ListValue> params_value(new base::ListValue());
90 scoped_ptr<base::DictionaryValue> param_object_value( 99 scoped_ptr<base::DictionaryValue> param_object_value(
91 new base::DictionaryValue()); 100 new base::DictionaryValue());
92 param_object_value->Set("boolean", new base::FundamentalValue(true)); 101 param_object_value->Set("boolean", new base::FundamentalValue(true));
93 params_value->Append(param_object_value.release()); 102 params_value->Append(param_object_value.release());
94 scoped_ptr<TestTypeInObject::Params> params( 103 scoped_ptr<crossref::TestTypeInObject::Params> params(
95 TestTypeInObject::Params::Create(*params_value)); 104 crossref::TestTypeInObject::Params::Create(*params_value));
96 EXPECT_TRUE(params.get()); 105 EXPECT_TRUE(params.get());
97 EXPECT_FALSE(params->param_object.test_type.get()); 106 EXPECT_FALSE(params->param_object.test_type.get());
98 EXPECT_TRUE(params->param_object.boolean); 107 EXPECT_TRUE(params->param_object.boolean);
99 } 108 }
100 { 109 {
101 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 110 scoped_ptr<base::ListValue> params_value(new base::ListValue());
102 scoped_ptr<base::DictionaryValue> param_object_value( 111 scoped_ptr<base::DictionaryValue> param_object_value(
103 new base::DictionaryValue()); 112 new base::DictionaryValue());
104 param_object_value->Set("testType", new base::StringValue("invalid")); 113 param_object_value->Set("testType", new base::StringValue("invalid"));
105 param_object_value->Set("boolean", new base::FundamentalValue(true)); 114 param_object_value->Set("boolean", new base::FundamentalValue(true));
106 params_value->Append(param_object_value.release()); 115 params_value->Append(param_object_value.release());
107 scoped_ptr<TestTypeInObject::Params> params( 116 scoped_ptr<crossref::TestTypeInObject::Params> params(
108 TestTypeInObject::Params::Create(*params_value)); 117 crossref::TestTypeInObject::Params::Create(*params_value));
109 EXPECT_FALSE(params.get()); 118 EXPECT_FALSE(params.get());
110 } 119 }
111 { 120 {
112 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 121 scoped_ptr<base::ListValue> params_value(new base::ListValue());
113 scoped_ptr<base::DictionaryValue> param_object_value( 122 scoped_ptr<base::DictionaryValue> param_object_value(
114 new base::DictionaryValue()); 123 new base::DictionaryValue());
115 param_object_value->Set("testType", CreateTestTypeDictionary().release()); 124 param_object_value->Set("testType", CreateTestTypeValue().release());
116 params_value->Append(param_object_value.release()); 125 params_value->Append(param_object_value.release());
117 scoped_ptr<TestTypeInObject::Params> params( 126 scoped_ptr<crossref::TestTypeInObject::Params> params(
118 TestTypeInObject::Params::Create(*params_value)); 127 crossref::TestTypeInObject::Params::Create(*params_value));
119 EXPECT_FALSE(params.get()); 128 EXPECT_FALSE(params.get());
120 } 129 }
121 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698