| 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> |
| 10 |
| 9 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "tools/json_schema_compiler/test/test_util.h" | 13 #include "tools/json_schema_compiler/test/test_util.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 using namespace test::api::choices; | 17 using namespace test::api::choices; |
| 16 using json_schema_compiler::test_util::Dictionary; | 18 using json_schema_compiler::test_util::Dictionary; |
| 17 using json_schema_compiler::test_util::List; | 19 using json_schema_compiler::test_util::List; |
| 18 using json_schema_compiler::test_util::ReadJson; | 20 using json_schema_compiler::test_util::ReadJson; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // TODO(kalman): Clean up the rest of these tests to use the | 72 // TODO(kalman): Clean up the rest of these tests to use the |
| 71 // Vector/List/Dictionary helpers. | 73 // Vector/List/Dictionary helpers. |
| 72 | 74 |
| 73 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) { | 75 TEST(JsonSchemaCompilerChoicesTest, ObjectWithChoicesParamsCreateFail) { |
| 74 { | 76 { |
| 75 std::unique_ptr<base::DictionaryValue> object_param( | 77 std::unique_ptr<base::DictionaryValue> object_param( |
| 76 new base::DictionaryValue()); | 78 new base::DictionaryValue()); |
| 77 object_param->SetWithoutPathExpansion("strings", | 79 object_param->SetWithoutPathExpansion("strings", |
| 78 new base::FundamentalValue(5)); | 80 new base::FundamentalValue(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(object_param.release()); | 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", | 90 object_param->SetWithoutPathExpansion("strings", |
| 89 new base::StringValue("asdf")); | 91 new base::StringValue("asdf")); |
| 90 object_param->SetWithoutPathExpansion("integers", | 92 object_param->SetWithoutPathExpansion("integers", |
| 91 new base::StringValue("asdf")); | 93 new base::StringValue("asdf")); |
| 92 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 94 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
| 93 params_value->Append(object_param.release()); | 95 params_value->Append(std::move(object_param)); |
| 94 std::unique_ptr<ObjectWithChoices::Params> params( | 96 std::unique_ptr<ObjectWithChoices::Params> params( |
| 95 ObjectWithChoices::Params::Create(*params_value)); | 97 ObjectWithChoices::Params::Create(*params_value)); |
| 96 EXPECT_FALSE(params.get()); | 98 EXPECT_FALSE(params.get()); |
| 97 } | 99 } |
| 98 { | 100 { |
| 99 std::unique_ptr<base::DictionaryValue> object_param( | 101 std::unique_ptr<base::DictionaryValue> object_param( |
| 100 new base::DictionaryValue()); | 102 new base::DictionaryValue()); |
| 101 object_param->SetWithoutPathExpansion("integers", | 103 object_param->SetWithoutPathExpansion("integers", |
| 102 new base::FundamentalValue(6)); | 104 new base::FundamentalValue(6)); |
| 103 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 105 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
| 104 params_value->Append(object_param.release()); | 106 params_value->Append(std::move(object_param)); |
| 105 std::unique_ptr<ObjectWithChoices::Params> params( | 107 std::unique_ptr<ObjectWithChoices::Params> params( |
| 106 ObjectWithChoices::Params::Create(*params_value)); | 108 ObjectWithChoices::Params::Create(*params_value)); |
| 107 EXPECT_FALSE(params.get()); | 109 EXPECT_FALSE(params.get()); |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 | 112 |
| 111 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { | 113 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { |
| 112 std::vector<std::string> strings = Vector(std::string("list"), | 114 std::vector<std::string> strings = Vector(std::string("list"), |
| 113 std::string("of"), | 115 std::string("of"), |
| 114 std::string("strings")); | 116 std::string("strings")); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 obj->as_choice2->as_choice_types.get(); | 291 obj->as_choice2->as_choice_types.get(); |
| 290 // Bleh too much effort to test everything. | 292 // Bleh too much effort to test everything. |
| 291 ASSERT_EQ(2u, choice_types->size()); | 293 ASSERT_EQ(2u, choice_types->size()); |
| 292 } | 294 } |
| 293 | 295 |
| 294 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); | 296 EXPECT_TRUE(base::Value::Equals(value.get(), obj->ToValue().get())); |
| 295 } | 297 } |
| 296 } | 298 } |
| 297 | 299 |
| 298 } // namespace | 300 } // namespace |
| OLD | NEW |