Chromium Code Reviews| 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/arrays.h" | 5 #include "tools/json_schema_compiler/test/arrays.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "tools/json_schema_compiler/test/enums.h" | |
| 8 | 9 |
| 9 using namespace test::api::arrays; | 10 using namespace test::api::arrays; |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 // TODO(calamity): Change to AppendString etc once kalman's patch goes through | 14 // TODO(calamity): Change to AppendString etc once kalman's patch goes through |
| 14 static scoped_ptr<base::DictionaryValue> CreateBasicArrayTypeDictionary() { | 15 static scoped_ptr<base::DictionaryValue> CreateBasicArrayTypeDictionary() { |
| 15 base::DictionaryValue* value = new base::DictionaryValue(); | 16 base::DictionaryValue* value = new base::DictionaryValue(); |
| 16 base::ListValue* strings_value = new base::ListValue(); | 17 base::ListValue* strings_value = new base::ListValue(); |
| 17 strings_value->Append(base::Value::CreateStringValue("a")); | 18 strings_value->Append(base::Value::CreateStringValue("a")); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 std::vector<EnumArrayType::TypesType> enums_vector( | 74 std::vector<EnumArrayType::TypesType> enums_vector( |
| 74 enums, enums + arraysize(enums)); | 75 enums, enums + arraysize(enums)); |
| 75 EXPECT_EQ(enums_vector, enum_array_type.types); | 76 EXPECT_EQ(enums_vector, enum_array_type.types); |
| 76 } | 77 } |
| 77 | 78 |
| 78 // Test ToValue. | 79 // Test ToValue. |
| 79 scoped_ptr<base::Value> as_value(enum_array_type.ToValue()); | 80 scoped_ptr<base::Value> as_value(enum_array_type.ToValue()); |
| 80 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; | 81 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; |
| 81 } | 82 } |
| 82 | 83 |
| 84 TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) { | |
| 85 // { "types": ["one", "two", "three"] } | |
| 86 base::ListValue* types = new base::ListValue(); | |
| 87 types->AppendString("one"); | |
| 88 types->AppendString("two"); | |
| 89 types->AppendString("three"); | |
| 90 base::DictionaryValue value; | |
| 91 value.Set("types", types); | |
| 92 | |
| 93 EnumArrayReference enum_array_reference; | |
| 94 | |
| 95 // Test Populate. | |
| 96 ASSERT_TRUE(EnumArrayReference::Populate(value, &enum_array_reference)); | |
| 97 | |
| 98 EXPECT_EQ(3u, enum_array_reference.types.size()); | |
| 99 | |
| 100 Enumeration expected_types[] = {ENUMERATION_ONE, ENUMERATION_TWO, | |
| 101 ENUMERATION_THREE}; | |
| 102 EXPECT_EQ(std::vector<Enumeration>( | |
| 103 expected_types, expected_types + arraysize(expected_types)), | |
| 104 enum_array_reference.types); | |
| 105 | |
| 106 // Test ToValue. | |
| 107 scoped_ptr<base::Value> as_value(enum_array_reference.ToValue()); | |
| 108 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; | |
| 109 } | |
| 110 | |
| 111 TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) { | |
| 112 // { "types": ["one", "two", "three"] } | |
| 113 base::ListValue* inline_enums = new base::ListValue(); | |
| 114 inline_enums->AppendString("one"); | |
| 115 inline_enums->AppendString("two"); | |
| 116 inline_enums->AppendString("three"); | |
| 117 | |
| 118 base::ListValue* infile_enums = new base::ListValue(); | |
| 119 infile_enums->AppendString("one"); | |
| 120 infile_enums->AppendString("two"); | |
| 121 infile_enums->AppendString("three"); | |
| 122 | |
| 123 base::ListValue* external_enums = new base::ListValue(); | |
| 124 external_enums->AppendString("one"); | |
| 125 external_enums->AppendString("two"); | |
| 126 external_enums->AppendString("three"); | |
| 127 | |
| 128 base::DictionaryValue value; | |
| 129 value.Set("inline_enums", inline_enums); | |
| 130 value.Set("infile_enums", infile_enums); | |
| 131 value.Set("external_enums", external_enums); | |
| 132 | |
| 133 EnumArrayMixed enum_array_mixed; | |
| 134 | |
| 135 // Test Populate. | |
| 136 ASSERT_TRUE(EnumArrayMixed::Populate(value, &enum_array_mixed)); | |
| 137 | |
| 138 EXPECT_EQ(3u, enum_array_mixed.inline_enums.size()); | |
|
wjywbs
2014/05/16 00:47:37
This is the result of git cl format.
not at google - send to devlin
2014/05/16 17:36:34
ouch.
| |
| 139 EnumArrayMixed::Inline_enumsType expected_inline_types[] = { | |
|
not at google - send to devlin
2014/05/16 17:36:34
... but you don't need to assert size if you're do
wjywbs
2014/05/16 19:12:23
Done.
| |
| 140 EnumArrayMixed::INLINE_ENUMS_TYPE_ONE, | |
| 141 EnumArrayMixed::INLINE_ENUMS_TYPE_TWO, | |
| 142 EnumArrayMixed::INLINE_ENUMS_TYPE_THREE}; | |
| 143 EXPECT_EQ(std::vector<EnumArrayMixed::Inline_enumsType>( | |
| 144 expected_inline_types, | |
| 145 expected_inline_types + arraysize(expected_inline_types)), | |
| 146 enum_array_mixed.inline_enums); | |
| 147 | |
| 148 EXPECT_EQ(3u, enum_array_mixed.infile_enums.size()); | |
| 149 Enumeration expected_infile_types[] = {ENUMERATION_ONE, ENUMERATION_TWO, | |
| 150 ENUMERATION_THREE}; | |
| 151 EXPECT_EQ(std::vector<Enumeration>( | |
| 152 expected_infile_types, | |
| 153 expected_infile_types + arraysize(expected_infile_types)), | |
| 154 enum_array_mixed.infile_enums); | |
| 155 | |
| 156 EXPECT_EQ(3u, enum_array_mixed.external_enums.size()); | |
| 157 test::api::enums::Enumeration expected_external_types[] = { | |
| 158 test::api::enums::ENUMERATION_ONE, test::api::enums::ENUMERATION_TWO, | |
| 159 test::api::enums::ENUMERATION_THREE}; | |
| 160 EXPECT_EQ(std::vector<test::api::enums::Enumeration>( | |
| 161 expected_external_types, | |
| 162 expected_external_types + arraysize(expected_external_types)), | |
| 163 enum_array_mixed.external_enums); | |
| 164 | |
| 165 // Test ToValue. | |
| 166 scoped_ptr<base::Value> as_value(enum_array_mixed.ToValue()); | |
| 167 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; | |
| 168 } | |
| 169 | |
| 83 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { | 170 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { |
| 84 { | 171 { |
| 85 std::vector<OptionalEnumArrayType::TypesType> enums; | 172 std::vector<OptionalEnumArrayType::TypesType> enums; |
| 86 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE); | 173 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE); |
| 87 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO); | 174 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO); |
| 88 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE); | 175 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE); |
| 89 | 176 |
| 90 scoped_ptr<base::ListValue> types(new base::ListValue()); | 177 scoped_ptr<base::ListValue> types(new base::ListValue()); |
| 91 for (size_t i = 0; i < enums.size(); ++i) { | 178 for (size_t i = 0; i < enums.size(); ++i) { |
| 92 types->Append(new base::StringValue( | 179 types->Append(new base::StringValue( |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 base::ListValue* expected_argument = new base::ListValue(); | 313 base::ListValue* expected_argument = new base::ListValue(); |
| 227 base::DictionaryValue* first = new base::DictionaryValue(); | 314 base::DictionaryValue* first = new base::DictionaryValue(); |
| 228 first->SetInteger("val", 1); | 315 first->SetInteger("val", 1); |
| 229 expected_argument->Append(first); | 316 expected_argument->Append(first); |
| 230 base::DictionaryValue* second = new base::DictionaryValue(); | 317 base::DictionaryValue* second = new base::DictionaryValue(); |
| 231 second->SetInteger("val", 2); | 318 second->SetInteger("val", 2); |
| 232 expected_argument->Append(second); | 319 expected_argument->Append(second); |
| 233 expected.Append(expected_argument); | 320 expected.Append(expected_argument); |
| 234 EXPECT_TRUE(results->Equals(&expected)); | 321 EXPECT_TRUE(results->Equals(&expected)); |
| 235 } | 322 } |
| OLD | NEW |