OLD | NEW |
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/crossref.h" | 5 #include "tools/json_schema_compiler/test/crossref.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "tools/json_schema_compiler/test/simple_api.h" | 11 #include "tools/json_schema_compiler/test/simple_api.h" |
12 | 12 |
13 using namespace test::api; | 13 using namespace test::api; |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 std::unique_ptr<base::DictionaryValue> CreateTestTypeValue() { | 17 std::unique_ptr<base::DictionaryValue> CreateTestTypeValue() { |
18 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 18 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
19 value->Set("number", new base::Value(1.1)); | 19 value->Set("number", new base::Value(1.1)); |
20 value->Set("integer", new base::Value(4)); | 20 value->Set("integer", new base::Value(4)); |
21 value->Set("string", new base::StringValue("bling")); | 21 value->Set("string", new base::Value("bling")); |
22 value->Set("boolean", new base::Value(true)); | 22 value->Set("boolean", new base::Value(true)); |
23 return value; | 23 return value; |
24 } | 24 } |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) { | 28 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) { |
29 base::DictionaryValue crossref_orig; | 29 base::DictionaryValue crossref_orig; |
30 crossref_orig.Set("testType", CreateTestTypeValue().release()); | 30 crossref_orig.Set("testType", CreateTestTypeValue().release()); |
31 crossref_orig.Set("testEnumRequired", new base::StringValue("one")); | 31 crossref_orig.Set("testEnumRequired", new base::Value("one")); |
32 crossref_orig.Set("testEnumOptional", new base::StringValue("two")); | 32 crossref_orig.Set("testEnumOptional", new base::Value("two")); |
33 | 33 |
34 // Test Populate of the value --> compiled type. | 34 // Test Populate of the value --> compiled type. |
35 crossref::CrossrefType crossref_type; | 35 crossref::CrossrefType crossref_type; |
36 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type)); | 36 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type)); |
37 EXPECT_EQ(1.1, crossref_type.test_type.number); | 37 EXPECT_EQ(1.1, crossref_type.test_type.number); |
38 EXPECT_EQ(4, crossref_type.test_type.integer); | 38 EXPECT_EQ(4, crossref_type.test_type.integer); |
39 EXPECT_EQ("bling", crossref_type.test_type.string); | 39 EXPECT_EQ("bling", crossref_type.test_type.string); |
40 EXPECT_EQ(true, crossref_type.test_type.boolean); | 40 EXPECT_EQ(true, crossref_type.test_type.boolean); |
41 EXPECT_EQ(simple_api::TEST_ENUM_ONE, crossref_type.test_enum_required); | 41 EXPECT_EQ(simple_api::TEST_ENUM_ONE, crossref_type.test_enum_required); |
42 EXPECT_EQ(simple_api::TEST_ENUM_TWO, crossref_type.test_enum_optional); | 42 EXPECT_EQ(simple_api::TEST_ENUM_TWO, crossref_type.test_enum_optional); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 std::unique_ptr<crossref::TestTypeInObject::Params> params( | 108 std::unique_ptr<crossref::TestTypeInObject::Params> params( |
109 crossref::TestTypeInObject::Params::Create(*params_value)); | 109 crossref::TestTypeInObject::Params::Create(*params_value)); |
110 EXPECT_TRUE(params.get()); | 110 EXPECT_TRUE(params.get()); |
111 EXPECT_FALSE(params->param_object.test_type.get()); | 111 EXPECT_FALSE(params->param_object.test_type.get()); |
112 EXPECT_TRUE(params->param_object.boolean); | 112 EXPECT_TRUE(params->param_object.boolean); |
113 } | 113 } |
114 { | 114 { |
115 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 115 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
116 std::unique_ptr<base::DictionaryValue> param_object_value( | 116 std::unique_ptr<base::DictionaryValue> param_object_value( |
117 new base::DictionaryValue()); | 117 new base::DictionaryValue()); |
118 param_object_value->Set("testType", new base::StringValue("invalid")); | 118 param_object_value->Set("testType", new base::Value("invalid")); |
119 param_object_value->Set("boolean", new base::Value(true)); | 119 param_object_value->Set("boolean", new base::Value(true)); |
120 params_value->Append(std::move(param_object_value)); | 120 params_value->Append(std::move(param_object_value)); |
121 std::unique_ptr<crossref::TestTypeInObject::Params> params( | 121 std::unique_ptr<crossref::TestTypeInObject::Params> params( |
122 crossref::TestTypeInObject::Params::Create(*params_value)); | 122 crossref::TestTypeInObject::Params::Create(*params_value)); |
123 EXPECT_FALSE(params.get()); | 123 EXPECT_FALSE(params.get()); |
124 } | 124 } |
125 { | 125 { |
126 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 126 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
127 std::unique_ptr<base::DictionaryValue> param_object_value( | 127 std::unique_ptr<base::DictionaryValue> param_object_value( |
128 new base::DictionaryValue()); | 128 new base::DictionaryValue()); |
129 param_object_value->Set("testType", CreateTestTypeValue().release()); | 129 param_object_value->Set("testType", CreateTestTypeValue().release()); |
130 params_value->Append(std::move(param_object_value)); | 130 params_value->Append(std::move(param_object_value)); |
131 std::unique_ptr<crossref::TestTypeInObject::Params> params( | 131 std::unique_ptr<crossref::TestTypeInObject::Params> params( |
132 crossref::TestTypeInObject::Params::Create(*params_value)); | 132 crossref::TestTypeInObject::Params::Create(*params_value)); |
133 EXPECT_FALSE(params.get()); | 133 EXPECT_FALSE(params.get()); |
134 } | 134 } |
135 } | 135 } |
OLD | NEW |