OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 <vector> | |
6 | |
7 #include "chrome/test/chromedriver/synchronized_map.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 TEST(SynchronizedMapTest, Set) { | |
11 SynchronizedMap<int, int> map; | |
12 map.Set(1, 2); | |
13 ASSERT_TRUE(map.Has(1)); | |
14 int val = 0; | |
15 ASSERT_TRUE(map.Get(1, &val)); | |
16 ASSERT_EQ(2, val); | |
17 | |
18 map.Set(1, 3); | |
19 ASSERT_TRUE(map.Has(1)); | |
20 ASSERT_TRUE(map.Get(1, &val)); | |
21 ASSERT_EQ(3, val); | |
22 | |
23 map.Set(3, 1); | |
24 ASSERT_TRUE(map.Has(1)); | |
25 ASSERT_TRUE(map.Get(1, &val)); | |
26 ASSERT_EQ(3, val); | |
27 ASSERT_TRUE(map.Has(3)); | |
28 ASSERT_TRUE(map.Get(3, &val)); | |
29 ASSERT_EQ(1, val); | |
30 } | |
31 | |
32 TEST(SynchronizedMapTest, Get) { | |
33 SynchronizedMap<int, int> map; | |
34 int val = 0; | |
35 ASSERT_FALSE(map.Get(1, &val)); | |
36 map.Set(1, 2); | |
37 ASSERT_TRUE(map.Get(1, &val)); | |
38 ASSERT_EQ(2, val); | |
39 | |
40 ASSERT_TRUE(map.Remove(1)); | |
41 val = 100; | |
42 ASSERT_FALSE(map.Get(1, &val)); | |
43 ASSERT_EQ(100, val); | |
44 } | |
45 | |
46 TEST(SynchronizedMapTest, Has) { | |
47 SynchronizedMap<int, int> map; | |
48 ASSERT_FALSE(map.Has(1)); | |
49 map.Set(1, 2); | |
50 ASSERT_TRUE(map.Has(1)); | |
51 ASSERT_FALSE(map.Has(2)); | |
52 | |
53 ASSERT_TRUE(map.Remove(1)); | |
54 ASSERT_FALSE(map.Has(1)); | |
55 } | |
56 | |
57 TEST(SynchronizedMapTest, GetKeys) { | |
58 SynchronizedMap<int, int> map; | |
59 | |
60 std::vector<int> keys; | |
61 map.GetKeys(&keys); | |
62 ASSERT_EQ(0u, keys.size()); | |
63 | |
64 keys.push_back(100); | |
65 map.GetKeys(&keys); | |
66 ASSERT_EQ(0u, keys.size()); | |
67 | |
68 map.Set(1, 2); | |
69 map.GetKeys(&keys); | |
70 ASSERT_EQ(1u, keys.size()); | |
71 ASSERT_EQ(1, keys[0]); | |
72 | |
73 map.Set(2, 4); | |
74 map.GetKeys(&keys); | |
75 ASSERT_EQ(2u, keys.size()); | |
76 ASSERT_EQ(1, keys[0]); | |
77 ASSERT_EQ(2, keys[1]); | |
78 } | |
OLD | NEW |