Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_programs.cc
blob8d6753753dd95f60324886a29afbb70ab1dafbe4
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/cmd_buffer_engine.h"
12 #include "gpu/command_buffer/service/context_group.h"
13 #include "gpu/command_buffer/service/context_state.h"
14 #include "gpu/command_buffer/service/gl_surface_mock.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
16 #include "gpu/command_buffer/service/image_manager.h"
17 #include "gpu/command_buffer/service/mailbox_manager.h"
18 #include "gpu/command_buffer/service/mocks.h"
19 #include "gpu/command_buffer/service/program_manager.h"
20 #include "gpu/command_buffer/service/test_helper.h"
21 #include "gpu/config/gpu_switches.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/gl/gl_implementation.h"
24 #include "ui/gl/gl_mock.h"
25 #include "ui/gl/gl_surface_stub.h"
27 #if !defined(GL_DEPTH24_STENCIL8)
28 #define GL_DEPTH24_STENCIL8 0x88F0
29 #endif
31 using ::gfx::MockGLInterface;
32 using ::testing::_;
33 using ::testing::DoAll;
34 using ::testing::InSequence;
35 using ::testing::Invoke;
36 using ::testing::MatcherCast;
37 using ::testing::Mock;
38 using ::testing::Pointee;
39 using ::testing::Return;
40 using ::testing::SaveArg;
41 using ::testing::SetArrayArgument;
42 using ::testing::SetArgPointee;
43 using ::testing::StrEq;
44 using ::testing::StrictMock;
46 namespace gpu {
47 namespace gles2 {
49 using namespace cmds;
51 TEST_P(GLES2DecoderWithShaderTest, GetProgramInfoCHROMIUMValidArgs) {
52 const uint32 kBucketId = 123;
53 GetProgramInfoCHROMIUM cmd;
54 cmd.Init(client_program_id_, kBucketId);
55 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
56 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
57 EXPECT_GT(bucket->size(), 0u);
60 TEST_P(GLES2DecoderWithShaderTest, GetProgramInfoCHROMIUMInvalidArgs) {
61 const uint32 kBucketId = 123;
62 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
63 EXPECT_TRUE(bucket == NULL);
64 GetProgramInfoCHROMIUM cmd;
65 cmd.Init(kInvalidClientId, kBucketId);
66 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
67 EXPECT_EQ(GL_NO_ERROR, GetGLError());
68 bucket = decoder_->GetBucket(kBucketId);
69 ASSERT_TRUE(bucket != NULL);
70 EXPECT_EQ(sizeof(ProgramInfoHeader), bucket->size());
71 ProgramInfoHeader* info =
72 bucket->GetDataAs<ProgramInfoHeader*>(0, sizeof(ProgramInfoHeader));
73 ASSERT_TRUE(info != 0);
74 EXPECT_EQ(0u, info->link_status);
75 EXPECT_EQ(0u, info->num_attribs);
76 EXPECT_EQ(0u, info->num_uniforms);
79 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlocksCHROMIUMValidArgs) {
80 const uint32 kBucketId = 123;
81 GetUniformBlocksCHROMIUM cmd;
82 cmd.Init(client_program_id_, kBucketId);
83 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
84 .WillOnce(SetArgPointee<2>(GL_TRUE))
85 .RetiresOnSaturation();
86 EXPECT_CALL(*gl_,
87 GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORM_BLOCKS, _))
88 .WillOnce(SetArgPointee<2>(0))
89 .RetiresOnSaturation();
90 decoder_->set_unsafe_es3_apis_enabled(true);
91 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
92 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
93 EXPECT_EQ(sizeof(UniformBlocksHeader), bucket->size());
94 UniformBlocksHeader* header =
95 bucket->GetDataAs<UniformBlocksHeader*>(0, sizeof(UniformBlocksHeader));
96 EXPECT_TRUE(header != NULL);
97 EXPECT_EQ(0u, header->num_uniform_blocks);
98 decoder_->set_unsafe_es3_apis_enabled(false);
99 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
102 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlocksCHROMIUMInvalidArgs) {
103 const uint32 kBucketId = 123;
104 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
105 EXPECT_TRUE(bucket == NULL);
106 GetUniformBlocksCHROMIUM cmd;
107 cmd.Init(kInvalidClientId, kBucketId);
108 decoder_->set_unsafe_es3_apis_enabled(true);
109 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
110 EXPECT_EQ(GL_NO_ERROR, GetGLError());
111 bucket = decoder_->GetBucket(kBucketId);
112 ASSERT_TRUE(bucket != NULL);
113 EXPECT_EQ(sizeof(UniformBlocksHeader), bucket->size());
114 UniformBlocksHeader* header =
115 bucket->GetDataAs<UniformBlocksHeader*>(0, sizeof(UniformBlocksHeader));
116 ASSERT_TRUE(header != NULL);
117 EXPECT_EQ(0u, header->num_uniform_blocks);
120 TEST_P(GLES2DecoderWithShaderTest, GetUniformsES3CHROMIUMValidArgs) {
121 const uint32 kBucketId = 123;
122 GetUniformsES3CHROMIUM cmd;
123 cmd.Init(client_program_id_, kBucketId);
124 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
125 .WillOnce(SetArgPointee<2>(GL_TRUE))
126 .RetiresOnSaturation();
127 EXPECT_CALL(*gl_,
128 GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORMS, _))
129 .WillOnce(SetArgPointee<2>(0))
130 .RetiresOnSaturation();
131 decoder_->set_unsafe_es3_apis_enabled(true);
132 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
133 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
134 EXPECT_EQ(sizeof(UniformsES3Header), bucket->size());
135 UniformsES3Header* header =
136 bucket->GetDataAs<UniformsES3Header*>(0, sizeof(UniformsES3Header));
137 EXPECT_TRUE(header != NULL);
138 EXPECT_EQ(0u, header->num_uniforms);
139 decoder_->set_unsafe_es3_apis_enabled(false);
140 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
143 TEST_P(GLES2DecoderWithShaderTest, GetUniformsES3CHROMIUMInvalidArgs) {
144 const uint32 kBucketId = 123;
145 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
146 EXPECT_TRUE(bucket == NULL);
147 GetUniformsES3CHROMIUM cmd;
148 cmd.Init(kInvalidClientId, kBucketId);
149 decoder_->set_unsafe_es3_apis_enabled(true);
150 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
151 EXPECT_EQ(GL_NO_ERROR, GetGLError());
152 bucket = decoder_->GetBucket(kBucketId);
153 ASSERT_TRUE(bucket != NULL);
154 EXPECT_EQ(sizeof(UniformsES3Header), bucket->size());
155 UniformsES3Header* header =
156 bucket->GetDataAs<UniformsES3Header*>(0, sizeof(UniformsES3Header));
157 ASSERT_TRUE(header != NULL);
158 EXPECT_EQ(0u, header->num_uniforms);
161 TEST_P(GLES2DecoderWithShaderTest,
162 GetTransformFeedbackVaryingsCHROMIUMValidArgs) {
163 const uint32 kBucketId = 123;
164 GetTransformFeedbackVaryingsCHROMIUM cmd;
165 cmd.Init(client_program_id_, kBucketId);
166 EXPECT_CALL(*(gl_.get()),
167 GetProgramiv(kServiceProgramId,
168 GL_TRANSFORM_FEEDBACK_BUFFER_MODE,
170 .WillOnce(SetArgPointee<2>(GL_INTERLEAVED_ATTRIBS))
171 .RetiresOnSaturation();
172 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
173 .WillOnce(SetArgPointee<2>(GL_TRUE))
174 .RetiresOnSaturation();
175 EXPECT_CALL(*gl_,
176 GetProgramiv(
177 kServiceProgramId, GL_TRANSFORM_FEEDBACK_VARYINGS, _))
178 .WillOnce(SetArgPointee<2>(0))
179 .RetiresOnSaturation();
180 decoder_->set_unsafe_es3_apis_enabled(true);
181 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
182 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
183 EXPECT_EQ(sizeof(TransformFeedbackVaryingsHeader), bucket->size());
184 TransformFeedbackVaryingsHeader* header =
185 bucket->GetDataAs<TransformFeedbackVaryingsHeader*>(
186 0, sizeof(TransformFeedbackVaryingsHeader));
187 EXPECT_TRUE(header != NULL);
188 EXPECT_EQ(static_cast<uint32_t>(GL_INTERLEAVED_ATTRIBS),
189 header->transform_feedback_buffer_mode);
190 EXPECT_EQ(0u, header->num_transform_feedback_varyings);
191 decoder_->set_unsafe_es3_apis_enabled(false);
192 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
195 TEST_P(GLES2DecoderWithShaderTest,
196 GetTransformFeedbackVaryingsCHROMIUMInvalidArgs) {
197 const uint32 kBucketId = 123;
198 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
199 EXPECT_TRUE(bucket == NULL);
200 GetTransformFeedbackVaryingsCHROMIUM cmd;
201 cmd.Init(kInvalidClientId, kBucketId);
202 decoder_->set_unsafe_es3_apis_enabled(true);
203 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
204 EXPECT_EQ(GL_NO_ERROR, GetGLError());
205 bucket = decoder_->GetBucket(kBucketId);
206 ASSERT_TRUE(bucket != NULL);
207 EXPECT_EQ(sizeof(TransformFeedbackVaryingsHeader), bucket->size());
208 TransformFeedbackVaryingsHeader* header =
209 bucket->GetDataAs<TransformFeedbackVaryingsHeader*>(
210 0, sizeof(TransformFeedbackVaryingsHeader));
211 ASSERT_TRUE(header != NULL);
212 EXPECT_EQ(0u, header->num_transform_feedback_varyings);
215 TEST_P(GLES2DecoderWithShaderTest, GetUniformivSucceeds) {
216 GetUniformiv::Result* result =
217 static_cast<GetUniformiv::Result*>(shared_memory_address_);
218 result->size = 0;
219 GetUniformiv cmd;
220 cmd.Init(client_program_id_,
221 kUniform2FakeLocation,
222 kSharedMemoryId,
223 kSharedMemoryOffset);
224 EXPECT_CALL(*gl_, GetUniformiv(kServiceProgramId, kUniform2RealLocation, _))
225 .Times(1);
226 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
227 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
228 static_cast<uint32>(result->GetNumResults()));
231 TEST_P(GLES2DecoderWithShaderTest, GetUniformivArrayElementSucceeds) {
232 GetUniformiv::Result* result =
233 static_cast<GetUniformiv::Result*>(shared_memory_address_);
234 result->size = 0;
235 GetUniformiv cmd;
236 cmd.Init(client_program_id_,
237 kUniform2ElementFakeLocation,
238 kSharedMemoryId,
239 kSharedMemoryOffset);
240 EXPECT_CALL(*gl_,
241 GetUniformiv(kServiceProgramId, kUniform2ElementRealLocation, _))
242 .Times(1);
243 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
244 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
245 static_cast<uint32>(result->GetNumResults()));
248 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadProgramFails) {
249 GetUniformiv::Result* result =
250 static_cast<GetUniformiv::Result*>(shared_memory_address_);
251 result->size = 0;
252 GetUniformiv cmd;
253 // non-existant program
254 cmd.Init(kInvalidClientId,
255 kUniform2FakeLocation,
256 kSharedMemoryId,
257 kSharedMemoryOffset);
258 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
259 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
260 EXPECT_EQ(0U, result->size);
261 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
262 // Valid id that is not a program. The GL spec requires a different error for
263 // this case.
264 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
265 result->size = kInitialResult;
266 cmd.Init(client_shader_id_,
267 kUniform2FakeLocation,
268 kSharedMemoryId,
269 kSharedMemoryOffset);
270 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
271 EXPECT_EQ(0U, result->size);
272 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
273 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
274 // Unlinked program
275 EXPECT_CALL(*gl_, CreateProgram())
276 .Times(1)
277 .WillOnce(Return(kNewServiceId))
278 .RetiresOnSaturation();
279 CreateProgram cmd2;
280 cmd2.Init(kNewClientId);
281 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
282 result->size = kInitialResult;
283 cmd.Init(kNewClientId,
284 kUniform2FakeLocation,
285 kSharedMemoryId,
286 kSharedMemoryOffset);
287 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
288 EXPECT_EQ(0U, result->size);
289 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
292 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadLocationFails) {
293 GetUniformiv::Result* result =
294 static_cast<GetUniformiv::Result*>(shared_memory_address_);
295 result->size = 0;
296 GetUniformiv cmd;
297 // invalid location
298 cmd.Init(client_program_id_,
299 kInvalidUniformLocation,
300 kSharedMemoryId,
301 kSharedMemoryOffset);
302 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
303 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
304 EXPECT_EQ(0U, result->size);
305 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
308 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadSharedMemoryFails) {
309 GetUniformiv cmd;
310 cmd.Init(client_program_id_,
311 kUniform2FakeLocation,
312 kInvalidSharedMemoryId,
313 kSharedMemoryOffset);
314 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
315 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
316 cmd.Init(client_program_id_,
317 kUniform2FakeLocation,
318 kSharedMemoryId,
319 kInvalidSharedMemoryOffset);
320 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
323 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivSucceeds) {
324 GetUniformuiv::Result* result =
325 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
326 result->size = 0;
327 GetUniformuiv cmd;
328 cmd.Init(client_program_id_,
329 kUniform2FakeLocation,
330 kSharedMemoryId,
331 kSharedMemoryOffset);
332 EXPECT_CALL(*gl_, GetUniformuiv(kServiceProgramId, kUniform2RealLocation, _))
333 .Times(1);
334 decoder_->set_unsafe_es3_apis_enabled(true);
335 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
336 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
337 static_cast<uint32>(result->GetNumResults()));
338 decoder_->set_unsafe_es3_apis_enabled(false);
339 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
342 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivArrayElementSucceeds) {
343 GetUniformuiv::Result* result =
344 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
345 result->size = 0;
346 GetUniformuiv cmd;
347 cmd.Init(client_program_id_,
348 kUniform2ElementFakeLocation,
349 kSharedMemoryId,
350 kSharedMemoryOffset);
351 EXPECT_CALL(*gl_,
352 GetUniformuiv(kServiceProgramId, kUniform2ElementRealLocation, _))
353 .Times(1);
354 decoder_->set_unsafe_es3_apis_enabled(true);
355 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
356 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
357 static_cast<uint32>(result->GetNumResults()));
360 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadProgramFails) {
361 GetUniformuiv::Result* result =
362 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
363 result->size = 0;
364 GetUniformuiv cmd;
365 // non-existant program
366 cmd.Init(kInvalidClientId,
367 kUniform2FakeLocation,
368 kSharedMemoryId,
369 kSharedMemoryOffset);
370 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
371 decoder_->set_unsafe_es3_apis_enabled(true);
372 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
373 EXPECT_EQ(0U, result->size);
374 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
375 // Valid id that is not a program. The GL spec requires a different error for
376 // this case.
377 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
378 result->size = kInitialResult;
379 cmd.Init(client_shader_id_,
380 kUniform2FakeLocation,
381 kSharedMemoryId,
382 kSharedMemoryOffset);
383 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
384 EXPECT_EQ(0U, result->size);
385 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
386 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
387 // Unlinked program
388 EXPECT_CALL(*gl_, CreateProgram())
389 .Times(1)
390 .WillOnce(Return(kNewServiceId))
391 .RetiresOnSaturation();
392 CreateProgram cmd2;
393 cmd2.Init(kNewClientId);
394 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
395 result->size = kInitialResult;
396 cmd.Init(kNewClientId,
397 kUniform2FakeLocation,
398 kSharedMemoryId,
399 kSharedMemoryOffset);
400 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
401 EXPECT_EQ(0U, result->size);
402 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
405 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadLocationFails) {
406 GetUniformuiv::Result* result =
407 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
408 result->size = 0;
409 GetUniformuiv cmd;
410 // invalid location
411 cmd.Init(client_program_id_,
412 kInvalidUniformLocation,
413 kSharedMemoryId,
414 kSharedMemoryOffset);
415 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
416 decoder_->set_unsafe_es3_apis_enabled(true);
417 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
418 EXPECT_EQ(0U, result->size);
419 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
422 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadSharedMemoryFails) {
423 GetUniformuiv cmd;
424 cmd.Init(client_program_id_,
425 kUniform2FakeLocation,
426 kInvalidSharedMemoryId,
427 kSharedMemoryOffset);
428 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
429 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
430 decoder_->set_unsafe_es3_apis_enabled(true);
431 cmd.Init(client_program_id_,
432 kUniform2FakeLocation,
433 kSharedMemoryId,
434 kInvalidSharedMemoryOffset);
435 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
438 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvSucceeds) {
439 GetUniformfv::Result* result =
440 static_cast<GetUniformfv::Result*>(shared_memory_address_);
441 result->size = 0;
442 GetUniformfv cmd;
443 cmd.Init(client_program_id_,
444 kUniform2FakeLocation,
445 kSharedMemoryId,
446 kSharedMemoryOffset);
447 EXPECT_CALL(*gl_, GetUniformfv(kServiceProgramId, kUniform2RealLocation, _))
448 .Times(1);
449 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
450 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
451 static_cast<uint32>(result->GetNumResults()));
454 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvArrayElementSucceeds) {
455 GetUniformfv::Result* result =
456 static_cast<GetUniformfv::Result*>(shared_memory_address_);
457 result->size = 0;
458 GetUniformfv cmd;
459 cmd.Init(client_program_id_,
460 kUniform2ElementFakeLocation,
461 kSharedMemoryId,
462 kSharedMemoryOffset);
463 EXPECT_CALL(*gl_,
464 GetUniformfv(kServiceProgramId, kUniform2ElementRealLocation, _))
465 .Times(1);
466 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
467 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
468 static_cast<uint32>(result->GetNumResults()));
471 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadProgramFails) {
472 GetUniformfv::Result* result =
473 static_cast<GetUniformfv::Result*>(shared_memory_address_);
474 result->size = 0;
475 GetUniformfv cmd;
476 // non-existant program
477 cmd.Init(kInvalidClientId,
478 kUniform2FakeLocation,
479 kSharedMemoryId,
480 kSharedMemoryOffset);
481 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
482 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
483 EXPECT_EQ(0U, result->size);
484 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
485 // Valid id that is not a program. The GL spec requires a different error for
486 // this case.
487 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
488 result->size = kInitialResult;
489 cmd.Init(client_shader_id_,
490 kUniform2FakeLocation,
491 kSharedMemoryId,
492 kSharedMemoryOffset);
493 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
494 EXPECT_EQ(0U, result->size);
495 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
496 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
497 // Unlinked program
498 EXPECT_CALL(*gl_, CreateProgram())
499 .Times(1)
500 .WillOnce(Return(kNewServiceId))
501 .RetiresOnSaturation();
502 CreateProgram cmd2;
503 cmd2.Init(kNewClientId);
504 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
505 result->size = kInitialResult;
506 cmd.Init(kNewClientId,
507 kUniform2FakeLocation,
508 kSharedMemoryId,
509 kSharedMemoryOffset);
510 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
511 EXPECT_EQ(0U, result->size);
512 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
515 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadLocationFails) {
516 GetUniformfv::Result* result =
517 static_cast<GetUniformfv::Result*>(shared_memory_address_);
518 result->size = 0;
519 GetUniformfv cmd;
520 // invalid location
521 cmd.Init(client_program_id_,
522 kInvalidUniformLocation,
523 kSharedMemoryId,
524 kSharedMemoryOffset);
525 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
526 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
527 EXPECT_EQ(0U, result->size);
528 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
531 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadSharedMemoryFails) {
532 GetUniformfv cmd;
533 cmd.Init(client_program_id_,
534 kUniform2FakeLocation,
535 kInvalidSharedMemoryId,
536 kSharedMemoryOffset);
537 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
538 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
539 cmd.Init(client_program_id_,
540 kUniform2FakeLocation,
541 kSharedMemoryId,
542 kInvalidSharedMemoryOffset);
543 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
546 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersSucceeds) {
547 GetAttachedShaders cmd;
548 typedef GetAttachedShaders::Result Result;
549 Result* result = static_cast<Result*>(shared_memory_address_);
550 result->size = 0;
551 EXPECT_CALL(*gl_, GetAttachedShaders(kServiceProgramId, 1, _, _)).WillOnce(
552 DoAll(SetArgPointee<2>(1), SetArgPointee<3>(kServiceShaderId)));
553 cmd.Init(client_program_id_,
554 shared_memory_id_,
555 shared_memory_offset_,
556 Result::ComputeSize(1));
557 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
558 EXPECT_EQ(1, result->GetNumResults());
559 EXPECT_EQ(client_shader_id_, result->GetData()[0]);
560 EXPECT_EQ(GL_NO_ERROR, GetGLError());
563 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersResultNotInitFail) {
564 GetAttachedShaders cmd;
565 typedef GetAttachedShaders::Result Result;
566 Result* result = static_cast<Result*>(shared_memory_address_);
567 result->size = 1;
568 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
569 cmd.Init(client_program_id_,
570 shared_memory_id_,
571 shared_memory_offset_,
572 Result::ComputeSize(1));
573 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
576 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersBadProgramFails) {
577 GetAttachedShaders cmd;
578 typedef GetAttachedShaders::Result Result;
579 Result* result = static_cast<Result*>(shared_memory_address_);
580 result->size = 0;
581 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
582 cmd.Init(kInvalidClientId,
583 shared_memory_id_,
584 shared_memory_offset_,
585 Result::ComputeSize(1));
586 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
587 EXPECT_EQ(0U, result->size);
588 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
591 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersBadSharedMemoryFails) {
592 GetAttachedShaders cmd;
593 typedef GetAttachedShaders::Result Result;
594 cmd.Init(client_program_id_,
595 kInvalidSharedMemoryId,
596 shared_memory_offset_,
597 Result::ComputeSize(1));
598 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
599 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
600 cmd.Init(client_program_id_,
601 shared_memory_id_,
602 kInvalidSharedMemoryOffset,
603 Result::ComputeSize(1));
604 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
607 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatSucceeds) {
608 ScopedGLImplementationSetter gl_impl(::gfx::kGLImplementationEGLGLES2);
609 GetShaderPrecisionFormat cmd;
610 typedef GetShaderPrecisionFormat::Result Result;
611 Result* result = static_cast<Result*>(shared_memory_address_);
612 result->success = 0;
613 const GLint range[2] = {62, 62};
614 const GLint precision = 16;
615 EXPECT_CALL(*gl_, GetShaderPrecisionFormat(_, _, _, _))
616 .WillOnce(DoAll(SetArrayArgument<2>(range, range + 2),
617 SetArgPointee<3>(precision)))
618 .RetiresOnSaturation();
619 cmd.Init(GL_VERTEX_SHADER,
620 GL_HIGH_FLOAT,
621 shared_memory_id_,
622 shared_memory_offset_);
623 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
624 EXPECT_NE(0, result->success);
625 EXPECT_EQ(range[0], result->min_range);
626 EXPECT_EQ(range[1], result->max_range);
627 EXPECT_EQ(precision, result->precision);
628 EXPECT_EQ(GL_NO_ERROR, GetGLError());
631 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatResultNotInitFails) {
632 GetShaderPrecisionFormat cmd;
633 typedef GetShaderPrecisionFormat::Result Result;
634 Result* result = static_cast<Result*>(shared_memory_address_);
635 result->success = 1;
636 // NOTE: GL might not be called. There is no Desktop OpenGL equivalent
637 cmd.Init(GL_VERTEX_SHADER,
638 GL_HIGH_FLOAT,
639 shared_memory_id_,
640 shared_memory_offset_);
641 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
644 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatBadArgsFails) {
645 typedef GetShaderPrecisionFormat::Result Result;
646 Result* result = static_cast<Result*>(shared_memory_address_);
647 result->success = 0;
648 GetShaderPrecisionFormat cmd;
649 cmd.Init(
650 GL_TEXTURE_2D, GL_HIGH_FLOAT, shared_memory_id_, shared_memory_offset_);
651 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
652 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
653 result->success = 0;
654 cmd.Init(GL_VERTEX_SHADER,
655 GL_TEXTURE_2D,
656 shared_memory_id_,
657 shared_memory_offset_);
658 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
659 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
662 TEST_P(GLES2DecoderWithShaderTest,
663 GetShaderPrecisionFormatBadSharedMemoryFails) {
664 GetShaderPrecisionFormat cmd;
665 cmd.Init(GL_VERTEX_SHADER,
666 GL_HIGH_FLOAT,
667 kInvalidSharedMemoryId,
668 shared_memory_offset_);
669 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
670 cmd.Init(GL_VERTEX_SHADER,
671 GL_TEXTURE_2D,
672 shared_memory_id_,
673 kInvalidSharedMemoryOffset);
674 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
677 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformSucceeds) {
678 const GLuint kUniformIndex = 1;
679 const uint32 kBucketId = 123;
680 GetActiveUniform cmd;
681 typedef GetActiveUniform::Result Result;
682 Result* result = static_cast<Result*>(shared_memory_address_);
683 result->success = 0;
684 cmd.Init(client_program_id_,
685 kUniformIndex,
686 kBucketId,
687 shared_memory_id_,
688 shared_memory_offset_);
689 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
690 EXPECT_NE(0, result->success);
691 EXPECT_EQ(kUniform2Size, result->size);
692 EXPECT_EQ(kUniform2Type, result->type);
693 EXPECT_EQ(GL_NO_ERROR, GetGLError());
694 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
695 ASSERT_TRUE(bucket != NULL);
696 EXPECT_EQ(
698 memcmp(
699 bucket->GetData(0, bucket->size()), kUniform2Name, bucket->size()));
702 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformResultNotInitFails) {
703 const GLuint kUniformIndex = 1;
704 const uint32 kBucketId = 123;
705 GetActiveUniform cmd;
706 typedef GetActiveUniform::Result Result;
707 Result* result = static_cast<Result*>(shared_memory_address_);
708 result->success = 1;
709 cmd.Init(client_program_id_,
710 kUniformIndex,
711 kBucketId,
712 shared_memory_id_,
713 shared_memory_offset_);
714 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
717 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadProgramFails) {
718 const GLuint kUniformIndex = 1;
719 const uint32 kBucketId = 123;
720 GetActiveUniform cmd;
721 typedef GetActiveUniform::Result Result;
722 Result* result = static_cast<Result*>(shared_memory_address_);
723 result->success = 0;
724 cmd.Init(kInvalidClientId,
725 kUniformIndex,
726 kBucketId,
727 shared_memory_id_,
728 shared_memory_offset_);
729 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
730 EXPECT_EQ(0, result->success);
731 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
732 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
733 result->success = 0;
734 cmd.Init(client_shader_id_,
735 kUniformIndex,
736 kBucketId,
737 shared_memory_id_,
738 shared_memory_offset_);
739 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
740 EXPECT_EQ(0, result->success);
741 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
742 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
745 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadIndexFails) {
746 const uint32 kBucketId = 123;
747 GetActiveUniform cmd;
748 typedef GetActiveUniform::Result Result;
749 Result* result = static_cast<Result*>(shared_memory_address_);
750 result->success = 0;
751 cmd.Init(client_program_id_,
752 kBadUniformIndex,
753 kBucketId,
754 shared_memory_id_,
755 shared_memory_offset_);
756 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
757 EXPECT_EQ(0, result->success);
758 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
761 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadSharedMemoryFails) {
762 const GLuint kUniformIndex = 1;
763 const uint32 kBucketId = 123;
764 GetActiveUniform cmd;
765 cmd.Init(client_program_id_,
766 kUniformIndex,
767 kBucketId,
768 kInvalidSharedMemoryId,
769 shared_memory_offset_);
770 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
771 cmd.Init(client_program_id_,
772 kUniformIndex,
773 kBucketId,
774 shared_memory_id_,
775 kInvalidSharedMemoryOffset);
776 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
779 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameSucceeds) {
780 const uint32 kBucketId = 123;
781 GetActiveUniformBlockName cmd;
782 typedef GetActiveUniformBlockName::Result Result;
783 Result* result = static_cast<Result*>(shared_memory_address_);
784 *result = 0;
785 cmd.Init(client_program_id_,
787 kBucketId,
788 shared_memory_id_,
789 shared_memory_offset_);
790 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
791 .WillOnce(SetArgPointee<2>(GL_TRUE))
792 .RetiresOnSaturation();
793 const char kName[] = "HolyCow";
794 const GLsizei kMaxLength = strlen(kName) + 1;
795 EXPECT_CALL(*gl_,
796 GetProgramiv(kServiceProgramId,
797 GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, _))
798 .WillOnce(SetArgPointee<2>(kMaxLength))
799 .RetiresOnSaturation();
800 EXPECT_CALL(*gl_,
801 GetActiveUniformBlockName(kServiceProgramId, 0, _, _, _))
802 .WillOnce(DoAll(SetArgPointee<3>(strlen(kName)),
803 SetArrayArgument<4>(kName, kName + strlen(kName) + 1)))
804 .RetiresOnSaturation();
805 decoder_->set_unsafe_es3_apis_enabled(true);
806 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
807 EXPECT_NE(0, *result);
808 EXPECT_EQ(GL_NO_ERROR, GetGLError());
809 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
810 ASSERT_TRUE(bucket != NULL);
811 EXPECT_EQ(0,
812 memcmp(bucket->GetData(0, bucket->size()), kName, bucket->size()));
813 decoder_->set_unsafe_es3_apis_enabled(false);
814 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
817 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameUnlinkedProgram) {
818 const uint32 kBucketId = 123;
819 GetActiveUniformBlockName cmd;
820 typedef GetActiveUniformBlockName::Result Result;
821 Result* result = static_cast<Result*>(shared_memory_address_);
822 *result = 0;
823 cmd.Init(client_program_id_,
825 kBucketId,
826 shared_memory_id_,
827 shared_memory_offset_);
828 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
829 .WillOnce(SetArgPointee<2>(GL_FALSE))
830 .RetiresOnSaturation();
831 decoder_->set_unsafe_es3_apis_enabled(true);
832 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
833 EXPECT_EQ(0, *result);
834 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
837 TEST_P(GLES2DecoderWithShaderTest,
838 GetActiveUniformBlockNameResultNotInitFails) {
839 const uint32 kBucketId = 123;
840 GetActiveUniformBlockName cmd;
841 typedef GetActiveUniformBlockName::Result Result;
842 Result* result = static_cast<Result*>(shared_memory_address_);
843 *result = 1;
844 cmd.Init(client_program_id_,
846 kBucketId,
847 shared_memory_id_,
848 shared_memory_offset_);
849 decoder_->set_unsafe_es3_apis_enabled(true);
850 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
853 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameBadProgramFails) {
854 const uint32 kBucketId = 123;
855 GetActiveUniformBlockName cmd;
856 typedef GetActiveUniformBlockName::Result Result;
857 Result* result = static_cast<Result*>(shared_memory_address_);
858 *result = 0;
859 cmd.Init(kInvalidClientId,
861 kBucketId,
862 shared_memory_id_,
863 shared_memory_offset_);
864 decoder_->set_unsafe_es3_apis_enabled(true);
865 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
866 EXPECT_EQ(0, *result);
867 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
870 TEST_P(GLES2DecoderWithShaderTest,
871 GetActiveUniformBlockNameBadSharedMemoryFails) {
872 const uint32 kBucketId = 123;
873 GetActiveUniformBlockName cmd;
874 decoder_->set_unsafe_es3_apis_enabled(true);
875 cmd.Init(client_program_id_,
877 kBucketId,
878 kInvalidSharedMemoryId,
879 shared_memory_offset_);
880 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
881 cmd.Init(client_program_id_,
883 kBucketId,
884 shared_memory_id_,
885 kInvalidSharedMemoryOffset);
886 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
889 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivSucceeds) {
890 GetActiveUniformBlockiv cmd;
891 typedef GetActiveUniformBlockiv::Result Result;
892 Result* result = static_cast<Result*>(shared_memory_address_);
893 GLenum kPname[] {
894 GL_UNIFORM_BLOCK_BINDING,
895 GL_UNIFORM_BLOCK_DATA_SIZE,
896 GL_UNIFORM_BLOCK_NAME_LENGTH,
897 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS,
898 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES,
899 GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER,
900 GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER,
902 for (size_t ii = 0; ii < arraysize(kPname); ++ii) {
903 result->SetNumResults(0);
904 cmd.Init(client_program_id_,
906 kPname[ii],
907 shared_memory_id_,
908 shared_memory_offset_);
909 EXPECT_CALL(*gl_, GetError())
910 .WillOnce(Return(GL_NO_ERROR))
911 .WillOnce(Return(GL_NO_ERROR))
912 .RetiresOnSaturation();
913 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
914 .WillOnce(SetArgPointee<2>(GL_TRUE))
915 .RetiresOnSaturation();
916 if (kPname[ii] == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) {
917 EXPECT_CALL(*gl_, GetError())
918 .WillOnce(Return(GL_NO_ERROR))
919 .RetiresOnSaturation();
920 EXPECT_CALL(*gl_,
921 GetActiveUniformBlockiv(kServiceProgramId, 0,
922 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, _))
923 .WillOnce(SetArgPointee<3>(1))
924 .RetiresOnSaturation();
926 EXPECT_CALL(*gl_,
927 GetActiveUniformBlockiv(
928 kServiceProgramId, 0, kPname[ii], _))
929 .WillOnce(SetArgPointee<3>(1976))
930 .RetiresOnSaturation();
931 decoder_->set_unsafe_es3_apis_enabled(true);
932 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
933 EXPECT_EQ(1, result->GetNumResults());
934 EXPECT_EQ(GL_NO_ERROR, GetGLError());
935 EXPECT_EQ(1976, result->GetData()[0]);
936 decoder_->set_unsafe_es3_apis_enabled(false);
937 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
941 TEST_P(GLES2DecoderWithShaderTest,
942 GetActiveUniformBlockivSucceedsZeroUniforms) {
943 GetActiveUniformBlockiv cmd;
944 typedef GetActiveUniformBlockiv::Result Result;
945 Result* result = static_cast<Result*>(shared_memory_address_);
946 result->SetNumResults(0);
947 cmd.Init(client_program_id_,
949 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES,
950 shared_memory_id_,
951 shared_memory_offset_);
952 EXPECT_CALL(*gl_, GetError())
953 .WillOnce(Return(GL_NO_ERROR))
954 .WillOnce(Return(GL_NO_ERROR))
955 .WillOnce(Return(GL_NO_ERROR))
956 .RetiresOnSaturation();
957 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
958 .WillOnce(SetArgPointee<2>(GL_TRUE))
959 .RetiresOnSaturation();
960 EXPECT_CALL(*gl_,
961 GetActiveUniformBlockiv(
962 kServiceProgramId, 0, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, _))
963 .WillOnce(SetArgPointee<3>(0))
964 .RetiresOnSaturation();
965 EXPECT_CALL(*gl_,
966 GetActiveUniformBlockiv(kServiceProgramId, 0,
967 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, _))
968 .Times(1)
969 .RetiresOnSaturation();
970 decoder_->set_unsafe_es3_apis_enabled(true);
971 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
972 EXPECT_EQ(0, result->GetNumResults());
973 EXPECT_EQ(GL_NO_ERROR, GetGLError());
976 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivUnlinkedProgram) {
977 GetActiveUniformBlockiv cmd;
978 typedef GetActiveUniformBlockiv::Result Result;
979 Result* result = static_cast<Result*>(shared_memory_address_);
980 result->SetNumResults(0);
981 cmd.Init(client_program_id_,
983 GL_UNIFORM_BLOCK_BINDING,
984 shared_memory_id_,
985 shared_memory_offset_);
986 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
987 .WillOnce(SetArgPointee<2>(GL_FALSE))
988 .RetiresOnSaturation();
989 decoder_->set_unsafe_es3_apis_enabled(true);
990 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
991 EXPECT_EQ(0, result->GetNumResults());
992 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
995 TEST_P(GLES2DecoderWithShaderTest,
996 GetActiveUniformBlockivResultNotInitFails) {
997 GetActiveUniformBlockiv cmd;
998 typedef GetActiveUniformBlockiv::Result Result;
999 Result* result = static_cast<Result*>(shared_memory_address_);
1000 result->SetNumResults(1); // Should be initialized to 0.
1001 cmd.Init(client_program_id_,
1003 GL_UNIFORM_BLOCK_BINDING,
1004 shared_memory_id_,
1005 shared_memory_offset_);
1006 decoder_->set_unsafe_es3_apis_enabled(true);
1007 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1008 .WillOnce(SetArgPointee<2>(GL_TRUE))
1009 .RetiresOnSaturation();
1010 EXPECT_CALL(*gl_, GetError())
1011 .WillOnce(Return(GL_NO_ERROR))
1012 .RetiresOnSaturation();
1013 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1016 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivBadProgramFails) {
1017 GetActiveUniformBlockiv cmd;
1018 typedef GetActiveUniformBlockiv::Result Result;
1019 Result* result = static_cast<Result*>(shared_memory_address_);
1020 result->SetNumResults(0);
1021 cmd.Init(kInvalidClientId,
1023 GL_UNIFORM_BLOCK_BINDING,
1024 shared_memory_id_,
1025 shared_memory_offset_);
1026 decoder_->set_unsafe_es3_apis_enabled(true);
1027 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1028 EXPECT_EQ(0, result->GetNumResults());
1029 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1032 TEST_P(GLES2DecoderWithShaderTest,
1033 GetActiveUniformBlockivBadSharedMemoryFails) {
1034 GetActiveUniformBlockiv cmd;
1035 decoder_->set_unsafe_es3_apis_enabled(true);
1036 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1037 .WillOnce(SetArgPointee<2>(GL_TRUE))
1038 .WillOnce(SetArgPointee<2>(GL_TRUE))
1039 .RetiresOnSaturation();
1040 EXPECT_CALL(*gl_, GetError())
1041 .WillOnce(Return(GL_NO_ERROR))
1042 .WillOnce(Return(GL_NO_ERROR))
1043 .RetiresOnSaturation();
1044 cmd.Init(client_program_id_,
1046 GL_UNIFORM_BLOCK_BINDING,
1047 kInvalidSharedMemoryId,
1048 shared_memory_offset_);
1049 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1050 cmd.Init(client_program_id_,
1052 GL_UNIFORM_BLOCK_BINDING,
1053 shared_memory_id_,
1054 kInvalidSharedMemoryOffset);
1055 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1058 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribSucceeds) {
1059 const GLuint kAttribIndex = 1;
1060 const uint32 kBucketId = 123;
1061 GetActiveAttrib cmd;
1062 typedef GetActiveAttrib::Result Result;
1063 Result* result = static_cast<Result*>(shared_memory_address_);
1064 result->success = 0;
1065 cmd.Init(client_program_id_,
1066 kAttribIndex,
1067 kBucketId,
1068 shared_memory_id_,
1069 shared_memory_offset_);
1070 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1071 EXPECT_NE(0, result->success);
1072 EXPECT_EQ(kAttrib2Size, result->size);
1073 EXPECT_EQ(kAttrib2Type, result->type);
1074 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1075 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1076 ASSERT_TRUE(bucket != NULL);
1077 EXPECT_EQ(
1079 memcmp(bucket->GetData(0, bucket->size()), kAttrib2Name, bucket->size()));
1082 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribResultNotInitFails) {
1083 const GLuint kAttribIndex = 1;
1084 const uint32 kBucketId = 123;
1085 GetActiveAttrib cmd;
1086 typedef GetActiveAttrib::Result Result;
1087 Result* result = static_cast<Result*>(shared_memory_address_);
1088 result->success = 1;
1089 cmd.Init(client_program_id_,
1090 kAttribIndex,
1091 kBucketId,
1092 shared_memory_id_,
1093 shared_memory_offset_);
1094 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1097 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadProgramFails) {
1098 const GLuint kAttribIndex = 1;
1099 const uint32 kBucketId = 123;
1100 GetActiveAttrib cmd;
1101 typedef GetActiveAttrib::Result Result;
1102 Result* result = static_cast<Result*>(shared_memory_address_);
1103 result->success = 0;
1104 cmd.Init(kInvalidClientId,
1105 kAttribIndex,
1106 kBucketId,
1107 shared_memory_id_,
1108 shared_memory_offset_);
1109 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1110 EXPECT_EQ(0, result->success);
1111 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1112 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1113 result->success = 0;
1114 cmd.Init(client_shader_id_,
1115 kAttribIndex,
1116 kBucketId,
1117 shared_memory_id_,
1118 shared_memory_offset_);
1119 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1120 EXPECT_EQ(0, result->success);
1121 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1122 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1125 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadIndexFails) {
1126 const uint32 kBucketId = 123;
1127 GetActiveAttrib cmd;
1128 typedef GetActiveAttrib::Result Result;
1129 Result* result = static_cast<Result*>(shared_memory_address_);
1130 result->success = 0;
1131 cmd.Init(client_program_id_,
1132 kBadAttribIndex,
1133 kBucketId,
1134 shared_memory_id_,
1135 shared_memory_offset_);
1136 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1137 EXPECT_EQ(0, result->success);
1138 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1141 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadSharedMemoryFails) {
1142 const GLuint kAttribIndex = 1;
1143 const uint32 kBucketId = 123;
1144 GetActiveAttrib cmd;
1145 cmd.Init(client_program_id_,
1146 kAttribIndex,
1147 kBucketId,
1148 kInvalidSharedMemoryId,
1149 shared_memory_offset_);
1150 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1151 cmd.Init(client_program_id_,
1152 kAttribIndex,
1153 kBucketId,
1154 shared_memory_id_,
1155 kInvalidSharedMemoryOffset);
1156 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1159 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesSucceeds) {
1160 const uint32 kBucketId = 123;
1161 const char kName0[] = "Cow";
1162 const char kName1[] = "Chicken";
1163 const char* kNames[] = { kName0, kName1 };
1164 const size_t kCount = arraysize(kNames);
1165 const char kValidStrEnd = 0;
1166 const GLuint kIndices[] = { 1, 2 };
1167 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1168 GetUniformIndices::Result* result =
1169 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1170 GetUniformIndices cmd;
1171 cmd.Init(client_program_id_,
1172 kBucketId,
1173 kSharedMemoryId,
1174 kSharedMemoryOffset);
1175 EXPECT_CALL(*gl_, GetUniformIndices(kServiceProgramId, kCount, _, _))
1176 .WillOnce(SetArrayArgument<3>(kIndices, kIndices + kCount))
1177 .RetiresOnSaturation();
1178 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1179 .WillOnce(SetArgPointee<2>(GL_TRUE))
1180 .RetiresOnSaturation();
1181 EXPECT_CALL(*gl_, GetError())
1182 .WillOnce(Return(GL_NO_ERROR))
1183 .WillOnce(Return(GL_NO_ERROR))
1184 .RetiresOnSaturation();
1185 decoder_->set_unsafe_es3_apis_enabled(true);
1186 result->size = 0;
1187 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1188 EXPECT_EQ(kCount, static_cast<size_t>(result->GetNumResults()));
1189 for (size_t ii = 0; ii < kCount; ++ii) {
1190 EXPECT_EQ(kIndices[ii], result->GetData()[ii]);
1192 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1193 decoder_->set_unsafe_es3_apis_enabled(false);
1194 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1197 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadProgramFails) {
1198 const uint32 kBucketId = 123;
1199 const char kName0[] = "Cow";
1200 const char kName1[] = "Chicken";
1201 const char* kNames[] = { kName0, kName1 };
1202 const size_t kCount = arraysize(kNames);
1203 const char kValidStrEnd = 0;
1204 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1205 GetUniformIndices::Result* result =
1206 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1207 decoder_->set_unsafe_es3_apis_enabled(true);
1208 GetUniformIndices cmd;
1209 // None-existant program
1210 cmd.Init(kInvalidClientId,
1211 kBucketId,
1212 kSharedMemoryId,
1213 kSharedMemoryOffset);
1214 result->size = 0;
1215 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1216 EXPECT_EQ(0, result->GetNumResults());
1217 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1218 // Unlinked program.
1219 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1220 .WillOnce(SetArgPointee<2>(GL_FALSE))
1221 .RetiresOnSaturation();
1222 cmd.Init(client_program_id_,
1223 kBucketId,
1224 kSharedMemoryId,
1225 kSharedMemoryOffset);
1226 result->size = 0;
1227 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1228 EXPECT_EQ(0, result->GetNumResults());
1229 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1232 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadParamsFails) {
1233 const uint32 kBucketId = 123;
1234 const char kName0[] = "Cow";
1235 const char kName1[] = "Chicken";
1236 const char* kNames[] = { kName0, kName1 };
1237 const size_t kCount = arraysize(kNames);
1238 const char kValidStrEnd = 0;
1239 const GLuint kIndices[] = { 1, 2 };
1240 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1241 GetUniformIndices::Result* result =
1242 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1243 GetUniformIndices cmd;
1244 cmd.Init(client_program_id_,
1245 kBucketId,
1246 kSharedMemoryId,
1247 kSharedMemoryOffset);
1248 EXPECT_CALL(*gl_, GetUniformIndices(kServiceProgramId, kCount, _, _))
1249 .WillOnce(SetArrayArgument<3>(kIndices, kIndices + kCount))
1250 .RetiresOnSaturation();
1251 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1252 .WillOnce(SetArgPointee<2>(GL_TRUE))
1253 .RetiresOnSaturation();
1254 EXPECT_CALL(*gl_, GetError())
1255 .WillOnce(Return(GL_NO_ERROR))
1256 .WillOnce(Return(GL_INVALID_VALUE))
1257 .RetiresOnSaturation();
1258 decoder_->set_unsafe_es3_apis_enabled(true);
1259 result->size = 0;
1260 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1261 EXPECT_EQ(0, result->GetNumResults());
1262 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1265 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesResultNotInitFails) {
1266 const uint32 kBucketId = 123;
1267 const char kName0[] = "Cow";
1268 const char kName1[] = "Chicken";
1269 const char* kNames[] = { kName0, kName1 };
1270 const size_t kCount = arraysize(kNames);
1271 const char kValidStrEnd = 0;
1272 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1273 GetUniformIndices::Result* result =
1274 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1275 decoder_->set_unsafe_es3_apis_enabled(true);
1276 GetUniformIndices cmd;
1277 result->size = 1976; // Any value other than 0.
1278 cmd.Init(kInvalidClientId,
1279 kBucketId,
1280 kSharedMemoryId,
1281 kSharedMemoryOffset);
1282 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1285 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadSharedMemoryFails) {
1286 const uint32 kBucketId = 123;
1287 const char kName0[] = "Cow";
1288 const char kName1[] = "Chicken";
1289 const char* kNames[] = { kName0, kName1 };
1290 const size_t kCount = arraysize(kNames);
1291 const char kValidStrEnd = 0;
1292 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1293 GetUniformIndices::Result* result =
1294 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1295 decoder_->set_unsafe_es3_apis_enabled(true);
1296 GetUniformIndices cmd;
1297 cmd.Init(client_program_id_,
1298 kBucketId,
1299 kInvalidSharedMemoryId,
1300 kSharedMemoryOffset);
1301 result->size = 0;
1302 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1303 cmd.Init(client_program_id_,
1304 kBucketId,
1305 kSharedMemoryId,
1306 kInvalidSharedMemoryOffset);
1307 result->size = 0;
1308 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1311 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivSucceeds) {
1312 const uint32 kBucketId = 123;
1313 const GLuint kIndices[] = { 1, 2 };
1314 const GLint kResults[] = { 1976, 321 };
1315 const size_t kCount = arraysize(kIndices);
1316 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1317 GetActiveUniformsiv::Result* result =
1318 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1319 GetActiveUniformsiv cmd;
1320 cmd.Init(client_program_id_,
1321 kBucketId,
1322 GL_UNIFORM_TYPE,
1323 kSharedMemoryId,
1324 kSharedMemoryOffset);
1325 EXPECT_CALL(*gl_,
1326 GetActiveUniformsiv(
1327 kServiceProgramId, kCount, _, GL_UNIFORM_TYPE, _))
1328 .WillOnce(SetArrayArgument<4>(kResults, kResults + kCount))
1329 .RetiresOnSaturation();
1330 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1331 .WillOnce(SetArgPointee<2>(GL_TRUE))
1332 .RetiresOnSaturation();
1333 EXPECT_CALL(*gl_, GetError())
1334 .WillOnce(Return(GL_NO_ERROR))
1335 .WillOnce(Return(GL_NO_ERROR))
1336 .RetiresOnSaturation();
1337 decoder_->set_unsafe_es3_apis_enabled(true);
1338 result->size = 0;
1339 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1340 EXPECT_EQ(kCount, static_cast<size_t>(result->GetNumResults()));
1341 for (size_t ii = 0; ii < kCount; ++ii) {
1342 EXPECT_EQ(kResults[ii], result->GetData()[ii]);
1344 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1345 decoder_->set_unsafe_es3_apis_enabled(false);
1346 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1349 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadProgramFails) {
1350 const uint32 kBucketId = 123;
1351 const GLuint kIndices[] = { 1, 2 };
1352 const size_t kCount = arraysize(kIndices);
1353 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1354 GetActiveUniformsiv::Result* result =
1355 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1356 decoder_->set_unsafe_es3_apis_enabled(true);
1357 GetActiveUniformsiv cmd;
1358 // None-existant program
1359 cmd.Init(kInvalidClientId,
1360 kBucketId,
1361 GL_UNIFORM_TYPE,
1362 kSharedMemoryId,
1363 kSharedMemoryOffset);
1364 result->size = 0;
1365 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1366 EXPECT_EQ(0, result->GetNumResults());
1367 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1368 // Unlinked program.
1369 cmd.Init(client_program_id_,
1370 kBucketId,
1371 GL_UNIFORM_TYPE,
1372 kSharedMemoryId,
1373 kSharedMemoryOffset);
1374 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1375 .WillOnce(SetArgPointee<2>(GL_FALSE))
1376 .RetiresOnSaturation();
1377 result->size = 0;
1378 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1379 EXPECT_EQ(0, result->GetNumResults());
1380 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1383 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadParamsFails) {
1384 const uint32 kBucketId = 123;
1385 const GLuint kIndices[] = { 1, 2 };
1386 const GLint kResults[] = { 1976, 321 };
1387 const size_t kCount = arraysize(kIndices);
1388 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1389 GetActiveUniformsiv::Result* result =
1390 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1391 GetActiveUniformsiv cmd;
1392 cmd.Init(client_program_id_,
1393 kBucketId,
1394 GL_UNIFORM_TYPE,
1395 kSharedMemoryId,
1396 kSharedMemoryOffset);
1397 EXPECT_CALL(*gl_,
1398 GetActiveUniformsiv(
1399 kServiceProgramId, kCount, _, GL_UNIFORM_TYPE, _))
1400 .WillOnce(SetArrayArgument<4>(kResults, kResults + kCount))
1401 .RetiresOnSaturation();
1402 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1403 .WillOnce(SetArgPointee<2>(GL_TRUE))
1404 .RetiresOnSaturation();
1405 EXPECT_CALL(*gl_, GetError())
1406 .WillOnce(Return(GL_NO_ERROR))
1407 .WillOnce(Return(GL_INVALID_VALUE))
1408 .RetiresOnSaturation();
1409 decoder_->set_unsafe_es3_apis_enabled(true);
1410 result->size = 0;
1411 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1412 EXPECT_EQ(0, result->GetNumResults());
1413 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1416 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivResultNotInitFails) {
1417 const uint32 kBucketId = 123;
1418 const GLuint kIndices[] = { 1, 2 };
1419 const size_t kCount = arraysize(kIndices);
1420 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1421 GetActiveUniformsiv::Result* result =
1422 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1423 GetActiveUniformsiv cmd;
1424 cmd.Init(client_program_id_,
1425 kBucketId,
1426 GL_UNIFORM_TYPE,
1427 kSharedMemoryId,
1428 kSharedMemoryOffset);
1429 decoder_->set_unsafe_es3_apis_enabled(true);
1430 result->size = 1976; // Any value other than 0.
1431 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1434 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadSharedMemoryFails) {
1435 const uint32 kBucketId = 123;
1436 const GLuint kIndices[] = { 1, 2 };
1437 const size_t kCount = arraysize(kIndices);
1438 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1439 GetActiveUniformsiv::Result* result =
1440 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1441 GetActiveUniformsiv cmd;
1442 decoder_->set_unsafe_es3_apis_enabled(true);
1443 result->size = 0;
1444 cmd.Init(client_program_id_,
1445 kBucketId,
1446 GL_UNIFORM_TYPE,
1447 kInvalidSharedMemoryId,
1448 kSharedMemoryOffset);
1449 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1450 result->size = 0;
1451 cmd.Init(client_program_id_,
1452 kBucketId,
1453 GL_UNIFORM_TYPE,
1454 kSharedMemoryId,
1455 kInvalidSharedMemoryOffset);
1456 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1459 TEST_P(GLES2DecoderWithShaderTest, GetShaderInfoLogValidArgs) {
1460 const uint32 kBucketId = 123;
1461 const char kSource0[] = "void main() { gl_Position = vec4(1.0); }";
1462 const char* kSource[] = {kSource0};
1463 const char kValidStrEnd = 0;
1464 SetBucketAsCStrings(kBucketId, 1, kSource, 1, kValidStrEnd);
1465 ShaderSourceBucket bucket_cmd;
1466 bucket_cmd.Init(client_shader_id_, kBucketId);
1467 EXPECT_EQ(error::kNoError, ExecuteCmd(bucket_cmd));
1468 ClearSharedMemory();
1470 const char* kInfo = "hello";
1471 CompileShader compile_cmd;
1472 GetShaderInfoLog cmd;
1473 EXPECT_CALL(*gl_, ShaderSource(kServiceShaderId, 1, _, _));
1474 EXPECT_CALL(*gl_, CompileShader(kServiceShaderId));
1475 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_COMPILE_STATUS, _))
1476 .WillOnce(SetArgPointee<2>(GL_FALSE))
1477 .RetiresOnSaturation();
1478 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_INFO_LOG_LENGTH, _))
1479 .WillOnce(SetArgPointee<2>(strlen(kInfo) + 1))
1480 .RetiresOnSaturation();
1481 EXPECT_CALL(*gl_, GetShaderInfoLog(kServiceShaderId, strlen(kInfo) + 1, _, _))
1482 .WillOnce(DoAll(SetArgPointee<2>(strlen(kInfo)),
1483 SetArrayArgument<3>(kInfo, kInfo + strlen(kInfo) + 1)));
1484 compile_cmd.Init(client_shader_id_);
1485 cmd.Init(client_shader_id_, kBucketId);
1486 EXPECT_EQ(error::kNoError, ExecuteCmd(compile_cmd));
1487 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1488 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1489 ASSERT_TRUE(bucket != NULL);
1490 EXPECT_EQ(strlen(kInfo) + 1, bucket->size());
1491 EXPECT_EQ(0,
1492 memcmp(bucket->GetData(0, bucket->size()), kInfo, bucket->size()));
1493 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1496 TEST_P(GLES2DecoderWithShaderTest, GetShaderInfoLogInvalidArgs) {
1497 const uint32 kBucketId = 123;
1498 GetShaderInfoLog cmd;
1499 cmd.Init(kInvalidClientId, kBucketId);
1500 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1501 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1504 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingSucceeds) {
1505 const GLuint kIndex = 1;
1506 const uint32 kBucketId = 123;
1507 const char kName[] = "HolyCow";
1508 const GLsizei kBufferSize = static_cast<GLsizei>(strlen(kName) + 1);
1509 const GLsizei kSize = 2;
1510 const GLenum kType = GL_FLOAT_VEC2;
1511 GetTransformFeedbackVarying cmd;
1512 typedef GetTransformFeedbackVarying::Result Result;
1513 Result* result = static_cast<Result*>(shared_memory_address_);
1514 result->success = 0;
1515 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1516 .WillOnce(SetArgPointee<2>(GL_TRUE))
1517 .RetiresOnSaturation();
1518 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId,
1519 GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, _))
1520 .WillOnce(SetArgPointee<2>(kBufferSize))
1521 .RetiresOnSaturation();
1522 EXPECT_CALL(*gl_, GetError())
1523 .WillOnce(Return(GL_NO_ERROR))
1524 .WillOnce(Return(GL_NO_ERROR))
1525 .RetiresOnSaturation();
1526 EXPECT_CALL(*gl_,
1527 GetTransformFeedbackVarying(
1528 kServiceProgramId, kIndex, _, _, _, _, _))
1529 .WillOnce(DoAll(SetArgPointee<3>(kBufferSize - 1),
1530 SetArgPointee<4>(kSize),
1531 SetArgPointee<5>(kType),
1532 SetArrayArgument<6>(kName, kName + kBufferSize)))
1533 .RetiresOnSaturation();
1534 cmd.Init(client_program_id_,
1535 kIndex,
1536 kBucketId,
1537 shared_memory_id_,
1538 shared_memory_offset_);
1539 decoder_->set_unsafe_es3_apis_enabled(true);
1540 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1541 EXPECT_NE(0, result->success);
1542 EXPECT_EQ(kSize, static_cast<GLsizei>(result->size));
1543 EXPECT_EQ(kType, static_cast<GLenum>(result->type));
1544 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1545 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1546 ASSERT_TRUE(bucket != NULL);
1547 EXPECT_EQ(
1548 0, memcmp(bucket->GetData(0, bucket->size()), kName, bucket->size()));
1549 decoder_->set_unsafe_es3_apis_enabled(false);
1550 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1553 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingNotInitFails) {
1554 const GLuint kIndex = 1;
1555 const uint32 kBucketId = 123;
1556 GetTransformFeedbackVarying cmd;
1557 typedef GetTransformFeedbackVarying::Result Result;
1558 Result* result = static_cast<Result*>(shared_memory_address_);
1559 result->success = 1;
1560 cmd.Init(client_program_id_,
1561 kIndex,
1562 kBucketId,
1563 shared_memory_id_,
1564 shared_memory_offset_);
1565 decoder_->set_unsafe_es3_apis_enabled(true);
1566 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1569 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingBadProgramFails) {
1570 const GLuint kIndex = 1;
1571 const uint32 kBucketId = 123;
1572 GetTransformFeedbackVarying cmd;
1573 typedef GetTransformFeedbackVarying::Result Result;
1574 Result* result = static_cast<Result*>(shared_memory_address_);
1575 result->success = 0;
1576 cmd.Init(kInvalidClientId,
1577 kIndex,
1578 kBucketId,
1579 shared_memory_id_,
1580 shared_memory_offset_);
1581 decoder_->set_unsafe_es3_apis_enabled(true);
1582 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1583 EXPECT_EQ(0, result->success);
1584 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1587 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingBadParamsFails) {
1588 const GLuint kIndex = 1;
1589 const uint32 kBucketId = 123;
1590 const GLsizei kBufferSize = 10;
1591 GetTransformFeedbackVarying cmd;
1592 typedef GetTransformFeedbackVarying::Result Result;
1593 Result* result = static_cast<Result*>(shared_memory_address_);
1594 result->success = 0;
1595 cmd.Init(client_program_id_,
1596 kIndex,
1597 kBucketId,
1598 shared_memory_id_,
1599 shared_memory_offset_);
1600 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1601 .WillOnce(SetArgPointee<2>(GL_TRUE))
1602 .RetiresOnSaturation();
1603 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId,
1604 GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, _))
1605 .WillOnce(SetArgPointee<2>(kBufferSize))
1606 .RetiresOnSaturation();
1607 EXPECT_CALL(*gl_, GetError())
1608 .WillOnce(Return(GL_NO_ERROR))
1609 .WillOnce(Return(GL_INVALID_VALUE))
1610 .RetiresOnSaturation();
1611 EXPECT_CALL(*gl_,
1612 GetTransformFeedbackVarying(
1613 kServiceProgramId, kIndex, _, _, _, _, _))
1614 .Times(1)
1615 .RetiresOnSaturation();
1616 decoder_->set_unsafe_es3_apis_enabled(true);
1617 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1618 EXPECT_EQ(0, result->success);
1619 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1622 TEST_P(GLES2DecoderWithShaderTest,
1623 GetTransformFeedbackVaryingBadSharedMemoryFails) {
1624 const GLuint kIndex = 1;
1625 const uint32 kBucketId = 123;
1626 GetTransformFeedbackVarying cmd;
1627 typedef GetTransformFeedbackVarying::Result Result;
1628 Result* result = static_cast<Result*>(shared_memory_address_);
1629 result->success = 0;
1630 decoder_->set_unsafe_es3_apis_enabled(true);
1631 cmd.Init(client_program_id_,
1632 kIndex,
1633 kBucketId,
1634 kInvalidSharedMemoryId,
1635 shared_memory_offset_);
1636 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1637 cmd.Init(client_program_id_,
1638 kIndex,
1639 kBucketId,
1640 shared_memory_id_,
1641 kInvalidSharedMemoryOffset);
1642 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1645 TEST_P(GLES2DecoderTest, CompileShaderValidArgs) {
1646 // ShaderSource should not actually call any GL calls yet.
1647 const uint32 kInBucketId = 123;
1648 const char kSource0[] = "void main() { gl_Position = vec4(1.0); }";
1649 const char* kSource[] = {kSource0};
1650 const char kValidStrEnd = 0;
1651 SetBucketAsCStrings(kInBucketId, 1, kSource, 1, kValidStrEnd);
1652 ShaderSourceBucket bucket_cmd;
1653 bucket_cmd.Init(client_shader_id_, kInBucketId);
1654 EXPECT_EQ(error::kNoError, ExecuteCmd(bucket_cmd));
1655 ClearSharedMemory();
1657 // Compile shader should not actually call any GL calls yet.
1658 CompileShader cmd;
1659 cmd.Init(client_shader_id_);
1660 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1662 // Getting the shader compilation state should trigger the actual GL calls.
1663 EXPECT_CALL(*gl_, ShaderSource(kServiceShaderId, 1, _, _));
1664 EXPECT_CALL(*gl_, CompileShader(kServiceShaderId));
1665 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_COMPILE_STATUS, _))
1666 .WillOnce(SetArgPointee<2>(GL_TRUE))
1667 .RetiresOnSaturation();
1668 EXPECT_CALL(*gl_, GetError())
1669 .WillOnce(Return(GL_NO_ERROR))
1670 .WillOnce(Return(GL_NO_ERROR))
1671 .RetiresOnSaturation();
1673 GetShaderiv::Result* result =
1674 static_cast<GetShaderiv::Result*>(shared_memory_address_);
1675 result->size = 0;
1676 GetShaderiv status_cmd;
1677 status_cmd.Init(client_shader_id_, GL_COMPILE_STATUS,
1678 kSharedMemoryId, kSharedMemoryOffset);
1679 EXPECT_EQ(error::kNoError, ExecuteCmd(status_cmd));
1680 EXPECT_EQ(GL_TRUE, *result->GetData());
1683 TEST_P(GLES2DecoderTest, CompileShaderInvalidArgs) {
1684 CompileShader cmd;
1685 cmd.Init(kInvalidClientId);
1686 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1687 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1688 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1689 cmd.Init(client_program_id_);
1690 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1691 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1692 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1695 TEST_P(GLES2DecoderTest, ShaderSourceBucketAndGetShaderSourceValidArgs) {
1696 const uint32 kInBucketId = 123;
1697 const uint32 kOutBucketId = 125;
1698 const char kSource0[] = "hello";
1699 const char* kSource[] = { kSource0 };
1700 const char kValidStrEnd = 0;
1701 SetBucketAsCStrings(kInBucketId, 1, kSource, 1, kValidStrEnd);
1702 ShaderSourceBucket cmd;
1703 cmd.Init(client_shader_id_, kInBucketId);
1704 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1705 ClearSharedMemory();
1706 GetShaderSource get_cmd;
1707 get_cmd.Init(client_shader_id_, kOutBucketId);
1708 EXPECT_EQ(error::kNoError, ExecuteCmd(get_cmd));
1709 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kOutBucketId);
1710 ASSERT_TRUE(bucket != NULL);
1711 EXPECT_EQ(sizeof(kSource0), bucket->size());
1712 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()),
1713 kSource0, bucket->size()));
1716 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1717 TEST_P(GLES2DecoderTest, ShaderSourceBucketWithProgramId) {
1718 const uint32 kBucketId = 123;
1719 const char kSource0[] = "hello";
1720 const char* kSource[] = { kSource0 };
1721 const char kValidStrEnd = 0;
1722 SetBucketAsCStrings(kBucketId, 1, kSource, 1, kValidStrEnd);
1723 ShaderSourceBucket cmd;
1724 cmd.Init(client_program_id_, kBucketId);
1725 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1726 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1728 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1730 TEST_P(GLES2DecoderTest, ShaderSourceStripComments) {
1731 const uint32 kInBucketId = 123;
1732 const char kSource0[] = "hello/*te\ast*/world//a\ab";
1733 const char* kSource[] = { kSource0 };
1734 const char kValidStrEnd = 0;
1735 SetBucketAsCStrings(kInBucketId, 1, kSource, 1, kValidStrEnd);
1736 ShaderSourceBucket cmd;
1737 cmd.Init(client_shader_id_, kInBucketId);
1738 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1739 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1742 TEST_P(GLES2DecoderWithShaderTest, Uniform1iValidArgs) {
1743 EXPECT_CALL(*gl_, Uniform1i(kUniform1RealLocation, 2));
1744 Uniform1i cmd;
1745 cmd.Init(kUniform1FakeLocation, 2);
1746 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1749 TEST_P(GLES2DecoderWithShaderTest, Uniform1uiValidArgs) {
1750 EXPECT_CALL(*gl_, Uniform1uiv(kUniform4RealLocation, 1, _));
1751 cmds::Uniform1ui cmd;
1752 cmd.Init(kUniform4FakeLocation, 2);
1753 decoder_->set_unsafe_es3_apis_enabled(true);
1754 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1755 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1756 decoder_->set_unsafe_es3_apis_enabled(false);
1757 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1760 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivImmediateValidArgs) {
1761 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1762 EXPECT_CALL(*gl_,
1763 Uniform1iv(kUniform1RealLocation,
1765 reinterpret_cast<GLint*>(ImmediateDataAddress(&cmd))));
1766 GLint temp[1 * 2] = {
1769 cmd.Init(kUniform1FakeLocation, 1, &temp[0]);
1770 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1773 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivImmediateInvalidValidArgs) {
1774 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1775 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1776 GLint temp[1 * 2] = {
1779 cmd.Init(kUniform1FakeLocation, 2, &temp[0]);
1780 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1781 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1784 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivZeroCount) {
1785 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1786 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1787 GLint temp = 0;
1788 cmd.Init(kUniform1FakeLocation, 0, &temp);
1789 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1790 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1793 TEST_P(GLES2DecoderWithShaderTest, Uniform1iSamplerIsLmited) {
1794 EXPECT_CALL(*gl_, Uniform1i(_, _)).Times(0);
1795 Uniform1i cmd;
1796 cmd.Init(kUniform1FakeLocation, kNumTextureUnits);
1797 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1798 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1801 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivSamplerIsLimited) {
1802 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1803 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1804 GLint temp[] = {kNumTextureUnits};
1805 cmd.Init(kUniform1FakeLocation, 1, &temp[0]);
1806 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1807 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1810 TEST_P(GLES2DecoderWithShaderTest, Uniform1uivImmediateValidArgs) {
1811 cmds::Uniform1uivImmediate& cmd =
1812 *GetImmediateAs<cmds::Uniform1uivImmediate>();
1813 EXPECT_CALL(
1814 *gl_,
1815 Uniform1uiv(kUniform4RealLocation, 1,
1816 reinterpret_cast<GLuint*>(ImmediateDataAddress(&cmd))));
1817 GLuint temp[1 * 2] = {
1820 cmd.Init(kUniform4FakeLocation, 1, &temp[0]);
1821 decoder_->set_unsafe_es3_apis_enabled(true);
1822 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1823 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1824 decoder_->set_unsafe_es3_apis_enabled(false);
1825 EXPECT_EQ(error::kUnknownCommand, ExecuteImmediateCmd(cmd, sizeof(temp)));
1828 TEST_P(GLES2DecoderWithShaderTest, Uniform1uivImmediateInvalidType) {
1829 EXPECT_CALL(*gl_, Uniform1uiv(_, _, _)).Times(0);
1830 Uniform1uivImmediate& cmd = *GetImmediateAs<Uniform1uivImmediate>();
1831 GLuint temp[1 * 2] = {
1834 // uniform1 is SAMPLER type.
1835 cmd.Init(kUniform1FakeLocation, 1, &temp[0]);
1836 decoder_->set_unsafe_es3_apis_enabled(true);
1837 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1838 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1841 TEST_P(GLES2DecoderWithShaderTest, Uniform1uivZeroCount) {
1842 EXPECT_CALL(*gl_, Uniform1uiv(_, _, _)).Times(0);
1843 Uniform1uivImmediate& cmd = *GetImmediateAs<Uniform1uivImmediate>();
1844 GLuint temp = 0;
1845 cmd.Init(kUniform4FakeLocation, 0, &temp);
1846 decoder_->set_unsafe_es3_apis_enabled(true);
1847 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1848 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1851 TEST_P(GLES2DecoderWithShaderTest, Uniform2uiValidArgs) {
1852 EXPECT_CALL(*gl_, Uniform2uiv(kUniform5RealLocation, 1, _));
1853 cmds::Uniform2ui cmd;
1854 cmd.Init(kUniform5FakeLocation, 2, 3);
1855 decoder_->set_unsafe_es3_apis_enabled(true);
1856 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1857 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1858 decoder_->set_unsafe_es3_apis_enabled(false);
1859 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1862 TEST_P(GLES2DecoderWithShaderTest, Uniform2uivImmediateValidArgs) {
1863 cmds::Uniform2uivImmediate& cmd =
1864 *GetImmediateAs<cmds::Uniform2uivImmediate>();
1865 EXPECT_CALL(
1866 *gl_,
1867 Uniform2uiv(kUniform5RealLocation, 1,
1868 reinterpret_cast<GLuint*>(ImmediateDataAddress(&cmd))));
1869 GLuint temp[2 * 1] = {
1872 cmd.Init(kUniform5FakeLocation, 1, &temp[0]);
1873 decoder_->set_unsafe_es3_apis_enabled(true);
1874 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1875 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1876 decoder_->set_unsafe_es3_apis_enabled(false);
1877 EXPECT_EQ(error::kUnknownCommand, ExecuteImmediateCmd(cmd, sizeof(temp)));
1880 TEST_P(GLES2DecoderWithShaderTest, Uniform3uiValidArgs) {
1881 EXPECT_CALL(*gl_, Uniform3uiv(kUniform6RealLocation, 1, _));
1882 cmds::Uniform3ui cmd;
1883 cmd.Init(kUniform6FakeLocation, 2, 3, 4);
1884 decoder_->set_unsafe_es3_apis_enabled(true);
1885 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1886 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1887 decoder_->set_unsafe_es3_apis_enabled(false);
1888 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1891 TEST_P(GLES2DecoderWithShaderTest, Uniform3uivImmediateValidArgs) {
1892 cmds::Uniform3uivImmediate& cmd =
1893 *GetImmediateAs<cmds::Uniform3uivImmediate>();
1894 EXPECT_CALL(
1895 *gl_,
1896 Uniform3uiv(kUniform6RealLocation, 1,
1897 reinterpret_cast<GLuint*>(ImmediateDataAddress(&cmd))));
1898 GLuint temp[3 * 1] = {
1901 cmd.Init(kUniform6FakeLocation, 1, &temp[0]);
1902 decoder_->set_unsafe_es3_apis_enabled(true);
1903 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1904 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1905 decoder_->set_unsafe_es3_apis_enabled(false);
1906 EXPECT_EQ(error::kUnknownCommand, ExecuteImmediateCmd(cmd, sizeof(temp)));
1909 TEST_P(GLES2DecoderWithShaderTest, Uniform4uiValidArgs) {
1910 EXPECT_CALL(*gl_, Uniform4uiv(kUniform7RealLocation, 1, _));
1911 cmds::Uniform4ui cmd;
1912 cmd.Init(kUniform7FakeLocation, 2, 3, 4, 5);
1913 decoder_->set_unsafe_es3_apis_enabled(true);
1914 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1915 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1916 decoder_->set_unsafe_es3_apis_enabled(false);
1917 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1920 TEST_P(GLES2DecoderWithShaderTest, Uniform4uivImmediateValidArgs) {
1921 cmds::Uniform4uivImmediate& cmd =
1922 *GetImmediateAs<cmds::Uniform4uivImmediate>();
1923 EXPECT_CALL(
1924 *gl_,
1925 Uniform4uiv(kUniform7RealLocation, 1,
1926 reinterpret_cast<GLuint*>(ImmediateDataAddress(&cmd))));
1927 GLuint temp[4 * 1] = {
1930 cmd.Init(kUniform7FakeLocation, 1, &temp[0]);
1931 decoder_->set_unsafe_es3_apis_enabled(true);
1932 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1933 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1934 decoder_->set_unsafe_es3_apis_enabled(false);
1935 EXPECT_EQ(error::kUnknownCommand, ExecuteImmediateCmd(cmd, sizeof(temp)));
1938 TEST_P(GLES2DecoderTest, BindAttribLocationBucket) {
1939 const uint32 kBucketId = 123;
1940 const GLint kLocation = 2;
1941 const char* kName = "testing";
1942 EXPECT_CALL(*gl_,
1943 BindAttribLocation(kServiceProgramId, kLocation, StrEq(kName)))
1944 .Times(1);
1945 SetBucketAsCString(kBucketId, kName);
1946 BindAttribLocationBucket cmd;
1947 cmd.Init(client_program_id_, kLocation, kBucketId);
1948 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1951 TEST_P(GLES2DecoderTest, BindAttribLocationBucketInvalidArgs) {
1952 const uint32 kBucketId = 123;
1953 const GLint kLocation = 2;
1954 const char* kName = "testing";
1955 EXPECT_CALL(*gl_, BindAttribLocation(_, _, _)).Times(0);
1956 BindAttribLocationBucket cmd;
1957 // check bucket does not exist.
1958 cmd.Init(client_program_id_, kLocation, kBucketId);
1959 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1960 // check bucket is empty.
1961 SetBucketAsCString(kBucketId, NULL);
1962 cmd.Init(client_program_id_, kLocation, kBucketId);
1963 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1964 // Check bad program id
1965 SetBucketAsCString(kBucketId, kName);
1966 cmd.Init(kInvalidClientId, kLocation, kBucketId);
1967 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1968 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1971 TEST_P(GLES2DecoderWithShaderTest, GetAttribLocation) {
1972 const uint32 kBucketId = 123;
1973 const char* kNonExistentName = "foobar";
1974 typedef GetAttribLocation::Result Result;
1975 Result* result = GetSharedMemoryAs<Result*>();
1976 SetBucketAsCString(kBucketId, kAttrib2Name);
1977 *result = -1;
1978 GetAttribLocation cmd;
1979 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1980 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1981 EXPECT_EQ(kAttrib2Location, *result);
1982 SetBucketAsCString(kBucketId, kNonExistentName);
1983 *result = -1;
1984 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1985 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1986 EXPECT_EQ(-1, *result);
1989 TEST_P(GLES2DecoderWithShaderTest, GetAttribLocationInvalidArgs) {
1990 const uint32 kBucketId = 123;
1991 typedef GetAttribLocation::Result Result;
1992 Result* result = GetSharedMemoryAs<Result*>();
1993 *result = -1;
1994 GetAttribLocation cmd;
1995 // Check no bucket
1996 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1997 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1998 EXPECT_EQ(-1, *result);
1999 // Check bad program id.
2000 SetBucketAsCString(kBucketId, kAttrib2Name);
2001 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2002 *result = -1;
2003 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2004 EXPECT_EQ(-1, *result);
2005 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2006 // Check bad memory
2007 cmd.Init(client_program_id_,
2008 kBucketId,
2009 kInvalidSharedMemoryId,
2010 kSharedMemoryOffset);
2011 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2012 cmd.Init(client_program_id_,
2013 kBucketId,
2014 kSharedMemoryId,
2015 kInvalidSharedMemoryOffset);
2016 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2019 TEST_P(GLES2DecoderWithShaderTest, GetFragDataLocation) {
2020 const uint32 kBucketId = 123;
2021 const GLint kLocation = 10;
2022 const char* kName = "color";
2023 typedef GetFragDataLocation::Result Result;
2024 Result* result = GetSharedMemoryAs<Result*>();
2025 SetBucketAsCString(kBucketId, kName);
2026 *result = -1;
2027 GetFragDataLocation cmd;
2028 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2029 EXPECT_CALL(*gl_, GetFragDataLocation(kServiceProgramId, StrEq(kName)))
2030 .WillOnce(Return(kLocation))
2031 .RetiresOnSaturation();
2032 decoder_->set_unsafe_es3_apis_enabled(true);
2033 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2034 EXPECT_EQ(kLocation, *result);
2035 decoder_->set_unsafe_es3_apis_enabled(false);
2036 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
2039 TEST_P(GLES2DecoderWithShaderTest, GetFragDataLocationInvalidArgs) {
2040 const uint32 kBucketId = 123;
2041 typedef GetFragDataLocation::Result Result;
2042 Result* result = GetSharedMemoryAs<Result*>();
2043 *result = -1;
2044 GetFragDataLocation cmd;
2045 decoder_->set_unsafe_es3_apis_enabled(true);
2046 // Check no bucket
2047 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2048 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2049 EXPECT_EQ(-1, *result);
2050 // Check bad program id.
2051 const char* kName = "color";
2052 SetBucketAsCString(kBucketId, kName);
2053 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2054 *result = -1;
2055 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2056 EXPECT_EQ(-1, *result);
2057 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2058 // Check bad memory
2059 cmd.Init(client_program_id_,
2060 kBucketId,
2061 kInvalidSharedMemoryId,
2062 kSharedMemoryOffset);
2063 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2064 cmd.Init(client_program_id_,
2065 kBucketId,
2066 kSharedMemoryId,
2067 kInvalidSharedMemoryOffset);
2068 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2071 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlockIndex) {
2072 const uint32 kBucketId = 123;
2073 const GLuint kIndex = 10;
2074 const char* kName = "color";
2075 typedef GetUniformBlockIndex::Result Result;
2076 Result* result = GetSharedMemoryAs<Result*>();
2077 SetBucketAsCString(kBucketId, kName);
2078 *result = GL_INVALID_INDEX;
2079 GetUniformBlockIndex cmd;
2080 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2081 EXPECT_CALL(*gl_, GetUniformBlockIndex(kServiceProgramId, StrEq(kName)))
2082 .WillOnce(Return(kIndex))
2083 .RetiresOnSaturation();
2084 decoder_->set_unsafe_es3_apis_enabled(true);
2085 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2086 EXPECT_EQ(kIndex, *result);
2087 decoder_->set_unsafe_es3_apis_enabled(false);
2088 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
2091 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlockIndexInvalidArgs) {
2092 const uint32 kBucketId = 123;
2093 typedef GetUniformBlockIndex::Result Result;
2094 Result* result = GetSharedMemoryAs<Result*>();
2095 *result = GL_INVALID_INDEX;
2096 GetUniformBlockIndex cmd;
2097 decoder_->set_unsafe_es3_apis_enabled(true);
2098 // Check no bucket
2099 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2100 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2101 EXPECT_EQ(GL_INVALID_INDEX, *result);
2102 // Check bad program id.
2103 const char* kName = "color";
2104 SetBucketAsCString(kBucketId, kName);
2105 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2106 *result = GL_INVALID_INDEX;
2107 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2108 EXPECT_EQ(GL_INVALID_INDEX, *result);
2109 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2110 // Check bad memory
2111 cmd.Init(client_program_id_,
2112 kBucketId,
2113 kInvalidSharedMemoryId,
2114 kSharedMemoryOffset);
2115 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2116 cmd.Init(client_program_id_,
2117 kBucketId,
2118 kSharedMemoryId,
2119 kInvalidSharedMemoryOffset);
2120 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2123 TEST_P(GLES2DecoderWithShaderTest, GetUniformLocation) {
2124 const uint32 kBucketId = 123;
2125 const char* kNonExistentName = "foobar";
2126 typedef GetUniformLocation::Result Result;
2127 Result* result = GetSharedMemoryAs<Result*>();
2128 SetBucketAsCString(kBucketId, kUniform2Name);
2129 *result = -1;
2130 GetUniformLocation cmd;
2131 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2132 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2133 EXPECT_EQ(kUniform2FakeLocation, *result);
2134 SetBucketAsCString(kBucketId, kNonExistentName);
2135 *result = -1;
2136 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2137 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2138 EXPECT_EQ(-1, *result);
2141 TEST_P(GLES2DecoderWithShaderTest, GetUniformLocationInvalidArgs) {
2142 const uint32 kBucketId = 123;
2143 typedef GetUniformLocation::Result Result;
2144 Result* result = GetSharedMemoryAs<Result*>();
2145 *result = -1;
2146 GetUniformLocation cmd;
2147 // Check no bucket
2148 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2149 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2150 EXPECT_EQ(-1, *result);
2151 // Check bad program id.
2152 SetBucketAsCString(kBucketId, kUniform2Name);
2153 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2154 *result = -1;
2155 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2156 EXPECT_EQ(-1, *result);
2157 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2158 // Check bad memory
2159 cmd.Init(client_program_id_,
2160 kBucketId,
2161 kInvalidSharedMemoryId,
2162 kSharedMemoryOffset);
2163 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2164 cmd.Init(client_program_id_,
2165 kBucketId,
2166 kSharedMemoryId,
2167 kInvalidSharedMemoryOffset);
2168 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2171 TEST_P(GLES2DecoderWithShaderTest, UniformBlockBindingValidArgs) {
2172 EXPECT_CALL(*gl_, UniformBlockBinding(kServiceProgramId, 2, 3));
2173 SpecializedSetup<cmds::UniformBlockBinding, 0>(true);
2174 cmds::UniformBlockBinding cmd;
2175 cmd.Init(client_program_id_, 2, 3);
2176 decoder_->set_unsafe_es3_apis_enabled(true);
2177 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2178 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2179 decoder_->set_unsafe_es3_apis_enabled(false);
2180 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
2183 TEST_P(GLES2DecoderWithShaderTest, BindUniformLocationCHROMIUMBucket) {
2184 const uint32 kBucketId = 123;
2185 const GLint kLocation = 2;
2186 const char* kName = "testing";
2187 const char* kBadName1 = "gl_testing";
2188 const char* kBadName2 = "testing[1]";
2190 SetBucketAsCString(kBucketId, kName);
2191 BindUniformLocationCHROMIUMBucket cmd;
2192 cmd.Init(client_program_id_,
2193 kLocation,
2194 kBucketId);
2195 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2196 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2197 // check negative location
2198 SetBucketAsCString(kBucketId, kName);
2199 cmd.Init(client_program_id_, -1, kBucketId);
2200 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2201 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2202 // check highest location
2203 SetBucketAsCString(kBucketId, kName);
2204 GLint kMaxLocation =
2205 (kMaxFragmentUniformVectors + kMaxVertexUniformVectors) * 4 - 1;
2206 cmd.Init(client_program_id_,
2207 kMaxLocation,
2208 kBucketId);
2209 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2210 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2211 // check too high location
2212 SetBucketAsCString(kBucketId, kName);
2213 cmd.Init(client_program_id_,
2214 kMaxLocation + 1,
2215 kBucketId);
2216 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2217 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2218 // check bad name "gl_..."
2219 SetBucketAsCString(kBucketId, kBadName1);
2220 cmd.Init(client_program_id_,
2221 kLocation,
2222 kBucketId);
2223 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2224 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2225 // check bad name "name[1]" non zero
2226 SetBucketAsCString(kBucketId, kBadName2);
2227 cmd.Init(client_program_id_,
2228 kLocation,
2229 kBucketId);
2230 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2231 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2234 TEST_P(GLES2DecoderManualInitTest, ClearUniformsBeforeFirstProgramUse) {
2235 base::CommandLine command_line(0, NULL);
2236 command_line.AppendSwitchASCII(
2237 switches::kGpuDriverBugWorkarounds,
2238 base::IntToString(gpu::CLEAR_UNIFORMS_BEFORE_FIRST_PROGRAM_USE));
2239 InitState init;
2240 init.has_alpha = true;
2241 init.request_alpha = true;
2242 init.bind_generates_resource = true;
2243 InitDecoderWithCommandLine(init, &command_line);
2245 static AttribInfo attribs[] = {
2247 kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location,
2250 kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location,
2253 kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location,
2256 static UniformInfo uniforms[] = {
2257 {kUniform1Name, kUniform1Size, kUniform1Type, kUniform1FakeLocation,
2258 kUniform1RealLocation, kUniform1DesiredLocation},
2259 {kUniform2Name, kUniform2Size, kUniform2Type, kUniform2FakeLocation,
2260 kUniform2RealLocation, kUniform2DesiredLocation},
2261 {kUniform3Name, kUniform3Size, kUniform3Type, kUniform3FakeLocation,
2262 kUniform3RealLocation, kUniform3DesiredLocation},
2264 SetupShader(attribs,
2265 arraysize(attribs),
2266 uniforms,
2267 arraysize(uniforms),
2268 client_program_id_,
2269 kServiceProgramId,
2270 client_vertex_shader_id_,
2271 kServiceVertexShaderId,
2272 client_fragment_shader_id_,
2273 kServiceFragmentShaderId);
2274 TestHelper::SetupExpectationsForClearingUniforms(
2275 gl_.get(), uniforms, arraysize(uniforms));
2279 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
2280 .Times(1)
2281 .RetiresOnSaturation();
2282 cmds::UseProgram cmd;
2283 cmd.Init(client_program_id_);
2284 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2288 // TODO(gman): DeleteProgram
2290 // TODO(gman): UseProgram
2292 // TODO(gman): DeleteShader
2294 } // namespace gles2
2295 } // namespace gpu