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/program_manager.h" | 5 #include "gpu/command_buffer/service/program_manager.h" |
6 #include "app/gfx/gl/gl_mock.h" | 6 #include "app/gfx/gl/gl_mock.h" |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 using ::gfx::MockGLInterface; | 11 using ::gfx::MockGLInterface; |
12 using ::testing::_; | 12 using ::testing::_; |
13 using ::testing::DoAll; | 13 using ::testing::DoAll; |
14 using ::testing::InSequence; | 14 using ::testing::InSequence; |
15 using ::testing::MatcherCast; | 15 using ::testing::MatcherCast; |
16 using ::testing::Pointee; | 16 using ::testing::Pointee; |
17 using ::testing::Return; | 17 using ::testing::Return; |
18 using ::testing::SetArrayArgument; | 18 using ::testing::SetArrayArgument; |
19 using ::testing::SetArgumentPointee; | 19 using ::testing::SetArgumentPointee; |
20 using ::testing::StrEq; | 20 using ::testing::StrEq; |
21 using ::testing::StrictMock; | 21 using ::testing::StrictMock; |
22 | 22 |
23 namespace gpu { | 23 namespace gpu { |
24 namespace gles2 { | 24 namespace gles2 { |
25 | 25 |
26 class ProgramManagerTest : public testing::Test { | 26 class ProgramManagerTest : public testing::Test { |
27 public: | 27 public: |
28 ProgramManagerTest() { } | 28 ProgramManagerTest() { } |
| 29 ~ProgramManagerTest() { |
| 30 manager_.Destroy(false); |
| 31 } |
29 | 32 |
30 protected: | 33 protected: |
31 virtual void SetUp() { | 34 virtual void SetUp() { |
| 35 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 36 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
32 } | 37 } |
33 | 38 |
34 virtual void TearDown() { | 39 virtual void TearDown() { |
| 40 ::gfx::GLInterface::SetGLInterface(NULL); |
| 41 gl_.reset(); |
35 } | 42 } |
36 | 43 |
| 44 // Use StrictMock to make 100% sure we know how GL will be called. |
| 45 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
37 ProgramManager manager_; | 46 ProgramManager manager_; |
38 }; | 47 }; |
39 | 48 |
40 TEST_F(ProgramManagerTest, Basic) { | 49 TEST_F(ProgramManagerTest, Basic) { |
41 const GLuint kClient1Id = 1; | 50 const GLuint kClient1Id = 1; |
42 const GLuint kService1Id = 11; | 51 const GLuint kService1Id = 11; |
43 const GLuint kClient2Id = 2; | 52 const GLuint kClient2Id = 2; |
44 // Check we can create program. | 53 // Check we can create program. |
45 manager_.CreateProgramInfo(kClient1Id, kService1Id); | 54 manager_.CreateProgramInfo(kClient1Id, kService1Id); |
46 // Check program got created. | 55 // Check program got created. |
47 ProgramManager::ProgramInfo* info1 = manager_.GetProgramInfo(kClient1Id); | 56 ProgramManager::ProgramInfo* info1 = manager_.GetProgramInfo(kClient1Id); |
48 ASSERT_TRUE(info1 != NULL); | 57 ASSERT_TRUE(info1 != NULL); |
49 EXPECT_EQ(kService1Id, info1->service_id()); | 58 EXPECT_EQ(kService1Id, info1->service_id()); |
50 EXPECT_FALSE(info1->CanLink()); | 59 EXPECT_FALSE(info1->CanLink()); |
51 EXPECT_STREQ("", info1->log_info().c_str()); | 60 EXPECT_STREQ("", info1->log_info().c_str()); |
52 GLuint client_id = 0; | 61 GLuint client_id = 0; |
53 EXPECT_TRUE(manager_.GetClientId(info1->service_id(), &client_id)); | 62 EXPECT_TRUE(manager_.GetClientId(info1->service_id(), &client_id)); |
54 EXPECT_EQ(kClient1Id, client_id); | 63 EXPECT_EQ(kClient1Id, client_id); |
55 // Check we get nothing for a non-existent program. | 64 // Check we get nothing for a non-existent program. |
56 EXPECT_TRUE(manager_.GetProgramInfo(kClient2Id) == NULL); | 65 EXPECT_TRUE(manager_.GetProgramInfo(kClient2Id) == NULL); |
57 // Check trying to a remove non-existent programs does not crash. | 66 // Check trying to a remove non-existent programs does not crash. |
58 manager_.RemoveProgramInfo(kClient2Id); | 67 manager_.RemoveProgramInfo(kClient2Id); |
59 // Check we can't get the program after we remove it. | 68 // Check we can't get the program after we remove it. |
60 manager_.RemoveProgramInfo(kClient1Id); | 69 manager_.RemoveProgramInfo(kClient1Id); |
61 EXPECT_TRUE(manager_.GetProgramInfo(kClient1Id) == NULL); | 70 EXPECT_TRUE(manager_.GetProgramInfo(kClient1Id) == NULL); |
62 } | 71 } |
63 | 72 |
| 73 TEST_F(ProgramManagerTest, Destroy) { |
| 74 const GLuint kClient1Id = 1; |
| 75 const GLuint kService1Id = 11; |
| 76 // Check we can create program. |
| 77 manager_.CreateProgramInfo(kClient1Id, kService1Id); |
| 78 // Check program got created. |
| 79 ProgramManager::ProgramInfo* info1 = |
| 80 manager_.GetProgramInfo(kClient1Id); |
| 81 ASSERT_TRUE(info1 != NULL); |
| 82 EXPECT_CALL(*gl_, DeleteProgram(kService1Id)) |
| 83 .Times(1) |
| 84 .RetiresOnSaturation(); |
| 85 manager_.Destroy(true); |
| 86 // Check the resources were released. |
| 87 info1 = manager_.GetProgramInfo(kClient1Id); |
| 88 ASSERT_TRUE(info1 == NULL); |
| 89 } |
| 90 |
64 class ProgramManagerWithShaderTest : public testing::Test { | 91 class ProgramManagerWithShaderTest : public testing::Test { |
65 public: | 92 public: |
66 ProgramManagerWithShaderTest() | 93 ProgramManagerWithShaderTest() |
67 : program_info_(NULL) { | 94 : program_info_(NULL) { |
68 } | 95 } |
69 | 96 |
| 97 ~ProgramManagerWithShaderTest() { |
| 98 manager_.Destroy(false); |
| 99 } |
| 100 |
70 static const GLint kNumVertexAttribs = 16; | 101 static const GLint kNumVertexAttribs = 16; |
71 | 102 |
72 static const GLuint kClientProgramId = 123; | 103 static const GLuint kClientProgramId = 123; |
73 static const GLuint kServiceProgramId = 456; | 104 static const GLuint kServiceProgramId = 456; |
74 | 105 |
75 static const char* kAttrib1Name; | 106 static const char* kAttrib1Name; |
76 static const char* kAttrib2Name; | 107 static const char* kAttrib2Name; |
77 static const char* kAttrib3Name; | 108 static const char* kAttrib3Name; |
78 static const GLint kAttrib1Size = 1; | 109 static const GLint kAttrib1Size = 1; |
79 static const GLint kAttrib2Size = 1; | 110 static const GLint kAttrib2Size = 1; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 program_info->AttachShader(fshader); | 434 program_info->AttachShader(fshader); |
404 EXPECT_TRUE(program_info->CanLink()); | 435 EXPECT_TRUE(program_info->CanLink()); |
405 vshader->SetStatus(false, ""); | 436 vshader->SetStatus(false, ""); |
406 EXPECT_FALSE(program_info->CanLink()); | 437 EXPECT_FALSE(program_info->CanLink()); |
407 vshader->SetStatus(true, ""); | 438 vshader->SetStatus(true, ""); |
408 EXPECT_TRUE(program_info->CanLink()); | 439 EXPECT_TRUE(program_info->CanLink()); |
409 fshader->SetStatus(false, ""); | 440 fshader->SetStatus(false, ""); |
410 EXPECT_FALSE(program_info->CanLink()); | 441 EXPECT_FALSE(program_info->CanLink()); |
411 fshader->SetStatus(true, ""); | 442 fshader->SetStatus(true, ""); |
412 EXPECT_TRUE(program_info->CanLink()); | 443 EXPECT_TRUE(program_info->CanLink()); |
| 444 shader_manager.Destroy(false); |
413 } | 445 } |
414 | 446 |
415 TEST_F(ProgramManagerWithShaderTest, GetUniformLocation) { | 447 TEST_F(ProgramManagerWithShaderTest, GetUniformLocation) { |
416 const ProgramManager::ProgramInfo* program_info = | 448 const ProgramManager::ProgramInfo* program_info = |
417 manager_.GetProgramInfo(kClientProgramId); | 449 manager_.GetProgramInfo(kClientProgramId); |
418 ASSERT_TRUE(program_info != NULL); | 450 ASSERT_TRUE(program_info != NULL); |
419 EXPECT_EQ(kUniform1Location, program_info->GetUniformLocation(kUniform1Name)); | 451 EXPECT_EQ(kUniform1Location, program_info->GetUniformLocation(kUniform1Name)); |
420 EXPECT_EQ(kUniform2Location, program_info->GetUniformLocation(kUniform2Name)); | 452 EXPECT_EQ(kUniform2Location, program_info->GetUniformLocation(kUniform2Name)); |
421 EXPECT_EQ(kUniform3Location, program_info->GetUniformLocation(kUniform3Name)); | 453 EXPECT_EQ(kUniform3Location, program_info->GetUniformLocation(kUniform3Name)); |
422 // Check we can get uniform2 as "uniform2" even though the name is | 454 // Check we can get uniform2 as "uniform2" even though the name is |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 // as the "gl_" uniform we skipped. | 514 // as the "gl_" uniform we skipped. |
483 // +4u is to account for "gl_" and NULL terminator. | 515 // +4u is to account for "gl_" and NULL terminator. |
484 program_info->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); | 516 program_info->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); |
485 EXPECT_EQ(strlen(kUniform3Name) + 4u, static_cast<size_t>(value)); | 517 EXPECT_EQ(strlen(kUniform3Name) + 4u, static_cast<size_t>(value)); |
486 } | 518 } |
487 | 519 |
488 } // namespace gles2 | 520 } // namespace gles2 |
489 } // namespace gpu | 521 } // namespace gpu |
490 | 522 |
491 | 523 |
OLD | NEW |