| 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 std::string key = lru_helper_->EvictKey(); |
| 35 ASSERT_EQ("1", key); |
| 36 ASSERT_FALSE(lru_helper_->IsEmpty()); |
| 37 ASSERT_EQ("2", lru_helper_->EvictKey()); |
| 38 ASSERT_FALSE(lru_helper_->IsEmpty()); |
| 39 ASSERT_EQ("3", lru_helper_->EvictKey()); |
| 40 ASSERT_FALSE(lru_helper_->IsEmpty()); |
| 41 ASSERT_EQ("4", lru_helper_->EvictKey()); |
| 42 ASSERT_TRUE(lru_helper_->IsEmpty()); |
| 43 } |
| 44 |
| 45 TEST_F(ProgramCacheLruHelperTest, ProgramCacheLruHelperClear) { |
| 46 ASSERT_TRUE(lru_helper_->IsEmpty()); |
| 47 lru_helper_->KeyUsed("1"); |
| 48 lru_helper_->KeyUsed("2"); |
| 49 lru_helper_->KeyUsed("3"); |
| 50 lru_helper_->KeyUsed("4"); |
| 51 ASSERT_FALSE(lru_helper_->IsEmpty()); |
| 52 lru_helper_->Clear(); |
| 53 ASSERT_TRUE(lru_helper_->IsEmpty()); |
| 54 } |
| 55 |
| 56 TEST_F(ProgramCacheLruHelperTest, ProgramCacheLruHelperEvictionOrderWithReuse) { |
| 57 lru_helper_->KeyUsed("1"); |
| 58 lru_helper_->KeyUsed("2"); |
| 59 lru_helper_->KeyUsed("4"); |
| 60 lru_helper_->KeyUsed("2"); |
| 61 lru_helper_->KeyUsed("3"); |
| 62 lru_helper_->KeyUsed("1"); |
| 63 lru_helper_->KeyUsed("1"); |
| 64 lru_helper_->KeyUsed("2"); |
| 65 ASSERT_EQ("4", lru_helper_->EvictKey()); |
| 66 ASSERT_EQ("3", lru_helper_->EvictKey()); |
| 67 ASSERT_EQ("1", lru_helper_->EvictKey()); |
| 68 ASSERT_FALSE(lru_helper_->IsEmpty()); |
| 69 ASSERT_EQ("2", lru_helper_->EvictKey()); |
| 70 ASSERT_TRUE(lru_helper_->IsEmpty()); |
| 71 } |
| 72 |
| 73 } // namespace gles2 |
| 74 } // namespace gpu |
| OLD | NEW |