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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 using namespace test::api::choices; | 9 using namespace test::api::choices; |
10 | 10 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 object_param->SetWithoutPathExpansion("integers", | 104 object_param->SetWithoutPathExpansion("integers", |
105 Value::CreateIntegerValue(6)); | 105 Value::CreateIntegerValue(6)); |
106 scoped_ptr<ListValue> params_value(new ListValue()); | 106 scoped_ptr<ListValue> params_value(new ListValue()); |
107 params_value->Append(object_param.release()); | 107 params_value->Append(object_param.release()); |
108 scoped_ptr<ObjectWithChoices::Params> params( | 108 scoped_ptr<ObjectWithChoices::Params> params( |
109 ObjectWithChoices::Params::Create(*params_value)); | 109 ObjectWithChoices::Params::Create(*params_value)); |
110 EXPECT_FALSE(params.get()); | 110 EXPECT_FALSE(params.get()); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
| 114 TEST(JsonSchemaCompilerChoicesTest, PopulateChoiceType) { |
| 115 std::vector<std::string> strings; |
| 116 strings.push_back("list"); |
| 117 strings.push_back("of"); |
| 118 strings.push_back("strings"); |
| 119 |
| 120 ListValue* strings_value = new ListValue(); |
| 121 for (size_t i = 0; i < strings.size(); ++i) |
| 122 strings_value->Append(Value::CreateStringValue(strings[i])); |
| 123 |
| 124 DictionaryValue value; |
| 125 value.SetInteger("integers", 4); |
| 126 value.Set("strings", strings_value); |
| 127 |
| 128 ChoiceType out; |
| 129 ASSERT_TRUE(ChoiceType::Populate(value, &out)); |
| 130 EXPECT_EQ(ChoiceType::INTEGERS_INTEGER, out.integers_type); |
| 131 ASSERT_TRUE(out.integers_integer.get()); |
| 132 EXPECT_FALSE(out.integers_array.get()); |
| 133 EXPECT_EQ(4, *out.integers_integer); |
| 134 |
| 135 EXPECT_EQ(ChoiceType::STRINGS_ARRAY, out.strings_type); |
| 136 EXPECT_FALSE(out.strings_string.get()); |
| 137 ASSERT_TRUE(out.strings_array.get()); |
| 138 EXPECT_EQ(strings, *out.strings_array); |
| 139 } |
| 140 |
| 141 TEST(JsonSchemaCompilerChoicesTest, ChoiceTypeToValue) { |
| 142 ListValue* strings_value = new ListValue(); |
| 143 strings_value->Append(Value::CreateStringValue("list")); |
| 144 strings_value->Append(Value::CreateStringValue("of")); |
| 145 strings_value->Append(Value::CreateStringValue("strings")); |
| 146 |
| 147 DictionaryValue value; |
| 148 value.SetInteger("integers", 5); |
| 149 value.Set("strings", strings_value); |
| 150 |
| 151 ChoiceType out; |
| 152 ASSERT_TRUE(ChoiceType::Populate(value, &out)); |
| 153 |
| 154 EXPECT_TRUE(value.Equals(out.ToValue().get())); |
| 155 } |
| 156 |
114 TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) { | 157 TEST(JsonSchemaCompilerChoicesTest, ReturnChoices) { |
115 { | 158 { |
116 std::vector<int> integers; | 159 std::vector<int> integers; |
117 integers.push_back(1); | 160 integers.push_back(1); |
118 integers.push_back(2); | 161 integers.push_back(2); |
119 scoped_ptr<ListValue> array_results = | 162 scoped_ptr<ListValue> array_results = |
120 ReturnChoices::Results::Create(integers); | 163 ReturnChoices::Results::Create(integers); |
121 | 164 |
122 ListValue expected; | 165 ListValue expected; |
123 ListValue* expected_argument = new ListValue(); | 166 ListValue* expected_argument = new ListValue(); |
124 expected_argument->Append(Value::CreateIntegerValue(1)); | 167 expected_argument->Append(Value::CreateIntegerValue(1)); |
125 expected_argument->Append(Value::CreateIntegerValue(2)); | 168 expected_argument->Append(Value::CreateIntegerValue(2)); |
126 expected.Append(expected_argument); | 169 expected.Append(expected_argument); |
127 EXPECT_TRUE(array_results->Equals(&expected)); | 170 EXPECT_TRUE(array_results->Equals(&expected)); |
128 } | 171 } |
129 { | 172 { |
130 scoped_ptr<ListValue> integer_results = ReturnChoices::Results::Create(5); | 173 scoped_ptr<ListValue> integer_results = ReturnChoices::Results::Create(5); |
131 ListValue expected; | 174 ListValue expected; |
132 expected.Append(Value::CreateIntegerValue(5)); | 175 expected.Append(Value::CreateIntegerValue(5)); |
133 EXPECT_TRUE(integer_results->Equals(&expected)); | 176 EXPECT_TRUE(integer_results->Equals(&expected)); |
134 } | 177 } |
135 } | 178 } |
OLD | NEW |