OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/shader_manager.h" | 5 #include "gpu/command_buffer/service/shader_manager.h" |
| 6 #include "base/scoped_ptr.h" |
| 7 #include "app/gfx/gl/gl_mock.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
7 | 9 |
8 namespace gpu { | 10 namespace gpu { |
9 namespace gles2 { | 11 namespace gles2 { |
10 | 12 |
11 class ShaderManagerTest : public testing::Test { | 13 class ShaderManagerTest : public testing::Test { |
12 public: | 14 public: |
13 ShaderManagerTest() { | 15 ShaderManagerTest() { |
14 } | 16 } |
15 | 17 |
| 18 ~ShaderManagerTest() { |
| 19 manager_.Destroy(false); |
| 20 } |
| 21 |
16 protected: | 22 protected: |
17 virtual void SetUp() { | 23 virtual void SetUp() { |
| 24 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 25 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
18 } | 26 } |
19 | 27 |
20 virtual void TearDown() { | 28 virtual void TearDown() { |
| 29 ::gfx::GLInterface::SetGLInterface(NULL); |
| 30 gl_.reset(); |
21 } | 31 } |
22 | 32 |
| 33 // Use StrictMock to make 100% sure we know how GL will be called. |
| 34 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
23 ShaderManager manager_; | 35 ShaderManager manager_; |
24 }; | 36 }; |
25 | 37 |
26 TEST_F(ShaderManagerTest, Basic) { | 38 TEST_F(ShaderManagerTest, Basic) { |
27 const GLuint kClient1Id = 1; | 39 const GLuint kClient1Id = 1; |
28 const GLuint kService1Id = 11; | 40 const GLuint kService1Id = 11; |
29 const GLenum kShader1Type = GL_VERTEX_SHADER; | 41 const GLenum kShader1Type = GL_VERTEX_SHADER; |
30 const std::string kClient1Source("hello world"); | 42 const std::string kClient1Source("hello world"); |
31 const GLuint kClient2Id = 2; | 43 const GLuint kClient2Id = 2; |
32 // Check we can create shader. | 44 // Check we can create shader. |
(...skipping 15 matching lines...) Expand all Loading... |
48 EXPECT_STREQ(kClient1Source.c_str(), info1->source().c_str()); | 60 EXPECT_STREQ(kClient1Source.c_str(), info1->source().c_str()); |
49 // Check we get nothing for a non-existent shader. | 61 // Check we get nothing for a non-existent shader. |
50 EXPECT_TRUE(manager_.GetShaderInfo(kClient2Id) == NULL); | 62 EXPECT_TRUE(manager_.GetShaderInfo(kClient2Id) == NULL); |
51 // Check trying to a remove non-existent shaders does not crash. | 63 // Check trying to a remove non-existent shaders does not crash. |
52 manager_.RemoveShaderInfo(kClient2Id); | 64 manager_.RemoveShaderInfo(kClient2Id); |
53 // Check we can't get the shader after we remove it. | 65 // Check we can't get the shader after we remove it. |
54 manager_.RemoveShaderInfo(kClient1Id); | 66 manager_.RemoveShaderInfo(kClient1Id); |
55 EXPECT_TRUE(manager_.GetShaderInfo(kClient1Id) == NULL); | 67 EXPECT_TRUE(manager_.GetShaderInfo(kClient1Id) == NULL); |
56 } | 68 } |
57 | 69 |
| 70 TEST_F(ShaderManagerTest, Destroy) { |
| 71 const GLuint kClient1Id = 1; |
| 72 const GLuint kService1Id = 11; |
| 73 const GLenum kShader1Type = GL_VERTEX_SHADER; |
| 74 // Check we can create shader. |
| 75 manager_.CreateShaderInfo(kClient1Id, kService1Id, kShader1Type); |
| 76 // Check shader got created. |
| 77 ShaderManager::ShaderInfo* info1 = manager_.GetShaderInfo(kClient1Id); |
| 78 ASSERT_TRUE(info1 != NULL); |
| 79 EXPECT_CALL(*gl_, DeleteShader(kService1Id)) |
| 80 .Times(1) |
| 81 .RetiresOnSaturation(); |
| 82 manager_.Destroy(true); |
| 83 // Check that resources got freed. |
| 84 info1 = manager_.GetShaderInfo(kClient1Id); |
| 85 ASSERT_TRUE(info1 == NULL); |
| 86 } |
| 87 |
58 } // namespace gles2 | 88 } // namespace gles2 |
59 } // namespace gpu | 89 } // namespace gpu |
60 | 90 |
61 | 91 |
OLD | NEW |