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

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

Issue 2884933002: Remove raw base::DictionaryValue::SetWithoutPathExpansion (Closed)
Patch Set: Include Created 3 years, 7 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
« no previous file with comments | « tools/ipc_fuzzer/fuzzer/fuzzer.cc ('k') | tools/json_schema_compiler/test/enums_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/ptr_util.h"
11 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "base/values.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 #include "tools/json_schema_compiler/test/test_util.h" 15 #include "tools/json_schema_compiler/test/test_util.h"
14 16
15 namespace { 17 namespace {
16 18
17 using namespace test::api::choices; 19 using namespace test::api::choices;
18 using json_schema_compiler::test_util::Dictionary; 20 using json_schema_compiler::test_util::Dictionary;
19 using json_schema_compiler::test_util::List; 21 using json_schema_compiler::test_util::List;
20 using json_schema_compiler::test_util::ReadJson; 22 using json_schema_compiler::test_util::ReadJson;
21 using json_schema_compiler::test_util::Vector; 23 using json_schema_compiler::test_util::Vector;
22 24
23 TEST(JsonSchemaCompilerChoicesTest, TakesIntegersParamsCreate) { 25 TEST(JsonSchemaCompilerChoicesTest, TakesIntegersParamsCreate) {
24 { 26 {
25 std::unique_ptr<TakesIntegers::Params> params( 27 std::unique_ptr<TakesIntegers::Params> params(TakesIntegers::Params::Create(
26 TakesIntegers::Params::Create(*List(new base::Value(true)))); 28 *List(base::MakeUnique<base::Value>(true))));
27 EXPECT_FALSE(params); 29 EXPECT_FALSE(params);
28 } 30 }
29 { 31 {
30 std::unique_ptr<TakesIntegers::Params> params( 32 std::unique_ptr<TakesIntegers::Params> params(
31 TakesIntegers::Params::Create(*List(new base::Value(6)))); 33 TakesIntegers::Params::Create(*List(base::MakeUnique<base::Value>(6))));
32 ASSERT_TRUE(params); 34 ASSERT_TRUE(params);
33 EXPECT_FALSE(params->nums.as_integers); 35 EXPECT_FALSE(params->nums.as_integers);
34 EXPECT_EQ(6, *params->nums.as_integer); 36 EXPECT_EQ(6, *params->nums.as_integer);
35 } 37 }
36 { 38 {
37 std::unique_ptr<TakesIntegers::Params> params(TakesIntegers::Params::Create( 39 std::unique_ptr<TakesIntegers::Params> params(
38 *List(List(new base::Value(2), new base::Value(6), new base::Value(8)) 40 TakesIntegers::Params::Create(*List(List(
39 .release()))); 41 base::MakeUnique<base::Value>(2), base::MakeUnique<base::Value>(6),
42 base::MakeUnique<base::Value>(8)))));
40 ASSERT_TRUE(params); 43 ASSERT_TRUE(params);
41 ASSERT_TRUE(params->nums.as_integers); 44 ASSERT_TRUE(params->nums.as_integers);
42 EXPECT_EQ(Vector(2, 6, 8), *params->nums.as_integers); 45 EXPECT_EQ(Vector(2, 6, 8), *params->nums.as_integers);
43 } 46 }
44 } 47 }
45 48
46 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { 49 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) {
47 { 50 {
48 std::unique_ptr<ObjectWithChoices::Params> params( 51 std::unique_ptr<ObjectWithChoices::Params> params(
49 ObjectWithChoices::Params::Create( 52 ObjectWithChoices::Params::Create(*List(
50 *List(Dictionary("strings", new base::Value("asdf")).release()))); 53 Dictionary("strings", base::MakeUnique<base::Value>("asdf")))));
51 ASSERT_TRUE(params); 54 ASSERT_TRUE(params);
52 EXPECT_FALSE(params->string_info.strings.as_strings); 55 EXPECT_FALSE(params->string_info.strings.as_strings);
53 EXPECT_EQ("asdf", *params->string_info.strings.as_string); 56 EXPECT_EQ("asdf", *params->string_info.strings.as_string);
54 EXPECT_FALSE(params->string_info.integers); 57 EXPECT_FALSE(params->string_info.integers);
55 } 58 }
56 { 59 {
57 std::unique_ptr<ObjectWithChoices::Params> params( 60 std::unique_ptr<ObjectWithChoices::Params> params(
58 ObjectWithChoices::Params::Create( 61 ObjectWithChoices::Params::Create(
59 *List(Dictionary("strings", new base::Value("asdf"), "integers", 62 *List(Dictionary("strings", base::MakeUnique<base::Value>("asdf"),
60 new base::Value(6)) 63 "integers", base::MakeUnique<base::Value>(6)))));
61 .release())));
62 ASSERT_TRUE(params); 64 ASSERT_TRUE(params);
63 EXPECT_FALSE(params->string_info.strings.as_strings); 65 EXPECT_FALSE(params->string_info.strings.as_strings);
64 EXPECT_EQ("asdf", *params->string_info.strings.as_string); 66 EXPECT_EQ("asdf", *params->string_info.strings.as_string);
65 ASSERT_TRUE(params->string_info.integers); 67 ASSERT_TRUE(params->string_info.integers);
66 EXPECT_FALSE(params->string_info.integers->as_integers); 68 EXPECT_FALSE(params->string_info.integers->as_integers);
67 EXPECT_EQ(6, *params->string_info.integers->as_integer); 69 EXPECT_EQ(6, *params->string_info.integers->as_integer);
68 } 70 }
69 } 71 }
70 72
71 // TODO(kalman): Clean up the rest of these tests to use the 73 // TODO(kalman): Clean up the rest of these tests to use the
72 // Vector/List/Dictionary helpers. 74 // Vector/List/Dictionary helpers.
73 75
74 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) { 76 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) {
75 { 77 {
76 std::unique_ptr<base::DictionaryValue> object_param( 78 std::unique_ptr<base::DictionaryValue> object_param(
77 new base::DictionaryValue()); 79 new base::DictionaryValue());
78 object_param->SetWithoutPathExpansion("strings", new base::Value(5)); 80 object_param->SetIntegerWithoutPathExpansion("strings", 5);
79 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 81 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
80 params_value->Append(std::move(object_param)); 82 params_value->Append(std::move(object_param));
81 std::unique_ptr<ObjectWithChoices::Params> params( 83 std::unique_ptr<ObjectWithChoices::Params> params(
82 ObjectWithChoices::Params::Create(*params_value)); 84 ObjectWithChoices::Params::Create(*params_value));
83 EXPECT_FALSE(params.get()); 85 EXPECT_FALSE(params.get());
84 } 86 }
85 { 87 {
86 std::unique_ptr<base::DictionaryValue> object_param( 88 std::unique_ptr<base::DictionaryValue> object_param(
87 new base::DictionaryValue()); 89 new base::DictionaryValue());
88 object_param->SetWithoutPathExpansion("strings", new base::Value("asdf")); 90 object_param->SetStringWithoutPathExpansion("strings", "asdf");
89 object_param->SetWithoutPathExpansion("integers", new base::Value("asdf")); 91 object_param->SetStringWithoutPathExpansion("integers", "asdf");
90 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 92 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
91 params_value->Append(std::move(object_param)); 93 params_value->Append(std::move(object_param));
92 std::unique_ptr<ObjectWithChoices::Params> params( 94 std::unique_ptr<ObjectWithChoices::Params> params(
93 ObjectWithChoices::Params::Create(*params_value)); 95 ObjectWithChoices::Params::Create(*params_value));
94 EXPECT_FALSE(params.get()); 96 EXPECT_FALSE(params.get());
95 } 97 }
96 { 98 {
97 std::unique_ptr<base::DictionaryValue> object_param( 99 std::unique_ptr<base::DictionaryValue> object_param(
98 new base::DictionaryValue()); 100 new base::DictionaryValue());
99 object_param->SetWithoutPathExpansion("integers", new base::Value(6)); 101 object_param->SetIntegerWithoutPathExpansion("integers", 6);
100 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 102 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
101 params_value->Append(std::move(object_param)); 103 params_value->Append(std::move(object_param));
102 std::unique_ptr<ObjectWithChoices::Params> params( 104 std::unique_ptr<ObjectWithChoices::Params> params(
103 ObjectWithChoices::Params::Create(*params_value)); 105 ObjectWithChoices::Params::Create(*params_value));
104 EXPECT_FALSE(params.get()); 106 EXPECT_FALSE(params.get());
105 } 107 }
106 } 108 }
107 109
108 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { 110 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) {
109 std::vector<std::string> strings = Vector(std::string("list"), 111 std::vector<std::string> strings = Vector(std::string("list"),
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 obj->as_choice2->as_choice_types.get(); 288 obj->as_choice2->as_choice_types.get();
287 // Bleh too much effort to test everything. 289 // Bleh too much effort to test everything.
288 ASSERT_EQ(2u, choice_types->size()); 290 ASSERT_EQ(2u, choice_types->size());
289 } 291 }
290 292
291 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); 293 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get()));
292 } 294 }
293 } 295 }
294 296
295 } // namespace 297 } // namespace
OLDNEW
« no previous file with comments | « tools/ipc_fuzzer/fuzzer/fuzzer.cc ('k') | tools/json_schema_compiler/test/enums_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698