Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_1.cc
blob912e9085fa89f3773a736192443984329cdbacff
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 "gpu/command_buffer/service/test_helper.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gl/gl_mock.h"
17 using ::gfx::MockGLInterface;
18 using ::testing::_;
19 using ::testing::DoAll;
20 using ::testing::InSequence;
21 using ::testing::MatcherCast;
22 using ::testing::Pointee;
23 using ::testing::Return;
24 using ::testing::SetArrayArgument;
25 using ::testing::SetArgumentPointee;
26 using ::testing::StrEq;
28 namespace gpu {
29 namespace gles2 {
31 namespace {
32 void ShaderCacheCb(const std::string& key, const std::string& shader) {
34 } // namespace
36 class GLES2DecoderTest1 : public GLES2DecoderTestBase {
37 public:
38 GLES2DecoderTest1() { }
41 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderTest1, ::testing::Bool());
43 template <>
44 void GLES2DecoderTestBase::SpecializedSetup<cmds::GenerateMipmap, 0>(
45 bool valid) {
46 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
47 DoTexImage2D(
48 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
49 kSharedMemoryId, kSharedMemoryOffset);
50 if (valid) {
51 EXPECT_CALL(*gl_, GetError())
52 .WillOnce(Return(GL_NO_ERROR))
53 .WillOnce(Return(GL_NO_ERROR))
54 .RetiresOnSaturation();
58 template <>
59 void GLES2DecoderTestBase::SpecializedSetup<cmds::CheckFramebufferStatus, 0>(
60 bool /* valid */) {
61 // Give it a valid framebuffer.
62 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
63 kServiceRenderbufferId);
64 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
65 kServiceFramebufferId);
66 DoRenderbufferStorage(
67 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
68 DoFramebufferRenderbuffer(
69 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
70 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
73 template <>
74 void GLES2DecoderTestBase::SpecializedSetup<cmds::Clear, 0>(bool valid) {
75 if (valid) {
76 SetupExpectationsForApplyingDefaultDirtyState();
80 template <>
81 void GLES2DecoderTestBase::SpecializedSetup<cmds::ColorMask, 0>(
82 bool /* valid */) {
83 // We bind a framebuffer color the colormask test since the framebuffer
84 // will be considered RGB.
85 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
86 kServiceFramebufferId);
89 template <>
90 void GLES2DecoderTestBase::SpecializedSetup<cmds::CopyTexImage2D, 0>(
91 bool valid) {
92 if (valid) {
93 EXPECT_CALL(*gl_, GetError())
94 .WillOnce(Return(GL_NO_ERROR))
95 .WillOnce(Return(GL_NO_ERROR))
96 .RetiresOnSaturation();
100 template <>
101 void GLES2DecoderTestBase::SpecializedSetup<cmds::CopyTexSubImage2D, 0>(
102 bool valid) {
103 if (valid) {
104 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
105 DoTexImage2D(
106 GL_TEXTURE_2D, 2, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
107 kSharedMemoryId, kSharedMemoryOffset);
111 template <>
112 void GLES2DecoderTestBase::SpecializedSetup<cmds::DetachShader, 0>(bool valid) {
113 if (valid) {
114 EXPECT_CALL(*gl_,
115 AttachShader(kServiceProgramId, kServiceShaderId))
116 .Times(1)
117 .RetiresOnSaturation();
118 cmds::AttachShader attach_cmd;
119 attach_cmd.Init(client_program_id_, client_shader_id_);
120 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
124 template <>
125 void GLES2DecoderTestBase::SpecializedSetup<cmds::FramebufferRenderbuffer, 0>(
126 bool valid) {
127 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
128 kServiceFramebufferId);
129 if (valid) {
130 EXPECT_CALL(*gl_, GetError())
131 .WillOnce(Return(GL_NO_ERROR))
132 .WillOnce(Return(GL_NO_ERROR))
133 .RetiresOnSaturation();
137 template <>
138 void GLES2DecoderTestBase::SpecializedSetup<cmds::FramebufferTexture2D, 0>(
139 bool valid) {
140 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
141 kServiceFramebufferId);
142 if (valid) {
143 EXPECT_CALL(*gl_, GetError())
144 .WillOnce(Return(GL_NO_ERROR))
145 .WillOnce(Return(GL_NO_ERROR))
146 .RetiresOnSaturation();
150 template <>
151 void GLES2DecoderTestBase::SpecializedSetup<
152 cmds::GetBufferParameteriv, 0>(bool /* valid */) {
153 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
156 template <>
157 void GLES2DecoderTestBase::SpecializedSetup<
158 cmds::GetFramebufferAttachmentParameteriv, 0>(bool /* valid */) {
159 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
160 kServiceFramebufferId);
163 template <>
164 void GLES2DecoderTestBase::SpecializedSetup<
165 cmds::GetRenderbufferParameteriv, 0>(
166 bool /* valid */) {
167 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
168 kServiceRenderbufferId);
171 template <>
172 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetProgramiv, 0>(
173 bool valid) {
174 if (valid) {
175 // GetProgramiv calls ClearGLError then GetError to make sure
176 // it actually got a value so it can report correctly to the client.
177 EXPECT_CALL(*gl_, GetError())
178 .WillOnce(Return(GL_NO_ERROR))
179 .RetiresOnSaturation();
180 EXPECT_CALL(*gl_, GetError())
181 .WillOnce(Return(GL_NO_ERROR))
182 .RetiresOnSaturation();
186 template <>
187 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetProgramInfoLog, 0>(
188 bool /* valid */) {
189 const GLuint kClientVertexShaderId = 5001;
190 const GLuint kServiceVertexShaderId = 6001;
191 const GLuint kClientFragmentShaderId = 5002;
192 const GLuint kServiceFragmentShaderId = 6002;
193 const char* log = "hello"; // Matches auto-generated unit test.
194 DoCreateShader(
195 GL_VERTEX_SHADER, kClientVertexShaderId, kServiceVertexShaderId);
196 DoCreateShader(
197 GL_FRAGMENT_SHADER, kClientFragmentShaderId, kServiceFragmentShaderId);
199 TestHelper::SetShaderStates(
200 gl_.get(), GetShader(kClientVertexShaderId), true);
201 TestHelper::SetShaderStates(
202 gl_.get(), GetShader(kClientFragmentShaderId), true);
204 InSequence dummy;
205 EXPECT_CALL(*gl_,
206 AttachShader(kServiceProgramId, kServiceVertexShaderId))
207 .Times(1)
208 .RetiresOnSaturation();
209 EXPECT_CALL(*gl_,
210 AttachShader(kServiceProgramId, kServiceFragmentShaderId))
211 .Times(1)
212 .RetiresOnSaturation();
213 EXPECT_CALL(*gl_, LinkProgram(kServiceProgramId))
214 .Times(1)
215 .RetiresOnSaturation();
216 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
217 .WillOnce(SetArgumentPointee<2>(1));
218 EXPECT_CALL(*gl_,
219 GetProgramiv(kServiceProgramId, GL_INFO_LOG_LENGTH, _))
220 .WillOnce(SetArgumentPointee<2>(strlen(log) + 1))
221 .RetiresOnSaturation();
222 EXPECT_CALL(*gl_,
223 GetProgramInfoLog(kServiceProgramId, strlen(log) + 1, _, _))
224 .WillOnce(DoAll(
225 SetArgumentPointee<2>(strlen(log)),
226 SetArrayArgument<3>(log, log + strlen(log) + 1)))
227 .RetiresOnSaturation();
228 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTES, _))
229 .WillOnce(SetArgumentPointee<2>(0));
230 EXPECT_CALL(
231 *gl_,
232 GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
233 .WillOnce(SetArgumentPointee<2>(0));
234 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORMS, _))
235 .WillOnce(SetArgumentPointee<2>(0));
236 EXPECT_CALL(
237 *gl_,
238 GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
239 .WillOnce(SetArgumentPointee<2>(0));
241 Program* program = GetProgram(client_program_id_);
242 ASSERT_TRUE(program != NULL);
244 cmds::AttachShader attach_cmd;
245 attach_cmd.Init(client_program_id_, kClientVertexShaderId);
246 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
248 attach_cmd.Init(client_program_id_, kClientFragmentShaderId);
249 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
251 program->Link(NULL, NULL, NULL, Program::kCountOnlyStaticallyUsed,
252 base::Bind(&ShaderCacheCb));
255 template <>
256 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetVertexAttribfv, 0>(
257 bool valid) {
258 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
259 DoVertexAttribPointer(1, 1, GL_FLOAT, 0, 0);
260 if (valid) {
261 EXPECT_CALL(*gl_, GetError())
262 .WillOnce(Return(GL_NO_ERROR))
263 .WillOnce(Return(GL_NO_ERROR))
264 .RetiresOnSaturation();
268 template <>
269 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetVertexAttribiv, 0>(
270 bool valid) {
271 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
272 DoVertexAttribPointer(1, 1, GL_FLOAT, 0, 0);
273 if (valid) {
274 EXPECT_CALL(*gl_, GetError())
275 .WillOnce(Return(GL_NO_ERROR))
276 .WillOnce(Return(GL_NO_ERROR))
277 .RetiresOnSaturation();
281 template <>
282 void GLES2DecoderTestBase::SpecializedSetup<cmds::RenderbufferStorage, 0>(
283 bool valid) {
284 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
285 kServiceRenderbufferId);
286 if (valid) {
287 EnsureRenderbufferBound(false);
288 EXPECT_CALL(*gl_, GetError())
289 .WillOnce(Return(GL_NO_ERROR))
290 .RetiresOnSaturation();
291 EXPECT_CALL(*gl_,
292 RenderbufferStorageEXT(GL_RENDERBUFFER, _, 3, 4))
293 .Times(1)
294 .RetiresOnSaturation();
295 EXPECT_CALL(*gl_, GetError())
296 .WillOnce(Return(GL_NO_ERROR))
297 .RetiresOnSaturation();
302 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h"
304 } // namespace gles2
305 } // namespace gpu