summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-10 23:36:23 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-10 23:36:23 +0000
commit0abf43e36fe308dd817d9770b4f1ab98efef9466 (patch)
tree868339d3ae5e5ed7e25e955c8284f765df444c76 /gpu
parentd24c13b516c6b69cc0e16176929749b4fb626917 (diff)
downloadchromium_src-0abf43e36fe308dd817d9770b4f1ab98efef9466.zip
chromium_src-0abf43e36fe308dd817d9770b4f1ab98efef9466.tar.gz
chromium_src-0abf43e36fe308dd817d9770b4f1ab98efef9466.tar.bz2
Consolidate GPU unit test expectiation functions.
TEST=unit tests still run BUG=none R=apatrick@chromium.org Review URL: https://chromiumcodereview.appspot.com/10389077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136447 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc169
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h22
-rw-r--r--gpu/command_buffer/service/program_manager_unittest.cc214
-rw-r--r--gpu/command_buffer/service/test_helper.cc179
-rw-r--r--gpu/command_buffer/service/test_helper.h28
5 files changed, 235 insertions, 377 deletions
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
index 8b7f0ca..71d6a30 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
@@ -1160,93 +1160,9 @@ void GLES2DecoderTestBase::SetupShader(
AttachShader(program_service_id, fragment_shader_service_id))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*gl_, LinkProgram(program_service_id))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_, GetProgramiv(program_service_id, GL_LINK_STATUS, _))
- .WillOnce(SetArgumentPointee<2>(GL_TRUE))
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_,
- GetProgramiv(program_service_id, GL_INFO_LOG_LENGTH, _))
- .WillOnce(SetArgumentPointee<2>(0))
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_,
- GetProgramiv(program_service_id, GL_ACTIVE_ATTRIBUTES, _))
- .WillOnce(SetArgumentPointee<2>(num_attribs))
- .RetiresOnSaturation();
- size_t max_attrib_len = 0;
- for (size_t ii = 0; ii < num_attribs; ++ii) {
- size_t len = strlen(attribs[ii].name) + 1;
- max_attrib_len = std::max(max_attrib_len, len);
- }
- EXPECT_CALL(*gl_,
- GetProgramiv(program_service_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
- .WillOnce(SetArgumentPointee<2>(max_attrib_len))
- .RetiresOnSaturation();
- for (size_t ii = 0; ii < num_attribs; ++ii) {
- const AttribInfo& info = attribs[ii];
- EXPECT_CALL(*gl_,
- GetActiveAttrib(program_service_id, ii, max_attrib_len, _, _, _, _))
- .WillOnce(DoAll(
- SetArgumentPointee<3>(strlen(info.name)),
- SetArgumentPointee<4>(info.size),
- SetArgumentPointee<5>(info.type),
- SetArrayArgument<6>(info.name,
- info.name + strlen(info.name) + 1)))
- .RetiresOnSaturation();
- if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
- EXPECT_CALL(*gl_, GetAttribLocation(program_service_id,
- StrEq(info.name)))
- .WillOnce(Return(info.location))
- .RetiresOnSaturation();
- }
- }
- EXPECT_CALL(*gl_,
- GetProgramiv(program_service_id, GL_ACTIVE_UNIFORMS, _))
- .WillOnce(SetArgumentPointee<2>(num_uniforms))
- .RetiresOnSaturation();
- size_t max_uniform_len = 0;
- for (size_t ii = 0; ii < num_uniforms; ++ii) {
- size_t len = strlen(uniforms[ii].name) + 1;
- max_uniform_len = std::max(max_uniform_len, len);
- }
- EXPECT_CALL(*gl_,
- GetProgramiv(program_service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
- .WillOnce(SetArgumentPointee<2>(max_uniform_len))
- .RetiresOnSaturation();
- for (size_t ii = 0; ii < num_uniforms; ++ii) {
- const UniformInfo& info = uniforms[ii];
- EXPECT_CALL(*gl_,
- GetActiveUniform(program_service_id, ii, max_uniform_len, _, _, _, _))
- .WillOnce(DoAll(
- SetArgumentPointee<3>(strlen(info.name)),
- SetArgumentPointee<4>(info.size),
- SetArgumentPointee<5>(info.type),
- SetArrayArgument<6>(info.name,
- info.name + strlen(info.name) + 1)))
- .RetiresOnSaturation();
- if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
- EXPECT_CALL(*gl_, GetUniformLocation(program_service_id,
- StrEq(info.name)))
- .WillOnce(Return(info.real_location))
- .RetiresOnSaturation();
- if (info.size > 1) {
- std::string base_name = info.name;
- size_t array_pos = base_name.rfind("[0]");
- if (base_name.size() > 3 && array_pos == base_name.size() - 3) {
- base_name = base_name.substr(0, base_name.size() - 3);
- }
- for (GLsizei jj = 1; jj < info.size; ++jj) {
- std::string element_name(
- std::string(base_name) + "[" + base::IntToString(jj) + "]");
- EXPECT_CALL(*gl_, GetUniformLocation(program_service_id,
- StrEq(element_name)))
- .WillOnce(Return(info.real_location + jj * 2))
- .RetiresOnSaturation();
- }
- }
- }
- }
+ TestHelper::SetupShader(
+ gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
+ program_service_id);
}
DoCreateShader(
@@ -1274,85 +1190,6 @@ void GLES2DecoderTestBase::SetupShader(
SetupExpectationsForClearingUniforms(uniforms, num_uniforms);
}
-void GLES2DecoderTestBase::SetupExpectationsForClearingUniforms(
- UniformInfo* uniforms, size_t num_uniforms) {
- for (size_t ii = 0; ii < num_uniforms; ++ii) {
- const UniformInfo& info = uniforms[ii];
- switch (info.type) {
- case GL_FLOAT:
- EXPECT_CALL(*gl_, Uniform1fv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_VEC2:
- EXPECT_CALL(*gl_, Uniform2fv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_VEC3:
- EXPECT_CALL(*gl_, Uniform3fv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_VEC4:
- EXPECT_CALL(*gl_, Uniform4fv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_INT:
- case GL_BOOL:
- case GL_SAMPLER_2D:
- case GL_SAMPLER_CUBE:
- case GL_SAMPLER_EXTERNAL_OES:
- case GL_SAMPLER_3D_OES:
- case GL_SAMPLER_2D_RECT_ARB:
- EXPECT_CALL(*gl_, Uniform1iv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_INT_VEC2:
- case GL_BOOL_VEC2:
- EXPECT_CALL(*gl_, Uniform2iv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_INT_VEC3:
- case GL_BOOL_VEC3:
- EXPECT_CALL(*gl_, Uniform3iv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_INT_VEC4:
- case GL_BOOL_VEC4:
- EXPECT_CALL(*gl_, Uniform4iv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_MAT2:
- EXPECT_CALL(*gl_, UniformMatrix2fv(
- info.real_location, info.size, false, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_MAT3:
- EXPECT_CALL(*gl_, UniformMatrix3fv(
- info.real_location, info.size, false, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_MAT4:
- EXPECT_CALL(*gl_, UniformMatrix4fv(
- info.real_location, info.size, false, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- default:
- NOTREACHED();
- break;
- }
- }
-}
-
void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
.Times(1)
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
index 4e5fa2b..0b621dd 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
@@ -17,6 +17,7 @@
#include "gpu/command_buffer/service/query_manager.h"
#include "gpu/command_buffer/service/renderbuffer_manager.h"
#include "gpu/command_buffer/service/shader_manager.h"
+#include "gpu/command_buffer/service/test_helper.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/gl/gl_context_stub.h"
@@ -154,20 +155,8 @@ class GLES2DecoderTestBase : public testing::Test {
return decoder_.get();
}
- struct AttribInfo {
- const char* name;
- GLint size;
- GLenum type;
- GLint location;
- };
-
- struct UniformInfo {
- const char* name;
- GLint size;
- GLenum type;
- GLint fake_location;
- GLint real_location;
- };
+ typedef TestHelper::AttribInfo AttribInfo;
+ typedef TestHelper::UniformInfo UniformInfo;
void SetupShader(
AttribInfo* attribs, size_t num_attribs,
@@ -177,7 +166,10 @@ class GLES2DecoderTestBase : public testing::Test {
GLuint fragment_shader_client_id, GLuint fragment_shader_service_id);
void SetupExpectationsForClearingUniforms(
- UniformInfo* uniforms, size_t num_uniforms);
+ UniformInfo* uniforms, size_t num_uniforms) {
+ TestHelper::SetupExpectationsForClearingUniforms(
+ gl_.get(), uniforms, num_uniforms);
+ }
// Setups up a shader for testing glUniform.
void SetupShaderForUniform();
diff --git a/gpu/command_buffer/service/program_manager_unittest.cc b/gpu/command_buffer/service/program_manager_unittest.cc
index 41d15ef..c0fad67 100644
--- a/gpu/command_buffer/service/program_manager_unittest.cc
+++ b/gpu/command_buffer/service/program_manager_unittest.cc
@@ -13,6 +13,7 @@
#include "gpu/command_buffer/common/gles2_cmd_format.h"
#include "gpu/command_buffer/service/common_decoder.h"
#include "gpu/command_buffer/service/mocks.h"
+#include "gpu/command_buffer/service/test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::gfx::MockGLInterface;
@@ -198,21 +199,8 @@ class ProgramManagerWithShaderTest : public testing::Test {
static const size_t kNumUniforms;
protected:
- struct AttribInfo {
- const char* name;
- GLint size;
- GLenum type;
- GLint location;
- };
-
- struct UniformInfo {
- const char* name;
- const char* good_name;
- GLint size;
- GLenum type;
- GLint fake_location;
- GLint real_location;
- };
+ typedef TestHelper::AttribInfo AttribInfo;
+ typedef TestHelper::UniformInfo UniformInfo;
virtual void SetUp() {
gl_.reset(new StrictMock<gfx::MockGLInterface>());
@@ -243,99 +231,8 @@ class ProgramManagerWithShaderTest : public testing::Test {
void SetupShader(AttribInfo* attribs, size_t num_attribs,
UniformInfo* uniforms, size_t num_uniforms,
GLuint service_id) {
- InSequence s;
-
- EXPECT_CALL(*gl_,
- LinkProgram(service_id))
- .Times(1)
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_,
- GetProgramiv(service_id, GL_LINK_STATUS, _))
- .WillOnce(SetArgumentPointee<2>(1))
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_,
- GetProgramiv(service_id, GL_INFO_LOG_LENGTH, _))
- .WillOnce(SetArgumentPointee<2>(0))
- .RetiresOnSaturation();
- EXPECT_CALL(*gl_,
- GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTES, _))
- .WillOnce(SetArgumentPointee<2>(num_attribs))
- .RetiresOnSaturation();
- size_t max_attrib_len = 0;
- for (size_t ii = 0; ii < num_attribs; ++ii) {
- size_t len = strlen(attribs[ii].name) + 1;
- max_attrib_len = std::max(max_attrib_len, len);
- }
- EXPECT_CALL(*gl_,
- GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
- .WillOnce(SetArgumentPointee<2>(max_attrib_len))
- .RetiresOnSaturation();
- for (size_t ii = 0; ii < num_attribs; ++ii) {
- const AttribInfo& info = attribs[ii];
- EXPECT_CALL(*gl_,
- GetActiveAttrib(service_id, ii,
- max_attrib_len, _, _, _, _))
- .WillOnce(DoAll(
- SetArgumentPointee<3>(strlen(info.name)),
- SetArgumentPointee<4>(info.size),
- SetArgumentPointee<5>(info.type),
- SetArrayArgument<6>(info.name,
- info.name + strlen(info.name) + 1)))
- .RetiresOnSaturation();
- if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
- EXPECT_CALL(*gl_, GetAttribLocation(service_id,
- StrEq(info.name)))
- .WillOnce(Return(info.location))
- .RetiresOnSaturation();
- }
- }
- EXPECT_CALL(*gl_,
- GetProgramiv(service_id, GL_ACTIVE_UNIFORMS, _))
- .WillOnce(SetArgumentPointee<2>(num_uniforms))
- .RetiresOnSaturation();
- size_t max_uniform_len = 0;
- for (size_t ii = 0; ii < num_uniforms; ++ii) {
- size_t len = strlen(uniforms[ii].name) + 1;
- max_uniform_len = std::max(max_uniform_len, len);
- }
- EXPECT_CALL(*gl_,
- GetProgramiv(service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
- .WillOnce(SetArgumentPointee<2>(max_uniform_len))
- .RetiresOnSaturation();
- for (size_t ii = 0; ii < num_uniforms; ++ii) {
- const UniformInfo& info = uniforms[ii];
- EXPECT_CALL(*gl_,
- GetActiveUniform(service_id, ii,
- max_uniform_len, _, _, _, _))
- .WillOnce(DoAll(
- SetArgumentPointee<3>(strlen(info.name)),
- SetArgumentPointee<4>(info.size),
- SetArgumentPointee<5>(info.type),
- SetArrayArgument<6>(info.name,
- info.name + strlen(info.name) + 1)))
- .RetiresOnSaturation();
- if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
- EXPECT_CALL(*gl_, GetUniformLocation(service_id,
- StrEq(info.name)))
- .WillOnce(Return(info.real_location))
- .RetiresOnSaturation();
- if (info.size > 1) {
- std::string base_name = info.name;
- size_t array_pos = base_name.rfind("[0]");
- if (base_name.size() > 3 && array_pos == base_name.size() - 3) {
- base_name = base_name.substr(0, base_name.size() - 3);
- }
- for (GLsizei jj = 1; jj < info.size; ++jj) {
- std::string element_name(
- std::string(base_name) + "[" + base::IntToString(jj) + "]");
- EXPECT_CALL(*gl_, GetUniformLocation(service_id,
- StrEq(element_name)))
- .WillOnce(Return(info.real_location + jj * 2))
- .RetiresOnSaturation();
- }
- }
- }
- }
+ TestHelper::SetupShader(
+ gl_.get(), attribs, num_attribs, uniforms, num_uniforms, service_id);
}
void SetupDefaultShaderExpectations() {
@@ -345,81 +242,8 @@ class ProgramManagerWithShaderTest : public testing::Test {
void SetupExpectationsForClearingUniforms(
UniformInfo* uniforms, size_t num_uniforms) {
- for (size_t ii = 0; ii < num_uniforms; ++ii) {
- const UniformInfo& info = uniforms[ii];
- switch (info.type) {
- case GL_FLOAT:
- EXPECT_CALL(*gl_, Uniform1fv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_VEC2:
- EXPECT_CALL(*gl_, Uniform2fv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_VEC3:
- EXPECT_CALL(*gl_, Uniform3fv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_VEC4:
- EXPECT_CALL(*gl_, Uniform4fv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_INT:
- case GL_BOOL:
- case GL_SAMPLER_2D:
- case GL_SAMPLER_CUBE:
- case GL_SAMPLER_EXTERNAL_OES:
- case GL_SAMPLER_3D_OES:
- case GL_SAMPLER_2D_RECT_ARB:
- EXPECT_CALL(*gl_, Uniform1iv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_INT_VEC2:
- case GL_BOOL_VEC2:
- EXPECT_CALL(*gl_, Uniform2iv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_INT_VEC3:
- case GL_BOOL_VEC3:
- EXPECT_CALL(*gl_, Uniform3iv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_INT_VEC4:
- case GL_BOOL_VEC4:
- EXPECT_CALL(*gl_, Uniform4iv(info.real_location, info.size, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_MAT2:
- EXPECT_CALL(*gl_, UniformMatrix2fv(
- info.real_location, info.size, false, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_MAT3:
- EXPECT_CALL(*gl_, UniformMatrix3fv(
- info.real_location, info.size, false, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- case GL_FLOAT_MAT4:
- EXPECT_CALL(*gl_, UniformMatrix4fv(
- info.real_location, info.size, false, _))
- .Times(1)
- .RetiresOnSaturation();
- break;
- default:
- NOTREACHED();
- break;
- }
- }
+ TestHelper::SetupExpectationsForClearingUniforms(
+ gl_.get(), uniforms, num_uniforms);
}
virtual void TearDown() {
@@ -499,25 +323,25 @@ const size_t ProgramManagerWithShaderTest::kNumAttribs =
ProgramManagerWithShaderTest::UniformInfo
ProgramManagerWithShaderTest::kUniforms[] = {
{ kUniform1Name,
- kUniform1Name,
kUniform1Size,
kUniform1Type,
kUniform1FakeLocation,
kUniform1RealLocation,
+ kUniform1Name,
},
{ kUniform2Name,
- kUniform2Name,
kUniform2Size,
kUniform2Type,
kUniform2FakeLocation,
kUniform2RealLocation,
+ kUniform2Name,
},
{ kUniform3BadName,
- kUniform3GoodName,
kUniform3Size,
kUniform3Type,
kUniform3FakeLocation,
kUniform3RealLocation,
+ kUniform3GoodName,
},
};
@@ -718,25 +542,25 @@ TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsGLUnderscoreUniform) {
static const char* kUniform2Name = "gl_longNameWeCanCheckFor";
static ProgramManagerWithShaderTest::UniformInfo kUniforms[] = {
{ kUniform1Name,
- kUniform1Name,
kUniform1Size,
kUniform1Type,
kUniform1FakeLocation,
kUniform1RealLocation,
+ kUniform1Name,
},
{ kUniform2Name,
- kUniform2Name,
kUniform2Size,
kUniform2Type,
kUniform2FakeLocation,
kUniform2RealLocation,
+ kUniform2Name,
},
{ kUniform3BadName,
- kUniform3GoodName,
kUniform3Size,
kUniform3Type,
kUniform3FakeLocation,
kUniform3RealLocation,
+ kUniform3GoodName,
},
};
const size_t kNumUniforms = arraysize(kUniforms);
@@ -820,25 +644,25 @@ TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsWrongTypeInfo) {
};
static ProgramManagerWithShaderTest::UniformInfo kUniforms[] = {
{ kUniform1Name,
- kUniform1Name,
kUniform1Size,
kUniform1Type,
kUniform1FakeLocation,
kUniform1RealLocation,
+ kUniform1Name,
},
{ kUniform2Name,
- kUniform2Name,
kUniform2Size,
kUniform2BadType,
kUniform2FakeLocation,
kUniform2RealLocation,
+ kUniform2Name,
},
{ kUniform3BadName,
- kUniform3GoodName,
kUniform3Size,
kUniform3Type,
kUniform3FakeLocation,
kUniform3RealLocation,
+ kUniform3GoodName,
},
};
const size_t kNumAttribs= arraysize(kAttribs);
@@ -1144,25 +968,25 @@ TEST_F(ProgramManagerWithShaderTest, ClearWithSamplerTypes) {
};
ProgramManagerWithShaderTest::UniformInfo kUniforms[] = {
{ kUniform1Name,
- kUniform1Name,
kUniform1Size,
kUniform1Type,
kUniform1FakeLocation,
kUniform1RealLocation,
+ kUniform1Name,
},
{ kUniform2Name,
- kUniform2Name,
kUniform2Size,
kSamplerTypes[ii],
kUniform2FakeLocation,
kUniform2RealLocation,
+ kUniform2Name,
},
{ kUniform3BadName,
- kUniform3GoodName,
kUniform3Size,
kUniform3Type,
kUniform3FakeLocation,
kUniform3RealLocation,
+ kUniform3GoodName,
},
};
const size_t kNumAttribs = arraysize(kAttribs);
diff --git a/gpu/command_buffer/service/test_helper.cc b/gpu/command_buffer/service/test_helper.cc
index 926eda5..cc14a59 100644
--- a/gpu/command_buffer/service/test_helper.cc
+++ b/gpu/command_buffer/service/test_helper.cc
@@ -4,10 +4,12 @@
#include "gpu/command_buffer/service/test_helper.h"
+#include "base/string_number_conversions.h"
#include "base/string_tokenizer.h"
#include "gpu/command_buffer/common/gl_mock.h"
#include "gpu/command_buffer/common/types.h"
#include "gpu/command_buffer/service/gl_utils.h"
+#include "gpu/command_buffer/service/program_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <string.h>
@@ -223,6 +225,183 @@ void TestHelper::SetupFeatureInfoInitExpectations(
.RetiresOnSaturation();
}
+void TestHelper::SetupExpectationsForClearingUniforms(
+ ::gfx::MockGLInterface* gl, UniformInfo* uniforms, size_t num_uniforms) {
+ for (size_t ii = 0; ii < num_uniforms; ++ii) {
+ const UniformInfo& info = uniforms[ii];
+ switch (info.type) {
+ case GL_FLOAT:
+ EXPECT_CALL(*gl, Uniform1fv(info.real_location, info.size, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_FLOAT_VEC2:
+ EXPECT_CALL(*gl, Uniform2fv(info.real_location, info.size, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_FLOAT_VEC3:
+ EXPECT_CALL(*gl, Uniform3fv(info.real_location, info.size, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_FLOAT_VEC4:
+ EXPECT_CALL(*gl, Uniform4fv(info.real_location, info.size, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_INT:
+ case GL_BOOL:
+ case GL_SAMPLER_2D:
+ case GL_SAMPLER_CUBE:
+ case GL_SAMPLER_EXTERNAL_OES:
+ case GL_SAMPLER_3D_OES:
+ case GL_SAMPLER_2D_RECT_ARB:
+ EXPECT_CALL(*gl, Uniform1iv(info.real_location, info.size, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_INT_VEC2:
+ case GL_BOOL_VEC2:
+ EXPECT_CALL(*gl, Uniform2iv(info.real_location, info.size, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_INT_VEC3:
+ case GL_BOOL_VEC3:
+ EXPECT_CALL(*gl, Uniform3iv(info.real_location, info.size, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_INT_VEC4:
+ case GL_BOOL_VEC4:
+ EXPECT_CALL(*gl, Uniform4iv(info.real_location, info.size, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_FLOAT_MAT2:
+ EXPECT_CALL(*gl, UniformMatrix2fv(
+ info.real_location, info.size, false, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_FLOAT_MAT3:
+ EXPECT_CALL(*gl, UniformMatrix3fv(
+ info.real_location, info.size, false, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ case GL_FLOAT_MAT4:
+ EXPECT_CALL(*gl, UniformMatrix4fv(
+ info.real_location, info.size, false, _))
+ .Times(1)
+ .RetiresOnSaturation();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ }
+}
+
+void TestHelper::SetupShader(
+ ::gfx::MockGLInterface* gl,
+ AttribInfo* attribs, size_t num_attribs,
+ UniformInfo* uniforms, size_t num_uniforms,
+ GLuint service_id) {
+ InSequence s;
+
+ EXPECT_CALL(*gl,
+ LinkProgram(service_id))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl,
+ GetProgramiv(service_id, GL_LINK_STATUS, _))
+ .WillOnce(SetArgumentPointee<2>(1))
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl,
+ GetProgramiv(service_id, GL_INFO_LOG_LENGTH, _))
+ .WillOnce(SetArgumentPointee<2>(0))
+ .RetiresOnSaturation();
+ EXPECT_CALL(*gl,
+ GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTES, _))
+ .WillOnce(SetArgumentPointee<2>(num_attribs))
+ .RetiresOnSaturation();
+ size_t max_attrib_len = 0;
+ for (size_t ii = 0; ii < num_attribs; ++ii) {
+ size_t len = strlen(attribs[ii].name) + 1;
+ max_attrib_len = std::max(max_attrib_len, len);
+ }
+ EXPECT_CALL(*gl,
+ GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
+ .WillOnce(SetArgumentPointee<2>(max_attrib_len))
+ .RetiresOnSaturation();
+ for (size_t ii = 0; ii < num_attribs; ++ii) {
+ const AttribInfo& info = attribs[ii];
+ EXPECT_CALL(*gl,
+ GetActiveAttrib(service_id, ii,
+ max_attrib_len, _, _, _, _))
+ .WillOnce(DoAll(
+ SetArgumentPointee<3>(strlen(info.name)),
+ SetArgumentPointee<4>(info.size),
+ SetArgumentPointee<5>(info.type),
+ SetArrayArgument<6>(info.name,
+ info.name + strlen(info.name) + 1)))
+ .RetiresOnSaturation();
+ if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
+ EXPECT_CALL(*gl, GetAttribLocation(service_id, StrEq(info.name)))
+ .WillOnce(Return(info.location))
+ .RetiresOnSaturation();
+ }
+ }
+ EXPECT_CALL(*gl,
+ GetProgramiv(service_id, GL_ACTIVE_UNIFORMS, _))
+ .WillOnce(SetArgumentPointee<2>(num_uniforms))
+ .RetiresOnSaturation();
+ size_t max_uniform_len = 0;
+ for (size_t ii = 0; ii < num_uniforms; ++ii) {
+ size_t len = strlen(uniforms[ii].name) + 1;
+ max_uniform_len = std::max(max_uniform_len, len);
+ }
+ EXPECT_CALL(*gl,
+ GetProgramiv(service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
+ .WillOnce(SetArgumentPointee<2>(max_uniform_len))
+ .RetiresOnSaturation();
+ for (size_t ii = 0; ii < num_uniforms; ++ii) {
+ const UniformInfo& info = uniforms[ii];
+ EXPECT_CALL(*gl,
+ GetActiveUniform(service_id, ii,
+ max_uniform_len, _, _, _, _))
+ .WillOnce(DoAll(
+ SetArgumentPointee<3>(strlen(info.name)),
+ SetArgumentPointee<4>(info.size),
+ SetArgumentPointee<5>(info.type),
+ SetArrayArgument<6>(info.name,
+ info.name + strlen(info.name) + 1)))
+ .RetiresOnSaturation();
+ if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
+ EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(info.name)))
+ .WillOnce(Return(info.real_location))
+ .RetiresOnSaturation();
+ if (info.size > 1) {
+ std::string base_name = info.name;
+ size_t array_pos = base_name.rfind("[0]");
+ if (base_name.size() > 3 && array_pos == base_name.size() - 3) {
+ base_name = base_name.substr(0, base_name.size() - 3);
+ }
+ for (GLsizei jj = 1; jj < info.size; ++jj) {
+ std::string element_name(
+ std::string(base_name) + "[" + base::IntToString(jj) + "]");
+ EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(element_name)))
+ .WillOnce(Return(info.real_location + jj * 2))
+ .RetiresOnSaturation();
+ }
+ }
+ }
+ }
+}
+
+
} // namespace gles2
} // namespace gpu
diff --git a/gpu/command_buffer/service/test_helper.h b/gpu/command_buffer/service/test_helper.h
index ec563315..961cae2 100644
--- a/gpu/command_buffer/service/test_helper.h
+++ b/gpu/command_buffer/service/test_helper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -39,6 +39,22 @@ class TestHelper {
static const GLint kMaxVertexUniformVectors = 128;
static const GLint kMaxVertexUniformComponents = kMaxVertexUniformVectors * 4;
+ struct AttribInfo {
+ const char* name;
+ GLint size;
+ GLenum type;
+ GLint location;
+ };
+
+ struct UniformInfo {
+ const char* name;
+ GLint size;
+ GLenum type;
+ GLint fake_location;
+ GLint real_location;
+ const char* good_name;
+ };
+
static void SetupContextGroupInitExpectations(
::gfx::MockGLInterface* gl,
const DisallowedFeatures& disallowed_features,
@@ -47,6 +63,16 @@ class TestHelper {
::gfx::MockGLInterface* gl, const char* extensions);
static void SetupTextureManagerInitExpectations(::gfx::MockGLInterface* gl,
const char* extensions);
+
+ static void SetupExpectationsForClearingUniforms(
+ ::gfx::MockGLInterface* gl, UniformInfo* uniforms, size_t num_uniforms);
+
+ static void SetupShader(
+ ::gfx::MockGLInterface* gl,
+ AttribInfo* attribs, size_t num_attribs,
+ UniformInfo* uniforms, size_t num_uniforms,
+ GLuint service_id);
+
private:
static void SetupTextureInitializationExpectations(::gfx::MockGLInterface* gl,
GLenum target);