Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_programs.cc
blob9c3d775f360c793292711f892d9b07fc02c6b0df
1 // Copyright 2014 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 "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
14 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
15 #include "gpu/command_buffer/service/context_group.h"
16 #include "gpu/command_buffer/service/context_state.h"
17 #include "gpu/command_buffer/service/gl_surface_mock.h"
18 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
19 #include "gpu/command_buffer/service/image_manager.h"
20 #include "gpu/command_buffer/service/mailbox_manager.h"
21 #include "gpu/command_buffer/service/mocks.h"
22 #include "gpu/command_buffer/service/program_manager.h"
23 #include "gpu/command_buffer/service/test_helper.h"
24 #include "gpu/config/gpu_switches.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gl/gl_implementation.h"
27 #include "ui/gl/gl_mock.h"
28 #include "ui/gl/gl_surface_stub.h"
30 #if !defined(GL_DEPTH24_STENCIL8)
31 #define GL_DEPTH24_STENCIL8 0x88F0
32 #endif
34 using ::gfx::MockGLInterface;
35 using ::testing::_;
36 using ::testing::DoAll;
37 using ::testing::InSequence;
38 using ::testing::Invoke;
39 using ::testing::MatcherCast;
40 using ::testing::Mock;
41 using ::testing::Pointee;
42 using ::testing::Return;
43 using ::testing::SaveArg;
44 using ::testing::SetArrayArgument;
45 using ::testing::SetArgPointee;
46 using ::testing::StrEq;
47 using ::testing::StrictMock;
49 namespace gpu {
50 namespace gles2 {
52 using namespace cmds;
54 TEST_P(GLES2DecoderWithShaderTest, GetProgramInfoCHROMIUMValidArgs) {
55 const uint32 kBucketId = 123;
56 GetProgramInfoCHROMIUM cmd;
57 cmd.Init(client_program_id_, kBucketId);
58 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
59 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
60 EXPECT_GT(bucket->size(), 0u);
63 TEST_P(GLES2DecoderWithShaderTest, GetProgramInfoCHROMIUMInvalidArgs) {
64 const uint32 kBucketId = 123;
65 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
66 EXPECT_TRUE(bucket == NULL);
67 GetProgramInfoCHROMIUM cmd;
68 cmd.Init(kInvalidClientId, kBucketId);
69 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
70 EXPECT_EQ(GL_NO_ERROR, GetGLError());
71 bucket = decoder_->GetBucket(kBucketId);
72 ASSERT_TRUE(bucket != NULL);
73 EXPECT_EQ(sizeof(ProgramInfoHeader), bucket->size());
74 ProgramInfoHeader* info =
75 bucket->GetDataAs<ProgramInfoHeader*>(0, sizeof(ProgramInfoHeader));
76 ASSERT_TRUE(info != 0);
77 EXPECT_EQ(0u, info->link_status);
78 EXPECT_EQ(0u, info->num_attribs);
79 EXPECT_EQ(0u, info->num_uniforms);
82 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlocksCHROMIUMValidArgs) {
83 const uint32 kBucketId = 123;
84 GetUniformBlocksCHROMIUM cmd;
85 cmd.Init(client_program_id_, kBucketId);
86 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
87 .WillOnce(SetArgPointee<2>(GL_TRUE))
88 .RetiresOnSaturation();
89 EXPECT_CALL(*gl_,
90 GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORM_BLOCKS, _))
91 .WillOnce(SetArgPointee<2>(0))
92 .RetiresOnSaturation();
93 decoder_->set_unsafe_es3_apis_enabled(true);
94 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
95 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
96 EXPECT_EQ(sizeof(UniformBlocksHeader), bucket->size());
97 UniformBlocksHeader* header =
98 bucket->GetDataAs<UniformBlocksHeader*>(0, sizeof(UniformBlocksHeader));
99 EXPECT_TRUE(header != NULL);
100 EXPECT_EQ(0u, header->num_uniform_blocks);
101 decoder_->set_unsafe_es3_apis_enabled(false);
102 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
105 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlocksCHROMIUMInvalidArgs) {
106 const uint32 kBucketId = 123;
107 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
108 EXPECT_TRUE(bucket == NULL);
109 GetUniformBlocksCHROMIUM cmd;
110 cmd.Init(kInvalidClientId, kBucketId);
111 decoder_->set_unsafe_es3_apis_enabled(true);
112 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
113 EXPECT_EQ(GL_NO_ERROR, GetGLError());
114 bucket = decoder_->GetBucket(kBucketId);
115 ASSERT_TRUE(bucket != NULL);
116 EXPECT_EQ(sizeof(UniformBlocksHeader), bucket->size());
117 UniformBlocksHeader* header =
118 bucket->GetDataAs<UniformBlocksHeader*>(0, sizeof(UniformBlocksHeader));
119 ASSERT_TRUE(header != NULL);
120 EXPECT_EQ(0u, header->num_uniform_blocks);
123 TEST_P(GLES2DecoderWithShaderTest, GetUniformsES3CHROMIUMValidArgs) {
124 const uint32 kBucketId = 123;
125 GetUniformsES3CHROMIUM cmd;
126 cmd.Init(client_program_id_, kBucketId);
127 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
128 .WillOnce(SetArgPointee<2>(GL_TRUE))
129 .RetiresOnSaturation();
130 EXPECT_CALL(*gl_,
131 GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORMS, _))
132 .WillOnce(SetArgPointee<2>(0))
133 .RetiresOnSaturation();
134 decoder_->set_unsafe_es3_apis_enabled(true);
135 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
136 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
137 EXPECT_EQ(sizeof(UniformsES3Header), bucket->size());
138 UniformsES3Header* header =
139 bucket->GetDataAs<UniformsES3Header*>(0, sizeof(UniformsES3Header));
140 EXPECT_TRUE(header != NULL);
141 EXPECT_EQ(0u, header->num_uniforms);
142 decoder_->set_unsafe_es3_apis_enabled(false);
143 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
146 TEST_P(GLES2DecoderWithShaderTest, GetUniformsES3CHROMIUMInvalidArgs) {
147 const uint32 kBucketId = 123;
148 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
149 EXPECT_TRUE(bucket == NULL);
150 GetUniformsES3CHROMIUM cmd;
151 cmd.Init(kInvalidClientId, kBucketId);
152 decoder_->set_unsafe_es3_apis_enabled(true);
153 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
154 EXPECT_EQ(GL_NO_ERROR, GetGLError());
155 bucket = decoder_->GetBucket(kBucketId);
156 ASSERT_TRUE(bucket != NULL);
157 EXPECT_EQ(sizeof(UniformsES3Header), bucket->size());
158 UniformsES3Header* header =
159 bucket->GetDataAs<UniformsES3Header*>(0, sizeof(UniformsES3Header));
160 ASSERT_TRUE(header != NULL);
161 EXPECT_EQ(0u, header->num_uniforms);
164 TEST_P(GLES2DecoderWithShaderTest,
165 GetTransformFeedbackVaryingsCHROMIUMValidArgs) {
166 const uint32 kBucketId = 123;
167 GetTransformFeedbackVaryingsCHROMIUM cmd;
168 cmd.Init(client_program_id_, kBucketId);
169 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
170 .WillOnce(SetArgPointee<2>(GL_TRUE))
171 .RetiresOnSaturation();
172 EXPECT_CALL(*gl_,
173 GetProgramiv(
174 kServiceProgramId, GL_TRANSFORM_FEEDBACK_VARYINGS, _))
175 .WillOnce(SetArgPointee<2>(0))
176 .RetiresOnSaturation();
177 decoder_->set_unsafe_es3_apis_enabled(true);
178 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
179 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
180 EXPECT_EQ(sizeof(TransformFeedbackVaryingsHeader), bucket->size());
181 TransformFeedbackVaryingsHeader* header =
182 bucket->GetDataAs<TransformFeedbackVaryingsHeader*>(
183 0, sizeof(TransformFeedbackVaryingsHeader));
184 EXPECT_TRUE(header != NULL);
185 EXPECT_EQ(0u, header->num_transform_feedback_varyings);
186 decoder_->set_unsafe_es3_apis_enabled(false);
187 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
190 TEST_P(GLES2DecoderWithShaderTest,
191 GetTransformFeedbackVaryingsCHROMIUMInvalidArgs) {
192 const uint32 kBucketId = 123;
193 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
194 EXPECT_TRUE(bucket == NULL);
195 GetTransformFeedbackVaryingsCHROMIUM cmd;
196 cmd.Init(kInvalidClientId, kBucketId);
197 decoder_->set_unsafe_es3_apis_enabled(true);
198 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
199 EXPECT_EQ(GL_NO_ERROR, GetGLError());
200 bucket = decoder_->GetBucket(kBucketId);
201 ASSERT_TRUE(bucket != NULL);
202 EXPECT_EQ(sizeof(TransformFeedbackVaryingsHeader), bucket->size());
203 TransformFeedbackVaryingsHeader* header =
204 bucket->GetDataAs<TransformFeedbackVaryingsHeader*>(
205 0, sizeof(TransformFeedbackVaryingsHeader));
206 ASSERT_TRUE(header != NULL);
207 EXPECT_EQ(0u, header->num_transform_feedback_varyings);
210 TEST_P(GLES2DecoderWithShaderTest, GetUniformivSucceeds) {
211 GetUniformiv::Result* result =
212 static_cast<GetUniformiv::Result*>(shared_memory_address_);
213 result->size = 0;
214 GetUniformiv cmd;
215 cmd.Init(client_program_id_,
216 kUniform2FakeLocation,
217 kSharedMemoryId,
218 kSharedMemoryOffset);
219 EXPECT_CALL(*gl_, GetUniformiv(kServiceProgramId, kUniform2RealLocation, _))
220 .Times(1);
221 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
222 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
223 static_cast<uint32>(result->GetNumResults()));
226 TEST_P(GLES2DecoderWithShaderTest, GetUniformivArrayElementSucceeds) {
227 GetUniformiv::Result* result =
228 static_cast<GetUniformiv::Result*>(shared_memory_address_);
229 result->size = 0;
230 GetUniformiv cmd;
231 cmd.Init(client_program_id_,
232 kUniform2ElementFakeLocation,
233 kSharedMemoryId,
234 kSharedMemoryOffset);
235 EXPECT_CALL(*gl_,
236 GetUniformiv(kServiceProgramId, kUniform2ElementRealLocation, _))
237 .Times(1);
238 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
239 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
240 static_cast<uint32>(result->GetNumResults()));
243 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadProgramFails) {
244 GetUniformiv::Result* result =
245 static_cast<GetUniformiv::Result*>(shared_memory_address_);
246 result->size = 0;
247 GetUniformiv cmd;
248 // non-existant program
249 cmd.Init(kInvalidClientId,
250 kUniform2FakeLocation,
251 kSharedMemoryId,
252 kSharedMemoryOffset);
253 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
254 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
255 EXPECT_EQ(0U, result->size);
256 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
257 // Valid id that is not a program. The GL spec requires a different error for
258 // this case.
259 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
260 result->size = kInitialResult;
261 cmd.Init(client_shader_id_,
262 kUniform2FakeLocation,
263 kSharedMemoryId,
264 kSharedMemoryOffset);
265 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
266 EXPECT_EQ(0U, result->size);
267 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
268 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
269 // Unlinked program
270 EXPECT_CALL(*gl_, CreateProgram())
271 .Times(1)
272 .WillOnce(Return(kNewServiceId))
273 .RetiresOnSaturation();
274 CreateProgram cmd2;
275 cmd2.Init(kNewClientId);
276 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
277 result->size = kInitialResult;
278 cmd.Init(kNewClientId,
279 kUniform2FakeLocation,
280 kSharedMemoryId,
281 kSharedMemoryOffset);
282 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
283 EXPECT_EQ(0U, result->size);
284 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
287 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadLocationFails) {
288 GetUniformiv::Result* result =
289 static_cast<GetUniformiv::Result*>(shared_memory_address_);
290 result->size = 0;
291 GetUniformiv cmd;
292 // invalid location
293 cmd.Init(client_program_id_,
294 kInvalidUniformLocation,
295 kSharedMemoryId,
296 kSharedMemoryOffset);
297 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
298 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
299 EXPECT_EQ(0U, result->size);
300 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
303 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadSharedMemoryFails) {
304 GetUniformiv cmd;
305 cmd.Init(client_program_id_,
306 kUniform2FakeLocation,
307 kInvalidSharedMemoryId,
308 kSharedMemoryOffset);
309 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
310 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
311 cmd.Init(client_program_id_,
312 kUniform2FakeLocation,
313 kSharedMemoryId,
314 kInvalidSharedMemoryOffset);
315 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
318 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivSucceeds) {
319 GetUniformuiv::Result* result =
320 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
321 result->size = 0;
322 GetUniformuiv cmd;
323 cmd.Init(client_program_id_,
324 kUniform2FakeLocation,
325 kSharedMemoryId,
326 kSharedMemoryOffset);
327 EXPECT_CALL(*gl_, GetUniformuiv(kServiceProgramId, kUniform2RealLocation, _))
328 .Times(1);
329 decoder_->set_unsafe_es3_apis_enabled(true);
330 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
331 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
332 static_cast<uint32>(result->GetNumResults()));
333 decoder_->set_unsafe_es3_apis_enabled(false);
334 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
337 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivArrayElementSucceeds) {
338 GetUniformuiv::Result* result =
339 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
340 result->size = 0;
341 GetUniformuiv cmd;
342 cmd.Init(client_program_id_,
343 kUniform2ElementFakeLocation,
344 kSharedMemoryId,
345 kSharedMemoryOffset);
346 EXPECT_CALL(*gl_,
347 GetUniformuiv(kServiceProgramId, kUniform2ElementRealLocation, _))
348 .Times(1);
349 decoder_->set_unsafe_es3_apis_enabled(true);
350 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
351 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
352 static_cast<uint32>(result->GetNumResults()));
355 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadProgramFails) {
356 GetUniformuiv::Result* result =
357 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
358 result->size = 0;
359 GetUniformuiv cmd;
360 // non-existant program
361 cmd.Init(kInvalidClientId,
362 kUniform2FakeLocation,
363 kSharedMemoryId,
364 kSharedMemoryOffset);
365 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
366 decoder_->set_unsafe_es3_apis_enabled(true);
367 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
368 EXPECT_EQ(0U, result->size);
369 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
370 // Valid id that is not a program. The GL spec requires a different error for
371 // this case.
372 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
373 result->size = kInitialResult;
374 cmd.Init(client_shader_id_,
375 kUniform2FakeLocation,
376 kSharedMemoryId,
377 kSharedMemoryOffset);
378 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
379 EXPECT_EQ(0U, result->size);
380 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
381 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
382 // Unlinked program
383 EXPECT_CALL(*gl_, CreateProgram())
384 .Times(1)
385 .WillOnce(Return(kNewServiceId))
386 .RetiresOnSaturation();
387 CreateProgram cmd2;
388 cmd2.Init(kNewClientId);
389 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
390 result->size = kInitialResult;
391 cmd.Init(kNewClientId,
392 kUniform2FakeLocation,
393 kSharedMemoryId,
394 kSharedMemoryOffset);
395 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
396 EXPECT_EQ(0U, result->size);
397 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
400 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadLocationFails) {
401 GetUniformuiv::Result* result =
402 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
403 result->size = 0;
404 GetUniformuiv cmd;
405 // invalid location
406 cmd.Init(client_program_id_,
407 kInvalidUniformLocation,
408 kSharedMemoryId,
409 kSharedMemoryOffset);
410 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
411 decoder_->set_unsafe_es3_apis_enabled(true);
412 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
413 EXPECT_EQ(0U, result->size);
414 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
417 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadSharedMemoryFails) {
418 GetUniformuiv cmd;
419 cmd.Init(client_program_id_,
420 kUniform2FakeLocation,
421 kInvalidSharedMemoryId,
422 kSharedMemoryOffset);
423 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
424 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
425 decoder_->set_unsafe_es3_apis_enabled(true);
426 cmd.Init(client_program_id_,
427 kUniform2FakeLocation,
428 kSharedMemoryId,
429 kInvalidSharedMemoryOffset);
430 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
433 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvSucceeds) {
434 GetUniformfv::Result* result =
435 static_cast<GetUniformfv::Result*>(shared_memory_address_);
436 result->size = 0;
437 GetUniformfv cmd;
438 cmd.Init(client_program_id_,
439 kUniform2FakeLocation,
440 kSharedMemoryId,
441 kSharedMemoryOffset);
442 EXPECT_CALL(*gl_, GetUniformfv(kServiceProgramId, kUniform2RealLocation, _))
443 .Times(1);
444 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
445 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
446 static_cast<uint32>(result->GetNumResults()));
449 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvArrayElementSucceeds) {
450 GetUniformfv::Result* result =
451 static_cast<GetUniformfv::Result*>(shared_memory_address_);
452 result->size = 0;
453 GetUniformfv cmd;
454 cmd.Init(client_program_id_,
455 kUniform2ElementFakeLocation,
456 kSharedMemoryId,
457 kSharedMemoryOffset);
458 EXPECT_CALL(*gl_,
459 GetUniformfv(kServiceProgramId, kUniform2ElementRealLocation, _))
460 .Times(1);
461 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
462 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
463 static_cast<uint32>(result->GetNumResults()));
466 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadProgramFails) {
467 GetUniformfv::Result* result =
468 static_cast<GetUniformfv::Result*>(shared_memory_address_);
469 result->size = 0;
470 GetUniformfv cmd;
471 // non-existant program
472 cmd.Init(kInvalidClientId,
473 kUniform2FakeLocation,
474 kSharedMemoryId,
475 kSharedMemoryOffset);
476 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
477 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
478 EXPECT_EQ(0U, result->size);
479 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
480 // Valid id that is not a program. The GL spec requires a different error for
481 // this case.
482 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
483 result->size = kInitialResult;
484 cmd.Init(client_shader_id_,
485 kUniform2FakeLocation,
486 kSharedMemoryId,
487 kSharedMemoryOffset);
488 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
489 EXPECT_EQ(0U, result->size);
490 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
491 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
492 // Unlinked program
493 EXPECT_CALL(*gl_, CreateProgram())
494 .Times(1)
495 .WillOnce(Return(kNewServiceId))
496 .RetiresOnSaturation();
497 CreateProgram cmd2;
498 cmd2.Init(kNewClientId);
499 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
500 result->size = kInitialResult;
501 cmd.Init(kNewClientId,
502 kUniform2FakeLocation,
503 kSharedMemoryId,
504 kSharedMemoryOffset);
505 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
506 EXPECT_EQ(0U, result->size);
507 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
510 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadLocationFails) {
511 GetUniformfv::Result* result =
512 static_cast<GetUniformfv::Result*>(shared_memory_address_);
513 result->size = 0;
514 GetUniformfv cmd;
515 // invalid location
516 cmd.Init(client_program_id_,
517 kInvalidUniformLocation,
518 kSharedMemoryId,
519 kSharedMemoryOffset);
520 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
521 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
522 EXPECT_EQ(0U, result->size);
523 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
526 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadSharedMemoryFails) {
527 GetUniformfv cmd;
528 cmd.Init(client_program_id_,
529 kUniform2FakeLocation,
530 kInvalidSharedMemoryId,
531 kSharedMemoryOffset);
532 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
533 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
534 cmd.Init(client_program_id_,
535 kUniform2FakeLocation,
536 kSharedMemoryId,
537 kInvalidSharedMemoryOffset);
538 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
541 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersSucceeds) {
542 GetAttachedShaders cmd;
543 typedef GetAttachedShaders::Result Result;
544 Result* result = static_cast<Result*>(shared_memory_address_);
545 result->size = 0;
546 EXPECT_CALL(*gl_, GetAttachedShaders(kServiceProgramId, 1, _, _)).WillOnce(
547 DoAll(SetArgPointee<2>(1), SetArgPointee<3>(kServiceShaderId)));
548 cmd.Init(client_program_id_,
549 shared_memory_id_,
550 shared_memory_offset_,
551 Result::ComputeSize(1));
552 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
553 EXPECT_EQ(1, result->GetNumResults());
554 EXPECT_EQ(client_shader_id_, result->GetData()[0]);
555 EXPECT_EQ(GL_NO_ERROR, GetGLError());
558 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersResultNotInitFail) {
559 GetAttachedShaders cmd;
560 typedef GetAttachedShaders::Result Result;
561 Result* result = static_cast<Result*>(shared_memory_address_);
562 result->size = 1;
563 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
564 cmd.Init(client_program_id_,
565 shared_memory_id_,
566 shared_memory_offset_,
567 Result::ComputeSize(1));
568 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
571 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersBadProgramFails) {
572 GetAttachedShaders cmd;
573 typedef GetAttachedShaders::Result Result;
574 Result* result = static_cast<Result*>(shared_memory_address_);
575 result->size = 0;
576 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
577 cmd.Init(kInvalidClientId,
578 shared_memory_id_,
579 shared_memory_offset_,
580 Result::ComputeSize(1));
581 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
582 EXPECT_EQ(0U, result->size);
583 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
586 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersBadSharedMemoryFails) {
587 GetAttachedShaders cmd;
588 typedef GetAttachedShaders::Result Result;
589 cmd.Init(client_program_id_,
590 kInvalidSharedMemoryId,
591 shared_memory_offset_,
592 Result::ComputeSize(1));
593 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
594 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
595 cmd.Init(client_program_id_,
596 shared_memory_id_,
597 kInvalidSharedMemoryOffset,
598 Result::ComputeSize(1));
599 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
602 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatSucceeds) {
603 ScopedGLImplementationSetter gl_impl(::gfx::kGLImplementationEGLGLES2);
604 GetShaderPrecisionFormat cmd;
605 typedef GetShaderPrecisionFormat::Result Result;
606 Result* result = static_cast<Result*>(shared_memory_address_);
607 result->success = 0;
608 const GLint range[2] = {62, 62};
609 const GLint precision = 16;
610 EXPECT_CALL(*gl_, GetShaderPrecisionFormat(_, _, _, _))
611 .WillOnce(DoAll(SetArrayArgument<2>(range, range + 2),
612 SetArgPointee<3>(precision)))
613 .RetiresOnSaturation();
614 cmd.Init(GL_VERTEX_SHADER,
615 GL_HIGH_FLOAT,
616 shared_memory_id_,
617 shared_memory_offset_);
618 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
619 EXPECT_NE(0, result->success);
620 EXPECT_EQ(range[0], result->min_range);
621 EXPECT_EQ(range[1], result->max_range);
622 EXPECT_EQ(precision, result->precision);
623 EXPECT_EQ(GL_NO_ERROR, GetGLError());
626 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatResultNotInitFails) {
627 GetShaderPrecisionFormat cmd;
628 typedef GetShaderPrecisionFormat::Result Result;
629 Result* result = static_cast<Result*>(shared_memory_address_);
630 result->success = 1;
631 // NOTE: GL might not be called. There is no Desktop OpenGL equivalent
632 cmd.Init(GL_VERTEX_SHADER,
633 GL_HIGH_FLOAT,
634 shared_memory_id_,
635 shared_memory_offset_);
636 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
639 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatBadArgsFails) {
640 typedef GetShaderPrecisionFormat::Result Result;
641 Result* result = static_cast<Result*>(shared_memory_address_);
642 result->success = 0;
643 GetShaderPrecisionFormat cmd;
644 cmd.Init(
645 GL_TEXTURE_2D, GL_HIGH_FLOAT, shared_memory_id_, shared_memory_offset_);
646 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
647 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
648 result->success = 0;
649 cmd.Init(GL_VERTEX_SHADER,
650 GL_TEXTURE_2D,
651 shared_memory_id_,
652 shared_memory_offset_);
653 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
654 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
657 TEST_P(GLES2DecoderWithShaderTest,
658 GetShaderPrecisionFormatBadSharedMemoryFails) {
659 GetShaderPrecisionFormat cmd;
660 cmd.Init(GL_VERTEX_SHADER,
661 GL_HIGH_FLOAT,
662 kInvalidSharedMemoryId,
663 shared_memory_offset_);
664 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
665 cmd.Init(GL_VERTEX_SHADER,
666 GL_TEXTURE_2D,
667 shared_memory_id_,
668 kInvalidSharedMemoryOffset);
669 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
672 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformSucceeds) {
673 const GLuint kUniformIndex = 1;
674 const uint32 kBucketId = 123;
675 GetActiveUniform cmd;
676 typedef GetActiveUniform::Result Result;
677 Result* result = static_cast<Result*>(shared_memory_address_);
678 result->success = 0;
679 cmd.Init(client_program_id_,
680 kUniformIndex,
681 kBucketId,
682 shared_memory_id_,
683 shared_memory_offset_);
684 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
685 EXPECT_NE(0, result->success);
686 EXPECT_EQ(kUniform2Size, result->size);
687 EXPECT_EQ(kUniform2Type, result->type);
688 EXPECT_EQ(GL_NO_ERROR, GetGLError());
689 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
690 ASSERT_TRUE(bucket != NULL);
691 EXPECT_EQ(
693 memcmp(
694 bucket->GetData(0, bucket->size()), kUniform2Name, bucket->size()));
697 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformResultNotInitFails) {
698 const GLuint kUniformIndex = 1;
699 const uint32 kBucketId = 123;
700 GetActiveUniform cmd;
701 typedef GetActiveUniform::Result Result;
702 Result* result = static_cast<Result*>(shared_memory_address_);
703 result->success = 1;
704 cmd.Init(client_program_id_,
705 kUniformIndex,
706 kBucketId,
707 shared_memory_id_,
708 shared_memory_offset_);
709 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
712 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadProgramFails) {
713 const GLuint kUniformIndex = 1;
714 const uint32 kBucketId = 123;
715 GetActiveUniform cmd;
716 typedef GetActiveUniform::Result Result;
717 Result* result = static_cast<Result*>(shared_memory_address_);
718 result->success = 0;
719 cmd.Init(kInvalidClientId,
720 kUniformIndex,
721 kBucketId,
722 shared_memory_id_,
723 shared_memory_offset_);
724 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
725 EXPECT_EQ(0, result->success);
726 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
727 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
728 result->success = 0;
729 cmd.Init(client_shader_id_,
730 kUniformIndex,
731 kBucketId,
732 shared_memory_id_,
733 shared_memory_offset_);
734 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
735 EXPECT_EQ(0, result->success);
736 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
737 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
740 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadIndexFails) {
741 const uint32 kBucketId = 123;
742 GetActiveUniform cmd;
743 typedef GetActiveUniform::Result Result;
744 Result* result = static_cast<Result*>(shared_memory_address_);
745 result->success = 0;
746 cmd.Init(client_program_id_,
747 kBadUniformIndex,
748 kBucketId,
749 shared_memory_id_,
750 shared_memory_offset_);
751 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
752 EXPECT_EQ(0, result->success);
753 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
756 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadSharedMemoryFails) {
757 const GLuint kUniformIndex = 1;
758 const uint32 kBucketId = 123;
759 GetActiveUniform cmd;
760 cmd.Init(client_program_id_,
761 kUniformIndex,
762 kBucketId,
763 kInvalidSharedMemoryId,
764 shared_memory_offset_);
765 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
766 cmd.Init(client_program_id_,
767 kUniformIndex,
768 kBucketId,
769 shared_memory_id_,
770 kInvalidSharedMemoryOffset);
771 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
774 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameSucceeds) {
775 const uint32 kBucketId = 123;
776 GetActiveUniformBlockName cmd;
777 typedef GetActiveUniformBlockName::Result Result;
778 Result* result = static_cast<Result*>(shared_memory_address_);
779 *result = 0;
780 cmd.Init(client_program_id_,
782 kBucketId,
783 shared_memory_id_,
784 shared_memory_offset_);
785 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
786 .WillOnce(SetArgPointee<2>(GL_TRUE))
787 .RetiresOnSaturation();
788 const char kName[] = "HolyCow";
789 const GLsizei kMaxLength = strlen(kName) + 1;
790 EXPECT_CALL(*gl_,
791 GetProgramiv(kServiceProgramId,
792 GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, _))
793 .WillOnce(SetArgPointee<2>(kMaxLength))
794 .RetiresOnSaturation();
795 EXPECT_CALL(*gl_,
796 GetActiveUniformBlockName(kServiceProgramId, 0, _, _, _))
797 .WillOnce(DoAll(SetArgPointee<3>(strlen(kName)),
798 SetArrayArgument<4>(kName, kName + strlen(kName) + 1)))
799 .RetiresOnSaturation();
800 decoder_->set_unsafe_es3_apis_enabled(true);
801 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
802 EXPECT_NE(0, *result);
803 EXPECT_EQ(GL_NO_ERROR, GetGLError());
804 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
805 ASSERT_TRUE(bucket != NULL);
806 EXPECT_EQ(0,
807 memcmp(bucket->GetData(0, bucket->size()), kName, bucket->size()));
808 decoder_->set_unsafe_es3_apis_enabled(false);
809 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
812 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameUnlinkedProgram) {
813 const uint32 kBucketId = 123;
814 GetActiveUniformBlockName cmd;
815 typedef GetActiveUniformBlockName::Result Result;
816 Result* result = static_cast<Result*>(shared_memory_address_);
817 *result = 0;
818 cmd.Init(client_program_id_,
820 kBucketId,
821 shared_memory_id_,
822 shared_memory_offset_);
823 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
824 .WillOnce(SetArgPointee<2>(GL_FALSE))
825 .RetiresOnSaturation();
826 decoder_->set_unsafe_es3_apis_enabled(true);
827 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
828 EXPECT_EQ(0, *result);
829 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
832 TEST_P(GLES2DecoderWithShaderTest,
833 GetActiveUniformBlockNameResultNotInitFails) {
834 const uint32 kBucketId = 123;
835 GetActiveUniformBlockName cmd;
836 typedef GetActiveUniformBlockName::Result Result;
837 Result* result = static_cast<Result*>(shared_memory_address_);
838 *result = 1;
839 cmd.Init(client_program_id_,
841 kBucketId,
842 shared_memory_id_,
843 shared_memory_offset_);
844 decoder_->set_unsafe_es3_apis_enabled(true);
845 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
848 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameBadProgramFails) {
849 const uint32 kBucketId = 123;
850 GetActiveUniformBlockName cmd;
851 typedef GetActiveUniformBlockName::Result Result;
852 Result* result = static_cast<Result*>(shared_memory_address_);
853 *result = 0;
854 cmd.Init(kInvalidClientId,
856 kBucketId,
857 shared_memory_id_,
858 shared_memory_offset_);
859 decoder_->set_unsafe_es3_apis_enabled(true);
860 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
861 EXPECT_EQ(0, *result);
862 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
865 TEST_P(GLES2DecoderWithShaderTest,
866 GetActiveUniformBlockNameBadSharedMemoryFails) {
867 const uint32 kBucketId = 123;
868 GetActiveUniformBlockName cmd;
869 decoder_->set_unsafe_es3_apis_enabled(true);
870 cmd.Init(client_program_id_,
872 kBucketId,
873 kInvalidSharedMemoryId,
874 shared_memory_offset_);
875 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
876 cmd.Init(client_program_id_,
878 kBucketId,
879 shared_memory_id_,
880 kInvalidSharedMemoryOffset);
881 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
884 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivSucceeds) {
885 GetActiveUniformBlockiv cmd;
886 typedef GetActiveUniformBlockiv::Result Result;
887 Result* result = static_cast<Result*>(shared_memory_address_);
888 GLenum kPname[] {
889 GL_UNIFORM_BLOCK_BINDING,
890 GL_UNIFORM_BLOCK_DATA_SIZE,
891 GL_UNIFORM_BLOCK_NAME_LENGTH,
892 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS,
893 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES,
894 GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER,
895 GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER,
897 for (size_t ii = 0; ii < arraysize(kPname); ++ii) {
898 result->SetNumResults(0);
899 cmd.Init(client_program_id_,
901 kPname[ii],
902 shared_memory_id_,
903 shared_memory_offset_);
904 EXPECT_CALL(*gl_, GetError())
905 .WillOnce(Return(GL_NO_ERROR))
906 .WillOnce(Return(GL_NO_ERROR))
907 .RetiresOnSaturation();
908 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
909 .WillOnce(SetArgPointee<2>(GL_TRUE))
910 .RetiresOnSaturation();
911 if (kPname[ii] == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) {
912 EXPECT_CALL(*gl_, GetError())
913 .WillOnce(Return(GL_NO_ERROR))
914 .RetiresOnSaturation();
915 EXPECT_CALL(*gl_,
916 GetActiveUniformBlockiv(kServiceProgramId, 0,
917 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, _))
918 .WillOnce(SetArgPointee<3>(1))
919 .RetiresOnSaturation();
921 EXPECT_CALL(*gl_,
922 GetActiveUniformBlockiv(
923 kServiceProgramId, 0, kPname[ii], _))
924 .WillOnce(SetArgPointee<3>(1976))
925 .RetiresOnSaturation();
926 decoder_->set_unsafe_es3_apis_enabled(true);
927 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
928 EXPECT_EQ(1, result->GetNumResults());
929 EXPECT_EQ(GL_NO_ERROR, GetGLError());
930 EXPECT_EQ(1976, result->GetData()[0]);
931 decoder_->set_unsafe_es3_apis_enabled(false);
932 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
936 TEST_P(GLES2DecoderWithShaderTest,
937 GetActiveUniformBlockivSucceedsZeroUniforms) {
938 GetActiveUniformBlockiv cmd;
939 typedef GetActiveUniformBlockiv::Result Result;
940 Result* result = static_cast<Result*>(shared_memory_address_);
941 result->SetNumResults(0);
942 cmd.Init(client_program_id_,
944 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES,
945 shared_memory_id_,
946 shared_memory_offset_);
947 EXPECT_CALL(*gl_, GetError())
948 .WillOnce(Return(GL_NO_ERROR))
949 .WillOnce(Return(GL_NO_ERROR))
950 .WillOnce(Return(GL_NO_ERROR))
951 .RetiresOnSaturation();
952 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
953 .WillOnce(SetArgPointee<2>(GL_TRUE))
954 .RetiresOnSaturation();
955 EXPECT_CALL(*gl_,
956 GetActiveUniformBlockiv(
957 kServiceProgramId, 0, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, _))
958 .WillOnce(SetArgPointee<3>(0))
959 .RetiresOnSaturation();
960 EXPECT_CALL(*gl_,
961 GetActiveUniformBlockiv(kServiceProgramId, 0,
962 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, _))
963 .Times(1)
964 .RetiresOnSaturation();
965 decoder_->set_unsafe_es3_apis_enabled(true);
966 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
967 EXPECT_EQ(0, result->GetNumResults());
968 EXPECT_EQ(GL_NO_ERROR, GetGLError());
971 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivUnlinkedProgram) {
972 GetActiveUniformBlockiv cmd;
973 typedef GetActiveUniformBlockiv::Result Result;
974 Result* result = static_cast<Result*>(shared_memory_address_);
975 result->SetNumResults(0);
976 cmd.Init(client_program_id_,
978 GL_UNIFORM_BLOCK_BINDING,
979 shared_memory_id_,
980 shared_memory_offset_);
981 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
982 .WillOnce(SetArgPointee<2>(GL_FALSE))
983 .RetiresOnSaturation();
984 decoder_->set_unsafe_es3_apis_enabled(true);
985 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
986 EXPECT_EQ(0, result->GetNumResults());
987 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
990 TEST_P(GLES2DecoderWithShaderTest,
991 GetActiveUniformBlockivResultNotInitFails) {
992 GetActiveUniformBlockiv cmd;
993 typedef GetActiveUniformBlockiv::Result Result;
994 Result* result = static_cast<Result*>(shared_memory_address_);
995 result->SetNumResults(1); // Should be initialized to 0.
996 cmd.Init(client_program_id_,
998 GL_UNIFORM_BLOCK_BINDING,
999 shared_memory_id_,
1000 shared_memory_offset_);
1001 decoder_->set_unsafe_es3_apis_enabled(true);
1002 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1003 .WillOnce(SetArgPointee<2>(GL_TRUE))
1004 .RetiresOnSaturation();
1005 EXPECT_CALL(*gl_, GetError())
1006 .WillOnce(Return(GL_NO_ERROR))
1007 .RetiresOnSaturation();
1008 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1011 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivBadProgramFails) {
1012 GetActiveUniformBlockiv cmd;
1013 typedef GetActiveUniformBlockiv::Result Result;
1014 Result* result = static_cast<Result*>(shared_memory_address_);
1015 result->SetNumResults(0);
1016 cmd.Init(kInvalidClientId,
1018 GL_UNIFORM_BLOCK_BINDING,
1019 shared_memory_id_,
1020 shared_memory_offset_);
1021 decoder_->set_unsafe_es3_apis_enabled(true);
1022 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1023 EXPECT_EQ(0, result->GetNumResults());
1024 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1027 TEST_P(GLES2DecoderWithShaderTest,
1028 GetActiveUniformBlockivBadSharedMemoryFails) {
1029 GetActiveUniformBlockiv cmd;
1030 decoder_->set_unsafe_es3_apis_enabled(true);
1031 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1032 .WillOnce(SetArgPointee<2>(GL_TRUE))
1033 .WillOnce(SetArgPointee<2>(GL_TRUE))
1034 .RetiresOnSaturation();
1035 EXPECT_CALL(*gl_, GetError())
1036 .WillOnce(Return(GL_NO_ERROR))
1037 .WillOnce(Return(GL_NO_ERROR))
1038 .RetiresOnSaturation();
1039 cmd.Init(client_program_id_,
1041 GL_UNIFORM_BLOCK_BINDING,
1042 kInvalidSharedMemoryId,
1043 shared_memory_offset_);
1044 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1045 cmd.Init(client_program_id_,
1047 GL_UNIFORM_BLOCK_BINDING,
1048 shared_memory_id_,
1049 kInvalidSharedMemoryOffset);
1050 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1053 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribSucceeds) {
1054 const GLuint kAttribIndex = 1;
1055 const uint32 kBucketId = 123;
1056 GetActiveAttrib cmd;
1057 typedef GetActiveAttrib::Result Result;
1058 Result* result = static_cast<Result*>(shared_memory_address_);
1059 result->success = 0;
1060 cmd.Init(client_program_id_,
1061 kAttribIndex,
1062 kBucketId,
1063 shared_memory_id_,
1064 shared_memory_offset_);
1065 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1066 EXPECT_NE(0, result->success);
1067 EXPECT_EQ(kAttrib2Size, result->size);
1068 EXPECT_EQ(kAttrib2Type, result->type);
1069 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1070 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1071 ASSERT_TRUE(bucket != NULL);
1072 EXPECT_EQ(
1074 memcmp(bucket->GetData(0, bucket->size()), kAttrib2Name, bucket->size()));
1077 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribResultNotInitFails) {
1078 const GLuint kAttribIndex = 1;
1079 const uint32 kBucketId = 123;
1080 GetActiveAttrib cmd;
1081 typedef GetActiveAttrib::Result Result;
1082 Result* result = static_cast<Result*>(shared_memory_address_);
1083 result->success = 1;
1084 cmd.Init(client_program_id_,
1085 kAttribIndex,
1086 kBucketId,
1087 shared_memory_id_,
1088 shared_memory_offset_);
1089 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1092 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadProgramFails) {
1093 const GLuint kAttribIndex = 1;
1094 const uint32 kBucketId = 123;
1095 GetActiveAttrib cmd;
1096 typedef GetActiveAttrib::Result Result;
1097 Result* result = static_cast<Result*>(shared_memory_address_);
1098 result->success = 0;
1099 cmd.Init(kInvalidClientId,
1100 kAttribIndex,
1101 kBucketId,
1102 shared_memory_id_,
1103 shared_memory_offset_);
1104 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1105 EXPECT_EQ(0, result->success);
1106 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1107 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1108 result->success = 0;
1109 cmd.Init(client_shader_id_,
1110 kAttribIndex,
1111 kBucketId,
1112 shared_memory_id_,
1113 shared_memory_offset_);
1114 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1115 EXPECT_EQ(0, result->success);
1116 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1117 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1120 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadIndexFails) {
1121 const uint32 kBucketId = 123;
1122 GetActiveAttrib cmd;
1123 typedef GetActiveAttrib::Result Result;
1124 Result* result = static_cast<Result*>(shared_memory_address_);
1125 result->success = 0;
1126 cmd.Init(client_program_id_,
1127 kBadAttribIndex,
1128 kBucketId,
1129 shared_memory_id_,
1130 shared_memory_offset_);
1131 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1132 EXPECT_EQ(0, result->success);
1133 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1136 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadSharedMemoryFails) {
1137 const GLuint kAttribIndex = 1;
1138 const uint32 kBucketId = 123;
1139 GetActiveAttrib cmd;
1140 cmd.Init(client_program_id_,
1141 kAttribIndex,
1142 kBucketId,
1143 kInvalidSharedMemoryId,
1144 shared_memory_offset_);
1145 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1146 cmd.Init(client_program_id_,
1147 kAttribIndex,
1148 kBucketId,
1149 shared_memory_id_,
1150 kInvalidSharedMemoryOffset);
1151 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1154 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesSucceeds) {
1155 const uint32 kBucketId = 123;
1156 const char kName0[] = "Cow";
1157 const char kName1[] = "Chicken";
1158 const char* kNames[] = { kName0, kName1 };
1159 const size_t kCount = arraysize(kNames);
1160 const char kValidStrEnd = 0;
1161 const GLuint kIndices[] = { 1, 2 };
1162 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1163 GetUniformIndices::Result* result =
1164 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1165 GetUniformIndices cmd;
1166 cmd.Init(client_program_id_,
1167 kBucketId,
1168 kSharedMemoryId,
1169 kSharedMemoryOffset);
1170 EXPECT_CALL(*gl_, GetUniformIndices(kServiceProgramId, kCount, _, _))
1171 .WillOnce(SetArrayArgument<3>(kIndices, kIndices + kCount))
1172 .RetiresOnSaturation();
1173 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1174 .WillOnce(SetArgPointee<2>(GL_TRUE))
1175 .RetiresOnSaturation();
1176 EXPECT_CALL(*gl_, GetError())
1177 .WillOnce(Return(GL_NO_ERROR))
1178 .WillOnce(Return(GL_NO_ERROR))
1179 .RetiresOnSaturation();
1180 decoder_->set_unsafe_es3_apis_enabled(true);
1181 result->size = 0;
1182 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1183 EXPECT_EQ(kCount, static_cast<size_t>(result->GetNumResults()));
1184 for (size_t ii = 0; ii < kCount; ++ii) {
1185 EXPECT_EQ(kIndices[ii], result->GetData()[ii]);
1187 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1188 decoder_->set_unsafe_es3_apis_enabled(false);
1189 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1192 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadProgramFails) {
1193 const uint32 kBucketId = 123;
1194 const char kName0[] = "Cow";
1195 const char kName1[] = "Chicken";
1196 const char* kNames[] = { kName0, kName1 };
1197 const size_t kCount = arraysize(kNames);
1198 const char kValidStrEnd = 0;
1199 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1200 GetUniformIndices::Result* result =
1201 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1202 decoder_->set_unsafe_es3_apis_enabled(true);
1203 GetUniformIndices cmd;
1204 // None-existant program
1205 cmd.Init(kInvalidClientId,
1206 kBucketId,
1207 kSharedMemoryId,
1208 kSharedMemoryOffset);
1209 result->size = 0;
1210 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1211 EXPECT_EQ(0, result->GetNumResults());
1212 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1213 // Unlinked program.
1214 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1215 .WillOnce(SetArgPointee<2>(GL_FALSE))
1216 .RetiresOnSaturation();
1217 cmd.Init(client_program_id_,
1218 kBucketId,
1219 kSharedMemoryId,
1220 kSharedMemoryOffset);
1221 result->size = 0;
1222 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1223 EXPECT_EQ(0, result->GetNumResults());
1224 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1227 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadParamsFails) {
1228 const uint32 kBucketId = 123;
1229 const char kName0[] = "Cow";
1230 const char kName1[] = "Chicken";
1231 const char* kNames[] = { kName0, kName1 };
1232 const size_t kCount = arraysize(kNames);
1233 const char kValidStrEnd = 0;
1234 const GLuint kIndices[] = { 1, 2 };
1235 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1236 GetUniformIndices::Result* result =
1237 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1238 GetUniformIndices cmd;
1239 cmd.Init(client_program_id_,
1240 kBucketId,
1241 kSharedMemoryId,
1242 kSharedMemoryOffset);
1243 EXPECT_CALL(*gl_, GetUniformIndices(kServiceProgramId, kCount, _, _))
1244 .WillOnce(SetArrayArgument<3>(kIndices, kIndices + kCount))
1245 .RetiresOnSaturation();
1246 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1247 .WillOnce(SetArgPointee<2>(GL_TRUE))
1248 .RetiresOnSaturation();
1249 EXPECT_CALL(*gl_, GetError())
1250 .WillOnce(Return(GL_NO_ERROR))
1251 .WillOnce(Return(GL_INVALID_VALUE))
1252 .RetiresOnSaturation();
1253 decoder_->set_unsafe_es3_apis_enabled(true);
1254 result->size = 0;
1255 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1256 EXPECT_EQ(0, result->GetNumResults());
1257 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1260 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesResultNotInitFails) {
1261 const uint32 kBucketId = 123;
1262 const char kName0[] = "Cow";
1263 const char kName1[] = "Chicken";
1264 const char* kNames[] = { kName0, kName1 };
1265 const size_t kCount = arraysize(kNames);
1266 const char kValidStrEnd = 0;
1267 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1268 GetUniformIndices::Result* result =
1269 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1270 decoder_->set_unsafe_es3_apis_enabled(true);
1271 GetUniformIndices cmd;
1272 result->size = 1976; // Any value other than 0.
1273 cmd.Init(kInvalidClientId,
1274 kBucketId,
1275 kSharedMemoryId,
1276 kSharedMemoryOffset);
1277 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1280 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadSharedMemoryFails) {
1281 const uint32 kBucketId = 123;
1282 const char kName0[] = "Cow";
1283 const char kName1[] = "Chicken";
1284 const char* kNames[] = { kName0, kName1 };
1285 const size_t kCount = arraysize(kNames);
1286 const char kValidStrEnd = 0;
1287 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1288 GetUniformIndices::Result* result =
1289 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1290 decoder_->set_unsafe_es3_apis_enabled(true);
1291 GetUniformIndices cmd;
1292 cmd.Init(client_program_id_,
1293 kBucketId,
1294 kInvalidSharedMemoryId,
1295 kSharedMemoryOffset);
1296 result->size = 0;
1297 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1298 cmd.Init(client_program_id_,
1299 kBucketId,
1300 kSharedMemoryId,
1301 kInvalidSharedMemoryOffset);
1302 result->size = 0;
1303 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1306 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivSucceeds) {
1307 const uint32 kBucketId = 123;
1308 const GLuint kIndices[] = { 1, 2 };
1309 const GLint kResults[] = { 1976, 321 };
1310 const size_t kCount = arraysize(kIndices);
1311 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1312 GetActiveUniformsiv::Result* result =
1313 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1314 GetActiveUniformsiv cmd;
1315 cmd.Init(client_program_id_,
1316 kBucketId,
1317 GL_UNIFORM_TYPE,
1318 kSharedMemoryId,
1319 kSharedMemoryOffset);
1320 EXPECT_CALL(*gl_,
1321 GetActiveUniformsiv(
1322 kServiceProgramId, kCount, _, GL_UNIFORM_TYPE, _))
1323 .WillOnce(SetArrayArgument<4>(kResults, kResults + kCount))
1324 .RetiresOnSaturation();
1325 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1326 .WillOnce(SetArgPointee<2>(GL_TRUE))
1327 .RetiresOnSaturation();
1328 EXPECT_CALL(*gl_, GetError())
1329 .WillOnce(Return(GL_NO_ERROR))
1330 .WillOnce(Return(GL_NO_ERROR))
1331 .RetiresOnSaturation();
1332 decoder_->set_unsafe_es3_apis_enabled(true);
1333 result->size = 0;
1334 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1335 EXPECT_EQ(kCount, static_cast<size_t>(result->GetNumResults()));
1336 for (size_t ii = 0; ii < kCount; ++ii) {
1337 EXPECT_EQ(kResults[ii], result->GetData()[ii]);
1339 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1340 decoder_->set_unsafe_es3_apis_enabled(false);
1341 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1344 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadProgramFails) {
1345 const uint32 kBucketId = 123;
1346 const GLuint kIndices[] = { 1, 2 };
1347 const size_t kCount = arraysize(kIndices);
1348 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1349 GetActiveUniformsiv::Result* result =
1350 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1351 decoder_->set_unsafe_es3_apis_enabled(true);
1352 GetActiveUniformsiv cmd;
1353 // None-existant program
1354 cmd.Init(kInvalidClientId,
1355 kBucketId,
1356 GL_UNIFORM_TYPE,
1357 kSharedMemoryId,
1358 kSharedMemoryOffset);
1359 result->size = 0;
1360 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1361 EXPECT_EQ(0, result->GetNumResults());
1362 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1363 // Unlinked program.
1364 cmd.Init(client_program_id_,
1365 kBucketId,
1366 GL_UNIFORM_TYPE,
1367 kSharedMemoryId,
1368 kSharedMemoryOffset);
1369 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1370 .WillOnce(SetArgPointee<2>(GL_FALSE))
1371 .RetiresOnSaturation();
1372 result->size = 0;
1373 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1374 EXPECT_EQ(0, result->GetNumResults());
1375 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1378 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadParamsFails) {
1379 const uint32 kBucketId = 123;
1380 const GLuint kIndices[] = { 1, 2 };
1381 const GLint kResults[] = { 1976, 321 };
1382 const size_t kCount = arraysize(kIndices);
1383 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1384 GetActiveUniformsiv::Result* result =
1385 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1386 GetActiveUniformsiv cmd;
1387 cmd.Init(client_program_id_,
1388 kBucketId,
1389 GL_UNIFORM_TYPE,
1390 kSharedMemoryId,
1391 kSharedMemoryOffset);
1392 EXPECT_CALL(*gl_,
1393 GetActiveUniformsiv(
1394 kServiceProgramId, kCount, _, GL_UNIFORM_TYPE, _))
1395 .WillOnce(SetArrayArgument<4>(kResults, kResults + kCount))
1396 .RetiresOnSaturation();
1397 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1398 .WillOnce(SetArgPointee<2>(GL_TRUE))
1399 .RetiresOnSaturation();
1400 EXPECT_CALL(*gl_, GetError())
1401 .WillOnce(Return(GL_NO_ERROR))
1402 .WillOnce(Return(GL_INVALID_VALUE))
1403 .RetiresOnSaturation();
1404 decoder_->set_unsafe_es3_apis_enabled(true);
1405 result->size = 0;
1406 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1407 EXPECT_EQ(0, result->GetNumResults());
1408 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1411 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivResultNotInitFails) {
1412 const uint32 kBucketId = 123;
1413 const GLuint kIndices[] = { 1, 2 };
1414 const size_t kCount = arraysize(kIndices);
1415 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1416 GetActiveUniformsiv::Result* result =
1417 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1418 GetActiveUniformsiv cmd;
1419 cmd.Init(client_program_id_,
1420 kBucketId,
1421 GL_UNIFORM_TYPE,
1422 kSharedMemoryId,
1423 kSharedMemoryOffset);
1424 decoder_->set_unsafe_es3_apis_enabled(true);
1425 result->size = 1976; // Any value other than 0.
1426 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1429 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadSharedMemoryFails) {
1430 const uint32 kBucketId = 123;
1431 const GLuint kIndices[] = { 1, 2 };
1432 const size_t kCount = arraysize(kIndices);
1433 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1434 GetActiveUniformsiv::Result* result =
1435 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1436 GetActiveUniformsiv cmd;
1437 decoder_->set_unsafe_es3_apis_enabled(true);
1438 result->size = 0;
1439 cmd.Init(client_program_id_,
1440 kBucketId,
1441 GL_UNIFORM_TYPE,
1442 kInvalidSharedMemoryId,
1443 kSharedMemoryOffset);
1444 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1445 result->size = 0;
1446 cmd.Init(client_program_id_,
1447 kBucketId,
1448 GL_UNIFORM_TYPE,
1449 kSharedMemoryId,
1450 kInvalidSharedMemoryOffset);
1451 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1454 TEST_P(GLES2DecoderWithShaderTest, GetShaderInfoLogValidArgs) {
1455 const char* kInfo = "hello";
1456 const uint32 kBucketId = 123;
1457 CompileShader compile_cmd;
1458 GetShaderInfoLog cmd;
1459 EXPECT_CALL(*gl_, ShaderSource(kServiceShaderId, 1, _, _));
1460 EXPECT_CALL(*gl_, CompileShader(kServiceShaderId));
1461 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_COMPILE_STATUS, _))
1462 .WillOnce(SetArgPointee<2>(GL_FALSE))
1463 .RetiresOnSaturation();
1464 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_INFO_LOG_LENGTH, _))
1465 .WillOnce(SetArgPointee<2>(strlen(kInfo) + 1))
1466 .RetiresOnSaturation();
1467 EXPECT_CALL(*gl_, GetShaderInfoLog(kServiceShaderId, strlen(kInfo) + 1, _, _))
1468 .WillOnce(DoAll(SetArgPointee<2>(strlen(kInfo)),
1469 SetArrayArgument<3>(kInfo, kInfo + strlen(kInfo) + 1)));
1470 compile_cmd.Init(client_shader_id_);
1471 cmd.Init(client_shader_id_, kBucketId);
1472 EXPECT_EQ(error::kNoError, ExecuteCmd(compile_cmd));
1473 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1474 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1475 ASSERT_TRUE(bucket != NULL);
1476 EXPECT_EQ(strlen(kInfo) + 1, bucket->size());
1477 EXPECT_EQ(0,
1478 memcmp(bucket->GetData(0, bucket->size()), kInfo, bucket->size()));
1479 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1482 TEST_P(GLES2DecoderWithShaderTest, GetShaderInfoLogInvalidArgs) {
1483 const uint32 kBucketId = 123;
1484 GetShaderInfoLog cmd;
1485 cmd.Init(kInvalidClientId, kBucketId);
1486 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1487 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1490 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingSucceeds) {
1491 const GLuint kIndex = 1;
1492 const uint32 kBucketId = 123;
1493 const char kName[] = "HolyCow";
1494 const GLsizei kBufferSize = static_cast<GLsizei>(strlen(kName) + 1);
1495 const GLsizei kSize = 2;
1496 const GLenum kType = GL_FLOAT_VEC2;
1497 GetTransformFeedbackVarying cmd;
1498 typedef GetTransformFeedbackVarying::Result Result;
1499 Result* result = static_cast<Result*>(shared_memory_address_);
1500 result->success = 0;
1501 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1502 .WillOnce(SetArgPointee<2>(GL_TRUE))
1503 .RetiresOnSaturation();
1504 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId,
1505 GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, _))
1506 .WillOnce(SetArgPointee<2>(kBufferSize))
1507 .RetiresOnSaturation();
1508 EXPECT_CALL(*gl_, GetError())
1509 .WillOnce(Return(GL_NO_ERROR))
1510 .WillOnce(Return(GL_NO_ERROR))
1511 .RetiresOnSaturation();
1512 EXPECT_CALL(*gl_,
1513 GetTransformFeedbackVarying(
1514 kServiceProgramId, kIndex, _, _, _, _, _))
1515 .WillOnce(DoAll(SetArgPointee<3>(kBufferSize - 1),
1516 SetArgPointee<4>(kSize),
1517 SetArgPointee<5>(kType),
1518 SetArrayArgument<6>(kName, kName + kBufferSize)))
1519 .RetiresOnSaturation();
1520 cmd.Init(client_program_id_,
1521 kIndex,
1522 kBucketId,
1523 shared_memory_id_,
1524 shared_memory_offset_);
1525 decoder_->set_unsafe_es3_apis_enabled(true);
1526 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1527 EXPECT_NE(0, result->success);
1528 EXPECT_EQ(kSize, static_cast<GLsizei>(result->size));
1529 EXPECT_EQ(kType, static_cast<GLenum>(result->type));
1530 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1531 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1532 ASSERT_TRUE(bucket != NULL);
1533 EXPECT_EQ(
1534 0, memcmp(bucket->GetData(0, bucket->size()), kName, bucket->size()));
1535 decoder_->set_unsafe_es3_apis_enabled(false);
1536 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1539 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingNotInitFails) {
1540 const GLuint kIndex = 1;
1541 const uint32 kBucketId = 123;
1542 GetTransformFeedbackVarying cmd;
1543 typedef GetTransformFeedbackVarying::Result Result;
1544 Result* result = static_cast<Result*>(shared_memory_address_);
1545 result->success = 1;
1546 cmd.Init(client_program_id_,
1547 kIndex,
1548 kBucketId,
1549 shared_memory_id_,
1550 shared_memory_offset_);
1551 decoder_->set_unsafe_es3_apis_enabled(true);
1552 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1555 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingBadProgramFails) {
1556 const GLuint kIndex = 1;
1557 const uint32 kBucketId = 123;
1558 GetTransformFeedbackVarying cmd;
1559 typedef GetTransformFeedbackVarying::Result Result;
1560 Result* result = static_cast<Result*>(shared_memory_address_);
1561 result->success = 0;
1562 cmd.Init(kInvalidClientId,
1563 kIndex,
1564 kBucketId,
1565 shared_memory_id_,
1566 shared_memory_offset_);
1567 decoder_->set_unsafe_es3_apis_enabled(true);
1568 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1569 EXPECT_EQ(0, result->success);
1570 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1573 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingBadParamsFails) {
1574 const GLuint kIndex = 1;
1575 const uint32 kBucketId = 123;
1576 const GLsizei kBufferSize = 10;
1577 GetTransformFeedbackVarying cmd;
1578 typedef GetTransformFeedbackVarying::Result Result;
1579 Result* result = static_cast<Result*>(shared_memory_address_);
1580 result->success = 0;
1581 cmd.Init(client_program_id_,
1582 kIndex,
1583 kBucketId,
1584 shared_memory_id_,
1585 shared_memory_offset_);
1586 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1587 .WillOnce(SetArgPointee<2>(GL_TRUE))
1588 .RetiresOnSaturation();
1589 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId,
1590 GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, _))
1591 .WillOnce(SetArgPointee<2>(kBufferSize))
1592 .RetiresOnSaturation();
1593 EXPECT_CALL(*gl_, GetError())
1594 .WillOnce(Return(GL_NO_ERROR))
1595 .WillOnce(Return(GL_INVALID_VALUE))
1596 .RetiresOnSaturation();
1597 EXPECT_CALL(*gl_,
1598 GetTransformFeedbackVarying(
1599 kServiceProgramId, kIndex, _, _, _, _, _))
1600 .Times(1)
1601 .RetiresOnSaturation();
1602 decoder_->set_unsafe_es3_apis_enabled(true);
1603 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1604 EXPECT_EQ(0, result->success);
1605 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1608 TEST_P(GLES2DecoderWithShaderTest,
1609 GetTransformFeedbackVaryingBadSharedMemoryFails) {
1610 const GLuint kIndex = 1;
1611 const uint32 kBucketId = 123;
1612 GetTransformFeedbackVarying cmd;
1613 typedef GetTransformFeedbackVarying::Result Result;
1614 Result* result = static_cast<Result*>(shared_memory_address_);
1615 result->success = 0;
1616 decoder_->set_unsafe_es3_apis_enabled(true);
1617 cmd.Init(client_program_id_,
1618 kIndex,
1619 kBucketId,
1620 kInvalidSharedMemoryId,
1621 shared_memory_offset_);
1622 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1623 cmd.Init(client_program_id_,
1624 kIndex,
1625 kBucketId,
1626 shared_memory_id_,
1627 kInvalidSharedMemoryOffset);
1628 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1631 TEST_P(GLES2DecoderTest, CompileShaderValidArgs) {
1632 // Compile shader should not actually call any GL calls yet.
1633 CompileShader cmd;
1634 cmd.Init(client_shader_id_);
1635 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1637 // Getting the shader compilation state should trigger the actual GL calls.
1638 EXPECT_CALL(*gl_, ShaderSource(kServiceShaderId, 1, _, _));
1639 EXPECT_CALL(*gl_, CompileShader(kServiceShaderId));
1640 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_COMPILE_STATUS, _))
1641 .WillOnce(SetArgPointee<2>(GL_TRUE))
1642 .RetiresOnSaturation();
1643 EXPECT_CALL(*gl_, GetError())
1644 .WillOnce(Return(GL_NO_ERROR))
1645 .WillOnce(Return(GL_NO_ERROR))
1646 .RetiresOnSaturation();
1648 GetShaderiv status_cmd;
1649 status_cmd.Init(client_shader_id_, GL_COMPILE_STATUS,
1650 kSharedMemoryId, kSharedMemoryOffset);
1651 EXPECT_EQ(error::kNoError, ExecuteCmd(status_cmd));
1654 TEST_P(GLES2DecoderTest, CompileShaderInvalidArgs) {
1655 CompileShader cmd;
1656 cmd.Init(kInvalidClientId);
1657 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1658 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1659 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1660 cmd.Init(client_program_id_);
1661 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1662 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1663 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1666 TEST_P(GLES2DecoderTest, ShaderSourceBucketAndGetShaderSourceValidArgs) {
1667 const uint32 kInBucketId = 123;
1668 const uint32 kOutBucketId = 125;
1669 const char kSource0[] = "hello";
1670 const char* kSource[] = { kSource0 };
1671 const char kValidStrEnd = 0;
1672 SetBucketAsCStrings(kInBucketId, 1, kSource, 1, kValidStrEnd);
1673 ShaderSourceBucket cmd;
1674 cmd.Init(client_shader_id_, kInBucketId);
1675 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1676 ClearSharedMemory();
1677 GetShaderSource get_cmd;
1678 get_cmd.Init(client_shader_id_, kOutBucketId);
1679 EXPECT_EQ(error::kNoError, ExecuteCmd(get_cmd));
1680 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kOutBucketId);
1681 ASSERT_TRUE(bucket != NULL);
1682 EXPECT_EQ(sizeof(kSource0), bucket->size());
1683 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()),
1684 kSource0, bucket->size()));
1687 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1688 TEST_P(GLES2DecoderTest, ShaderSourceBucketWithProgramId) {
1689 const uint32 kBucketId = 123;
1690 const char kSource0[] = "hello";
1691 const char* kSource[] = { kSource0 };
1692 const char kValidStrEnd = 0;
1693 SetBucketAsCStrings(kBucketId, 1, kSource, 1, kValidStrEnd);
1694 ShaderSourceBucket cmd;
1695 cmd.Init(client_program_id_, kBucketId);
1696 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1697 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1699 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1701 TEST_P(GLES2DecoderTest, ShaderSourceStripComments) {
1702 const uint32 kInBucketId = 123;
1703 const char kSource0[] = "hello/*te\ast*/world//a\ab";
1704 const char* kSource[] = { kSource0 };
1705 const char kValidStrEnd = 0;
1706 SetBucketAsCStrings(kInBucketId, 1, kSource, 1, kValidStrEnd);
1707 ShaderSourceBucket cmd;
1708 cmd.Init(client_shader_id_, kInBucketId);
1709 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1710 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1713 TEST_P(GLES2DecoderWithShaderTest, Uniform1iValidArgs) {
1714 EXPECT_CALL(*gl_, Uniform1i(kUniform1RealLocation, 2));
1715 Uniform1i cmd;
1716 cmd.Init(kUniform1FakeLocation, 2);
1717 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1720 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivImmediateValidArgs) {
1721 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1722 EXPECT_CALL(*gl_,
1723 Uniform1iv(kUniform1RealLocation,
1725 reinterpret_cast<GLint*>(ImmediateDataAddress(&cmd))));
1726 GLint temp[1 * 2] = {
1729 cmd.Init(kUniform1FakeLocation, 1, &temp[0]);
1730 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1733 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivImmediateInvalidValidArgs) {
1734 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1735 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1736 GLint temp[1 * 2] = {
1739 cmd.Init(kUniform1FakeLocation, 2, &temp[0]);
1740 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1741 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1744 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivZeroCount) {
1745 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1746 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1747 GLint temp = 0;
1748 cmd.Init(kUniform1FakeLocation, 0, &temp);
1749 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1750 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1753 TEST_P(GLES2DecoderWithShaderTest, Uniform1iSamplerIsLmited) {
1754 EXPECT_CALL(*gl_, Uniform1i(_, _)).Times(0);
1755 Uniform1i cmd;
1756 cmd.Init(kUniform1FakeLocation, kNumTextureUnits);
1757 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1758 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1761 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivSamplerIsLimited) {
1762 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1763 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1764 GLint temp[] = {kNumTextureUnits};
1765 cmd.Init(kUniform1FakeLocation, 1, &temp[0]);
1766 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1767 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1770 TEST_P(GLES2DecoderTest, BindAttribLocationBucket) {
1771 const uint32 kBucketId = 123;
1772 const GLint kLocation = 2;
1773 const char* kName = "testing";
1774 EXPECT_CALL(*gl_,
1775 BindAttribLocation(kServiceProgramId, kLocation, StrEq(kName)))
1776 .Times(1);
1777 SetBucketAsCString(kBucketId, kName);
1778 BindAttribLocationBucket cmd;
1779 cmd.Init(client_program_id_, kLocation, kBucketId);
1780 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1783 TEST_P(GLES2DecoderTest, BindAttribLocationBucketInvalidArgs) {
1784 const uint32 kBucketId = 123;
1785 const GLint kLocation = 2;
1786 const char* kName = "testing";
1787 EXPECT_CALL(*gl_, BindAttribLocation(_, _, _)).Times(0);
1788 BindAttribLocationBucket cmd;
1789 // check bucket does not exist.
1790 cmd.Init(client_program_id_, kLocation, kBucketId);
1791 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1792 // check bucket is empty.
1793 SetBucketAsCString(kBucketId, NULL);
1794 cmd.Init(client_program_id_, kLocation, kBucketId);
1795 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1796 // Check bad program id
1797 SetBucketAsCString(kBucketId, kName);
1798 cmd.Init(kInvalidClientId, kLocation, kBucketId);
1799 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1800 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1803 TEST_P(GLES2DecoderWithShaderTest, GetAttribLocation) {
1804 const uint32 kBucketId = 123;
1805 const char* kNonExistentName = "foobar";
1806 typedef GetAttribLocation::Result Result;
1807 Result* result = GetSharedMemoryAs<Result*>();
1808 SetBucketAsCString(kBucketId, kAttrib2Name);
1809 *result = -1;
1810 GetAttribLocation cmd;
1811 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1812 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1813 EXPECT_EQ(kAttrib2Location, *result);
1814 SetBucketAsCString(kBucketId, kNonExistentName);
1815 *result = -1;
1816 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1817 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1818 EXPECT_EQ(-1, *result);
1821 TEST_P(GLES2DecoderWithShaderTest, GetAttribLocationInvalidArgs) {
1822 const uint32 kBucketId = 123;
1823 typedef GetAttribLocation::Result Result;
1824 Result* result = GetSharedMemoryAs<Result*>();
1825 *result = -1;
1826 GetAttribLocation cmd;
1827 // Check no bucket
1828 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1829 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1830 EXPECT_EQ(-1, *result);
1831 // Check bad program id.
1832 SetBucketAsCString(kBucketId, kAttrib2Name);
1833 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1834 *result = -1;
1835 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1836 EXPECT_EQ(-1, *result);
1837 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1838 // Check bad memory
1839 cmd.Init(client_program_id_,
1840 kBucketId,
1841 kInvalidSharedMemoryId,
1842 kSharedMemoryOffset);
1843 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1844 cmd.Init(client_program_id_,
1845 kBucketId,
1846 kSharedMemoryId,
1847 kInvalidSharedMemoryOffset);
1848 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1851 TEST_P(GLES2DecoderWithShaderTest, GetFragDataLocation) {
1852 const uint32 kBucketId = 123;
1853 const GLint kLocation = 10;
1854 const char* kName = "color";
1855 typedef GetFragDataLocation::Result Result;
1856 Result* result = GetSharedMemoryAs<Result*>();
1857 SetBucketAsCString(kBucketId, kName);
1858 *result = -1;
1859 GetFragDataLocation cmd;
1860 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1861 EXPECT_CALL(*gl_, GetFragDataLocation(kServiceProgramId, StrEq(kName)))
1862 .WillOnce(Return(kLocation))
1863 .RetiresOnSaturation();
1864 decoder_->set_unsafe_es3_apis_enabled(true);
1865 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1866 EXPECT_EQ(kLocation, *result);
1867 decoder_->set_unsafe_es3_apis_enabled(false);
1868 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1871 TEST_P(GLES2DecoderWithShaderTest, GetFragDataLocationInvalidArgs) {
1872 const uint32 kBucketId = 123;
1873 typedef GetFragDataLocation::Result Result;
1874 Result* result = GetSharedMemoryAs<Result*>();
1875 *result = -1;
1876 GetFragDataLocation cmd;
1877 decoder_->set_unsafe_es3_apis_enabled(true);
1878 // Check no bucket
1879 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1880 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1881 EXPECT_EQ(-1, *result);
1882 // Check bad program id.
1883 const char* kName = "color";
1884 SetBucketAsCString(kBucketId, kName);
1885 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1886 *result = -1;
1887 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1888 EXPECT_EQ(-1, *result);
1889 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1890 // Check bad memory
1891 cmd.Init(client_program_id_,
1892 kBucketId,
1893 kInvalidSharedMemoryId,
1894 kSharedMemoryOffset);
1895 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1896 cmd.Init(client_program_id_,
1897 kBucketId,
1898 kSharedMemoryId,
1899 kInvalidSharedMemoryOffset);
1900 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1903 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlockIndex) {
1904 const uint32 kBucketId = 123;
1905 const GLuint kIndex = 10;
1906 const char* kName = "color";
1907 typedef GetUniformBlockIndex::Result Result;
1908 Result* result = GetSharedMemoryAs<Result*>();
1909 SetBucketAsCString(kBucketId, kName);
1910 *result = GL_INVALID_INDEX;
1911 GetUniformBlockIndex cmd;
1912 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1913 EXPECT_CALL(*gl_, GetUniformBlockIndex(kServiceProgramId, StrEq(kName)))
1914 .WillOnce(Return(kIndex))
1915 .RetiresOnSaturation();
1916 decoder_->set_unsafe_es3_apis_enabled(true);
1917 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1918 EXPECT_EQ(kIndex, *result);
1919 decoder_->set_unsafe_es3_apis_enabled(false);
1920 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1923 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlockIndexInvalidArgs) {
1924 const uint32 kBucketId = 123;
1925 typedef GetUniformBlockIndex::Result Result;
1926 Result* result = GetSharedMemoryAs<Result*>();
1927 *result = GL_INVALID_INDEX;
1928 GetUniformBlockIndex cmd;
1929 decoder_->set_unsafe_es3_apis_enabled(true);
1930 // Check no bucket
1931 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1932 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1933 EXPECT_EQ(GL_INVALID_INDEX, *result);
1934 // Check bad program id.
1935 const char* kName = "color";
1936 SetBucketAsCString(kBucketId, kName);
1937 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1938 *result = GL_INVALID_INDEX;
1939 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1940 EXPECT_EQ(GL_INVALID_INDEX, *result);
1941 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1942 // Check bad memory
1943 cmd.Init(client_program_id_,
1944 kBucketId,
1945 kInvalidSharedMemoryId,
1946 kSharedMemoryOffset);
1947 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1948 cmd.Init(client_program_id_,
1949 kBucketId,
1950 kSharedMemoryId,
1951 kInvalidSharedMemoryOffset);
1952 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1955 TEST_P(GLES2DecoderWithShaderTest, GetUniformLocation) {
1956 const uint32 kBucketId = 123;
1957 const char* kNonExistentName = "foobar";
1958 typedef GetUniformLocation::Result Result;
1959 Result* result = GetSharedMemoryAs<Result*>();
1960 SetBucketAsCString(kBucketId, kUniform2Name);
1961 *result = -1;
1962 GetUniformLocation cmd;
1963 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1964 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1965 EXPECT_EQ(kUniform2FakeLocation, *result);
1966 SetBucketAsCString(kBucketId, kNonExistentName);
1967 *result = -1;
1968 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1969 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1970 EXPECT_EQ(-1, *result);
1973 TEST_P(GLES2DecoderWithShaderTest, GetUniformLocationInvalidArgs) {
1974 const uint32 kBucketId = 123;
1975 typedef GetUniformLocation::Result Result;
1976 Result* result = GetSharedMemoryAs<Result*>();
1977 *result = -1;
1978 GetUniformLocation cmd;
1979 // Check no bucket
1980 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1981 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1982 EXPECT_EQ(-1, *result);
1983 // Check bad program id.
1984 SetBucketAsCString(kBucketId, kUniform2Name);
1985 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1986 *result = -1;
1987 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1988 EXPECT_EQ(-1, *result);
1989 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1990 // Check bad memory
1991 cmd.Init(client_program_id_,
1992 kBucketId,
1993 kInvalidSharedMemoryId,
1994 kSharedMemoryOffset);
1995 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1996 cmd.Init(client_program_id_,
1997 kBucketId,
1998 kSharedMemoryId,
1999 kInvalidSharedMemoryOffset);
2000 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2003 TEST_P(GLES2DecoderWithShaderTest, UniformBlockBindingValidArgs) {
2004 EXPECT_CALL(*gl_, UniformBlockBinding(kServiceProgramId, 2, 3));
2005 SpecializedSetup<cmds::UniformBlockBinding, 0>(true);
2006 cmds::UniformBlockBinding cmd;
2007 cmd.Init(client_program_id_, 2, 3);
2008 decoder_->set_unsafe_es3_apis_enabled(true);
2009 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2010 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2011 decoder_->set_unsafe_es3_apis_enabled(false);
2012 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
2015 TEST_P(GLES2DecoderWithShaderTest, BindUniformLocationCHROMIUMBucket) {
2016 const uint32 kBucketId = 123;
2017 const GLint kLocation = 2;
2018 const char* kName = "testing";
2019 const char* kBadName1 = "gl_testing";
2020 const char* kBadName2 = "testing[1]";
2022 SetBucketAsCString(kBucketId, kName);
2023 BindUniformLocationCHROMIUMBucket cmd;
2024 cmd.Init(client_program_id_,
2025 kLocation,
2026 kBucketId);
2027 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2028 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2029 // check negative location
2030 SetBucketAsCString(kBucketId, kName);
2031 cmd.Init(client_program_id_, -1, kBucketId);
2032 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2033 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2034 // check highest location
2035 SetBucketAsCString(kBucketId, kName);
2036 GLint kMaxLocation =
2037 (kMaxFragmentUniformVectors + kMaxVertexUniformVectors) * 4 - 1;
2038 cmd.Init(client_program_id_,
2039 kMaxLocation,
2040 kBucketId);
2041 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2042 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2043 // check too high location
2044 SetBucketAsCString(kBucketId, kName);
2045 cmd.Init(client_program_id_,
2046 kMaxLocation + 1,
2047 kBucketId);
2048 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2049 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2050 // check bad name "gl_..."
2051 SetBucketAsCString(kBucketId, kBadName1);
2052 cmd.Init(client_program_id_,
2053 kLocation,
2054 kBucketId);
2055 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2056 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2057 // check bad name "name[1]" non zero
2058 SetBucketAsCString(kBucketId, kBadName2);
2059 cmd.Init(client_program_id_,
2060 kLocation,
2061 kBucketId);
2062 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2063 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2066 TEST_P(GLES2DecoderManualInitTest, ClearUniformsBeforeFirstProgramUse) {
2067 base::CommandLine command_line(0, NULL);
2068 command_line.AppendSwitchASCII(
2069 switches::kGpuDriverBugWorkarounds,
2070 base::IntToString(gpu::CLEAR_UNIFORMS_BEFORE_FIRST_PROGRAM_USE));
2071 InitState init;
2072 init.has_alpha = true;
2073 init.request_alpha = true;
2074 init.bind_generates_resource = true;
2075 InitDecoderWithCommandLine(init, &command_line);
2077 static AttribInfo attribs[] = {
2079 kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location,
2082 kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location,
2085 kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location,
2088 static UniformInfo uniforms[] = {
2089 {kUniform1Name, kUniform1Size, kUniform1Type, kUniform1FakeLocation,
2090 kUniform1RealLocation, kUniform1DesiredLocation},
2091 {kUniform2Name, kUniform2Size, kUniform2Type, kUniform2FakeLocation,
2092 kUniform2RealLocation, kUniform2DesiredLocation},
2093 {kUniform3Name, kUniform3Size, kUniform3Type, kUniform3FakeLocation,
2094 kUniform3RealLocation, kUniform3DesiredLocation},
2096 SetupShader(attribs,
2097 arraysize(attribs),
2098 uniforms,
2099 arraysize(uniforms),
2100 client_program_id_,
2101 kServiceProgramId,
2102 client_vertex_shader_id_,
2103 kServiceVertexShaderId,
2104 client_fragment_shader_id_,
2105 kServiceFragmentShaderId);
2106 TestHelper::SetupExpectationsForClearingUniforms(
2107 gl_.get(), uniforms, arraysize(uniforms));
2111 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
2112 .Times(1)
2113 .RetiresOnSaturation();
2114 cmds::UseProgram cmd;
2115 cmd.Init(client_program_id_);
2116 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2120 // TODO(gman): DeleteProgram
2122 // TODO(gman): UseProgram
2124 // TODO(gman): DeleteShader
2126 } // namespace gles2
2127 } // namespace gpu