Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_1.cc
blobef3323f084c4eef465129ef70e2fe343594b2c31
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
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "gpu/command_buffer/common/gles2_cmd_format.h"
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h"
10 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
11 #include "gpu/command_buffer/service/context_group.h"
12 #include "gpu/command_buffer/service/program_manager.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gl/gl_mock.h"
16 using ::gfx::MockGLInterface;
17 using ::testing::_;
18 using ::testing::DoAll;
19 using ::testing::InSequence;
20 using ::testing::MatcherCast;
21 using ::testing::Pointee;
22 using ::testing::Return;
23 using ::testing::SetArrayArgument;
24 using ::testing::SetArgumentPointee;
25 using ::testing::StrEq;
27 namespace gpu {
28 namespace gles2 {
30 namespace {
31 void ShaderCacheCb(const std::string& key, const std::string& shader) {
33 } // namespace
35 class GLES2DecoderTest1 : public GLES2DecoderTestBase {
36 public:
37 GLES2DecoderTest1() { }
40 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderTest1, ::testing::Bool());
42 template <>
43 void GLES2DecoderTestBase::SpecializedSetup<cmds::GenerateMipmap, 0>(
44 bool valid) {
45 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
46 DoTexImage2D(
47 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
48 kSharedMemoryId, kSharedMemoryOffset);
49 if (valid) {
50 EXPECT_CALL(*gl_, GetError())
51 .WillOnce(Return(GL_NO_ERROR))
52 .WillOnce(Return(GL_NO_ERROR))
53 .RetiresOnSaturation();
57 template <>
58 void GLES2DecoderTestBase::SpecializedSetup<cmds::CheckFramebufferStatus, 0>(
59 bool /* valid */) {
60 // Give it a valid framebuffer.
61 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
62 kServiceRenderbufferId);
63 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
64 kServiceFramebufferId);
65 DoRenderbufferStorage(
66 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
67 DoFramebufferRenderbuffer(
68 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
69 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
72 template <>
73 void GLES2DecoderTestBase::SpecializedSetup<cmds::Clear, 0>(bool valid) {
74 if (valid) {
75 SetupExpectationsForApplyingDefaultDirtyState();
79 template <>
80 void GLES2DecoderTestBase::SpecializedSetup<cmds::ColorMask, 0>(
81 bool /* valid */) {
82 // We bind a framebuffer color the colormask test since the framebuffer
83 // will be considered RGB.
84 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
85 kServiceFramebufferId);
88 template <>
89 void GLES2DecoderTestBase::SpecializedSetup<cmds::CopyTexImage2D, 0>(
90 bool valid) {
91 if (valid) {
92 EXPECT_CALL(*gl_, GetError())
93 .WillOnce(Return(GL_NO_ERROR))
94 .WillOnce(Return(GL_NO_ERROR))
95 .RetiresOnSaturation();
99 template <>
100 void GLES2DecoderTestBase::SpecializedSetup<cmds::CopyTexSubImage2D, 0>(
101 bool valid) {
102 if (valid) {
103 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
104 DoTexImage2D(
105 GL_TEXTURE_2D, 2, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
106 kSharedMemoryId, kSharedMemoryOffset);
110 template <>
111 void GLES2DecoderTestBase::SpecializedSetup<cmds::DetachShader, 0>(bool valid) {
112 if (valid) {
113 EXPECT_CALL(*gl_,
114 AttachShader(kServiceProgramId, kServiceShaderId))
115 .Times(1)
116 .RetiresOnSaturation();
117 cmds::AttachShader attach_cmd;
118 attach_cmd.Init(client_program_id_, client_shader_id_);
119 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
123 template <>
124 void GLES2DecoderTestBase::SpecializedSetup<cmds::FramebufferRenderbuffer, 0>(
125 bool valid) {
126 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
127 kServiceFramebufferId);
128 if (valid) {
129 EXPECT_CALL(*gl_, GetError())
130 .WillOnce(Return(GL_NO_ERROR))
131 .WillOnce(Return(GL_NO_ERROR))
132 .RetiresOnSaturation();
136 template <>
137 void GLES2DecoderTestBase::SpecializedSetup<cmds::FramebufferTexture2D, 0>(
138 bool valid) {
139 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
140 kServiceFramebufferId);
141 if (valid) {
142 EXPECT_CALL(*gl_, GetError())
143 .WillOnce(Return(GL_NO_ERROR))
144 .WillOnce(Return(GL_NO_ERROR))
145 .RetiresOnSaturation();
149 template <>
150 void GLES2DecoderTestBase::SpecializedSetup<
151 cmds::GetBufferParameteriv, 0>(bool /* valid */) {
152 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
155 template <>
156 void GLES2DecoderTestBase::SpecializedSetup<
157 cmds::GetFramebufferAttachmentParameteriv, 0>(bool /* valid */) {
158 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
159 kServiceFramebufferId);
162 template <>
163 void GLES2DecoderTestBase::SpecializedSetup<
164 cmds::GetRenderbufferParameteriv, 0>(
165 bool /* valid */) {
166 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
167 kServiceRenderbufferId);
170 template <>
171 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetProgramiv, 0>(
172 bool valid) {
173 if (valid) {
174 // GetProgramiv calls ClearGLError then GetError to make sure
175 // it actually got a value so it can report correctly to the client.
176 EXPECT_CALL(*gl_, GetError())
177 .WillOnce(Return(GL_NO_ERROR))
178 .RetiresOnSaturation();
179 EXPECT_CALL(*gl_, GetError())
180 .WillOnce(Return(GL_NO_ERROR))
181 .RetiresOnSaturation();
185 template <>
186 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetProgramInfoLog, 0>(
187 bool /* valid */) {
188 const GLuint kClientVertexShaderId = 5001;
189 const GLuint kServiceVertexShaderId = 6001;
190 const GLuint kClientFragmentShaderId = 5002;
191 const GLuint kServiceFragmentShaderId = 6002;
192 const char* log = "hello"; // Matches auto-generated unit test.
193 DoCreateShader(
194 GL_VERTEX_SHADER, kClientVertexShaderId, kServiceVertexShaderId);
195 DoCreateShader(
196 GL_FRAGMENT_SHADER, kClientFragmentShaderId, kServiceFragmentShaderId);
198 GetShader(kClientVertexShaderId)->SetStatus(true, "", NULL);
199 GetShader(kClientFragmentShaderId)->SetStatus(true, "", NULL);
201 InSequence dummy;
202 EXPECT_CALL(*gl_,
203 AttachShader(kServiceProgramId, kServiceVertexShaderId))
204 .Times(1)
205 .RetiresOnSaturation();
206 EXPECT_CALL(*gl_,
207 AttachShader(kServiceProgramId, kServiceFragmentShaderId))
208 .Times(1)
209 .RetiresOnSaturation();
210 EXPECT_CALL(*gl_, LinkProgram(kServiceProgramId))
211 .Times(1)
212 .RetiresOnSaturation();
213 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
214 .WillOnce(SetArgumentPointee<2>(1));
215 EXPECT_CALL(*gl_,
216 GetProgramiv(kServiceProgramId, GL_INFO_LOG_LENGTH, _))
217 .WillOnce(SetArgumentPointee<2>(strlen(log) + 1))
218 .RetiresOnSaturation();
219 EXPECT_CALL(*gl_,
220 GetProgramInfoLog(kServiceProgramId, strlen(log) + 1, _, _))
221 .WillOnce(DoAll(
222 SetArgumentPointee<2>(strlen(log)),
223 SetArrayArgument<3>(log, log + strlen(log) + 1)))
224 .RetiresOnSaturation();
225 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTES, _))
226 .WillOnce(SetArgumentPointee<2>(0));
227 EXPECT_CALL(
228 *gl_,
229 GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
230 .WillOnce(SetArgumentPointee<2>(0));
231 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORMS, _))
232 .WillOnce(SetArgumentPointee<2>(0));
233 EXPECT_CALL(
234 *gl_,
235 GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
236 .WillOnce(SetArgumentPointee<2>(0));
238 Program* program = GetProgram(client_program_id_);
239 ASSERT_TRUE(program != NULL);
241 cmds::AttachShader attach_cmd;
242 attach_cmd.Init(client_program_id_, kClientVertexShaderId);
243 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
245 attach_cmd.Init(client_program_id_, kClientFragmentShaderId);
246 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
248 program->Link(NULL, NULL, NULL, Program::kCountOnlyStaticallyUsed,
249 base::Bind(&ShaderCacheCb));
252 template <>
253 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetVertexAttribfv, 0>(
254 bool valid) {
255 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
256 DoVertexAttribPointer(1, 1, GL_FLOAT, 0, 0);
257 if (valid) {
258 EXPECT_CALL(*gl_, GetError())
259 .WillOnce(Return(GL_NO_ERROR))
260 .WillOnce(Return(GL_NO_ERROR))
261 .RetiresOnSaturation();
265 template <>
266 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetVertexAttribiv, 0>(
267 bool valid) {
268 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
269 DoVertexAttribPointer(1, 1, GL_FLOAT, 0, 0);
270 if (valid) {
271 EXPECT_CALL(*gl_, GetError())
272 .WillOnce(Return(GL_NO_ERROR))
273 .WillOnce(Return(GL_NO_ERROR))
274 .RetiresOnSaturation();
278 template <>
279 void GLES2DecoderTestBase::SpecializedSetup<cmds::RenderbufferStorage, 0>(
280 bool valid) {
281 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
282 kServiceRenderbufferId);
283 if (valid) {
284 EnsureRenderbufferBound(false);
285 EXPECT_CALL(*gl_, GetError())
286 .WillOnce(Return(GL_NO_ERROR))
287 .RetiresOnSaturation();
288 EXPECT_CALL(*gl_,
289 RenderbufferStorageEXT(GL_RENDERBUFFER, _, 3, 4))
290 .Times(1)
291 .RetiresOnSaturation();
292 EXPECT_CALL(*gl_, GetError())
293 .WillOnce(Return(GL_NO_ERROR))
294 .RetiresOnSaturation();
299 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h"
301 } // namespace gles2
302 } // namespace gpu