Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: components/copresence/timed_map_unittest.cc

Issue 419073002: Add the copresence DirectiveHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gn fix Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "base/basictypes.h"
6 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h"
8 #include "components/copresence/timed_map.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace {
12
13 struct Value {
14 Value() : value(0) {}
15 explicit Value(int new_value) : value(new_value) {}
16
17 int value;
18 };
19
20 } // namespace
21
22 class TimedMapTest : public testing::Test {
23 public:
24 TimedMapTest() {}
25
26 private:
27 // Exists since the timer needs a message loop.
28 base::MessageLoop message_loop_;
29
30 DISALLOW_COPY_AND_ASSIGN(TimedMapTest);
31 };
32
33 TEST_F(TimedMapTest, Basic) {
34 typedef copresence::TimedMap<int, Value> Map;
35 Map map(base::TimeDelta::FromSeconds(0x7331), 3);
36
37 EXPECT_FALSE(map.HasKey(0));
38 EXPECT_EQ(0, map.GetValue(0).value);
39
40 map.Add(0x1337, Value(0x7331));
41 EXPECT_TRUE(map.HasKey(0x1337));
42 EXPECT_EQ(0x7331, map.GetValue(0x1337).value);
43
44 map.Add(0xbaad, Value(0xf00d));
45 EXPECT_TRUE(map.HasKey(0xbaad));
46 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value);
47 EXPECT_EQ(0x7331, map.GetValue(0x1337).value);
48
49 map.Add(0x1234, Value(0x5678));
50 EXPECT_TRUE(map.HasKey(0x1234));
51 EXPECT_TRUE(map.HasKey(0xbaad));
52 EXPECT_TRUE(map.HasKey(0x1337));
53
54 EXPECT_EQ(0x5678, map.GetValue(0x1234).value);
55 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value);
56 EXPECT_EQ(0x7331, map.GetValue(0x1337).value);
57 }
58
59 TEST_F(TimedMapTest, ValueReplacement) {
60 typedef copresence::TimedMap<int, Value> Map;
61 Map map(base::TimeDelta::FromSeconds(0x7331), 10);
62
63 map.Add(0x1337, Value(0x7331));
64 EXPECT_TRUE(map.HasKey(0x1337));
65 EXPECT_EQ(0x7331, map.GetValue(0x1337).value);
66
67 map.Add(0xbaad, Value(0xf00d));
68 EXPECT_TRUE(map.HasKey(0xbaad));
69 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value);
70
71 map.Add(0x1337, Value(0xd00d));
72 EXPECT_TRUE(map.HasKey(0x1337));
73 EXPECT_EQ(0xd00d, map.GetValue(0x1337).value);
74 }
75
76 TEST_F(TimedMapTest, SizeEvict) {
77 typedef copresence::TimedMap<int, Value> Map;
78 Map two_element_map(base::TimeDelta::FromSeconds(0x7331), 2);
79
80 two_element_map.Add(0x1337, Value(0x7331));
81 EXPECT_TRUE(two_element_map.HasKey(0x1337));
82 EXPECT_EQ(0x7331, two_element_map.GetValue(0x1337).value);
83
84 two_element_map.Add(0xbaad, Value(0xf00d));
85 EXPECT_TRUE(two_element_map.HasKey(0xbaad));
86 EXPECT_EQ(0xf00d, two_element_map.GetValue(0xbaad).value);
87
88 two_element_map.Add(0x1234, Value(0x5678));
89 EXPECT_TRUE(two_element_map.HasKey(0x1234));
90 EXPECT_EQ(0xf00d, two_element_map.GetValue(0xbaad).value);
91
92 EXPECT_FALSE(two_element_map.HasKey(0x1337));
93 EXPECT_EQ(0, two_element_map.GetValue(0x1337).value);
94 }
95
96 // TODO(rkc): Figure out how to test timed eviction and add a TimedEvict test.
OLDNEW
« components/copresence/timed_map.h ('K') | « components/copresence/timed_map.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698