| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/public/cpp/bindings/array.h" | 5 #include "mojo/public/cpp/bindings/array.h" |
| 6 #include "mojo/public/cpp/bindings/lib/array_serialization.h" | 6 #include "mojo/public/cpp/bindings/lib/array_serialization.h" |
| 7 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 7 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
| 9 #include "mojo/public/cpp/bindings/lib/map_serialization.h" | 9 #include "mojo/public/cpp/bindings/lib/map_serialization.h" |
| 10 #include "mojo/public/cpp/bindings/lib/validate_params.h" | 10 #include "mojo/public/cpp/bindings/lib/validate_params.h" |
| 11 #include "mojo/public/cpp/bindings/map.h" | 11 #include "mojo/public/cpp/bindings/map.h" |
| 12 #include "mojo/public/cpp/bindings/string.h" | 12 #include "mojo/public/cpp/bindings/string.h" |
| 13 #include "mojo/public/cpp/bindings/tests/container_test_util.h" | 13 #include "mojo/public/cpp/bindings/tests/container_test_util.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" | |
| 15 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h" | 14 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 16 |
| 18 namespace mojo { | 17 namespace mojo { |
| 19 namespace test { | 18 namespace test { |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 using mojo::internal::Array_Data; | 22 using mojo::internal::Array_Data; |
| 24 using mojo::internal::ArrayValidateParams; | 23 using mojo::internal::ArrayValidateParams; |
| 25 using mojo::internal::FixedBufferForTesting; | 24 using mojo::internal::FixedBufferForTesting; |
| 26 using mojo::internal::Map_Data; | 25 using mojo::internal::Map_Data; |
| 27 using mojo::internal::String_Data; | 26 using mojo::internal::String_Data; |
| 28 using mojo::internal::ValidationError; | 27 using mojo::internal::ValidationError; |
| 29 | 28 |
| 30 struct StringIntData { | 29 struct StringIntData { |
| 31 const char* string_data; | 30 const char* string_data; |
| 32 int int_data; | 31 int int_data; |
| 33 } kStringIntData[] = { | 32 } kStringIntData[] = { |
| 34 {"one", 1}, | 33 {"one", 1}, |
| 35 {"two", 2}, | 34 {"two", 2}, |
| 36 {"three", 3}, | 35 {"three", 3}, |
| 37 {"four", 4}, | 36 {"four", 4}, |
| 38 }; | 37 }; |
| 39 | 38 |
| 40 const size_t kStringIntDataSize = 4; | 39 const size_t kStringIntDataSize = 4; |
| 41 | 40 |
| 42 class MapTest : public testing::Test { | 41 TEST(MapTest, Testability) { |
| 43 public: | |
| 44 ~MapTest() override {} | |
| 45 | |
| 46 private: | |
| 47 Environment env_; | |
| 48 }; | |
| 49 | |
| 50 TEST_F(MapTest, Testability) { | |
| 51 Map<int32_t, int32_t> map; | 42 Map<int32_t, int32_t> map; |
| 52 EXPECT_FALSE(map); | 43 EXPECT_FALSE(map); |
| 53 EXPECT_TRUE(map.is_null()); | 44 EXPECT_TRUE(map.is_null()); |
| 54 | 45 |
| 55 map[123] = 456; | 46 map[123] = 456; |
| 56 EXPECT_TRUE(map); | 47 EXPECT_TRUE(map); |
| 57 EXPECT_FALSE(map.is_null()); | 48 EXPECT_FALSE(map.is_null()); |
| 58 } | 49 } |
| 59 | 50 |
| 60 // Tests that basic Map operations work. | 51 // Tests that basic Map operations work. |
| 61 TEST_F(MapTest, InsertWorks) { | 52 TEST(MapTest, InsertWorks) { |
| 62 Map<String, int> map; | 53 Map<String, int> map; |
| 63 for (size_t i = 0; i < kStringIntDataSize; ++i) | 54 for (size_t i = 0; i < kStringIntDataSize; ++i) |
| 64 map.insert(kStringIntData[i].string_data, kStringIntData[i].int_data); | 55 map.insert(kStringIntData[i].string_data, kStringIntData[i].int_data); |
| 65 | 56 |
| 66 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 57 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 67 EXPECT_EQ(kStringIntData[i].int_data, | 58 EXPECT_EQ(kStringIntData[i].int_data, |
| 68 map.at(kStringIntData[i].string_data)); | 59 map.at(kStringIntData[i].string_data)); |
| 69 } | 60 } |
| 70 } | 61 } |
| 71 | 62 |
| 72 TEST_F(MapTest, TestIndexOperator) { | 63 TEST(MapTest, TestIndexOperator) { |
| 73 Map<String, int> map; | 64 Map<String, int> map; |
| 74 for (size_t i = 0; i < kStringIntDataSize; ++i) | 65 for (size_t i = 0; i < kStringIntDataSize; ++i) |
| 75 map[kStringIntData[i].string_data] = kStringIntData[i].int_data; | 66 map[kStringIntData[i].string_data] = kStringIntData[i].int_data; |
| 76 | 67 |
| 77 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 68 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 78 EXPECT_EQ(kStringIntData[i].int_data, | 69 EXPECT_EQ(kStringIntData[i].int_data, |
| 79 map.at(kStringIntData[i].string_data)); | 70 map.at(kStringIntData[i].string_data)); |
| 80 } | 71 } |
| 81 } | 72 } |
| 82 | 73 |
| 83 TEST_F(MapTest, TestIndexOperatorAsRValue) { | 74 TEST(MapTest, TestIndexOperatorAsRValue) { |
| 84 Map<String, int> map; | 75 Map<String, int> map; |
| 85 for (size_t i = 0; i < kStringIntDataSize; ++i) | 76 for (size_t i = 0; i < kStringIntDataSize; ++i) |
| 86 map.insert(kStringIntData[i].string_data, kStringIntData[i].int_data); | 77 map.insert(kStringIntData[i].string_data, kStringIntData[i].int_data); |
| 87 | 78 |
| 88 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 79 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 89 EXPECT_EQ(kStringIntData[i].int_data, map[kStringIntData[i].string_data]); | 80 EXPECT_EQ(kStringIntData[i].int_data, map[kStringIntData[i].string_data]); |
| 90 } | 81 } |
| 91 } | 82 } |
| 92 | 83 |
| 93 TEST_F(MapTest, TestIndexOperatorMoveOnly) { | 84 TEST(MapTest, TestIndexOperatorMoveOnly) { |
| 94 ASSERT_EQ(0u, MoveOnlyType::num_instances()); | 85 ASSERT_EQ(0u, MoveOnlyType::num_instances()); |
| 95 mojo::Map<mojo::String, mojo::Array<int32_t>> map; | 86 mojo::Map<mojo::String, mojo::Array<int32_t>> map; |
| 96 std::vector<MoveOnlyType*> value_ptrs; | 87 std::vector<MoveOnlyType*> value_ptrs; |
| 97 | 88 |
| 98 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 89 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 99 const char* key = kStringIntData[i].string_data; | 90 const char* key = kStringIntData[i].string_data; |
| 100 auto array = Array<int32_t>::New(1); | 91 auto array = Array<int32_t>::New(1); |
| 101 array[0] = kStringIntData[i].int_data; | 92 array[0] = kStringIntData[i].int_data; |
| 102 map[key] = array.Pass(); | 93 map[key] = array.Pass(); |
| 103 EXPECT_TRUE(map); | 94 EXPECT_TRUE(map); |
| 104 } | 95 } |
| 105 | 96 |
| 106 // We now read back that data, to test the behavior of operator[]. | 97 // We now read back that data, to test the behavior of operator[]. |
| 107 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 98 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 108 auto it = map.find(kStringIntData[i].string_data); | 99 auto it = map.find(kStringIntData[i].string_data); |
| 109 ASSERT_TRUE(it != map.end()); | 100 ASSERT_TRUE(it != map.end()); |
| 110 ASSERT_EQ(1u, it.GetValue().size()); | 101 ASSERT_EQ(1u, it.GetValue().size()); |
| 111 EXPECT_EQ(kStringIntData[i].int_data, it.GetValue()[0]); | 102 EXPECT_EQ(kStringIntData[i].int_data, it.GetValue()[0]); |
| 112 } | 103 } |
| 113 } | 104 } |
| 114 | 105 |
| 115 TEST_F(MapTest, ConstructedFromArray) { | 106 TEST(MapTest, ConstructedFromArray) { |
| 116 auto keys = Array<String>::New(kStringIntDataSize); | 107 auto keys = Array<String>::New(kStringIntDataSize); |
| 117 auto values = Array<int>::New(kStringIntDataSize); | 108 auto values = Array<int>::New(kStringIntDataSize); |
| 118 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 109 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 119 keys[i] = kStringIntData[i].string_data; | 110 keys[i] = kStringIntData[i].string_data; |
| 120 values[i] = kStringIntData[i].int_data; | 111 values[i] = kStringIntData[i].int_data; |
| 121 } | 112 } |
| 122 | 113 |
| 123 Map<String, int> map(keys.Pass(), values.Pass()); | 114 Map<String, int> map(keys.Pass(), values.Pass()); |
| 124 | 115 |
| 125 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 116 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 126 EXPECT_EQ(kStringIntData[i].int_data, | 117 EXPECT_EQ(kStringIntData[i].int_data, |
| 127 map.at(mojo::String(kStringIntData[i].string_data))); | 118 map.at(mojo::String(kStringIntData[i].string_data))); |
| 128 } | 119 } |
| 129 } | 120 } |
| 130 | 121 |
| 131 TEST_F(MapTest, Insert_Copyable) { | 122 TEST(MapTest, Insert_Copyable) { |
| 132 ASSERT_EQ(0u, CopyableType::num_instances()); | 123 ASSERT_EQ(0u, CopyableType::num_instances()); |
| 133 mojo::Map<mojo::String, CopyableType> map; | 124 mojo::Map<mojo::String, CopyableType> map; |
| 134 std::vector<CopyableType*> value_ptrs; | 125 std::vector<CopyableType*> value_ptrs; |
| 135 | 126 |
| 136 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 127 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 137 const char* key = kStringIntData[i].string_data; | 128 const char* key = kStringIntData[i].string_data; |
| 138 CopyableType value; | 129 CopyableType value; |
| 139 value_ptrs.push_back(value.ptr()); | 130 value_ptrs.push_back(value.ptr()); |
| 140 map.insert(key, value); | 131 map.insert(key, value); |
| 141 ASSERT_EQ(i + 1, map.size()); | 132 ASSERT_EQ(i + 1, map.size()); |
| 142 ASSERT_EQ(i + 1, value_ptrs.size()); | 133 ASSERT_EQ(i + 1, value_ptrs.size()); |
| 143 EXPECT_EQ(map.size() + 1, CopyableType::num_instances()); | 134 EXPECT_EQ(map.size() + 1, CopyableType::num_instances()); |
| 144 EXPECT_TRUE(map.at(key).copied()); | 135 EXPECT_TRUE(map.at(key).copied()); |
| 145 EXPECT_EQ(value_ptrs[i], map.at(key).ptr()); | 136 EXPECT_EQ(value_ptrs[i], map.at(key).ptr()); |
| 146 map.at(key).ResetCopied(); | 137 map.at(key).ResetCopied(); |
| 147 EXPECT_TRUE(map); | 138 EXPECT_TRUE(map); |
| 148 } | 139 } |
| 149 | 140 |
| 150 // std::map doesn't have a capacity() method like std::vector so this test is | 141 // std::map doesn't have a capacity() method like std::vector so this test is |
| 151 // a lot more boring. | 142 // a lot more boring. |
| 152 | 143 |
| 153 map.reset(); | 144 map.reset(); |
| 154 EXPECT_EQ(0u, CopyableType::num_instances()); | 145 EXPECT_EQ(0u, CopyableType::num_instances()); |
| 155 } | 146 } |
| 156 | 147 |
| 157 TEST_F(MapTest, Insert_MoveOnly) { | 148 TEST(MapTest, Insert_MoveOnly) { |
| 158 ASSERT_EQ(0u, MoveOnlyType::num_instances()); | 149 ASSERT_EQ(0u, MoveOnlyType::num_instances()); |
| 159 mojo::Map<mojo::String, MoveOnlyType> map; | 150 mojo::Map<mojo::String, MoveOnlyType> map; |
| 160 std::vector<MoveOnlyType*> value_ptrs; | 151 std::vector<MoveOnlyType*> value_ptrs; |
| 161 | 152 |
| 162 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 153 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 163 const char* key = kStringIntData[i].string_data; | 154 const char* key = kStringIntData[i].string_data; |
| 164 MoveOnlyType value; | 155 MoveOnlyType value; |
| 165 value_ptrs.push_back(value.ptr()); | 156 value_ptrs.push_back(value.ptr()); |
| 166 map.insert(key, value.Pass()); | 157 map.insert(key, value.Pass()); |
| 167 ASSERT_EQ(i + 1, map.size()); | 158 ASSERT_EQ(i + 1, map.size()); |
| 168 ASSERT_EQ(i + 1, value_ptrs.size()); | 159 ASSERT_EQ(i + 1, value_ptrs.size()); |
| 169 EXPECT_EQ(map.size() + 1, MoveOnlyType::num_instances()); | 160 EXPECT_EQ(map.size() + 1, MoveOnlyType::num_instances()); |
| 170 EXPECT_TRUE(map.at(key).moved()); | 161 EXPECT_TRUE(map.at(key).moved()); |
| 171 EXPECT_EQ(value_ptrs[i], map.at(key).ptr()); | 162 EXPECT_EQ(value_ptrs[i], map.at(key).ptr()); |
| 172 map.at(key).ResetMoved(); | 163 map.at(key).ResetMoved(); |
| 173 EXPECT_TRUE(map); | 164 EXPECT_TRUE(map); |
| 174 } | 165 } |
| 175 | 166 |
| 176 // std::map doesn't have a capacity() method like std::vector so this test is | 167 // std::map doesn't have a capacity() method like std::vector so this test is |
| 177 // a lot more boring. | 168 // a lot more boring. |
| 178 | 169 |
| 179 map.reset(); | 170 map.reset(); |
| 180 EXPECT_EQ(0u, MoveOnlyType::num_instances()); | 171 EXPECT_EQ(0u, MoveOnlyType::num_instances()); |
| 181 } | 172 } |
| 182 | 173 |
| 183 TEST_F(MapTest, IndexOperator_MoveOnly) { | 174 TEST(MapTest, IndexOperator_MoveOnly) { |
| 184 ASSERT_EQ(0u, MoveOnlyType::num_instances()); | 175 ASSERT_EQ(0u, MoveOnlyType::num_instances()); |
| 185 mojo::Map<mojo::String, MoveOnlyType> map; | 176 mojo::Map<mojo::String, MoveOnlyType> map; |
| 186 std::vector<MoveOnlyType*> value_ptrs; | 177 std::vector<MoveOnlyType*> value_ptrs; |
| 187 | 178 |
| 188 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 179 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 189 const char* key = kStringIntData[i].string_data; | 180 const char* key = kStringIntData[i].string_data; |
| 190 MoveOnlyType value; | 181 MoveOnlyType value; |
| 191 value_ptrs.push_back(value.ptr()); | 182 value_ptrs.push_back(value.ptr()); |
| 192 map[key] = value.Pass(); | 183 map[key] = value.Pass(); |
| 193 ASSERT_EQ(i + 1, map.size()); | 184 ASSERT_EQ(i + 1, map.size()); |
| 194 ASSERT_EQ(i + 1, value_ptrs.size()); | 185 ASSERT_EQ(i + 1, value_ptrs.size()); |
| 195 EXPECT_EQ(map.size() + 1, MoveOnlyType::num_instances()); | 186 EXPECT_EQ(map.size() + 1, MoveOnlyType::num_instances()); |
| 196 EXPECT_TRUE(map.at(key).moved()); | 187 EXPECT_TRUE(map.at(key).moved()); |
| 197 EXPECT_EQ(value_ptrs[i], map.at(key).ptr()); | 188 EXPECT_EQ(value_ptrs[i], map.at(key).ptr()); |
| 198 map.at(key).ResetMoved(); | 189 map.at(key).ResetMoved(); |
| 199 EXPECT_TRUE(map); | 190 EXPECT_TRUE(map); |
| 200 } | 191 } |
| 201 | 192 |
| 202 // std::map doesn't have a capacity() method like std::vector so this test is | 193 // std::map doesn't have a capacity() method like std::vector so this test is |
| 203 // a lot more boring. | 194 // a lot more boring. |
| 204 | 195 |
| 205 map.reset(); | 196 map.reset(); |
| 206 EXPECT_EQ(0u, MoveOnlyType::num_instances()); | 197 EXPECT_EQ(0u, MoveOnlyType::num_instances()); |
| 207 } | 198 } |
| 208 | 199 |
| 209 TEST_F(MapTest, STLToMojo) { | 200 TEST(MapTest, STLToMojo) { |
| 210 std::map<std::string, int> stl_data; | 201 std::map<std::string, int> stl_data; |
| 211 for (size_t i = 0; i < kStringIntDataSize; ++i) | 202 for (size_t i = 0; i < kStringIntDataSize; ++i) |
| 212 stl_data[kStringIntData[i].string_data] = kStringIntData[i].int_data; | 203 stl_data[kStringIntData[i].string_data] = kStringIntData[i].int_data; |
| 213 | 204 |
| 214 Map<String, int32_t> mojo_data = Map<String, int32_t>::From(stl_data); | 205 Map<String, int32_t> mojo_data = Map<String, int32_t>::From(stl_data); |
| 215 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 206 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 216 EXPECT_EQ(kStringIntData[i].int_data, | 207 EXPECT_EQ(kStringIntData[i].int_data, |
| 217 mojo_data.at(kStringIntData[i].string_data)); | 208 mojo_data.at(kStringIntData[i].string_data)); |
| 218 } | 209 } |
| 219 } | 210 } |
| 220 | 211 |
| 221 TEST_F(MapTest, MojoToSTL) { | 212 TEST(MapTest, MojoToSTL) { |
| 222 Map<String, int32_t> mojo_map; | 213 Map<String, int32_t> mojo_map; |
| 223 for (size_t i = 0; i < kStringIntDataSize; ++i) | 214 for (size_t i = 0; i < kStringIntDataSize; ++i) |
| 224 mojo_map.insert(kStringIntData[i].string_data, kStringIntData[i].int_data); | 215 mojo_map.insert(kStringIntData[i].string_data, kStringIntData[i].int_data); |
| 225 | 216 |
| 226 std::map<std::string, int> stl_map = | 217 std::map<std::string, int> stl_map = |
| 227 mojo_map.To<std::map<std::string, int>>(); | 218 mojo_map.To<std::map<std::string, int>>(); |
| 228 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 219 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 229 auto it = stl_map.find(kStringIntData[i].string_data); | 220 auto it = stl_map.find(kStringIntData[i].string_data); |
| 230 ASSERT_TRUE(it != stl_map.end()); | 221 ASSERT_TRUE(it != stl_map.end()); |
| 231 EXPECT_EQ(kStringIntData[i].int_data, it->second); | 222 EXPECT_EQ(kStringIntData[i].int_data, it->second); |
| 232 } | 223 } |
| 233 } | 224 } |
| 234 | 225 |
| 235 TEST_F(MapTest, MapArrayClone) { | 226 TEST(MapTest, MapArrayClone) { |
| 236 Map<String, Array<String>> m; | 227 Map<String, Array<String>> m; |
| 237 for (size_t i = 0; i < kStringIntDataSize; ++i) { | 228 for (size_t i = 0; i < kStringIntDataSize; ++i) { |
| 238 Array<String> s; | 229 Array<String> s; |
| 239 s.push_back(kStringIntData[i].string_data); | 230 s.push_back(kStringIntData[i].string_data); |
| 240 m.insert(kStringIntData[i].string_data, s.Pass()); | 231 m.insert(kStringIntData[i].string_data, s.Pass()); |
| 241 } | 232 } |
| 242 | 233 |
| 243 Map<String, Array<String>> m2 = m.Clone(); | 234 Map<String, Array<String>> m2 = m.Clone(); |
| 244 | 235 |
| 245 for (auto it = m2.begin(); it != m2.end(); ++it) { | 236 for (auto it = m2.begin(); it != m2.end(); ++it) { |
| 246 ASSERT_EQ(1u, it.GetValue().size()); | 237 ASSERT_EQ(1u, it.GetValue().size()); |
| 247 EXPECT_EQ(it.GetKey(), it.GetValue().at(0)); | 238 EXPECT_EQ(it.GetKey(), it.GetValue().at(0)); |
| 248 } | 239 } |
| 249 } | 240 } |
| 250 | 241 |
| 251 TEST_F(MapTest, ArrayOfMap) { | 242 TEST(MapTest, ArrayOfMap) { |
| 252 { | 243 { |
| 253 auto array = Array<Map<int32_t, int8_t>>::New(1); | 244 auto array = Array<Map<int32_t, int8_t>>::New(1); |
| 254 array[0].insert(1, 42); | 245 array[0].insert(1, 42); |
| 255 | 246 |
| 256 size_t size = GetSerializedSize_(array); | 247 size_t size = GetSerializedSize_(array); |
| 257 FixedBufferForTesting buf(size); | 248 FixedBufferForTesting buf(size); |
| 258 Array_Data<Map_Data<int32_t, int8_t>*>* data = nullptr; | 249 Array_Data<Map_Data<int32_t, int8_t>*>* data = nullptr; |
| 259 ArrayValidateParams validate_params( | 250 ArrayValidateParams validate_params( |
| 260 0, false, new ArrayValidateParams(0, false, nullptr)); | 251 0, false, new ArrayValidateParams(0, false, nullptr)); |
| 261 EXPECT_EQ(ValidationError::NONE, | 252 EXPECT_EQ(ValidationError::NONE, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 288 Array<Map<String, Array<bool>>> deserialized_array; | 279 Array<Map<String, Array<bool>>> deserialized_array; |
| 289 Deserialize_(data, &deserialized_array); | 280 Deserialize_(data, &deserialized_array); |
| 290 | 281 |
| 291 ASSERT_EQ(1u, deserialized_array.size()); | 282 ASSERT_EQ(1u, deserialized_array.size()); |
| 292 ASSERT_EQ(1u, deserialized_array[0].size()); | 283 ASSERT_EQ(1u, deserialized_array[0].size()); |
| 293 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); | 284 ASSERT_FALSE(deserialized_array[0].at("hello world")[0]); |
| 294 ASSERT_TRUE(deserialized_array[0].at("hello world")[1]); | 285 ASSERT_TRUE(deserialized_array[0].at("hello world")[1]); |
| 295 } | 286 } |
| 296 } | 287 } |
| 297 | 288 |
| 298 TEST_F(MapTest, Serialization_MapWithScopedEnumKeys) { | 289 TEST(MapTest, Serialization_MapWithScopedEnumKeys) { |
| 299 enum class TestEnum : int32_t { | 290 enum class TestEnum : int32_t { |
| 300 E0, | 291 E0, |
| 301 E1, | 292 E1, |
| 302 E2, | 293 E2, |
| 303 E3, | 294 E3, |
| 304 }; | 295 }; |
| 305 static const TestEnum TEST_KEYS[] = { | 296 static const TestEnum TEST_KEYS[] = { |
| 306 TestEnum::E0, TestEnum::E2, TestEnum::E1, TestEnum::E3, | 297 TestEnum::E0, TestEnum::E2, TestEnum::E1, TestEnum::E3, |
| 307 }; | 298 }; |
| 308 static const uint32_t TEST_VALS[] = {17, 29, 5, 61}; | 299 static const uint32_t TEST_VALS[] = {17, 29, 5, 61}; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 330 ASSERT_NE(test_map2.find(iter.GetKey()), test_map2.end()); | 321 ASSERT_NE(test_map2.find(iter.GetKey()), test_map2.end()); |
| 331 EXPECT_EQ(test_map.at(iter.GetKey()), test_map.at(iter.GetKey())); | 322 EXPECT_EQ(test_map.at(iter.GetKey()), test_map.at(iter.GetKey())); |
| 332 } | 323 } |
| 333 | 324 |
| 334 for (auto iter = test_map2.cbegin(); iter != test_map2.cend(); ++iter) { | 325 for (auto iter = test_map2.cbegin(); iter != test_map2.cend(); ++iter) { |
| 335 ASSERT_NE(test_map.find(iter.GetKey()), test_map.end()); | 326 ASSERT_NE(test_map.find(iter.GetKey()), test_map.end()); |
| 336 EXPECT_EQ(test_map2.at(iter.GetKey()), test_map2.at(iter.GetKey())); | 327 EXPECT_EQ(test_map2.at(iter.GetKey()), test_map2.at(iter.GetKey())); |
| 337 } | 328 } |
| 338 } | 329 } |
| 339 | 330 |
| 340 TEST_F(MapTest, Serialization_MapWithScopedEnumVals) { | 331 TEST(MapTest, Serialization_MapWithScopedEnumVals) { |
| 341 enum class TestEnum : int32_t { | 332 enum class TestEnum : int32_t { |
| 342 E0, | 333 E0, |
| 343 E1, | 334 E1, |
| 344 E2, | 335 E2, |
| 345 E3, | 336 E3, |
| 346 }; | 337 }; |
| 347 static const uint32_t TEST_KEYS[] = {17, 29, 5, 61}; | 338 static const uint32_t TEST_KEYS[] = {17, 29, 5, 61}; |
| 348 static const TestEnum TEST_VALS[] = { | 339 static const TestEnum TEST_VALS[] = { |
| 349 TestEnum::E0, TestEnum::E2, TestEnum::E1, TestEnum::E3, | 340 TestEnum::E0, TestEnum::E2, TestEnum::E1, TestEnum::E3, |
| 350 }; | 341 }; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 373 EXPECT_EQ(test_map.at(iter.GetKey()), test_map.at(iter.GetKey())); | 364 EXPECT_EQ(test_map.at(iter.GetKey()), test_map.at(iter.GetKey())); |
| 374 } | 365 } |
| 375 | 366 |
| 376 for (auto iter = test_map2.cbegin(); iter != test_map2.cend(); ++iter) { | 367 for (auto iter = test_map2.cbegin(); iter != test_map2.cend(); ++iter) { |
| 377 ASSERT_NE(test_map.find(iter.GetKey()), test_map.end()); | 368 ASSERT_NE(test_map.find(iter.GetKey()), test_map.end()); |
| 378 EXPECT_EQ(test_map2.at(iter.GetKey()), test_map2.at(iter.GetKey())); | 369 EXPECT_EQ(test_map2.at(iter.GetKey()), test_map2.at(iter.GetKey())); |
| 379 } | 370 } |
| 380 } | 371 } |
| 381 | 372 |
| 382 // Test serialization/deserialization of a map with null elements. | 373 // Test serialization/deserialization of a map with null elements. |
| 383 TEST_F(MapTest, Serialization_MapOfNullableStructs) { | 374 TEST(MapTest, Serialization_MapOfNullableStructs) { |
| 384 ArrayValidateParams validate_nullable(2, true, nullptr); | 375 ArrayValidateParams validate_nullable(2, true, nullptr); |
| 385 ArrayValidateParams validate_non_nullable(2, false, nullptr); | 376 ArrayValidateParams validate_non_nullable(2, false, nullptr); |
| 386 | 377 |
| 387 Map<uint32_t, RectPtr> map; | 378 Map<uint32_t, RectPtr> map; |
| 388 map[0] = RectPtr(); | 379 map[0] = RectPtr(); |
| 389 map[1] = Rect::New(); | 380 map[1] = Rect::New(); |
| 390 map[1]->x = 1; | 381 map[1]->x = 1; |
| 391 map[1]->y = 2; | 382 map[1]->y = 2; |
| 392 map[1]->width = 3; | 383 map[1]->width = 3; |
| 393 map[1]->height = 4; | 384 map[1]->height = 4; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 EXPECT_FALSE(map2[1].is_null()); | 420 EXPECT_FALSE(map2[1].is_null()); |
| 430 EXPECT_EQ(1, map2[1]->x); | 421 EXPECT_EQ(1, map2[1]->x); |
| 431 EXPECT_EQ(2, map2[1]->y); | 422 EXPECT_EQ(2, map2[1]->y); |
| 432 EXPECT_EQ(3, map2[1]->width); | 423 EXPECT_EQ(3, map2[1]->width); |
| 433 EXPECT_EQ(4, map2[1]->height); | 424 EXPECT_EQ(4, map2[1]->height); |
| 434 } | 425 } |
| 435 | 426 |
| 436 } // namespace | 427 } // namespace |
| 437 } // namespace test | 428 } // namespace test |
| 438 } // namespace mojo | 429 } // namespace mojo |
| OLD | NEW |