OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Tests for GLES2Implementation. | 5 // Tests for GLES2Implementation. |
6 | 6 |
7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 | 8 |
9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
10 #include "gpu/command_buffer/client/client_test_helper.h" | 10 #include "gpu/command_buffer/client/client_test_helper.h" |
(...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 | 2296 |
2297 TEST_F(GLES2ImplementationTest, GetString) { | 2297 TEST_F(GLES2ImplementationTest, GetString) { |
2298 const uint32 kBucketId = GLES2Implementation::kResultBucketId; | 2298 const uint32 kBucketId = GLES2Implementation::kResultBucketId; |
2299 const Str7 kString = {"foobar"}; | 2299 const Str7 kString = {"foobar"}; |
2300 // GL_CHROMIUM_map_sub GL_CHROMIUM_flipy are hard coded into | 2300 // GL_CHROMIUM_map_sub GL_CHROMIUM_flipy are hard coded into |
2301 // GLES2Implementation. | 2301 // GLES2Implementation. |
2302 const char* expected_str = | 2302 const char* expected_str = |
2303 "foobar " | 2303 "foobar " |
2304 "GL_CHROMIUM_map_sub " | 2304 "GL_CHROMIUM_map_sub " |
2305 "GL_CHROMIUM_flipy " | 2305 "GL_CHROMIUM_flipy " |
2306 "GL_CHROMIUM_consistent_uniform_locations " | |
2307 "GL_EXT_unpack_subimage"; | 2306 "GL_EXT_unpack_subimage"; |
2308 const char kBad = 0x12; | 2307 const char kBad = 0x12; |
2309 struct Cmds { | 2308 struct Cmds { |
2310 cmd::SetBucketSize set_bucket_size1; | 2309 cmd::SetBucketSize set_bucket_size1; |
2311 GetString get_string; | 2310 GetString get_string; |
2312 cmd::GetBucketStart get_bucket_start; | 2311 cmd::GetBucketStart get_bucket_start; |
2313 cmd::SetToken set_token1; | 2312 cmd::SetToken set_token1; |
2314 cmd::SetBucketSize set_bucket_size2; | 2313 cmd::SetBucketSize set_bucket_size2; |
2315 }; | 2314 }; |
2316 ExpectedMemoryInfo mem1 = GetExpectedMemory(MaxTransferBufferSize()); | 2315 ExpectedMemoryInfo mem1 = GetExpectedMemory(MaxTransferBufferSize()); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2558 EXPECT_EQ(0xBDu, available); | 2557 EXPECT_EQ(0xBDu, available); |
2559 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); | 2558 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); |
2560 | 2559 |
2561 // Test GetQueryObjectuivEXT CheckResultsAvailable | 2560 // Test GetQueryObjectuivEXT CheckResultsAvailable |
2562 ClearCommands(); | 2561 ClearCommands(); |
2563 gl_->GetQueryObjectuivEXT(id1, GL_QUERY_RESULT_AVAILABLE_EXT, &available); | 2562 gl_->GetQueryObjectuivEXT(id1, GL_QUERY_RESULT_AVAILABLE_EXT, &available); |
2564 EXPECT_TRUE(NoCommandsWritten()); | 2563 EXPECT_TRUE(NoCommandsWritten()); |
2565 EXPECT_EQ(0u, available); | 2564 EXPECT_EQ(0u, available); |
2566 } | 2565 } |
2567 | 2566 |
2568 namespace { | |
2569 | |
2570 class MockProgramInfoManager : public ProgramInfoManager { | |
2571 public: | |
2572 virtual ~MockProgramInfoManager() {}; | |
2573 | |
2574 MOCK_METHOD1(CreateInfo, void(GLuint program)); | |
2575 | |
2576 MOCK_METHOD1(DeleteInfo, void(GLuint program)); | |
2577 | |
2578 MOCK_METHOD4(GetProgramiv, bool( | |
2579 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params)); | |
2580 | |
2581 MOCK_METHOD3(GetAttribLocation, GLint( | |
2582 GLES2Implementation* gl, GLuint program, const char* name)); | |
2583 | |
2584 MOCK_METHOD3(GetUniformLocation, GLint( | |
2585 GLES2Implementation* gl, GLuint program, const char* name)); | |
2586 | |
2587 MOCK_METHOD8(GetActiveAttrib, bool( | |
2588 GLES2Implementation* gl, | |
2589 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | |
2590 GLint* size, GLenum* type, char* name)); | |
2591 | |
2592 MOCK_METHOD8(GetActiveUniform, bool( | |
2593 GLES2Implementation* gl, | |
2594 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, | |
2595 GLint* size, GLenum* type, char* name)); | |
2596 }; | |
2597 | |
2598 } // anonymous namespace | |
2599 | |
2600 TEST_F(GLES2ImplementationTest, GetUniformLocationsCHROMIUM) { | |
2601 MockProgramInfoManager* manager = new MockProgramInfoManager(); | |
2602 SetProgramInfoManager(manager); | |
2603 | |
2604 const GLuint kProgramId = 123; | |
2605 static const GLUniformDefinitionCHROMIUM good_defs[] = { | |
2606 { GL_FLOAT_VEC4, 1, "moo", }, | |
2607 { GL_FLOAT_VEC4, 4, "bar", }, | |
2608 { GL_FLOAT_VEC4, 3, "foo", }, | |
2609 }; | |
2610 | |
2611 static const GLUniformDefinitionCHROMIUM bad_defs[] = { | |
2612 { GL_FLOAT_VEC4, 1, "moo", }, | |
2613 { GL_FLOAT_VEC4, 0, "bar", }, | |
2614 { GL_FLOAT_VEC4, 3, "foo", }, | |
2615 }; | |
2616 | |
2617 // Test bad count | |
2618 GLint locations[50] = { -1, }; | |
2619 gl_->GetUniformLocationsCHROMIUM(kProgramId, bad_defs, 0, 1, locations); | |
2620 EXPECT_EQ(GL_INVALID_VALUE, CheckError()); | |
2621 EXPECT_EQ(-1, locations[0]); | |
2622 | |
2623 // Test bad size. | |
2624 gl_->GetUniformLocationsCHROMIUM( | |
2625 kProgramId, bad_defs, arraysize(bad_defs), 1, locations); | |
2626 EXPECT_EQ(GL_INVALID_VALUE, CheckError()); | |
2627 EXPECT_EQ(-1, locations[0]); | |
2628 | |
2629 #if defined(GPU_CLIENT_DEBUG) | |
2630 EXPECT_CALL(*manager, GetUniformLocation(_, kProgramId, _)) | |
2631 .WillOnce(Return( | |
2632 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)))) | |
2633 .WillOnce(Return( | |
2634 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)))) | |
2635 .WillOnce(Return( | |
2636 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)))) | |
2637 .RetiresOnSaturation(); | |
2638 #endif | |
2639 | |
2640 // Test max_locations | |
2641 gl_->GetUniformLocationsCHROMIUM( | |
2642 kProgramId, good_defs, arraysize(good_defs), 3, locations); | |
2643 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)), | |
2644 locations[0]); | |
2645 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)), | |
2646 locations[1]); | |
2647 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)), | |
2648 locations[2]); | |
2649 EXPECT_EQ(0, locations[3]); | |
2650 | |
2651 #if defined(GPU_CLIENT_DEBUG) | |
2652 EXPECT_CALL(*manager, GetUniformLocation(_, kProgramId, _)) | |
2653 .WillOnce(Return( | |
2654 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)))) | |
2655 .WillOnce(Return( | |
2656 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)))) | |
2657 .WillOnce(Return( | |
2658 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)))) | |
2659 .WillOnce(Return( | |
2660 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 2)))) | |
2661 .WillOnce(Return( | |
2662 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 3)))) | |
2663 .WillOnce(Return( | |
2664 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 0)))) | |
2665 .WillOnce(Return( | |
2666 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 1)))) | |
2667 .WillOnce(Return( | |
2668 GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 2)))) | |
2669 .RetiresOnSaturation(); | |
2670 #endif | |
2671 | |
2672 // Test all. | |
2673 gl_->GetUniformLocationsCHROMIUM( | |
2674 kProgramId, good_defs, arraysize(good_defs), arraysize(locations), | |
2675 locations); | |
2676 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(2, 0)), | |
2677 locations[0]); | |
2678 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 0)), | |
2679 locations[1]); | |
2680 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 1)), | |
2681 locations[2]); | |
2682 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 2)), | |
2683 locations[3]); | |
2684 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(0, 3)), | |
2685 locations[4]); | |
2686 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 0)), | |
2687 locations[5]); | |
2688 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 1)), | |
2689 locations[6]); | |
2690 EXPECT_EQ(GLES2Util::SwizzleLocation(GLES2Util::MakeFakeLocation(1, 2)), | |
2691 locations[7]); | |
2692 EXPECT_EQ(0, locations[8]); | |
2693 } | |
2694 | |
2695 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 2567 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
2696 | 2568 |
2697 } // namespace gles2 | 2569 } // namespace gles2 |
2698 } // namespace gpu | 2570 } // namespace gpu |
2699 | 2571 |
OLD | NEW |