| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
| 9 #include "components/copresence/timed_map.h" | 9 #include "components/copresence/timed_map.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 map.Add(0xbaad, Value(0xf00d)); | 68 map.Add(0xbaad, Value(0xf00d)); |
| 69 EXPECT_TRUE(map.HasKey(0xbaad)); | 69 EXPECT_TRUE(map.HasKey(0xbaad)); |
| 70 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value); | 70 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value); |
| 71 | 71 |
| 72 map.Add(0x1337, Value(0xd00d)); | 72 map.Add(0x1337, Value(0xd00d)); |
| 73 EXPECT_TRUE(map.HasKey(0x1337)); | 73 EXPECT_TRUE(map.HasKey(0x1337)); |
| 74 EXPECT_EQ(0xd00d, map.GetValue(0x1337).value); | 74 EXPECT_EQ(0xd00d, map.GetValue(0x1337).value); |
| 75 } | 75 } |
| 76 | 76 |
| 77 TEST_F(TimedMapTest, SizeEvict) { | 77 // TODO(rkc): Find and fix the memory leak here. |
| 78 #define MAYBE_SizeEvict DISABLED_SizeEvict |
| 79 |
| 80 TEST_F(TimedMapTest, MAYBE_SizeEvict) { |
| 78 typedef copresence::TimedMap<int, Value> Map; | 81 typedef copresence::TimedMap<int, Value> Map; |
| 79 Map two_element_map(base::TimeDelta::FromSeconds(9999), 2); | 82 Map two_element_map(base::TimeDelta::FromSeconds(9999), 2); |
| 80 | 83 |
| 81 two_element_map.Add(0x1337, Value(0x7331)); | 84 two_element_map.Add(0x1337, Value(0x7331)); |
| 82 EXPECT_TRUE(two_element_map.HasKey(0x1337)); | 85 EXPECT_TRUE(two_element_map.HasKey(0x1337)); |
| 83 EXPECT_EQ(0x7331, two_element_map.GetValue(0x1337).value); | 86 EXPECT_EQ(0x7331, two_element_map.GetValue(0x1337).value); |
| 84 | 87 |
| 85 two_element_map.Add(0xbaad, Value(0xf00d)); | 88 two_element_map.Add(0xbaad, Value(0xf00d)); |
| 86 EXPECT_TRUE(two_element_map.HasKey(0xbaad)); | 89 EXPECT_TRUE(two_element_map.HasKey(0xbaad)); |
| 87 EXPECT_EQ(0xf00d, two_element_map.GetValue(0xbaad).value); | 90 EXPECT_EQ(0xf00d, two_element_map.GetValue(0xbaad).value); |
| 88 | 91 |
| 89 two_element_map.Add(0x1234, Value(0x5678)); | 92 two_element_map.Add(0x1234, Value(0x5678)); |
| 90 EXPECT_TRUE(two_element_map.HasKey(0x1234)); | 93 EXPECT_TRUE(two_element_map.HasKey(0x1234)); |
| 91 EXPECT_EQ(0xf00d, two_element_map.GetValue(0xbaad).value); | 94 EXPECT_EQ(0xf00d, two_element_map.GetValue(0xbaad).value); |
| 92 | 95 |
| 93 EXPECT_FALSE(two_element_map.HasKey(0x1337)); | 96 EXPECT_FALSE(two_element_map.HasKey(0x1337)); |
| 94 EXPECT_EQ(0, two_element_map.GetValue(0x1337).value); | 97 EXPECT_EQ(0, two_element_map.GetValue(0x1337).value); |
| 95 } | 98 } |
| 96 | 99 |
| 97 TEST_F(TimedMapTest, TimedEvict) { | 100 // TODO(rkc): Find and fix the memory leak here. |
| 101 #define MAYBE_TimedEvict DISABLED_TimedEvict |
| 102 |
| 103 TEST_F(TimedMapTest, MAYBE_TimedEvict) { |
| 98 const int kLargeTimeValueSeconds = 9999; | 104 const int kLargeTimeValueSeconds = 9999; |
| 99 base::SimpleTestTickClock clock; | 105 base::SimpleTestTickClock clock; |
| 100 typedef copresence::TimedMap<int, Value> Map; | 106 typedef copresence::TimedMap<int, Value> Map; |
| 101 Map map(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds), 2); | 107 Map map(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds), 2); |
| 102 map.set_clock_for_testing(&clock); | 108 map.set_clock_for_testing(&clock); |
| 103 | 109 |
| 104 // Add value at T=0. | 110 // Add value at T=0. |
| 105 map.Add(0x1337, Value(0x7331)); | 111 map.Add(0x1337, Value(0x7331)); |
| 106 EXPECT_TRUE(map.HasKey(0x1337)); | 112 EXPECT_TRUE(map.HasKey(0x1337)); |
| 107 EXPECT_EQ(0x7331, map.GetValue(0x1337).value); | 113 EXPECT_EQ(0x7331, map.GetValue(0x1337).value); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 121 EXPECT_FALSE(map.HasKey(0x1337)); | 127 EXPECT_FALSE(map.HasKey(0x1337)); |
| 122 EXPECT_EQ(0, map.GetValue(0x1337).value); | 128 EXPECT_EQ(0, map.GetValue(0x1337).value); |
| 123 EXPECT_TRUE(map.HasKey(0xbaad)); | 129 EXPECT_TRUE(map.HasKey(0xbaad)); |
| 124 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value); | 130 EXPECT_EQ(0xf00d, map.GetValue(0xbaad).value); |
| 125 | 131 |
| 126 // Check values at T=2*kLargeTimeValueSeconds | 132 // Check values at T=2*kLargeTimeValueSeconds |
| 127 clock.Advance(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds)); | 133 clock.Advance(base::TimeDelta::FromSeconds(kLargeTimeValueSeconds)); |
| 128 EXPECT_FALSE(map.HasKey(0xbaad)); | 134 EXPECT_FALSE(map.HasKey(0xbaad)); |
| 129 EXPECT_EQ(0, map.GetValue(0xbaad).value); | 135 EXPECT_EQ(0, map.GetValue(0xbaad).value); |
| 130 } | 136 } |
| OLD | NEW |