| 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/map.h" | 5 #include "mojo/public/cpp/bindings/map.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <unordered_map> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "mojo/public/cpp/bindings/array.h" | 12 #include "mojo/public/cpp/bindings/array.h" |
| 12 #include "mojo/public/cpp/bindings/string.h" | 13 #include "mojo/public/cpp/bindings/string.h" |
| 13 #include "mojo/public/cpp/bindings/tests/container_test_util.h" | 14 #include "mojo/public/cpp/bindings/tests/container_test_util.h" |
| 14 #include "mojo/public/cpp/bindings/tests/map_common_test.h" | 15 #include "mojo/public/cpp/bindings/tests/map_common_test.h" |
| 16 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 namespace mojo { | 19 namespace mojo { |
| 18 namespace test { | 20 namespace test { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 using MapTest = testing::Test; | 24 using MapTest = testing::Test; |
| 23 | 25 |
| 24 MAP_COMMON_TEST(Map, NullAndEmpty) | 26 MAP_COMMON_TEST(Map, NullAndEmpty) |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 ASSERT_NE(mojo_map.end(), mojo_map.find(123)); | 217 ASSERT_NE(mojo_map.end(), mojo_map.find(123)); |
| 216 | 218 |
| 217 std::map<int32_t, MoveOnlyType> map2(mojo_map.PassStorage()); | 219 std::map<int32_t, MoveOnlyType> map2(mojo_map.PassStorage()); |
| 218 ASSERT_EQ(1u, map2.size()); | 220 ASSERT_EQ(1u, map2.size()); |
| 219 ASSERT_NE(map2.end(), map2.find(123)); | 221 ASSERT_NE(map2.end(), map2.find(123)); |
| 220 | 222 |
| 221 ASSERT_EQ(0u, mojo_map.size()); | 223 ASSERT_EQ(0u, mojo_map.size()); |
| 222 ASSERT_TRUE(mojo_map.is_null()); | 224 ASSERT_TRUE(mojo_map.is_null()); |
| 223 } | 225 } |
| 224 | 226 |
| 227 static RectPtr MakeRect(int32_t x, int32_t y, int32_t width, int32_t height) { |
| 228 RectPtr rect_ptr = Rect::New(); |
| 229 rect_ptr->x = x; |
| 230 rect_ptr->y = y; |
| 231 rect_ptr->width = width; |
| 232 rect_ptr->height = height; |
| 233 return rect_ptr; |
| 234 } |
| 235 |
| 236 TEST_F(MapTest, StructKey) { |
| 237 std::unordered_map<RectPtr, int32_t> map; |
| 238 map.insert(std::make_pair(MakeRect(1, 2, 3, 4), 123)); |
| 239 |
| 240 RectPtr key = MakeRect(1, 2, 3, 4); |
| 241 ASSERT_NE(map.end(), map.find(key)); |
| 242 ASSERT_EQ(123, map.find(key)->second); |
| 243 |
| 244 map.erase(key); |
| 245 ASSERT_EQ(0u, map.size()); |
| 246 } |
| 247 |
| 225 } // namespace | 248 } // namespace |
| 226 } // namespace test | 249 } // namespace test |
| 227 } // namespace mojo | 250 } // namespace mojo |
| OLD | NEW |