Chromium Code Reviews| Index: gpu/command_buffer/service/program_cache_lru_helper_unittest.cc |
| diff --git a/gpu/command_buffer/service/program_cache_lru_helper_unittest.cc b/gpu/command_buffer/service/program_cache_lru_helper_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8e3e372cbbc25e9dc26f6d0c2b80f3b348d97e60 |
| --- /dev/null |
| +++ b/gpu/command_buffer/service/program_cache_lru_helper_unittest.cc |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "gpu/command_buffer/service/program_cache_lru_helper.h" |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace gpu { |
| +namespace gles2 { |
| + |
| +class ProgramCacheLruHelperTest : public testing::Test { |
| + public: |
| + ProgramCacheLruHelperTest() : |
| + lru_helper_(new ProgramCacheLruHelper()) { } |
| + |
| + protected: |
| + virtual void SetUp() { |
| + } |
| + |
| + virtual void TearDown() { |
| + lru_helper_->Clear(); |
| + } |
| + |
| + scoped_ptr<ProgramCacheLruHelper> lru_helper_; |
| +}; |
| + |
| +TEST_F(ProgramCacheLruHelperTest, ProgramCacheLruHelperEvictionOrderNoReuse) { |
| + lru_helper_->KeyUsed("1"); |
| + lru_helper_->KeyUsed("2"); |
| + lru_helper_->KeyUsed("3"); |
| + lru_helper_->KeyUsed("4"); |
| + const std::string& key = lru_helper_->PeekKey(); |
| + ASSERT_EQ("1", key); |
|
greggman
2012/06/26 23:00:27
All these ASSERT_XX should be EXPECT_XX
ASSERT_XX
dmurph
2012/07/04 00:01:29
Done.
|
| + ASSERT_EQ("1", lru_helper_->PeekKey()); |
| + lru_helper_->PopKey(); |
| + ASSERT_FALSE(lru_helper_->IsEmpty()); |
| + ASSERT_EQ("2", lru_helper_->PeekKey()); |
| + lru_helper_->PopKey(); |
| + ASSERT_FALSE(lru_helper_->IsEmpty()); |
| + ASSERT_EQ("3", lru_helper_->PeekKey()); |
| + lru_helper_->PopKey(); |
| + ASSERT_FALSE(lru_helper_->IsEmpty()); |
| + ASSERT_EQ("4", lru_helper_->PeekKey()); |
| + lru_helper_->PopKey(); |
| + ASSERT_TRUE(lru_helper_->IsEmpty()); |
| +} |
| + |
| +TEST_F(ProgramCacheLruHelperTest, ProgramCacheLruHelperClear) { |
| + ASSERT_TRUE(lru_helper_->IsEmpty()); |
| + lru_helper_->KeyUsed("1"); |
| + lru_helper_->KeyUsed("2"); |
| + lru_helper_->KeyUsed("3"); |
| + lru_helper_->KeyUsed("4"); |
| + ASSERT_FALSE(lru_helper_->IsEmpty()); |
| + lru_helper_->Clear(); |
| + ASSERT_TRUE(lru_helper_->IsEmpty()); |
| +} |
| + |
| +TEST_F(ProgramCacheLruHelperTest, ProgramCacheLruHelperEvictionOrderWithReuse) { |
| + lru_helper_->KeyUsed("1"); |
| + lru_helper_->KeyUsed("2"); |
| + lru_helper_->KeyUsed("4"); |
| + lru_helper_->KeyUsed("2"); |
| + lru_helper_->KeyUsed("3"); |
| + lru_helper_->KeyUsed("1"); |
| + lru_helper_->KeyUsed("1"); |
| + lru_helper_->KeyUsed("2"); |
| + ASSERT_EQ("4", lru_helper_->PeekKey()); |
|
greggman
2012/06/26 23:00:27
same check twice?
dmurph
2012/07/04 00:01:29
Yeah, checking that it didn't pop
|
| + ASSERT_EQ("4", lru_helper_->PeekKey()); |
| + lru_helper_->PopKey(); |
| + ASSERT_EQ("3", lru_helper_->PeekKey()); |
| + lru_helper_->PopKey(); |
| + ASSERT_EQ("1", lru_helper_->PeekKey()); |
| + lru_helper_->PopKey(); |
| + ASSERT_FALSE(lru_helper_->IsEmpty()); |
| + ASSERT_EQ("2", lru_helper_->PeekKey()); |
| + lru_helper_->PopKey(); |
| + ASSERT_TRUE(lru_helper_->IsEmpty()); |
| +} |
| + |
| +} // namespace gles2 |
| +} // namespace gpu |