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 <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 gl_->GetProgramInfoCHROMIUM(kProgramId, -1, &size, &buf); | 2017 gl_->GetProgramInfoCHROMIUM(kProgramId, -1, &size, &buf); |
2018 EXPECT_TRUE(NoCommandsWritten()); | 2018 EXPECT_TRUE(NoCommandsWritten()); |
2019 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); | 2019 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
2020 ClearCommands(); | 2020 ClearCommands(); |
2021 // try no size ptr. | 2021 // try no size ptr. |
2022 gl_->GetProgramInfoCHROMIUM(kProgramId, sizeof(buf), NULL, &buf); | 2022 gl_->GetProgramInfoCHROMIUM(kProgramId, sizeof(buf), NULL, &buf); |
2023 EXPECT_TRUE(NoCommandsWritten()); | 2023 EXPECT_TRUE(NoCommandsWritten()); |
2024 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); | 2024 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
2025 } | 2025 } |
2026 | 2026 |
| 2027 TEST_F(GLES2ImplementationTest, GetUniformBlocksCHROMIUMGoodArgs) { |
| 2028 const uint32 kBucketId = GLES2Implementation::kResultBucketId; |
| 2029 const GLuint kProgramId = 123; |
| 2030 const char kBad = 0x12; |
| 2031 GLsizei size = 0; |
| 2032 const Str7 kString = {"foobar"}; |
| 2033 char buf[20]; |
| 2034 |
| 2035 ExpectedMemoryInfo mem1 = |
| 2036 GetExpectedMemory(MaxTransferBufferSize()); |
| 2037 ExpectedMemoryInfo result1 = |
| 2038 GetExpectedResultMemory(sizeof(cmd::GetBucketStart::Result)); |
| 2039 ExpectedMemoryInfo result2 = |
| 2040 GetExpectedResultMemory(sizeof(cmds::GetError::Result)); |
| 2041 |
| 2042 memset(buf, kBad, sizeof(buf)); |
| 2043 EXPECT_CALL(*command_buffer(), OnFlush()) |
| 2044 .WillOnce(DoAll(SetMemory(result1.ptr, uint32(sizeof(kString))), |
| 2045 SetMemory(mem1.ptr, kString))) |
| 2046 .WillOnce(SetMemory(result2.ptr, GLuint(GL_NO_ERROR))) |
| 2047 .RetiresOnSaturation(); |
| 2048 |
| 2049 struct Cmds { |
| 2050 cmd::SetBucketSize set_bucket_size1; |
| 2051 cmds::GetUniformBlocksCHROMIUM get_uniform_blocks; |
| 2052 cmd::GetBucketStart get_bucket_start; |
| 2053 cmd::SetToken set_token1; |
| 2054 cmd::SetBucketSize set_bucket_size2; |
| 2055 }; |
| 2056 Cmds expected; |
| 2057 expected.set_bucket_size1.Init(kBucketId, 0); |
| 2058 expected.get_uniform_blocks.Init(kProgramId, kBucketId); |
| 2059 expected.get_bucket_start.Init( |
| 2060 kBucketId, result1.id, result1.offset, |
| 2061 MaxTransferBufferSize(), mem1.id, mem1.offset); |
| 2062 expected.set_token1.Init(GetNextToken()); |
| 2063 expected.set_bucket_size2.Init(kBucketId, 0); |
| 2064 gl_->GetUniformBlocksCHROMIUM(kProgramId, sizeof(buf), &size, &buf); |
| 2065 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
| 2066 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), gl_->GetError()); |
| 2067 EXPECT_EQ(sizeof(kString), static_cast<size_t>(size)); |
| 2068 EXPECT_STREQ(kString.str, buf); |
| 2069 EXPECT_EQ(buf[sizeof(kString)], kBad); |
| 2070 } |
| 2071 |
| 2072 TEST_F(GLES2ImplementationTest, GetUniformBlocksCHROMIUMBadArgs) { |
| 2073 const uint32 kBucketId = GLES2Implementation::kResultBucketId; |
| 2074 const GLuint kProgramId = 123; |
| 2075 GLsizei size = 0; |
| 2076 const Str7 kString = {"foobar"}; |
| 2077 char buf[20]; |
| 2078 |
| 2079 ExpectedMemoryInfo mem1 = GetExpectedMemory(MaxTransferBufferSize()); |
| 2080 ExpectedMemoryInfo result1 = |
| 2081 GetExpectedResultMemory(sizeof(cmd::GetBucketStart::Result)); |
| 2082 ExpectedMemoryInfo result2 = |
| 2083 GetExpectedResultMemory(sizeof(cmds::GetError::Result)); |
| 2084 ExpectedMemoryInfo result3 = |
| 2085 GetExpectedResultMemory(sizeof(cmds::GetError::Result)); |
| 2086 ExpectedMemoryInfo result4 = |
| 2087 GetExpectedResultMemory(sizeof(cmds::GetError::Result)); |
| 2088 |
| 2089 EXPECT_CALL(*command_buffer(), OnFlush()) |
| 2090 .WillOnce(DoAll(SetMemory(result1.ptr, uint32(sizeof(kString))), |
| 2091 SetMemory(mem1.ptr, kString))) |
| 2092 .WillOnce(SetMemory(result2.ptr, GLuint(GL_NO_ERROR))) |
| 2093 .WillOnce(SetMemory(result3.ptr, GLuint(GL_NO_ERROR))) |
| 2094 .WillOnce(SetMemory(result4.ptr, GLuint(GL_NO_ERROR))) |
| 2095 .RetiresOnSaturation(); |
| 2096 |
| 2097 // try bufsize not big enough. |
| 2098 struct Cmds { |
| 2099 cmd::SetBucketSize set_bucket_size1; |
| 2100 cmds::GetUniformBlocksCHROMIUM get_uniform_blocks; |
| 2101 cmd::GetBucketStart get_bucket_start; |
| 2102 cmd::SetToken set_token1; |
| 2103 cmd::SetBucketSize set_bucket_size2; |
| 2104 }; |
| 2105 Cmds expected; |
| 2106 expected.set_bucket_size1.Init(kBucketId, 0); |
| 2107 expected.get_uniform_blocks.Init(kProgramId, kBucketId); |
| 2108 expected.get_bucket_start.Init( |
| 2109 kBucketId, result1.id, result1.offset, |
| 2110 MaxTransferBufferSize(), mem1.id, mem1.offset); |
| 2111 expected.set_token1.Init(GetNextToken()); |
| 2112 expected.set_bucket_size2.Init(kBucketId, 0); |
| 2113 gl_->GetUniformBlocksCHROMIUM(kProgramId, 6, &size, &buf); |
| 2114 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); |
| 2115 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), gl_->GetError()); |
| 2116 ClearCommands(); |
| 2117 |
| 2118 // try bad bufsize |
| 2119 gl_->GetUniformBlocksCHROMIUM(kProgramId, -1, &size, &buf); |
| 2120 EXPECT_TRUE(NoCommandsWritten()); |
| 2121 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 2122 ClearCommands(); |
| 2123 // try no size ptr. |
| 2124 gl_->GetUniformBlocksCHROMIUM(kProgramId, sizeof(buf), NULL, &buf); |
| 2125 EXPECT_TRUE(NoCommandsWritten()); |
| 2126 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), gl_->GetError()); |
| 2127 } |
| 2128 |
2027 // Test that things are cached | 2129 // Test that things are cached |
2028 TEST_F(GLES2ImplementationTest, GetIntegerCacheRead) { | 2130 TEST_F(GLES2ImplementationTest, GetIntegerCacheRead) { |
2029 struct PNameValue { | 2131 struct PNameValue { |
2030 GLenum pname; | 2132 GLenum pname; |
2031 GLint expected; | 2133 GLint expected; |
2032 }; | 2134 }; |
2033 const PNameValue pairs[] = { | 2135 const PNameValue pairs[] = { |
2034 {GL_ACTIVE_TEXTURE, GL_TEXTURE0, }, | 2136 {GL_ACTIVE_TEXTURE, GL_TEXTURE0, }, |
2035 {GL_TEXTURE_BINDING_2D, 0, }, | 2137 {GL_TEXTURE_BINDING_2D, 0, }, |
2036 {GL_TEXTURE_BINDING_CUBE_MAP, 0, }, | 2138 {GL_TEXTURE_BINDING_CUBE_MAP, 0, }, |
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3541 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { | 3643 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { |
3542 ContextInitOptions init_options; | 3644 ContextInitOptions init_options; |
3543 init_options.transfer_buffer_initialize_fail = true; | 3645 init_options.transfer_buffer_initialize_fail = true; |
3544 EXPECT_FALSE(Initialize(init_options)); | 3646 EXPECT_FALSE(Initialize(init_options)); |
3545 } | 3647 } |
3546 | 3648 |
3547 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 3649 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
3548 | 3650 |
3549 } // namespace gles2 | 3651 } // namespace gles2 |
3550 } // namespace gpu | 3652 } // namespace gpu |
OLD | NEW |