| 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.h" |
| 6 |
| 7 #include <map> |
| 8 #include "gpu/command_buffer/service/program_manager.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_util.h" |
| 13 #include "gpu/command_buffer/common/gl_mock.h" |
| 14 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 15 #include "gpu/command_buffer/service/common_decoder.h" |
| 16 #include "gpu/command_buffer/service/mocks.h" |
| 17 #include "gpu/command_buffer/service/test_helper.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 |
| 20 typedef std::map<std::string, GLint> location_map; |
| 21 |
| 22 namespace gpu { |
| 23 namespace gles2 { |
| 24 class NoBackendProgramCache : public ProgramCache { |
| 25 public: |
| 26 void LoadLinkedProgram(GLuint program, |
| 27 ShaderManager::ShaderInfo* shader_a, |
| 28 ShaderManager::ShaderInfo* shader_b, |
| 29 location_map* bind_attrib_location_map) const { |
| 30 |
| 31 } |
| 32 void SaveLinkedProgram(GLuint program, |
| 33 ShaderManager::ShaderInfo* shader_a, |
| 34 ShaderManager::ShaderInfo* shader_b, |
| 35 location_map* bind_attrib_location_map) { |
| 36 |
| 37 } |
| 38 }; |
| 39 |
| 40 class ProgramCacheTest : public testing::Test { |
| 41 public: |
| 42 ProgramCacheTest() : |
| 43 program_cache_(new NoBackendProgramCache()), |
| 44 manager_(program_cache_->AsWeakPtr()) { } |
| 45 ~ProgramCacheTest() { |
| 46 manager_.Destroy(false); |
| 47 } |
| 48 |
| 49 protected: |
| 50 virtual void SetUp() { |
| 51 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 52 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
| 53 } |
| 54 |
| 55 virtual void TearDown() { |
| 56 ::gfx::GLInterface::SetGLInterface(NULL); |
| 57 gl_.reset(); |
| 58 } |
| 59 |
| 60 scoped_ptr<ProgramCache> program_cache_; |
| 61 // Use StrictMock to make 100% sure we know how GL will be called. |
| 62 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
| 63 ProgramManager manager_; |
| 64 }; |
| 65 |
| 66 TEST_F(ProgramCacheTest, TestProgramCacheCompilationStatus) { |
| 67 const std::string shader1 = "abcd1234"; |
| 68 { |
| 69 std::string shader = shader1; |
| 70 ASSERT_EQ(ProgramCache::COMPILATION_UNKNOWN, |
| 71 program_cache_->GetShaderCompilationStatus(shader)); |
| 72 program_cache_->SetShaderCompilationStatus( |
| 73 shader, |
| 74 ProgramCache::COMPILATION_SUCCEEDED); |
| 75 shader.clear(); |
| 76 } |
| 77 // make sure it was copied |
| 78 ASSERT_EQ(ProgramCache::COMPILATION_SUCCEEDED, |
| 79 program_cache_->GetShaderCompilationStatus(shader1)); |
| 80 program_cache_->SetShaderCompilationStatus( |
| 81 shader1, |
| 82 ProgramCache::COMPILATION_UNKNOWN); |
| 83 ASSERT_EQ(ProgramCache::COMPILATION_UNKNOWN, |
| 84 program_cache_->GetShaderCompilationStatus(shader1)); |
| 85 } |
| 86 |
| 87 TEST_F(ProgramCacheTest, TestProgramCacheProgramLinkStatus) { |
| 88 const std::string shader1 = "abcd1234"; |
| 89 const std::string shader2 = "abcda sda b1~#4 bbbbb1234"; |
| 90 { |
| 91 std::string shaderA = shader1; |
| 92 std::string shaderB = shader2; |
| 93 ASSERT_EQ(ProgramCache::LINK_UNKNOWN, |
| 94 program_cache_->GetLinkedProgramStatus(shaderA, shaderB, NULL)); |
| 95 program_cache_->SetLinkedProgramStatus( |
| 96 shaderA, shaderB, NULL, |
| 97 ProgramCache::LINK_SUCCEEDED); |
| 98 shaderA.clear(); |
| 99 shaderB.clear(); |
| 100 } |
| 101 // make sure it was copied |
| 102 ASSERT_EQ(ProgramCache::LINK_SUCCEEDED, |
| 103 program_cache_->GetLinkedProgramStatus(shader1, shader2, NULL)); |
| 104 program_cache_->SetLinkedProgramStatus( |
| 105 shader1, shader2, NULL, |
| 106 ProgramCache::LINK_UNKNOWN); |
| 107 ASSERT_EQ(ProgramCache::LINK_UNKNOWN, |
| 108 program_cache_->GetLinkedProgramStatus(shader1, shader2, NULL)); |
| 109 } |
| 110 |
| 111 } // namespace gles2 |
| 112 } // namespace gpu |
| OLD | NEW |