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

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

Issue 2666093002: Remove base::FundamentalValue (Closed)
Patch Set: Rebase Created 3 years, 9 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/choices.h" 5 #include "tools/json_schema_compiler/test/choices.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "tools/json_schema_compiler/test/test_util.h" 13 #include "tools/json_schema_compiler/test/test_util.h"
14 14
15 namespace { 15 namespace {
16 16
17 using namespace test::api::choices; 17 using namespace test::api::choices;
18 using json_schema_compiler::test_util::Dictionary; 18 using json_schema_compiler::test_util::Dictionary;
19 using json_schema_compiler::test_util::List; 19 using json_schema_compiler::test_util::List;
20 using json_schema_compiler::test_util::ReadJson; 20 using json_schema_compiler::test_util::ReadJson;
21 using json_schema_compiler::test_util::Vector; 21 using json_schema_compiler::test_util::Vector;
22 22
23 TEST(JsonSchemaCompilerChoicesTest, TakesIntegersParamsCreate) { 23 TEST(JsonSchemaCompilerChoicesTest, TakesIntegersParamsCreate) {
24 { 24 {
25 std::unique_ptr<TakesIntegers::Params> params( 25 std::unique_ptr<TakesIntegers::Params> params(
26 TakesIntegers::Params::Create(*List(new base::FundamentalValue(true)))); 26 TakesIntegers::Params::Create(*List(new base::Value(true))));
27 EXPECT_FALSE(params); 27 EXPECT_FALSE(params);
28 } 28 }
29 { 29 {
30 std::unique_ptr<TakesIntegers::Params> params( 30 std::unique_ptr<TakesIntegers::Params> params(
31 TakesIntegers::Params::Create(*List(new base::FundamentalValue(6)))); 31 TakesIntegers::Params::Create(*List(new base::Value(6))));
32 ASSERT_TRUE(params); 32 ASSERT_TRUE(params);
33 EXPECT_FALSE(params->nums.as_integers); 33 EXPECT_FALSE(params->nums.as_integers);
34 EXPECT_EQ(6, *params->nums.as_integer); 34 EXPECT_EQ(6, *params->nums.as_integer);
35 } 35 }
36 { 36 {
37 std::unique_ptr<TakesIntegers::Params> params(TakesIntegers::Params::Create( 37 std::unique_ptr<TakesIntegers::Params> params(TakesIntegers::Params::Create(
38 *List(List(new base::FundamentalValue(2), new base::FundamentalValue(6), 38 *List(List(new base::Value(2), new base::Value(6), new base::Value(8))
39 new base::FundamentalValue(8))
40 .release()))); 39 .release())));
41 ASSERT_TRUE(params); 40 ASSERT_TRUE(params);
42 ASSERT_TRUE(params->nums.as_integers); 41 ASSERT_TRUE(params->nums.as_integers);
43 EXPECT_EQ(Vector(2, 6, 8), *params->nums.as_integers); 42 EXPECT_EQ(Vector(2, 6, 8), *params->nums.as_integers);
44 } 43 }
45 } 44 }
46 45
47 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { 46 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) {
48 { 47 {
49 std::unique_ptr<ObjectWithChoices::Params> params( 48 std::unique_ptr<ObjectWithChoices::Params> params(
50 ObjectWithChoices::Params::Create(*List( 49 ObjectWithChoices::Params::Create(*List(
51 Dictionary("strings", new base::StringValue("asdf")).release()))); 50 Dictionary("strings", new base::StringValue("asdf")).release())));
52 ASSERT_TRUE(params); 51 ASSERT_TRUE(params);
53 EXPECT_FALSE(params->string_info.strings.as_strings); 52 EXPECT_FALSE(params->string_info.strings.as_strings);
54 EXPECT_EQ("asdf", *params->string_info.strings.as_string); 53 EXPECT_EQ("asdf", *params->string_info.strings.as_string);
55 EXPECT_FALSE(params->string_info.integers); 54 EXPECT_FALSE(params->string_info.integers);
56 } 55 }
57 { 56 {
58 std::unique_ptr<ObjectWithChoices::Params> params( 57 std::unique_ptr<ObjectWithChoices::Params> params(
59 ObjectWithChoices::Params::Create( 58 ObjectWithChoices::Params::Create(
60 *List(Dictionary("strings", new base::StringValue("asdf"), 59 *List(Dictionary("strings", new base::StringValue("asdf"),
61 "integers", new base::FundamentalValue(6)) 60 "integers", new base::Value(6))
62 .release()))); 61 .release())));
63 ASSERT_TRUE(params); 62 ASSERT_TRUE(params);
64 EXPECT_FALSE(params->string_info.strings.as_strings); 63 EXPECT_FALSE(params->string_info.strings.as_strings);
65 EXPECT_EQ("asdf", *params->string_info.strings.as_string); 64 EXPECT_EQ("asdf", *params->string_info.strings.as_string);
66 ASSERT_TRUE(params->string_info.integers); 65 ASSERT_TRUE(params->string_info.integers);
67 EXPECT_FALSE(params->string_info.integers->as_integers); 66 EXPECT_FALSE(params->string_info.integers->as_integers);
68 EXPECT_EQ(6, *params->string_info.integers->as_integer); 67 EXPECT_EQ(6, *params->string_info.integers->as_integer);
69 } 68 }
70 } 69 }
71 70
72 // TODO(kalman): Clean up the rest of these tests to use the 71 // TODO(kalman): Clean up the rest of these tests to use the
73 // Vector/List/Dictionary helpers. 72 // Vector/List/Dictionary helpers.
74 73
75 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) { 74 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) {
76 { 75 {
77 std::unique_ptr<base::DictionaryValue> object_param( 76 std::unique_ptr<base::DictionaryValue> object_param(
78 new base::DictionaryValue()); 77 new base::DictionaryValue());
79 object_param->SetWithoutPathExpansion("strings", 78 object_param->SetWithoutPathExpansion("strings", new base::Value(5));
80 new base::FundamentalValue(5));
81 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 79 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
82 params_value->Append(std::move(object_param)); 80 params_value->Append(std::move(object_param));
83 std::unique_ptr<ObjectWithChoices::Params> params( 81 std::unique_ptr<ObjectWithChoices::Params> params(
84 ObjectWithChoices::Params::Create(*params_value)); 82 ObjectWithChoices::Params::Create(*params_value));
85 EXPECT_FALSE(params.get()); 83 EXPECT_FALSE(params.get());
86 } 84 }
87 { 85 {
88 std::unique_ptr<base::DictionaryValue> object_param( 86 std::unique_ptr<base::DictionaryValue> object_param(
89 new base::DictionaryValue()); 87 new base::DictionaryValue());
90 object_param->SetWithoutPathExpansion("strings", 88 object_param->SetWithoutPathExpansion("strings",
91 new base::StringValue("asdf")); 89 new base::StringValue("asdf"));
92 object_param->SetWithoutPathExpansion("integers", 90 object_param->SetWithoutPathExpansion("integers",
93 new base::StringValue("asdf")); 91 new base::StringValue("asdf"));
94 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 92 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
95 params_value->Append(std::move(object_param)); 93 params_value->Append(std::move(object_param));
96 std::unique_ptr<ObjectWithChoices::Params> params( 94 std::unique_ptr<ObjectWithChoices::Params> params(
97 ObjectWithChoices::Params::Create(*params_value)); 95 ObjectWithChoices::Params::Create(*params_value));
98 EXPECT_FALSE(params.get()); 96 EXPECT_FALSE(params.get());
99 } 97 }
100 { 98 {
101 std::unique_ptr<base::DictionaryValue> object_param( 99 std::unique_ptr<base::DictionaryValue> object_param(
102 new base::DictionaryValue()); 100 new base::DictionaryValue());
103 object_param->SetWithoutPathExpansion("integers", 101 object_param->SetWithoutPathExpansion("integers", new base::Value(6));
104 new base::FundamentalValue(6));
105 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 102 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
106 params_value->Append(std::move(object_param)); 103 params_value->Append(std::move(object_param));
107 std::unique_ptr<ObjectWithChoices::Params> params( 104 std::unique_ptr<ObjectWithChoices::Params> params(
108 ObjectWithChoices::Params::Create(*params_value)); 105 ObjectWithChoices::Params::Create(*params_value));
109 EXPECT_FALSE(params.get()); 106 EXPECT_FALSE(params.get());
110 } 107 }
111 } 108 }
112 109
113 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { 110 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) {
114 std::vector<std::string> strings = Vector(std::string("list"), 111 std::vector<std::string> strings = Vector(std::string("list"),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 161
165 EXPECT_TRUE(expected.Equals(results_value.get())); 162 EXPECT_TRUE(expected.Equals(results_value.get()));
166 } 163 }
167 { 164 {
168 ReturnChoices::Results::Result results; 165 ReturnChoices::Results::Result results;
169 results.as_integer.reset(new int(5)); 166 results.as_integer.reset(new int(5));
170 167
171 std::unique_ptr<base::Value> results_value = results.ToValue(); 168 std::unique_ptr<base::Value> results_value = results.ToValue();
172 ASSERT_TRUE(results_value); 169 ASSERT_TRUE(results_value);
173 170
174 base::FundamentalValue expected(5); 171 base::Value expected(5);
175 172
176 EXPECT_TRUE(expected.Equals(results_value.get())); 173 EXPECT_TRUE(expected.Equals(results_value.get()));
177 } 174 }
178 } 175 }
179 176
180 TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { 177 TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
181 // These test both ToValue and FromValue for every legitimate configuration of 178 // These test both ToValue and FromValue for every legitimate configuration of
182 // NestedChoices. 179 // NestedChoices.
183 { 180 {
184 // The plain integer choice. 181 // The plain integer choice.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 obj->as_choice2->as_choice_types.get(); 288 obj->as_choice2->as_choice_types.get();
292 // Bleh too much effort to test everything. 289 // Bleh too much effort to test everything.
293 ASSERT_EQ(2u, choice_types->size()); 290 ASSERT_EQ(2u, choice_types->size());
294 } 291 }
295 292
296 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); 293 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get()));
297 } 294 }
298 } 295 }
299 296
300 } // namespace 297 } // namespace
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/arrays_unittest.cc ('k') | tools/json_schema_compiler/test/crossref_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698