• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "mojo/public/cpp/bindings/wtf_map.h"
6 
7 #include "mojo/public/cpp/bindings/lib/wtf_serialization.h"
8 #include "mojo/public/cpp/bindings/tests/container_test_util.h"
9 #include "mojo/public/cpp/bindings/tests/map_common_test.h"
10 #include "mojo/public/cpp/bindings/wtf_array.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/Source/wtf/text/WTFString.h"
13 
14 namespace mojo {
15 namespace test {
16 
17 namespace {
18 
19 using WTFMapTest = testing::Test;
20 
MAP_COMMON_TEST(WTFMap,NullAndEmpty)21 MAP_COMMON_TEST(WTFMap, NullAndEmpty)
22 MAP_COMMON_TEST(WTFMap, InsertWorks)
23 MAP_COMMON_TEST(WTFMap, TestIndexOperator)
24 MAP_COMMON_TEST(WTFMap, TestIndexOperatorAsRValue)
25 MAP_COMMON_TEST(WTFMap, TestIndexOperatorMoveOnly)
26 MAP_COMMON_TEST(WTFMap, MapArrayClone)
27 MAP_COMMON_TEST(WTFMap, ArrayOfMap)
28 
29 TEST_F(WTFMapTest, MoveFromAndToWTFHashMap_Copyable) {
30   WTF::HashMap<int32_t, CopyableType> map1;
31   map1.add(123, CopyableType());
32   map1.find(123)->value.ResetCopied();
33   ASSERT_FALSE(map1.find(123)->value.copied());
34 
35   WTFMap<int32_t, CopyableType> mojo_map(std::move(map1));
36   ASSERT_EQ(1u, mojo_map.size());
37   ASSERT_NE(mojo_map.end(), mojo_map.find(123));
38   ASSERT_FALSE(mojo_map[123].copied());
39 
40   WTF::HashMap<int32_t, CopyableType> map2(mojo_map.PassStorage());
41   ASSERT_EQ(1u, map2.size());
42   ASSERT_NE(map2.end(), map2.find(123));
43   ASSERT_FALSE(map2.find(123)->value.copied());
44 
45   ASSERT_EQ(0u, mojo_map.size());
46   ASSERT_TRUE(mojo_map.is_null());
47 }
48 
TEST_F(WTFMapTest,MoveFromAndToWTFHashMap_MoveOnly)49 TEST_F(WTFMapTest, MoveFromAndToWTFHashMap_MoveOnly) {
50   WTF::HashMap<int32_t, MoveOnlyType> map1;
51   map1.add(123, MoveOnlyType());
52 
53   WTFMap<int32_t, MoveOnlyType> mojo_map(std::move(map1));
54   ASSERT_EQ(1u, mojo_map.size());
55   ASSERT_NE(mojo_map.end(), mojo_map.find(123));
56 
57   WTF::HashMap<int32_t, MoveOnlyType> map2(mojo_map.PassStorage());
58   ASSERT_EQ(1u, map2.size());
59   ASSERT_NE(map2.end(), map2.find(123));
60 
61   ASSERT_EQ(0u, mojo_map.size());
62   ASSERT_TRUE(mojo_map.is_null());
63 }
64 
65 }  // namespace
66 }  // namespace test
67 }  // namespace mojo
68