OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "gpu/command_buffer/service/program_cache_lru_helper.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace gpu { |
| 11 namespace gles2 { |
| 12 |
| 13 class ProgramCacheLruHelperTest : public testing::Test { |
| 14 public: |
| 15 ProgramCacheLruHelperTest() : |
| 16 lru_helper_(new ProgramCacheLruHelper()) { } |
| 17 |
| 18 protected: |
| 19 virtual void SetUp() { |
| 20 } |
| 21 |
| 22 virtual void TearDown() { |
| 23 lru_helper_->Clear(); |
| 24 } |
| 25 |
| 26 scoped_ptr<ProgramCacheLruHelper> lru_helper_; |
| 27 }; |
| 28 |
| 29 TEST_F(ProgramCacheLruHelperTest, ProgramCacheLruHelperEvictionOrderNoReuse) { |
| 30 lru_helper_->KeyUsed("1"); |
| 31 lru_helper_->KeyUsed("2"); |
| 32 lru_helper_->KeyUsed("3"); |
| 33 lru_helper_->KeyUsed("4"); |
| 34 const std::string* key = lru_helper_->PeekKey(); |
| 35 EXPECT_EQ("1", *key); |
| 36 EXPECT_EQ("1", *lru_helper_->PeekKey()); |
| 37 lru_helper_->PopKey(); |
| 38 EXPECT_FALSE(lru_helper_->IsEmpty()); |
| 39 EXPECT_EQ("2", *lru_helper_->PeekKey()); |
| 40 lru_helper_->PopKey(); |
| 41 EXPECT_FALSE(lru_helper_->IsEmpty()); |
| 42 EXPECT_EQ("3", *lru_helper_->PeekKey()); |
| 43 lru_helper_->PopKey(); |
| 44 EXPECT_FALSE(lru_helper_->IsEmpty()); |
| 45 EXPECT_EQ("4", *lru_helper_->PeekKey()); |
| 46 lru_helper_->PopKey(); |
| 47 EXPECT_TRUE(lru_helper_->IsEmpty()); |
| 48 } |
| 49 |
| 50 TEST_F(ProgramCacheLruHelperTest, ProgramCacheLruHelperClear) { |
| 51 EXPECT_TRUE(lru_helper_->IsEmpty()); |
| 52 lru_helper_->KeyUsed("1"); |
| 53 lru_helper_->KeyUsed("2"); |
| 54 lru_helper_->KeyUsed("3"); |
| 55 lru_helper_->KeyUsed("4"); |
| 56 EXPECT_FALSE(lru_helper_->IsEmpty()); |
| 57 lru_helper_->Clear(); |
| 58 EXPECT_TRUE(lru_helper_->IsEmpty()); |
| 59 } |
| 60 |
| 61 TEST_F(ProgramCacheLruHelperTest, ProgramCacheLruHelperEvictionOrderWithReuse) { |
| 62 lru_helper_->KeyUsed("1"); |
| 63 lru_helper_->KeyUsed("2"); |
| 64 lru_helper_->KeyUsed("4"); |
| 65 lru_helper_->KeyUsed("2"); |
| 66 lru_helper_->KeyUsed("3"); |
| 67 lru_helper_->KeyUsed("1"); |
| 68 lru_helper_->KeyUsed("1"); |
| 69 lru_helper_->KeyUsed("2"); |
| 70 EXPECT_EQ("4", *lru_helper_->PeekKey()); |
| 71 EXPECT_EQ("4", *lru_helper_->PeekKey()); |
| 72 lru_helper_->PopKey(); |
| 73 EXPECT_EQ("3", *lru_helper_->PeekKey()); |
| 74 lru_helper_->PopKey(); |
| 75 EXPECT_EQ("1", *lru_helper_->PeekKey()); |
| 76 lru_helper_->PopKey(); |
| 77 EXPECT_FALSE(lru_helper_->IsEmpty()); |
| 78 EXPECT_EQ("2", *lru_helper_->PeekKey()); |
| 79 lru_helper_->PopKey(); |
| 80 EXPECT_TRUE(lru_helper_->IsEmpty()); |
| 81 } |
| 82 |
| 83 } // namespace gles2 |
| 84 } // namespace gpu |
OLD | NEW |