OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "net/base/expiring_cache.h" | 5 #include "net/base/expiring_cache.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using testing::Pointee; | 16 using testing::Pointee; |
17 using testing::StrEq; | 17 using testing::StrEq; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int kMaxCacheEntries = 10; | 23 const int kMaxCacheEntries = 10; |
24 typedef ExpiringCache<std::string, std::string, base::TimeTicks, | 24 typedef ExpiringCache<std::string, |
| 25 std::string, |
| 26 base::TimeTicks, |
25 std::less<base::TimeTicks> > Cache; | 27 std::less<base::TimeTicks> > Cache; |
26 | 28 |
27 struct TestFunctor { | 29 struct TestFunctor { |
28 bool operator()(const std::string& now, | 30 bool operator()(const std::string& now, const std::string& expiration) const { |
29 const std::string& expiration) const { | |
30 return now != expiration; | 31 return now != expiration; |
31 } | 32 } |
32 }; | 33 }; |
33 | 34 |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 TEST(ExpiringCacheTest, Basic) { | 37 TEST(ExpiringCacheTest, Basic) { |
37 const base::TimeDelta kTTL = base::TimeDelta::FromSeconds(10); | 38 const base::TimeDelta kTTL = base::TimeDelta::FromSeconds(10); |
38 | 39 |
39 Cache cache(kMaxCacheEntries); | 40 Cache cache(kMaxCacheEntries); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // should be able to add something at kHeatDeath that expires at kMuchLater. | 303 // should be able to add something at kHeatDeath that expires at kMuchLater. |
303 cache.Put("test7", "foo7", kHeatDeath, kMuchLater); | 304 cache.Put("test7", "foo7", kHeatDeath, kMuchLater); |
304 EXPECT_EQ(1U, cache.size()); | 305 EXPECT_EQ(1U, cache.size()); |
305 EXPECT_THAT(cache.Get("test7", kNow), Pointee(StrEq("foo7"))); | 306 EXPECT_THAT(cache.Get("test7", kNow), Pointee(StrEq("foo7"))); |
306 EXPECT_THAT(cache.Get("test7", kLater), Pointee(StrEq("foo7"))); | 307 EXPECT_THAT(cache.Get("test7", kLater), Pointee(StrEq("foo7"))); |
307 EXPECT_THAT(cache.Get("test7", kHeatDeath), Pointee(StrEq("foo7"))); | 308 EXPECT_THAT(cache.Get("test7", kHeatDeath), Pointee(StrEq("foo7"))); |
308 EXPECT_FALSE(cache.Get("test7", kMuchLater)); | 309 EXPECT_FALSE(cache.Get("test7", kMuchLater)); |
309 } | 310 } |
310 | 311 |
311 } // namespace net | 312 } // namespace net |
OLD | NEW |