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

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

Issue 2911033002: Remove raw base::DictionaryValue::Set (Closed)
Patch Set: Proper Windows Fix Created 3 years, 6 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/enums.h" 5 #include "tools/json_schema_compiler/test/enums.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "tools/json_schema_compiler/test/test_util.h" 10 #include "tools/json_schema_compiler/test/test_util.h"
11 11
12 using namespace test::api::enums; 12 using namespace test::api::enums;
13 using json_schema_compiler::test_util::List; 13 using json_schema_compiler::test_util::List;
14 14
15 TEST(JsonSchemaCompilerEnumsTest, EnumTypePopulate) { 15 TEST(JsonSchemaCompilerEnumsTest, EnumTypePopulate) {
16 { 16 {
17 EnumType enum_type; 17 EnumType enum_type;
18 base::DictionaryValue value; 18 base::DictionaryValue value;
19 value.Set("type", new base::Value("one")); 19 value.SetString("type", "one");
20 EXPECT_TRUE(EnumType::Populate(value, &enum_type)); 20 EXPECT_TRUE(EnumType::Populate(value, &enum_type));
21 EXPECT_EQ(ENUMERATION_ONE, enum_type.type); 21 EXPECT_EQ(ENUMERATION_ONE, enum_type.type);
22 EXPECT_TRUE(value.Equals(enum_type.ToValue().get())); 22 EXPECT_TRUE(value.Equals(enum_type.ToValue().get()));
23 } 23 }
24 { 24 {
25 EnumType enum_type; 25 EnumType enum_type;
26 base::DictionaryValue value; 26 base::DictionaryValue value;
27 value.Set("type", new base::Value("invalid")); 27 value.SetString("type", "invalid");
28 EXPECT_FALSE(EnumType::Populate(value, &enum_type)); 28 EXPECT_FALSE(EnumType::Populate(value, &enum_type));
29 } 29 }
30 } 30 }
31 31
32 TEST(JsonSchemaCompilerEnumsTest, EnumsAsTypes) { 32 TEST(JsonSchemaCompilerEnumsTest, EnumsAsTypes) {
33 { 33 {
34 base::ListValue args; 34 base::ListValue args;
35 args.AppendString("one"); 35 args.AppendString("one");
36 36
37 std::unique_ptr<TakesEnumAsType::Params> params( 37 std::unique_ptr<TakesEnumAsType::Params> params(
38 TakesEnumAsType::Params::Create(args)); 38 TakesEnumAsType::Params::Create(args));
39 ASSERT_TRUE(params.get()); 39 ASSERT_TRUE(params.get());
40 EXPECT_EQ(ENUMERATION_ONE, params->enumeration); 40 EXPECT_EQ(ENUMERATION_ONE, params->enumeration);
41 41
42 EXPECT_TRUE(args.Equals(ReturnsEnumAsType::Results::Create( 42 EXPECT_TRUE(args.Equals(ReturnsEnumAsType::Results::Create(
43 ENUMERATION_ONE).get())); 43 ENUMERATION_ONE).get()));
44 } 44 }
45 { 45 {
46 HasEnumeration enumeration; 46 HasEnumeration enumeration;
47 EXPECT_EQ(ENUMERATION_NONE, enumeration.enumeration); 47 EXPECT_EQ(ENUMERATION_NONE, enumeration.enumeration);
48 EXPECT_EQ(ENUMERATION_NONE, enumeration.optional_enumeration); 48 EXPECT_EQ(ENUMERATION_NONE, enumeration.optional_enumeration);
49 } 49 }
50 { 50 {
51 HasEnumeration enumeration; 51 HasEnumeration enumeration;
52 base::DictionaryValue value; 52 base::DictionaryValue value;
53 ASSERT_FALSE(HasEnumeration::Populate(value, &enumeration)); 53 ASSERT_FALSE(HasEnumeration::Populate(value, &enumeration));
54 54
55 value.Set("enumeration", new base::Value("one")); 55 value.SetString("enumeration", "one");
56 ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration)); 56 ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration));
57 EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); 57 EXPECT_TRUE(value.Equals(enumeration.ToValue().get()));
58 58
59 value.Set("optional_enumeration", new base::Value("two")); 59 value.SetString("optional_enumeration", "two");
60 ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration)); 60 ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration));
61 EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); 61 EXPECT_TRUE(value.Equals(enumeration.ToValue().get()));
62 } 62 }
63 { 63 {
64 ReferenceEnum enumeration; 64 ReferenceEnum enumeration;
65 base::DictionaryValue value; 65 base::DictionaryValue value;
66 ASSERT_FALSE(ReferenceEnum::Populate(value, &enumeration)); 66 ASSERT_FALSE(ReferenceEnum::Populate(value, &enumeration));
67 67
68 value.Set("reference_enum", new base::Value("one")); 68 value.SetString("reference_enum", "one");
69 ASSERT_TRUE(ReferenceEnum::Populate(value, &enumeration)); 69 ASSERT_TRUE(ReferenceEnum::Populate(value, &enumeration));
70 EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); 70 EXPECT_TRUE(value.Equals(enumeration.ToValue().get()));
71 } 71 }
72 } 72 }
73 73
74 TEST(JsonSchemaCompilerEnumsTest, EnumsArrayAsType) { 74 TEST(JsonSchemaCompilerEnumsTest, EnumsArrayAsType) {
75 { 75 {
76 base::ListValue params_value; 76 base::ListValue params_value;
77 params_value.Append(List(base::MakeUnique<base::Value>("one"), 77 params_value.Append(List(base::MakeUnique<base::Value>("one"),
78 base::MakeUnique<base::Value>("two"))); 78 base::MakeUnique<base::Value>("two")));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 expected.AppendString("one"); 117 expected.AppendString("one");
118 expected.AppendString("ham"); 118 expected.AppendString("ham");
119 EXPECT_TRUE(results->Equals(&expected)); 119 EXPECT_TRUE(results->Equals(&expected));
120 } 120 }
121 } 121 }
122 122
123 TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) { 123 TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) {
124 { 124 {
125 OptionalEnumType enum_type; 125 OptionalEnumType enum_type;
126 base::DictionaryValue value; 126 base::DictionaryValue value;
127 value.Set("type", new base::Value("two")); 127 value.SetString("type", "two");
128 EXPECT_TRUE(OptionalEnumType::Populate(value, &enum_type)); 128 EXPECT_TRUE(OptionalEnumType::Populate(value, &enum_type));
129 EXPECT_EQ(ENUMERATION_TWO, enum_type.type); 129 EXPECT_EQ(ENUMERATION_TWO, enum_type.type);
130 EXPECT_TRUE(value.Equals(enum_type.ToValue().get())); 130 EXPECT_TRUE(value.Equals(enum_type.ToValue().get()));
131 } 131 }
132 { 132 {
133 OptionalEnumType enum_type; 133 OptionalEnumType enum_type;
134 base::DictionaryValue value; 134 base::DictionaryValue value;
135 EXPECT_TRUE(OptionalEnumType::Populate(value, &enum_type)); 135 EXPECT_TRUE(OptionalEnumType::Populate(value, &enum_type));
136 EXPECT_EQ(ENUMERATION_NONE, enum_type.type); 136 EXPECT_EQ(ENUMERATION_NONE, enum_type.type);
137 EXPECT_TRUE(value.Equals(enum_type.ToValue().get())); 137 EXPECT_TRUE(value.Equals(enum_type.ToValue().get()));
138 } 138 }
139 { 139 {
140 OptionalEnumType enum_type; 140 OptionalEnumType enum_type;
141 base::DictionaryValue value; 141 base::DictionaryValue value;
142 value.Set("type", new base::Value("invalid")); 142 value.SetString("type", "invalid");
143 EXPECT_FALSE(OptionalEnumType::Populate(value, &enum_type)); 143 EXPECT_FALSE(OptionalEnumType::Populate(value, &enum_type));
144 } 144 }
145 } 145 }
146 146
147 TEST(JsonSchemaCompilerEnumsTest, TakesEnumParamsCreate) { 147 TEST(JsonSchemaCompilerEnumsTest, TakesEnumParamsCreate) {
148 { 148 {
149 base::ListValue params_value; 149 base::ListValue params_value;
150 params_value.AppendString("two"); 150 params_value.AppendString("two");
151 std::unique_ptr<TakesEnum::Params> params( 151 std::unique_ptr<TakesEnum::Params> params(
152 TakesEnum::Params::Create(params_value)); 152 TakesEnum::Params::Create(params_value));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 TEST(JsonSchemaCompilerEnumsTest, OnTwoEnumsFiredCreate) { 265 TEST(JsonSchemaCompilerEnumsTest, OnTwoEnumsFiredCreate) {
266 { 266 {
267 std::unique_ptr<base::Value> results( 267 std::unique_ptr<base::Value> results(
268 OnTwoEnumsFired::Create(ENUMERATION_ONE, OTHER_ENUMERATION_HAM)); 268 OnTwoEnumsFired::Create(ENUMERATION_ONE, OTHER_ENUMERATION_HAM));
269 base::ListValue expected; 269 base::ListValue expected;
270 expected.AppendString("one"); 270 expected.AppendString("one");
271 expected.AppendString("ham"); 271 expected.AppendString("ham");
272 EXPECT_TRUE(results->Equals(&expected)); 272 EXPECT_TRUE(results->Equals(&expected));
273 } 273 }
274 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698