Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
vmpstr
2016/04/18 19:38:11
nit: 2016
nyquist
2016/04/18 20:12:02
I totally didn't copy-paste this from an existing
| |
| 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 <algorithm> | |
| 6 #include <memory> | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "blimp/common/blob_cache/blob_cache.h" | |
| 13 #include "blimp/common/blob_cache/in_memory_blob_cache.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace blimp { | |
| 17 namespace { | |
| 18 | |
| 19 const char kFoo[] = "foo"; | |
| 20 const char kBar[] = "bar"; | |
| 21 const char kDeadbeef[] = "\xde\xad\xbe\xef"; | |
| 22 const char kForbiddenCode[] = "\x4b\x1d\xc0\xd3"; | |
| 23 | |
| 24 BlobData CreateBlobData(const std::string& data) { | |
| 25 return new base::RefCountedData<const std::string>(data); | |
| 26 } | |
| 27 | |
| 28 class InMemoryBlobCacheTest : public testing::Test { | |
| 29 public: | |
| 30 InMemoryBlobCacheTest() {} | |
| 31 ~InMemoryBlobCacheTest() override {} | |
| 32 | |
| 33 protected: | |
| 34 InMemoryBlobCache cache_; | |
| 35 }; | |
| 36 | |
| 37 TEST_F(InMemoryBlobCacheTest, SimplePutContainsAndGetOperations) { | |
| 38 EXPECT_FALSE(cache_.Contains(kFoo)); | |
| 39 EXPECT_EQ(nullptr, cache_.Get(kFoo)); | |
| 40 | |
| 41 BlobData blob_data = CreateBlobData(kDeadbeef); | |
| 42 cache_.Put(kFoo, blob_data); | |
| 43 | |
| 44 EXPECT_TRUE(cache_.Contains(kFoo)); | |
| 45 EXPECT_FALSE(cache_.Contains(kBar)); | |
| 46 | |
| 47 BlobData out = cache_.Get(kFoo); | |
| 48 | |
| 49 EXPECT_EQ(blob_data, out); | |
| 50 } | |
| 51 | |
| 52 TEST_F(InMemoryBlobCacheTest, TestDuplicatePut) { | |
| 53 BlobData first = CreateBlobData(kDeadbeef); | |
| 54 BlobData duplicate = CreateBlobData(kForbiddenCode); | |
| 55 cache_.Put(kFoo, first); | |
| 56 | |
| 57 BlobData out1 = cache_.Get(kFoo); | |
| 58 EXPECT_EQ(first, out1); | |
| 59 | |
| 60 // The second put should be ignored and retrieving kFoo should still retrieve | |
| 61 // the first item. | |
| 62 cache_.Put(kFoo, duplicate); | |
| 63 BlobData out2 = cache_.Get(kFoo); | |
| 64 EXPECT_EQ(first, out2); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 } // namespace blimp | |
| OLD | NEW |