| Index: gpu/command_buffer/service/program_cache_unittest.cc
|
| diff --git a/gpu/command_buffer/service/program_cache_unittest.cc b/gpu/command_buffer/service/program_cache_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3418874e74dca9756d7c0a8a37aa10b36f7e3bb5
|
| --- /dev/null
|
| +++ b/gpu/command_buffer/service/program_cache_unittest.cc
|
| @@ -0,0 +1,112 @@
|
| +// 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.h"
|
| +
|
| +#include <map>
|
| +#include "gpu/command_buffer/service/program_manager.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/string_number_conversions.h"
|
| +#include "base/string_util.h"
|
| +#include "gpu/command_buffer/common/gl_mock.h"
|
| +#include "gpu/command_buffer/common/gles2_cmd_format.h"
|
| +#include "gpu/command_buffer/service/common_decoder.h"
|
| +#include "gpu/command_buffer/service/mocks.h"
|
| +#include "gpu/command_buffer/service/test_helper.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +typedef std::map<std::string, GLint> location_map;
|
| +
|
| +namespace gpu {
|
| +namespace gles2 {
|
| +class NoBackendProgramCache : public ProgramCache {
|
| +public:
|
| + void LoadLinkedProgram(GLuint program,
|
| + ShaderManager::ShaderInfo* shader_a,
|
| + ShaderManager::ShaderInfo* shader_b,
|
| + location_map* bind_attrib_location_map) const {
|
| +
|
| + }
|
| + void SaveLinkedProgram(GLuint program,
|
| + ShaderManager::ShaderInfo* shader_a,
|
| + ShaderManager::ShaderInfo* shader_b,
|
| + location_map* bind_attrib_location_map) {
|
| +
|
| + }
|
| +};
|
| +
|
| +class ProgramCacheTest : public testing::Test {
|
| + public:
|
| + ProgramCacheTest() :
|
| + program_cache_(new NoBackendProgramCache()),
|
| + manager_(program_cache_->AsWeakPtr()) { }
|
| + ~ProgramCacheTest() {
|
| + manager_.Destroy(false);
|
| + }
|
| +
|
| + protected:
|
| + virtual void SetUp() {
|
| + gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
|
| + ::gfx::GLInterface::SetGLInterface(gl_.get());
|
| + }
|
| +
|
| + virtual void TearDown() {
|
| + ::gfx::GLInterface::SetGLInterface(NULL);
|
| + gl_.reset();
|
| + }
|
| +
|
| + scoped_ptr<ProgramCache> program_cache_;
|
| + // Use StrictMock to make 100% sure we know how GL will be called.
|
| + scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
|
| + ProgramManager manager_;
|
| +};
|
| +
|
| +TEST_F(ProgramCacheTest, TestProgramCacheCompilationStatus) {
|
| + const std::string shader1 = "abcd1234";
|
| + {
|
| + std::string shader = shader1;
|
| + ASSERT_EQ(ProgramCache::COMPILATION_UNKNOWN,
|
| + program_cache_->GetShaderCompilationStatus(shader));
|
| + program_cache_->SetShaderCompilationStatus(
|
| + shader,
|
| + ProgramCache::COMPILATION_SUCCEEDED);
|
| + shader.clear();
|
| + }
|
| + // make sure it was copied
|
| + ASSERT_EQ(ProgramCache::COMPILATION_SUCCEEDED,
|
| + program_cache_->GetShaderCompilationStatus(shader1));
|
| + program_cache_->SetShaderCompilationStatus(
|
| + shader1,
|
| + ProgramCache::COMPILATION_UNKNOWN);
|
| + ASSERT_EQ(ProgramCache::COMPILATION_UNKNOWN,
|
| + program_cache_->GetShaderCompilationStatus(shader1));
|
| +}
|
| +
|
| +TEST_F(ProgramCacheTest, TestProgramCacheProgramLinkStatus) {
|
| + const std::string shader1 = "abcd1234";
|
| + const std::string shader2 = "abcda sda b1~#4 bbbbb1234";
|
| + {
|
| + std::string shaderA = shader1;
|
| + std::string shaderB = shader2;
|
| + ASSERT_EQ(ProgramCache::LINK_UNKNOWN,
|
| + program_cache_->GetLinkedProgramStatus(shaderA, shaderB, NULL));
|
| + program_cache_->SetLinkedProgramStatus(
|
| + shaderA, shaderB, NULL,
|
| + ProgramCache::LINK_SUCCEEDED);
|
| + shaderA.clear();
|
| + shaderB.clear();
|
| + }
|
| + // make sure it was copied
|
| + ASSERT_EQ(ProgramCache::LINK_SUCCEEDED,
|
| + program_cache_->GetLinkedProgramStatus(shader1, shader2, NULL));
|
| + program_cache_->SetLinkedProgramStatus(
|
| + shader1, shader2, NULL,
|
| + ProgramCache::LINK_UNKNOWN);
|
| + ASSERT_EQ(ProgramCache::LINK_UNKNOWN,
|
| + program_cache_->GetLinkedProgramStatus(shader1, shader2, NULL));
|
| +}
|
| +
|
| +} // namespace gles2
|
| +} // namespace gpu
|
|
|