| 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 #include "tools/json_schema_compiler/test/enums.h" |
| 9 | 9 |
| 10 using namespace test::api::arrays; | 10 using namespace test::api::arrays; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) { | 46 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) { |
| 47 { | 47 { |
| 48 scoped_ptr<base::DictionaryValue> value = CreateBasicArrayTypeDictionary(); | 48 scoped_ptr<base::DictionaryValue> value = CreateBasicArrayTypeDictionary(); |
| 49 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType()); | 49 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType()); |
| 50 ASSERT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get())); | 50 ASSERT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get())); |
| 51 EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get())); | 51 EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get())); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 TEST(JsonSchemaCompilerArrayTest, EnumArrayType) { | |
| 56 // { "types": ["one", "two", "three"] } | |
| 57 base::ListValue* types = new base::ListValue(); | |
| 58 types->AppendString("one"); | |
| 59 types->AppendString("two"); | |
| 60 types->AppendString("three"); | |
| 61 base::DictionaryValue value; | |
| 62 value.Set("types", types); | |
| 63 | |
| 64 EnumArrayType enum_array_type; | |
| 65 | |
| 66 // Test Populate. | |
| 67 ASSERT_TRUE(EnumArrayType::Populate(value, &enum_array_type)); | |
| 68 { | |
| 69 EnumArrayType::TypesType enums[] = { | |
| 70 EnumArrayType::TYPES_TYPE_ONE, | |
| 71 EnumArrayType::TYPES_TYPE_TWO, | |
| 72 EnumArrayType::TYPES_TYPE_THREE, | |
| 73 }; | |
| 74 std::vector<EnumArrayType::TypesType> enums_vector( | |
| 75 enums, enums + arraysize(enums)); | |
| 76 EXPECT_EQ(enums_vector, enum_array_type.types); | |
| 77 } | |
| 78 | |
| 79 // Test ToValue. | |
| 80 scoped_ptr<base::Value> as_value(enum_array_type.ToValue()); | |
| 81 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; | |
| 82 } | |
| 83 | |
| 84 TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) { | 55 TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) { |
| 85 // { "types": ["one", "two", "three"] } | 56 // { "types": ["one", "two", "three"] } |
| 86 base::ListValue* types = new base::ListValue(); | 57 base::ListValue* types = new base::ListValue(); |
| 87 types->AppendString("one"); | 58 types->AppendString("one"); |
| 88 types->AppendString("two"); | 59 types->AppendString("two"); |
| 89 types->AppendString("three"); | 60 types->AppendString("three"); |
| 90 base::DictionaryValue value; | 61 base::DictionaryValue value; |
| 91 value.Set("types", types); | 62 value.Set("types", types); |
| 92 | 63 |
| 93 EnumArrayReference enum_array_reference; | 64 EnumArrayReference enum_array_reference; |
| 94 | 65 |
| 95 // Test Populate. | 66 // Test Populate. |
| 96 ASSERT_TRUE(EnumArrayReference::Populate(value, &enum_array_reference)); | 67 ASSERT_TRUE(EnumArrayReference::Populate(value, &enum_array_reference)); |
| 97 | 68 |
| 98 Enumeration expected_types[] = {ENUMERATION_ONE, ENUMERATION_TWO, | 69 Enumeration expected_types[] = {ENUMERATION_ONE, ENUMERATION_TWO, |
| 99 ENUMERATION_THREE}; | 70 ENUMERATION_THREE}; |
| 100 EXPECT_EQ(std::vector<Enumeration>( | 71 EXPECT_EQ(std::vector<Enumeration>( |
| 101 expected_types, expected_types + arraysize(expected_types)), | 72 expected_types, expected_types + arraysize(expected_types)), |
| 102 enum_array_reference.types); | 73 enum_array_reference.types); |
| 103 | 74 |
| 104 // Test ToValue. | 75 // Test ToValue. |
| 105 scoped_ptr<base::Value> as_value(enum_array_reference.ToValue()); | 76 scoped_ptr<base::Value> as_value(enum_array_reference.ToValue()); |
| 106 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; | 77 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; |
| 107 } | 78 } |
| 108 | 79 |
| 109 TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) { | 80 TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) { |
| 110 // { "types": ["one", "two", "three"] } | 81 // { "types": ["one", "two", "three"] } |
| 111 base::ListValue* inline_enums = new base::ListValue(); | |
| 112 inline_enums->AppendString("one"); | |
| 113 inline_enums->AppendString("two"); | |
| 114 inline_enums->AppendString("three"); | |
| 115 | |
| 116 base::ListValue* infile_enums = new base::ListValue(); | 82 base::ListValue* infile_enums = new base::ListValue(); |
| 117 infile_enums->AppendString("one"); | 83 infile_enums->AppendString("one"); |
| 118 infile_enums->AppendString("two"); | 84 infile_enums->AppendString("two"); |
| 119 infile_enums->AppendString("three"); | 85 infile_enums->AppendString("three"); |
| 120 | 86 |
| 121 base::ListValue* external_enums = new base::ListValue(); | 87 base::ListValue* external_enums = new base::ListValue(); |
| 122 external_enums->AppendString("one"); | 88 external_enums->AppendString("one"); |
| 123 external_enums->AppendString("two"); | 89 external_enums->AppendString("two"); |
| 124 external_enums->AppendString("three"); | 90 external_enums->AppendString("three"); |
| 125 | 91 |
| 126 base::DictionaryValue value; | 92 base::DictionaryValue value; |
| 127 value.Set("inline_enums", inline_enums); | |
| 128 value.Set("infile_enums", infile_enums); | 93 value.Set("infile_enums", infile_enums); |
| 129 value.Set("external_enums", external_enums); | 94 value.Set("external_enums", external_enums); |
| 130 | 95 |
| 131 EnumArrayMixed enum_array_mixed; | 96 EnumArrayMixed enum_array_mixed; |
| 132 | 97 |
| 133 // Test Populate. | 98 // Test Populate. |
| 134 ASSERT_TRUE(EnumArrayMixed::Populate(value, &enum_array_mixed)); | 99 ASSERT_TRUE(EnumArrayMixed::Populate(value, &enum_array_mixed)); |
| 135 | 100 |
| 136 EnumArrayMixed::Inline_enumsType expected_inline_types[] = { | |
| 137 EnumArrayMixed::INLINE_ENUMS_TYPE_ONE, | |
| 138 EnumArrayMixed::INLINE_ENUMS_TYPE_TWO, | |
| 139 EnumArrayMixed::INLINE_ENUMS_TYPE_THREE}; | |
| 140 EXPECT_EQ(std::vector<EnumArrayMixed::Inline_enumsType>( | |
| 141 expected_inline_types, | |
| 142 expected_inline_types + arraysize(expected_inline_types)), | |
| 143 enum_array_mixed.inline_enums); | |
| 144 | |
| 145 Enumeration expected_infile_types[] = {ENUMERATION_ONE, ENUMERATION_TWO, | 101 Enumeration expected_infile_types[] = {ENUMERATION_ONE, ENUMERATION_TWO, |
| 146 ENUMERATION_THREE}; | 102 ENUMERATION_THREE}; |
| 147 EXPECT_EQ(std::vector<Enumeration>( | 103 EXPECT_EQ(std::vector<Enumeration>( |
| 148 expected_infile_types, | 104 expected_infile_types, |
| 149 expected_infile_types + arraysize(expected_infile_types)), | 105 expected_infile_types + arraysize(expected_infile_types)), |
| 150 enum_array_mixed.infile_enums); | 106 enum_array_mixed.infile_enums); |
| 151 | 107 |
| 152 test::api::enums::Enumeration expected_external_types[] = { | 108 test::api::enums::Enumeration expected_external_types[] = { |
| 153 test::api::enums::ENUMERATION_ONE, test::api::enums::ENUMERATION_TWO, | 109 test::api::enums::ENUMERATION_ONE, test::api::enums::ENUMERATION_TWO, |
| 154 test::api::enums::ENUMERATION_THREE}; | 110 test::api::enums::ENUMERATION_THREE}; |
| 155 EXPECT_EQ(std::vector<test::api::enums::Enumeration>( | 111 EXPECT_EQ(std::vector<test::api::enums::Enumeration>( |
| 156 expected_external_types, | 112 expected_external_types, |
| 157 expected_external_types + arraysize(expected_external_types)), | 113 expected_external_types + arraysize(expected_external_types)), |
| 158 enum_array_mixed.external_enums); | 114 enum_array_mixed.external_enums); |
| 159 | 115 |
| 160 // Test ToValue. | 116 // Test ToValue. |
| 161 scoped_ptr<base::Value> as_value(enum_array_mixed.ToValue()); | 117 scoped_ptr<base::Value> as_value(enum_array_mixed.ToValue()); |
| 162 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; | 118 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; |
| 163 } | 119 } |
| 164 | 120 |
| 165 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { | 121 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { |
| 166 { | 122 { |
| 167 std::vector<OptionalEnumArrayType::TypesType> enums; | 123 std::vector<Enumeration> enums; |
| 168 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE); | 124 enums.push_back(ENUMERATION_ONE); |
| 169 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO); | 125 enums.push_back(ENUMERATION_TWO); |
| 170 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE); | 126 enums.push_back(ENUMERATION_THREE); |
| 171 | 127 |
| 172 scoped_ptr<base::ListValue> types(new base::ListValue()); | 128 scoped_ptr<base::ListValue> types(new base::ListValue()); |
| 173 for (size_t i = 0; i < enums.size(); ++i) { | 129 for (size_t i = 0; i < enums.size(); ++i) |
| 174 types->Append(new base::StringValue( | 130 types->Append(new base::StringValue(ToString(enums[i]))); |
| 175 OptionalEnumArrayType::ToString(enums[i]))); | |
| 176 } | |
| 177 | 131 |
| 178 base::DictionaryValue value; | 132 base::DictionaryValue value; |
| 179 value.Set("types", types.release()); | 133 value.Set("types", types.release()); |
| 180 | 134 |
| 181 OptionalEnumArrayType enum_array_type; | 135 OptionalEnumArrayType enum_array_type; |
| 182 ASSERT_TRUE(OptionalEnumArrayType::Populate(value, &enum_array_type)); | 136 ASSERT_TRUE(OptionalEnumArrayType::Populate(value, &enum_array_type)); |
| 183 EXPECT_EQ(enums, *enum_array_type.types); | 137 EXPECT_EQ(enums, *enum_array_type.types); |
| 184 } | 138 } |
| 185 { | 139 { |
| 186 base::DictionaryValue value; | 140 base::DictionaryValue value; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 base::ListValue* expected_argument = new base::ListValue(); | 262 base::ListValue* expected_argument = new base::ListValue(); |
| 309 base::DictionaryValue* first = new base::DictionaryValue(); | 263 base::DictionaryValue* first = new base::DictionaryValue(); |
| 310 first->SetInteger("val", 1); | 264 first->SetInteger("val", 1); |
| 311 expected_argument->Append(first); | 265 expected_argument->Append(first); |
| 312 base::DictionaryValue* second = new base::DictionaryValue(); | 266 base::DictionaryValue* second = new base::DictionaryValue(); |
| 313 second->SetInteger("val", 2); | 267 second->SetInteger("val", 2); |
| 314 expected_argument->Append(second); | 268 expected_argument->Append(second); |
| 315 expected.Append(expected_argument); | 269 expected.Append(expected_argument); |
| 316 EXPECT_TRUE(results->Equals(&expected)); | 270 EXPECT_TRUE(results->Equals(&expected)); |
| 317 } | 271 } |
| OLD | NEW |