1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6 #include <stdint.h>
7 #include <utility>
8
9 #include "base/containers/flat_map.h"
10 #include "mojo/public/cpp/bindings/tests/rect_chromium.h"
11 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h"
12 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace mojo {
16 namespace test {
17 namespace {
18
TEST(MapTest,StructKey)19 TEST(MapTest, StructKey) {
20 base::flat_map<RectPtr, int32_t> map;
21 map.insert(std::make_pair(Rect::New(1, 2, 3, 4), 123));
22
23 RectPtr key = Rect::New(1, 2, 3, 4);
24 ASSERT_NE(map.end(), map.find(key));
25 ASSERT_EQ(123, map.find(key)->second);
26
27 map.erase(key);
28 ASSERT_EQ(0u, map.size());
29 }
30
TEST(MapTest,TypemappedStructKey)31 TEST(MapTest, TypemappedStructKey) {
32 base::flat_map<ContainsHashablePtr, int32_t> map;
33 map.insert(
34 std::make_pair(ContainsHashable::New(RectChromium(1, 2, 3, 4)), 123));
35
36 ContainsHashablePtr key = ContainsHashable::New(RectChromium(1, 2, 3, 4));
37 ASSERT_NE(map.end(), map.find(key));
38 ASSERT_EQ(123, map.find(key)->second);
39
40 map.erase(key);
41 ASSERT_EQ(0u, map.size());
42 }
43
44 } // namespace
45 } // namespace test
46 } // namespace mojo
47