| 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 .release()))); | 39 .release()))); |
| 40 ASSERT_TRUE(params); | 40 ASSERT_TRUE(params); |
| 41 ASSERT_TRUE(params->nums.as_integers); | 41 ASSERT_TRUE(params->nums.as_integers); |
| 42 EXPECT_EQ(Vector(2, 6, 8), *params->nums.as_integers); | 42 EXPECT_EQ(Vector(2, 6, 8), *params->nums.as_integers); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { | 46 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreate) { |
| 47 { | 47 { |
| 48 std::unique_ptr<ObjectWithChoices::Params> params( | 48 std::unique_ptr<ObjectWithChoices::Params> params( |
| 49 ObjectWithChoices::Params::Create(*List( | 49 ObjectWithChoices::Params::Create( |
| 50 Dictionary("strings", new base::StringValue("asdf")).release()))); | 50 *List(Dictionary("strings", new base::Value("asdf")).release()))); |
| 51 ASSERT_TRUE(params); | 51 ASSERT_TRUE(params); |
| 52 EXPECT_FALSE(params->string_info.strings.as_strings); | 52 EXPECT_FALSE(params->string_info.strings.as_strings); |
| 53 EXPECT_EQ("asdf", *params->string_info.strings.as_string); | 53 EXPECT_EQ("asdf", *params->string_info.strings.as_string); |
| 54 EXPECT_FALSE(params->string_info.integers); | 54 EXPECT_FALSE(params->string_info.integers); |
| 55 } | 55 } |
| 56 { | 56 { |
| 57 std::unique_ptr<ObjectWithChoices::Params> params( | 57 std::unique_ptr<ObjectWithChoices::Params> params( |
| 58 ObjectWithChoices::Params::Create( | 58 ObjectWithChoices::Params::Create( |
| 59 *List(Dictionary("strings", new base::StringValue("asdf"), | 59 *List(Dictionary("strings", new base::Value("asdf"), "integers", |
| 60 "integers", new base::Value(6)) | 60 new base::Value(6)) |
| 61 .release()))); | 61 .release()))); |
| 62 ASSERT_TRUE(params); | 62 ASSERT_TRUE(params); |
| 63 EXPECT_FALSE(params->string_info.strings.as_strings); | 63 EXPECT_FALSE(params->string_info.strings.as_strings); |
| 64 EXPECT_EQ("asdf", *params->string_info.strings.as_string); | 64 EXPECT_EQ("asdf", *params->string_info.strings.as_string); |
| 65 ASSERT_TRUE(params->string_info.integers); | 65 ASSERT_TRUE(params->string_info.integers); |
| 66 EXPECT_FALSE(params->string_info.integers->as_integers); | 66 EXPECT_FALSE(params->string_info.integers->as_integers); |
| 67 EXPECT_EQ(6, *params->string_info.integers->as_integer); | 67 EXPECT_EQ(6, *params->string_info.integers->as_integer); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 // 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 |
| 72 // Vector/List/Dictionary helpers. | 72 // Vector/List/Dictionary helpers. |
| 73 | 73 |
| 74 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) { | 74 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) { |
| 75 { | 75 { |
| 76 std::unique_ptr<base::DictionaryValue> object_param( | 76 std::unique_ptr<base::DictionaryValue> object_param( |
| 77 new base::DictionaryValue()); | 77 new base::DictionaryValue()); |
| 78 object_param->SetWithoutPathExpansion("strings", new base::Value(5)); | 78 object_param->SetWithoutPathExpansion("strings", new base::Value(5)); |
| 79 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 79 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
| 80 params_value->Append(std::move(object_param)); | 80 params_value->Append(std::move(object_param)); |
| 81 std::unique_ptr<ObjectWithChoices::Params> params( | 81 std::unique_ptr<ObjectWithChoices::Params> params( |
| 82 ObjectWithChoices::Params::Create(*params_value)); | 82 ObjectWithChoices::Params::Create(*params_value)); |
| 83 EXPECT_FALSE(params.get()); | 83 EXPECT_FALSE(params.get()); |
| 84 } | 84 } |
| 85 { | 85 { |
| 86 std::unique_ptr<base::DictionaryValue> object_param( | 86 std::unique_ptr<base::DictionaryValue> object_param( |
| 87 new base::DictionaryValue()); | 87 new base::DictionaryValue()); |
| 88 object_param->SetWithoutPathExpansion("strings", | 88 object_param->SetWithoutPathExpansion("strings", new base::Value("asdf")); |
| 89 new base::StringValue("asdf")); | 89 object_param->SetWithoutPathExpansion("integers", new base::Value("asdf")); |
| 90 object_param->SetWithoutPathExpansion("integers", | |
| 91 new base::StringValue("asdf")); | |
| 92 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 90 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
| 93 params_value->Append(std::move(object_param)); | 91 params_value->Append(std::move(object_param)); |
| 94 std::unique_ptr<ObjectWithChoices::Params> params( | 92 std::unique_ptr<ObjectWithChoices::Params> params( |
| 95 ObjectWithChoices::Params::Create(*params_value)); | 93 ObjectWithChoices::Params::Create(*params_value)); |
| 96 EXPECT_FALSE(params.get()); | 94 EXPECT_FALSE(params.get()); |
| 97 } | 95 } |
| 98 { | 96 { |
| 99 std::unique_ptr<base::DictionaryValue> object_param( | 97 std::unique_ptr<base::DictionaryValue> object_param( |
| 100 new base::DictionaryValue()); | 98 new base::DictionaryValue()); |
| 101 object_param->SetWithoutPathExpansion("integers", new base::Value(6)); | 99 object_param->SetWithoutPathExpansion("integers", new base::Value(6)); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 obj->as_choice2->as_choice_types.get(); | 286 obj->as_choice2->as_choice_types.get(); |
| 289 // Bleh too much effort to test everything. | 287 // Bleh too much effort to test everything. |
| 290 ASSERT_EQ(2u, choice_types->size()); | 288 ASSERT_EQ(2u, choice_types->size()); |
| 291 } | 289 } |
| 292 | 290 |
| 293 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); | 291 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); |
| 294 } | 292 } |
| 295 } | 293 } |
| 296 | 294 |
| 297 } // namespace | 295 } // namespace |
| OLD | NEW |