OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 <algorithm> | 5 #include <algorithm> |
6 #include <memory> | 6 #include <memory> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 public: | 29 public: |
30 InMemoryBlobCacheTest() {} | 30 InMemoryBlobCacheTest() {} |
31 ~InMemoryBlobCacheTest() override {} | 31 ~InMemoryBlobCacheTest() override {} |
32 | 32 |
33 protected: | 33 protected: |
34 InMemoryBlobCache cache_; | 34 InMemoryBlobCache cache_; |
35 }; | 35 }; |
36 | 36 |
37 TEST_F(InMemoryBlobCacheTest, SimplePutContainsAndGetOperations) { | 37 TEST_F(InMemoryBlobCacheTest, SimplePutContainsAndGetOperations) { |
38 EXPECT_FALSE(cache_.Contains(kFoo)); | 38 EXPECT_FALSE(cache_.Contains(kFoo)); |
39 EXPECT_EQ(nullptr, cache_.Get(kFoo)); | 39 EXPECT_FALSE(cache_.Get(kFoo)); |
40 | 40 |
41 BlobDataPtr blob_data = CreateBlobDataPtr(kDeadbeef); | 41 BlobDataPtr blob_data = CreateBlobDataPtr(kDeadbeef); |
42 cache_.Put(kFoo, blob_data); | 42 cache_.Put(kFoo, blob_data); |
43 | 43 |
44 EXPECT_TRUE(cache_.Contains(kFoo)); | 44 EXPECT_TRUE(cache_.Contains(kFoo)); |
45 EXPECT_FALSE(cache_.Contains(kBar)); | 45 EXPECT_FALSE(cache_.Contains(kBar)); |
46 | 46 |
47 BlobDataPtr out = cache_.Get(kFoo); | 47 BlobDataPtr out = cache_.Get(kFoo); |
48 | 48 |
49 EXPECT_EQ(blob_data, out); | 49 EXPECT_EQ(blob_data, out); |
50 } | 50 } |
51 | 51 |
52 TEST_F(InMemoryBlobCacheTest, TestDuplicatePut) { | 52 TEST_F(InMemoryBlobCacheTest, TestDuplicatePut) { |
53 BlobDataPtr first = CreateBlobDataPtr(kDeadbeef); | 53 BlobDataPtr first = CreateBlobDataPtr(kDeadbeef); |
54 BlobDataPtr duplicate = CreateBlobDataPtr(kForbiddenCode); | 54 BlobDataPtr duplicate = CreateBlobDataPtr(kForbiddenCode); |
55 cache_.Put(kFoo, first); | 55 cache_.Put(kFoo, first); |
56 | 56 |
57 BlobDataPtr out1 = cache_.Get(kFoo); | 57 BlobDataPtr out1 = cache_.Get(kFoo); |
58 EXPECT_EQ(first, out1); | 58 EXPECT_EQ(first, out1); |
59 | 59 |
60 // The second put should be ignored and retrieving kFoo should still retrieve | 60 // The second put should be ignored and retrieving kFoo should still retrieve |
61 // the first item. | 61 // the first item. |
62 cache_.Put(kFoo, duplicate); | 62 cache_.Put(kFoo, duplicate); |
63 BlobDataPtr out2 = cache_.Get(kFoo); | 63 BlobDataPtr out2 = cache_.Get(kFoo); |
64 EXPECT_EQ(first, out2); | 64 EXPECT_EQ(first, out2); |
65 } | 65 } |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 } // namespace blimp | 68 } // namespace blimp |
OLD | NEW |