| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/wtf_map.h" | 5 #include "mojo/public/cpp/bindings/wtf_map.h" |
| 6 | 6 |
| 7 #include "mojo/public/cpp/bindings/lib/wtf_serialization.h" | 7 #include "mojo/public/cpp/bindings/lib/wtf_serialization.h" |
| 8 #include "mojo/public/cpp/bindings/tests/container_test_util.h" | 8 #include "mojo/public/cpp/bindings/tests/container_test_util.h" |
| 9 #include "mojo/public/cpp/bindings/tests/map_common_test.h" | 9 #include "mojo/public/cpp/bindings/tests/map_common_test.h" |
| 10 #include "mojo/public/cpp/bindings/tests/rect_blink.h" |
| 10 #include "mojo/public/cpp/bindings/wtf_array.h" | 11 #include "mojo/public/cpp/bindings/wtf_array.h" |
| 12 #include "mojo/public/interfaces/bindings/tests/rect.mojom-blink.h" |
| 13 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom-blink.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/WebKit/Source/wtf/text/WTFString.h" | 15 #include "third_party/WebKit/Source/wtf/text/WTFString.h" |
| 13 | 16 |
| 14 namespace mojo { | 17 namespace mojo { |
| 15 namespace test { | 18 namespace test { |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 using WTFMapTest = testing::Test; | 22 using WTFMapTest = testing::Test; |
| 20 | 23 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 ASSERT_NE(mojo_map.end(), mojo_map.find(123)); | 58 ASSERT_NE(mojo_map.end(), mojo_map.find(123)); |
| 56 | 59 |
| 57 WTF::HashMap<int32_t, MoveOnlyType> map2(mojo_map.PassStorage()); | 60 WTF::HashMap<int32_t, MoveOnlyType> map2(mojo_map.PassStorage()); |
| 58 ASSERT_EQ(1u, map2.size()); | 61 ASSERT_EQ(1u, map2.size()); |
| 59 ASSERT_NE(map2.end(), map2.find(123)); | 62 ASSERT_NE(map2.end(), map2.find(123)); |
| 60 | 63 |
| 61 ASSERT_EQ(0u, mojo_map.size()); | 64 ASSERT_EQ(0u, mojo_map.size()); |
| 62 ASSERT_TRUE(mojo_map.is_null()); | 65 ASSERT_TRUE(mojo_map.is_null()); |
| 63 } | 66 } |
| 64 | 67 |
| 68 static blink::RectPtr MakeRect(int32_t x, |
| 69 int32_t y, |
| 70 int32_t width, |
| 71 int32_t height) { |
| 72 blink::RectPtr rect_ptr = blink::Rect::New(); |
| 73 rect_ptr->x = x; |
| 74 rect_ptr->y = y; |
| 75 rect_ptr->width = width; |
| 76 rect_ptr->height = height; |
| 77 return rect_ptr; |
| 78 } |
| 79 |
| 80 TEST_F(WTFMapTest, StructKey) { |
| 81 WTF::HashMap<blink::RectPtr, int32_t> map; |
| 82 map.add(MakeRect(1, 2, 3, 4), 123); |
| 83 |
| 84 blink::RectPtr key = MakeRect(1, 2, 3, 4); |
| 85 ASSERT_NE(map.end(), map.find(key)); |
| 86 ASSERT_EQ(123, map.find(key)->value); |
| 87 |
| 88 map.remove(key); |
| 89 ASSERT_EQ(0u, map.size()); |
| 90 } |
| 91 |
| 92 static blink::ContainsHashablePtr MakeContainsHashablePtr(RectBlink rect) { |
| 93 blink::ContainsHashablePtr ptr = blink::ContainsHashable::New(); |
| 94 ptr->rect = rect; |
| 95 return ptr; |
| 96 } |
| 97 |
| 98 TEST_F(WTFMapTest, TypemappedStructKey) { |
| 99 WTF::HashMap<blink::ContainsHashablePtr, int32_t> map; |
| 100 map.add(MakeContainsHashablePtr(RectBlink(1, 2, 3, 4)), 123); |
| 101 |
| 102 blink::ContainsHashablePtr key = |
| 103 MakeContainsHashablePtr(RectBlink(1, 2, 3, 4)); |
| 104 ASSERT_NE(map.end(), map.find(key)); |
| 105 ASSERT_EQ(123, map.find(key)->value); |
| 106 |
| 107 map.remove(key); |
| 108 ASSERT_EQ(0u, map.size()); |
| 109 } |
| 110 |
| 65 } // namespace | 111 } // namespace |
| 66 } // namespace test | 112 } // namespace test |
| 67 } // namespace mojo | 113 } // namespace mojo |
| OLD | NEW |