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/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" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "tools/json_schema_compiler/test/test_util.h" | 14 #include "tools/json_schema_compiler/test/test_util.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 using namespace test::api::choices; | 18 using namespace test::api::choices; |
18 using json_schema_compiler::test_util::Dictionary; | 19 using json_schema_compiler::test_util::Dictionary; |
19 using json_schema_compiler::test_util::List; | 20 using json_schema_compiler::test_util::List; |
20 using json_schema_compiler::test_util::ReadJson; | 21 using json_schema_compiler::test_util::ReadJson; |
(...skipping 19 matching lines...) Expand all Loading... |
40 ASSERT_TRUE(params); | 41 ASSERT_TRUE(params); |
41 ASSERT_TRUE(params->nums.as_integers); | 42 ASSERT_TRUE(params->nums.as_integers); |
42 EXPECT_EQ(Vector(2, 6, 8), *params->nums.as_integers); | 43 EXPECT_EQ(Vector(2, 6, 8), *params->nums.as_integers); |
43 } | 44 } |
44 } | 45 } |
45 | 46 |
46 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { | 47 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { |
47 { | 48 { |
48 std::unique_ptr<ObjectWithChoices::Params> params( | 49 std::unique_ptr<ObjectWithChoices::Params> params( |
49 ObjectWithChoices::Params::Create( | 50 ObjectWithChoices::Params::Create( |
50 *List(Dictionary("strings", new base::Value("asdf")).release()))); | 51 *List(Dictionary("strings", base::MakeUnique<base::Value>("asdf")) |
| 52 .release()))); |
51 ASSERT_TRUE(params); | 53 ASSERT_TRUE(params); |
52 EXPECT_FALSE(params->string_info.strings.as_strings); | 54 EXPECT_FALSE(params->string_info.strings.as_strings); |
53 EXPECT_EQ("asdf", *params->string_info.strings.as_string); | 55 EXPECT_EQ("asdf", *params->string_info.strings.as_string); |
54 EXPECT_FALSE(params->string_info.integers); | 56 EXPECT_FALSE(params->string_info.integers); |
55 } | 57 } |
56 { | 58 { |
57 std::unique_ptr<ObjectWithChoices::Params> params( | 59 std::unique_ptr<ObjectWithChoices::Params> params( |
58 ObjectWithChoices::Params::Create( | 60 ObjectWithChoices::Params::Create( |
59 *List(Dictionary("strings", new base::Value("asdf"), "integers", | 61 *List(Dictionary("strings", base::MakeUnique<base::Value>("asdf"), |
60 new base::Value(6)) | 62 "integers", base::MakeUnique<base::Value>(6)) |
61 .release()))); | 63 .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 Loading... |
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 |
OLD | NEW |