Fix crash in SpeechRecognizerImpl introduced in AudioParams refactor.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_programs.cc
blob2a3dc20d2010ab8d4e6dd5efcde9a3b9272e7d58
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_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
167 .WillOnce(SetArgPointee<2>(GL_TRUE))
168 .RetiresOnSaturation();
169 EXPECT_CALL(*gl_,
170 GetProgramiv(
171 kServiceProgramId, GL_TRANSFORM_FEEDBACK_VARYINGS, _))
172 .WillOnce(SetArgPointee<2>(0))
173 .RetiresOnSaturation();
174 decoder_->set_unsafe_es3_apis_enabled(true);
175 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
176 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
177 EXPECT_EQ(sizeof(TransformFeedbackVaryingsHeader), bucket->size());
178 TransformFeedbackVaryingsHeader* header =
179 bucket->GetDataAs<TransformFeedbackVaryingsHeader*>(
180 0, sizeof(TransformFeedbackVaryingsHeader));
181 EXPECT_TRUE(header != NULL);
182 EXPECT_EQ(0u, header->num_transform_feedback_varyings);
183 decoder_->set_unsafe_es3_apis_enabled(false);
184 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
187 TEST_P(GLES2DecoderWithShaderTest,
188 GetTransformFeedbackVaryingsCHROMIUMInvalidArgs) {
189 const uint32 kBucketId = 123;
190 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
191 EXPECT_TRUE(bucket == NULL);
192 GetTransformFeedbackVaryingsCHROMIUM cmd;
193 cmd.Init(kInvalidClientId, kBucketId);
194 decoder_->set_unsafe_es3_apis_enabled(true);
195 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
196 EXPECT_EQ(GL_NO_ERROR, GetGLError());
197 bucket = decoder_->GetBucket(kBucketId);
198 ASSERT_TRUE(bucket != NULL);
199 EXPECT_EQ(sizeof(TransformFeedbackVaryingsHeader), bucket->size());
200 TransformFeedbackVaryingsHeader* header =
201 bucket->GetDataAs<TransformFeedbackVaryingsHeader*>(
202 0, sizeof(TransformFeedbackVaryingsHeader));
203 ASSERT_TRUE(header != NULL);
204 EXPECT_EQ(0u, header->num_transform_feedback_varyings);
207 TEST_P(GLES2DecoderWithShaderTest, GetUniformivSucceeds) {
208 GetUniformiv::Result* result =
209 static_cast<GetUniformiv::Result*>(shared_memory_address_);
210 result->size = 0;
211 GetUniformiv cmd;
212 cmd.Init(client_program_id_,
213 kUniform2FakeLocation,
214 kSharedMemoryId,
215 kSharedMemoryOffset);
216 EXPECT_CALL(*gl_, GetUniformiv(kServiceProgramId, kUniform2RealLocation, _))
217 .Times(1);
218 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
219 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
220 static_cast<uint32>(result->GetNumResults()));
223 TEST_P(GLES2DecoderWithShaderTest, GetUniformivArrayElementSucceeds) {
224 GetUniformiv::Result* result =
225 static_cast<GetUniformiv::Result*>(shared_memory_address_);
226 result->size = 0;
227 GetUniformiv cmd;
228 cmd.Init(client_program_id_,
229 kUniform2ElementFakeLocation,
230 kSharedMemoryId,
231 kSharedMemoryOffset);
232 EXPECT_CALL(*gl_,
233 GetUniformiv(kServiceProgramId, kUniform2ElementRealLocation, _))
234 .Times(1);
235 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
236 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
237 static_cast<uint32>(result->GetNumResults()));
240 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadProgramFails) {
241 GetUniformiv::Result* result =
242 static_cast<GetUniformiv::Result*>(shared_memory_address_);
243 result->size = 0;
244 GetUniformiv cmd;
245 // non-existant program
246 cmd.Init(kInvalidClientId,
247 kUniform2FakeLocation,
248 kSharedMemoryId,
249 kSharedMemoryOffset);
250 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
251 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
252 EXPECT_EQ(0U, result->size);
253 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
254 // Valid id that is not a program. The GL spec requires a different error for
255 // this case.
256 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
257 result->size = kInitialResult;
258 cmd.Init(client_shader_id_,
259 kUniform2FakeLocation,
260 kSharedMemoryId,
261 kSharedMemoryOffset);
262 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
263 EXPECT_EQ(0U, result->size);
264 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
265 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
266 // Unlinked program
267 EXPECT_CALL(*gl_, CreateProgram())
268 .Times(1)
269 .WillOnce(Return(kNewServiceId))
270 .RetiresOnSaturation();
271 CreateProgram cmd2;
272 cmd2.Init(kNewClientId);
273 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
274 result->size = kInitialResult;
275 cmd.Init(kNewClientId,
276 kUniform2FakeLocation,
277 kSharedMemoryId,
278 kSharedMemoryOffset);
279 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
280 EXPECT_EQ(0U, result->size);
281 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
284 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadLocationFails) {
285 GetUniformiv::Result* result =
286 static_cast<GetUniformiv::Result*>(shared_memory_address_);
287 result->size = 0;
288 GetUniformiv cmd;
289 // invalid location
290 cmd.Init(client_program_id_,
291 kInvalidUniformLocation,
292 kSharedMemoryId,
293 kSharedMemoryOffset);
294 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
295 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
296 EXPECT_EQ(0U, result->size);
297 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
300 TEST_P(GLES2DecoderWithShaderTest, GetUniformivBadSharedMemoryFails) {
301 GetUniformiv cmd;
302 cmd.Init(client_program_id_,
303 kUniform2FakeLocation,
304 kInvalidSharedMemoryId,
305 kSharedMemoryOffset);
306 EXPECT_CALL(*gl_, GetUniformiv(_, _, _)).Times(0);
307 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
308 cmd.Init(client_program_id_,
309 kUniform2FakeLocation,
310 kSharedMemoryId,
311 kInvalidSharedMemoryOffset);
312 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
315 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivSucceeds) {
316 GetUniformuiv::Result* result =
317 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
318 result->size = 0;
319 GetUniformuiv cmd;
320 cmd.Init(client_program_id_,
321 kUniform2FakeLocation,
322 kSharedMemoryId,
323 kSharedMemoryOffset);
324 EXPECT_CALL(*gl_, GetUniformuiv(kServiceProgramId, kUniform2RealLocation, _))
325 .Times(1);
326 decoder_->set_unsafe_es3_apis_enabled(true);
327 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
328 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
329 static_cast<uint32>(result->GetNumResults()));
330 decoder_->set_unsafe_es3_apis_enabled(false);
331 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
334 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivArrayElementSucceeds) {
335 GetUniformuiv::Result* result =
336 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
337 result->size = 0;
338 GetUniformuiv cmd;
339 cmd.Init(client_program_id_,
340 kUniform2ElementFakeLocation,
341 kSharedMemoryId,
342 kSharedMemoryOffset);
343 EXPECT_CALL(*gl_,
344 GetUniformuiv(kServiceProgramId, kUniform2ElementRealLocation, _))
345 .Times(1);
346 decoder_->set_unsafe_es3_apis_enabled(true);
347 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
348 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
349 static_cast<uint32>(result->GetNumResults()));
352 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadProgramFails) {
353 GetUniformuiv::Result* result =
354 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
355 result->size = 0;
356 GetUniformuiv cmd;
357 // non-existant program
358 cmd.Init(kInvalidClientId,
359 kUniform2FakeLocation,
360 kSharedMemoryId,
361 kSharedMemoryOffset);
362 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
363 decoder_->set_unsafe_es3_apis_enabled(true);
364 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
365 EXPECT_EQ(0U, result->size);
366 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
367 // Valid id that is not a program. The GL spec requires a different error for
368 // this case.
369 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
370 result->size = kInitialResult;
371 cmd.Init(client_shader_id_,
372 kUniform2FakeLocation,
373 kSharedMemoryId,
374 kSharedMemoryOffset);
375 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
376 EXPECT_EQ(0U, result->size);
377 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
378 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
379 // Unlinked program
380 EXPECT_CALL(*gl_, CreateProgram())
381 .Times(1)
382 .WillOnce(Return(kNewServiceId))
383 .RetiresOnSaturation();
384 CreateProgram cmd2;
385 cmd2.Init(kNewClientId);
386 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
387 result->size = kInitialResult;
388 cmd.Init(kNewClientId,
389 kUniform2FakeLocation,
390 kSharedMemoryId,
391 kSharedMemoryOffset);
392 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
393 EXPECT_EQ(0U, result->size);
394 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
397 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadLocationFails) {
398 GetUniformuiv::Result* result =
399 static_cast<GetUniformuiv::Result*>(shared_memory_address_);
400 result->size = 0;
401 GetUniformuiv cmd;
402 // invalid location
403 cmd.Init(client_program_id_,
404 kInvalidUniformLocation,
405 kSharedMemoryId,
406 kSharedMemoryOffset);
407 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
408 decoder_->set_unsafe_es3_apis_enabled(true);
409 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
410 EXPECT_EQ(0U, result->size);
411 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
414 TEST_P(GLES2DecoderWithShaderTest, GetUniformuivBadSharedMemoryFails) {
415 GetUniformuiv cmd;
416 cmd.Init(client_program_id_,
417 kUniform2FakeLocation,
418 kInvalidSharedMemoryId,
419 kSharedMemoryOffset);
420 EXPECT_CALL(*gl_, GetUniformuiv(_, _, _)).Times(0);
421 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
422 decoder_->set_unsafe_es3_apis_enabled(true);
423 cmd.Init(client_program_id_,
424 kUniform2FakeLocation,
425 kSharedMemoryId,
426 kInvalidSharedMemoryOffset);
427 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
430 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvSucceeds) {
431 GetUniformfv::Result* result =
432 static_cast<GetUniformfv::Result*>(shared_memory_address_);
433 result->size = 0;
434 GetUniformfv cmd;
435 cmd.Init(client_program_id_,
436 kUniform2FakeLocation,
437 kSharedMemoryId,
438 kSharedMemoryOffset);
439 EXPECT_CALL(*gl_, GetUniformfv(kServiceProgramId, kUniform2RealLocation, _))
440 .Times(1);
441 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
442 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
443 static_cast<uint32>(result->GetNumResults()));
446 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvArrayElementSucceeds) {
447 GetUniformfv::Result* result =
448 static_cast<GetUniformfv::Result*>(shared_memory_address_);
449 result->size = 0;
450 GetUniformfv cmd;
451 cmd.Init(client_program_id_,
452 kUniform2ElementFakeLocation,
453 kSharedMemoryId,
454 kSharedMemoryOffset);
455 EXPECT_CALL(*gl_,
456 GetUniformfv(kServiceProgramId, kUniform2ElementRealLocation, _))
457 .Times(1);
458 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
459 EXPECT_EQ(GLES2Util::GetElementCountForUniformType(kUniform2Type),
460 static_cast<uint32>(result->GetNumResults()));
463 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadProgramFails) {
464 GetUniformfv::Result* result =
465 static_cast<GetUniformfv::Result*>(shared_memory_address_);
466 result->size = 0;
467 GetUniformfv cmd;
468 // non-existant program
469 cmd.Init(kInvalidClientId,
470 kUniform2FakeLocation,
471 kSharedMemoryId,
472 kSharedMemoryOffset);
473 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
474 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
475 EXPECT_EQ(0U, result->size);
476 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
477 // Valid id that is not a program. The GL spec requires a different error for
478 // this case.
479 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
480 result->size = kInitialResult;
481 cmd.Init(client_shader_id_,
482 kUniform2FakeLocation,
483 kSharedMemoryId,
484 kSharedMemoryOffset);
485 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
486 EXPECT_EQ(0U, result->size);
487 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
488 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
489 // Unlinked program
490 EXPECT_CALL(*gl_, CreateProgram())
491 .Times(1)
492 .WillOnce(Return(kNewServiceId))
493 .RetiresOnSaturation();
494 CreateProgram cmd2;
495 cmd2.Init(kNewClientId);
496 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
497 result->size = kInitialResult;
498 cmd.Init(kNewClientId,
499 kUniform2FakeLocation,
500 kSharedMemoryId,
501 kSharedMemoryOffset);
502 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
503 EXPECT_EQ(0U, result->size);
504 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
507 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadLocationFails) {
508 GetUniformfv::Result* result =
509 static_cast<GetUniformfv::Result*>(shared_memory_address_);
510 result->size = 0;
511 GetUniformfv cmd;
512 // invalid location
513 cmd.Init(client_program_id_,
514 kInvalidUniformLocation,
515 kSharedMemoryId,
516 kSharedMemoryOffset);
517 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
518 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
519 EXPECT_EQ(0U, result->size);
520 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
523 TEST_P(GLES2DecoderWithShaderTest, GetUniformfvBadSharedMemoryFails) {
524 GetUniformfv cmd;
525 cmd.Init(client_program_id_,
526 kUniform2FakeLocation,
527 kInvalidSharedMemoryId,
528 kSharedMemoryOffset);
529 EXPECT_CALL(*gl_, GetUniformfv(_, _, _)).Times(0);
530 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
531 cmd.Init(client_program_id_,
532 kUniform2FakeLocation,
533 kSharedMemoryId,
534 kInvalidSharedMemoryOffset);
535 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
538 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersSucceeds) {
539 GetAttachedShaders cmd;
540 typedef GetAttachedShaders::Result Result;
541 Result* result = static_cast<Result*>(shared_memory_address_);
542 result->size = 0;
543 EXPECT_CALL(*gl_, GetAttachedShaders(kServiceProgramId, 1, _, _)).WillOnce(
544 DoAll(SetArgPointee<2>(1), SetArgPointee<3>(kServiceShaderId)));
545 cmd.Init(client_program_id_,
546 shared_memory_id_,
547 shared_memory_offset_,
548 Result::ComputeSize(1));
549 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
550 EXPECT_EQ(1, result->GetNumResults());
551 EXPECT_EQ(client_shader_id_, result->GetData()[0]);
552 EXPECT_EQ(GL_NO_ERROR, GetGLError());
555 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersResultNotInitFail) {
556 GetAttachedShaders cmd;
557 typedef GetAttachedShaders::Result Result;
558 Result* result = static_cast<Result*>(shared_memory_address_);
559 result->size = 1;
560 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
561 cmd.Init(client_program_id_,
562 shared_memory_id_,
563 shared_memory_offset_,
564 Result::ComputeSize(1));
565 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
568 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersBadProgramFails) {
569 GetAttachedShaders cmd;
570 typedef GetAttachedShaders::Result Result;
571 Result* result = static_cast<Result*>(shared_memory_address_);
572 result->size = 0;
573 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
574 cmd.Init(kInvalidClientId,
575 shared_memory_id_,
576 shared_memory_offset_,
577 Result::ComputeSize(1));
578 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
579 EXPECT_EQ(0U, result->size);
580 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
583 TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersBadSharedMemoryFails) {
584 GetAttachedShaders cmd;
585 typedef GetAttachedShaders::Result Result;
586 cmd.Init(client_program_id_,
587 kInvalidSharedMemoryId,
588 shared_memory_offset_,
589 Result::ComputeSize(1));
590 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _)).Times(0);
591 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
592 cmd.Init(client_program_id_,
593 shared_memory_id_,
594 kInvalidSharedMemoryOffset,
595 Result::ComputeSize(1));
596 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
599 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatSucceeds) {
600 ScopedGLImplementationSetter gl_impl(::gfx::kGLImplementationEGLGLES2);
601 GetShaderPrecisionFormat cmd;
602 typedef GetShaderPrecisionFormat::Result Result;
603 Result* result = static_cast<Result*>(shared_memory_address_);
604 result->success = 0;
605 const GLint range[2] = {62, 62};
606 const GLint precision = 16;
607 EXPECT_CALL(*gl_, GetShaderPrecisionFormat(_, _, _, _))
608 .WillOnce(DoAll(SetArrayArgument<2>(range, range + 2),
609 SetArgPointee<3>(precision)))
610 .RetiresOnSaturation();
611 cmd.Init(GL_VERTEX_SHADER,
612 GL_HIGH_FLOAT,
613 shared_memory_id_,
614 shared_memory_offset_);
615 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
616 EXPECT_NE(0, result->success);
617 EXPECT_EQ(range[0], result->min_range);
618 EXPECT_EQ(range[1], result->max_range);
619 EXPECT_EQ(precision, result->precision);
620 EXPECT_EQ(GL_NO_ERROR, GetGLError());
623 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatResultNotInitFails) {
624 GetShaderPrecisionFormat cmd;
625 typedef GetShaderPrecisionFormat::Result Result;
626 Result* result = static_cast<Result*>(shared_memory_address_);
627 result->success = 1;
628 // NOTE: GL might not be called. There is no Desktop OpenGL equivalent
629 cmd.Init(GL_VERTEX_SHADER,
630 GL_HIGH_FLOAT,
631 shared_memory_id_,
632 shared_memory_offset_);
633 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
636 TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatBadArgsFails) {
637 typedef GetShaderPrecisionFormat::Result Result;
638 Result* result = static_cast<Result*>(shared_memory_address_);
639 result->success = 0;
640 GetShaderPrecisionFormat cmd;
641 cmd.Init(
642 GL_TEXTURE_2D, GL_HIGH_FLOAT, shared_memory_id_, shared_memory_offset_);
643 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
644 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
645 result->success = 0;
646 cmd.Init(GL_VERTEX_SHADER,
647 GL_TEXTURE_2D,
648 shared_memory_id_,
649 shared_memory_offset_);
650 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
651 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
654 TEST_P(GLES2DecoderWithShaderTest,
655 GetShaderPrecisionFormatBadSharedMemoryFails) {
656 GetShaderPrecisionFormat cmd;
657 cmd.Init(GL_VERTEX_SHADER,
658 GL_HIGH_FLOAT,
659 kInvalidSharedMemoryId,
660 shared_memory_offset_);
661 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
662 cmd.Init(GL_VERTEX_SHADER,
663 GL_TEXTURE_2D,
664 shared_memory_id_,
665 kInvalidSharedMemoryOffset);
666 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
669 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformSucceeds) {
670 const GLuint kUniformIndex = 1;
671 const uint32 kBucketId = 123;
672 GetActiveUniform cmd;
673 typedef GetActiveUniform::Result Result;
674 Result* result = static_cast<Result*>(shared_memory_address_);
675 result->success = 0;
676 cmd.Init(client_program_id_,
677 kUniformIndex,
678 kBucketId,
679 shared_memory_id_,
680 shared_memory_offset_);
681 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
682 EXPECT_NE(0, result->success);
683 EXPECT_EQ(kUniform2Size, result->size);
684 EXPECT_EQ(kUniform2Type, result->type);
685 EXPECT_EQ(GL_NO_ERROR, GetGLError());
686 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
687 ASSERT_TRUE(bucket != NULL);
688 EXPECT_EQ(
690 memcmp(
691 bucket->GetData(0, bucket->size()), kUniform2Name, bucket->size()));
694 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformResultNotInitFails) {
695 const GLuint kUniformIndex = 1;
696 const uint32 kBucketId = 123;
697 GetActiveUniform cmd;
698 typedef GetActiveUniform::Result Result;
699 Result* result = static_cast<Result*>(shared_memory_address_);
700 result->success = 1;
701 cmd.Init(client_program_id_,
702 kUniformIndex,
703 kBucketId,
704 shared_memory_id_,
705 shared_memory_offset_);
706 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
709 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadProgramFails) {
710 const GLuint kUniformIndex = 1;
711 const uint32 kBucketId = 123;
712 GetActiveUniform cmd;
713 typedef GetActiveUniform::Result Result;
714 Result* result = static_cast<Result*>(shared_memory_address_);
715 result->success = 0;
716 cmd.Init(kInvalidClientId,
717 kUniformIndex,
718 kBucketId,
719 shared_memory_id_,
720 shared_memory_offset_);
721 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
722 EXPECT_EQ(0, result->success);
723 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
724 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
725 result->success = 0;
726 cmd.Init(client_shader_id_,
727 kUniformIndex,
728 kBucketId,
729 shared_memory_id_,
730 shared_memory_offset_);
731 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
732 EXPECT_EQ(0, result->success);
733 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
734 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
737 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadIndexFails) {
738 const uint32 kBucketId = 123;
739 GetActiveUniform cmd;
740 typedef GetActiveUniform::Result Result;
741 Result* result = static_cast<Result*>(shared_memory_address_);
742 result->success = 0;
743 cmd.Init(client_program_id_,
744 kBadUniformIndex,
745 kBucketId,
746 shared_memory_id_,
747 shared_memory_offset_);
748 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
749 EXPECT_EQ(0, result->success);
750 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
753 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBadSharedMemoryFails) {
754 const GLuint kUniformIndex = 1;
755 const uint32 kBucketId = 123;
756 GetActiveUniform cmd;
757 cmd.Init(client_program_id_,
758 kUniformIndex,
759 kBucketId,
760 kInvalidSharedMemoryId,
761 shared_memory_offset_);
762 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
763 cmd.Init(client_program_id_,
764 kUniformIndex,
765 kBucketId,
766 shared_memory_id_,
767 kInvalidSharedMemoryOffset);
768 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
771 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameSucceeds) {
772 const uint32 kBucketId = 123;
773 GetActiveUniformBlockName cmd;
774 typedef GetActiveUniformBlockName::Result Result;
775 Result* result = static_cast<Result*>(shared_memory_address_);
776 *result = 0;
777 cmd.Init(client_program_id_,
779 kBucketId,
780 shared_memory_id_,
781 shared_memory_offset_);
782 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
783 .WillOnce(SetArgPointee<2>(GL_TRUE))
784 .RetiresOnSaturation();
785 const char kName[] = "HolyCow";
786 const GLsizei kMaxLength = strlen(kName) + 1;
787 EXPECT_CALL(*gl_,
788 GetProgramiv(kServiceProgramId,
789 GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, _))
790 .WillOnce(SetArgPointee<2>(kMaxLength))
791 .RetiresOnSaturation();
792 EXPECT_CALL(*gl_,
793 GetActiveUniformBlockName(kServiceProgramId, 0, _, _, _))
794 .WillOnce(DoAll(SetArgPointee<3>(strlen(kName)),
795 SetArrayArgument<4>(kName, kName + strlen(kName) + 1)))
796 .RetiresOnSaturation();
797 decoder_->set_unsafe_es3_apis_enabled(true);
798 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
799 EXPECT_NE(0, *result);
800 EXPECT_EQ(GL_NO_ERROR, GetGLError());
801 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
802 ASSERT_TRUE(bucket != NULL);
803 EXPECT_EQ(0,
804 memcmp(bucket->GetData(0, bucket->size()), kName, bucket->size()));
805 decoder_->set_unsafe_es3_apis_enabled(false);
806 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
809 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameUnlinkedProgram) {
810 const uint32 kBucketId = 123;
811 GetActiveUniformBlockName cmd;
812 typedef GetActiveUniformBlockName::Result Result;
813 Result* result = static_cast<Result*>(shared_memory_address_);
814 *result = 0;
815 cmd.Init(client_program_id_,
817 kBucketId,
818 shared_memory_id_,
819 shared_memory_offset_);
820 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
821 .WillOnce(SetArgPointee<2>(GL_FALSE))
822 .RetiresOnSaturation();
823 decoder_->set_unsafe_es3_apis_enabled(true);
824 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
825 EXPECT_EQ(0, *result);
826 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
829 TEST_P(GLES2DecoderWithShaderTest,
830 GetActiveUniformBlockNameResultNotInitFails) {
831 const uint32 kBucketId = 123;
832 GetActiveUniformBlockName cmd;
833 typedef GetActiveUniformBlockName::Result Result;
834 Result* result = static_cast<Result*>(shared_memory_address_);
835 *result = 1;
836 cmd.Init(client_program_id_,
838 kBucketId,
839 shared_memory_id_,
840 shared_memory_offset_);
841 decoder_->set_unsafe_es3_apis_enabled(true);
842 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
845 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockNameBadProgramFails) {
846 const uint32 kBucketId = 123;
847 GetActiveUniformBlockName cmd;
848 typedef GetActiveUniformBlockName::Result Result;
849 Result* result = static_cast<Result*>(shared_memory_address_);
850 *result = 0;
851 cmd.Init(kInvalidClientId,
853 kBucketId,
854 shared_memory_id_,
855 shared_memory_offset_);
856 decoder_->set_unsafe_es3_apis_enabled(true);
857 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
858 EXPECT_EQ(0, *result);
859 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
862 TEST_P(GLES2DecoderWithShaderTest,
863 GetActiveUniformBlockNameBadSharedMemoryFails) {
864 const uint32 kBucketId = 123;
865 GetActiveUniformBlockName cmd;
866 decoder_->set_unsafe_es3_apis_enabled(true);
867 cmd.Init(client_program_id_,
869 kBucketId,
870 kInvalidSharedMemoryId,
871 shared_memory_offset_);
872 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
873 cmd.Init(client_program_id_,
875 kBucketId,
876 shared_memory_id_,
877 kInvalidSharedMemoryOffset);
878 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
881 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivSucceeds) {
882 GetActiveUniformBlockiv cmd;
883 typedef GetActiveUniformBlockiv::Result Result;
884 Result* result = static_cast<Result*>(shared_memory_address_);
885 GLenum kPname[] {
886 GL_UNIFORM_BLOCK_BINDING,
887 GL_UNIFORM_BLOCK_DATA_SIZE,
888 GL_UNIFORM_BLOCK_NAME_LENGTH,
889 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS,
890 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES,
891 GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER,
892 GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER,
894 for (size_t ii = 0; ii < arraysize(kPname); ++ii) {
895 result->SetNumResults(0);
896 cmd.Init(client_program_id_,
898 kPname[ii],
899 shared_memory_id_,
900 shared_memory_offset_);
901 EXPECT_CALL(*gl_, GetError())
902 .WillOnce(Return(GL_NO_ERROR))
903 .WillOnce(Return(GL_NO_ERROR))
904 .RetiresOnSaturation();
905 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
906 .WillOnce(SetArgPointee<2>(GL_TRUE))
907 .RetiresOnSaturation();
908 if (kPname[ii] == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) {
909 EXPECT_CALL(*gl_, GetError())
910 .WillOnce(Return(GL_NO_ERROR))
911 .RetiresOnSaturation();
912 EXPECT_CALL(*gl_,
913 GetActiveUniformBlockiv(kServiceProgramId, 0,
914 GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, _))
915 .WillOnce(SetArgPointee<3>(1))
916 .RetiresOnSaturation();
918 EXPECT_CALL(*gl_,
919 GetActiveUniformBlockiv(
920 kServiceProgramId, 0, kPname[ii], _))
921 .WillOnce(SetArgPointee<3>(1976))
922 .RetiresOnSaturation();
923 decoder_->set_unsafe_es3_apis_enabled(true);
924 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
925 EXPECT_EQ(1, result->GetNumResults());
926 EXPECT_EQ(GL_NO_ERROR, GetGLError());
927 EXPECT_EQ(1976, result->GetData()[0]);
928 decoder_->set_unsafe_es3_apis_enabled(false);
929 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
933 TEST_P(GLES2DecoderWithShaderTest,
934 GetActiveUniformBlockivSucceedsZeroUniforms) {
935 GetActiveUniformBlockiv cmd;
936 typedef GetActiveUniformBlockiv::Result Result;
937 Result* result = static_cast<Result*>(shared_memory_address_);
938 result->SetNumResults(0);
939 cmd.Init(client_program_id_,
941 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES,
942 shared_memory_id_,
943 shared_memory_offset_);
944 EXPECT_CALL(*gl_, GetError())
945 .WillOnce(Return(GL_NO_ERROR))
946 .WillOnce(Return(GL_NO_ERROR))
947 .WillOnce(Return(GL_NO_ERROR))
948 .RetiresOnSaturation();
949 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
950 .WillOnce(SetArgPointee<2>(GL_TRUE))
951 .RetiresOnSaturation();
952 EXPECT_CALL(*gl_,
953 GetActiveUniformBlockiv(
954 kServiceProgramId, 0, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, _))
955 .WillOnce(SetArgPointee<3>(0))
956 .RetiresOnSaturation();
957 EXPECT_CALL(*gl_,
958 GetActiveUniformBlockiv(kServiceProgramId, 0,
959 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, _))
960 .Times(1)
961 .RetiresOnSaturation();
962 decoder_->set_unsafe_es3_apis_enabled(true);
963 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
964 EXPECT_EQ(0, result->GetNumResults());
965 EXPECT_EQ(GL_NO_ERROR, GetGLError());
968 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivUnlinkedProgram) {
969 GetActiveUniformBlockiv cmd;
970 typedef GetActiveUniformBlockiv::Result Result;
971 Result* result = static_cast<Result*>(shared_memory_address_);
972 result->SetNumResults(0);
973 cmd.Init(client_program_id_,
975 GL_UNIFORM_BLOCK_BINDING,
976 shared_memory_id_,
977 shared_memory_offset_);
978 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
979 .WillOnce(SetArgPointee<2>(GL_FALSE))
980 .RetiresOnSaturation();
981 decoder_->set_unsafe_es3_apis_enabled(true);
982 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
983 EXPECT_EQ(0, result->GetNumResults());
984 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
987 TEST_P(GLES2DecoderWithShaderTest,
988 GetActiveUniformBlockivResultNotInitFails) {
989 GetActiveUniformBlockiv cmd;
990 typedef GetActiveUniformBlockiv::Result Result;
991 Result* result = static_cast<Result*>(shared_memory_address_);
992 result->SetNumResults(1); // Should be initialized to 0.
993 cmd.Init(client_program_id_,
995 GL_UNIFORM_BLOCK_BINDING,
996 shared_memory_id_,
997 shared_memory_offset_);
998 decoder_->set_unsafe_es3_apis_enabled(true);
999 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1000 .WillOnce(SetArgPointee<2>(GL_TRUE))
1001 .RetiresOnSaturation();
1002 EXPECT_CALL(*gl_, GetError())
1003 .WillOnce(Return(GL_NO_ERROR))
1004 .RetiresOnSaturation();
1005 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1008 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformBlockivBadProgramFails) {
1009 GetActiveUniformBlockiv cmd;
1010 typedef GetActiveUniformBlockiv::Result Result;
1011 Result* result = static_cast<Result*>(shared_memory_address_);
1012 result->SetNumResults(0);
1013 cmd.Init(kInvalidClientId,
1015 GL_UNIFORM_BLOCK_BINDING,
1016 shared_memory_id_,
1017 shared_memory_offset_);
1018 decoder_->set_unsafe_es3_apis_enabled(true);
1019 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1020 EXPECT_EQ(0, result->GetNumResults());
1021 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1024 TEST_P(GLES2DecoderWithShaderTest,
1025 GetActiveUniformBlockivBadSharedMemoryFails) {
1026 GetActiveUniformBlockiv cmd;
1027 decoder_->set_unsafe_es3_apis_enabled(true);
1028 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1029 .WillOnce(SetArgPointee<2>(GL_TRUE))
1030 .WillOnce(SetArgPointee<2>(GL_TRUE))
1031 .RetiresOnSaturation();
1032 EXPECT_CALL(*gl_, GetError())
1033 .WillOnce(Return(GL_NO_ERROR))
1034 .WillOnce(Return(GL_NO_ERROR))
1035 .RetiresOnSaturation();
1036 cmd.Init(client_program_id_,
1038 GL_UNIFORM_BLOCK_BINDING,
1039 kInvalidSharedMemoryId,
1040 shared_memory_offset_);
1041 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1042 cmd.Init(client_program_id_,
1044 GL_UNIFORM_BLOCK_BINDING,
1045 shared_memory_id_,
1046 kInvalidSharedMemoryOffset);
1047 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1050 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribSucceeds) {
1051 const GLuint kAttribIndex = 1;
1052 const uint32 kBucketId = 123;
1053 GetActiveAttrib cmd;
1054 typedef GetActiveAttrib::Result Result;
1055 Result* result = static_cast<Result*>(shared_memory_address_);
1056 result->success = 0;
1057 cmd.Init(client_program_id_,
1058 kAttribIndex,
1059 kBucketId,
1060 shared_memory_id_,
1061 shared_memory_offset_);
1062 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1063 EXPECT_NE(0, result->success);
1064 EXPECT_EQ(kAttrib2Size, result->size);
1065 EXPECT_EQ(kAttrib2Type, result->type);
1066 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1067 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1068 ASSERT_TRUE(bucket != NULL);
1069 EXPECT_EQ(
1071 memcmp(bucket->GetData(0, bucket->size()), kAttrib2Name, bucket->size()));
1074 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribResultNotInitFails) {
1075 const GLuint kAttribIndex = 1;
1076 const uint32 kBucketId = 123;
1077 GetActiveAttrib cmd;
1078 typedef GetActiveAttrib::Result Result;
1079 Result* result = static_cast<Result*>(shared_memory_address_);
1080 result->success = 1;
1081 cmd.Init(client_program_id_,
1082 kAttribIndex,
1083 kBucketId,
1084 shared_memory_id_,
1085 shared_memory_offset_);
1086 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1089 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadProgramFails) {
1090 const GLuint kAttribIndex = 1;
1091 const uint32 kBucketId = 123;
1092 GetActiveAttrib cmd;
1093 typedef GetActiveAttrib::Result Result;
1094 Result* result = static_cast<Result*>(shared_memory_address_);
1095 result->success = 0;
1096 cmd.Init(kInvalidClientId,
1097 kAttribIndex,
1098 kBucketId,
1099 shared_memory_id_,
1100 shared_memory_offset_);
1101 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1102 EXPECT_EQ(0, result->success);
1103 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1104 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1105 result->success = 0;
1106 cmd.Init(client_shader_id_,
1107 kAttribIndex,
1108 kBucketId,
1109 shared_memory_id_,
1110 shared_memory_offset_);
1111 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1112 EXPECT_EQ(0, result->success);
1113 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1114 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1117 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadIndexFails) {
1118 const uint32 kBucketId = 123;
1119 GetActiveAttrib cmd;
1120 typedef GetActiveAttrib::Result Result;
1121 Result* result = static_cast<Result*>(shared_memory_address_);
1122 result->success = 0;
1123 cmd.Init(client_program_id_,
1124 kBadAttribIndex,
1125 kBucketId,
1126 shared_memory_id_,
1127 shared_memory_offset_);
1128 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1129 EXPECT_EQ(0, result->success);
1130 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1133 TEST_P(GLES2DecoderWithShaderTest, GetActiveAttribBadSharedMemoryFails) {
1134 const GLuint kAttribIndex = 1;
1135 const uint32 kBucketId = 123;
1136 GetActiveAttrib cmd;
1137 cmd.Init(client_program_id_,
1138 kAttribIndex,
1139 kBucketId,
1140 kInvalidSharedMemoryId,
1141 shared_memory_offset_);
1142 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1143 cmd.Init(client_program_id_,
1144 kAttribIndex,
1145 kBucketId,
1146 shared_memory_id_,
1147 kInvalidSharedMemoryOffset);
1148 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1151 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesSucceeds) {
1152 const uint32 kBucketId = 123;
1153 const char kName0[] = "Cow";
1154 const char kName1[] = "Chicken";
1155 const char* kNames[] = { kName0, kName1 };
1156 const size_t kCount = arraysize(kNames);
1157 const char kValidStrEnd = 0;
1158 const GLuint kIndices[] = { 1, 2 };
1159 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1160 GetUniformIndices::Result* result =
1161 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1162 GetUniformIndices cmd;
1163 cmd.Init(client_program_id_,
1164 kBucketId,
1165 kSharedMemoryId,
1166 kSharedMemoryOffset);
1167 EXPECT_CALL(*gl_, GetUniformIndices(kServiceProgramId, kCount, _, _))
1168 .WillOnce(SetArrayArgument<3>(kIndices, kIndices + kCount))
1169 .RetiresOnSaturation();
1170 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1171 .WillOnce(SetArgPointee<2>(GL_TRUE))
1172 .RetiresOnSaturation();
1173 EXPECT_CALL(*gl_, GetError())
1174 .WillOnce(Return(GL_NO_ERROR))
1175 .WillOnce(Return(GL_NO_ERROR))
1176 .RetiresOnSaturation();
1177 decoder_->set_unsafe_es3_apis_enabled(true);
1178 result->size = 0;
1179 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1180 EXPECT_EQ(kCount, static_cast<size_t>(result->GetNumResults()));
1181 for (size_t ii = 0; ii < kCount; ++ii) {
1182 EXPECT_EQ(kIndices[ii], result->GetData()[ii]);
1184 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1185 decoder_->set_unsafe_es3_apis_enabled(false);
1186 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1189 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadProgramFails) {
1190 const uint32 kBucketId = 123;
1191 const char kName0[] = "Cow";
1192 const char kName1[] = "Chicken";
1193 const char* kNames[] = { kName0, kName1 };
1194 const size_t kCount = arraysize(kNames);
1195 const char kValidStrEnd = 0;
1196 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1197 GetUniformIndices::Result* result =
1198 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1199 decoder_->set_unsafe_es3_apis_enabled(true);
1200 GetUniformIndices cmd;
1201 // None-existant program
1202 cmd.Init(kInvalidClientId,
1203 kBucketId,
1204 kSharedMemoryId,
1205 kSharedMemoryOffset);
1206 result->size = 0;
1207 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1208 EXPECT_EQ(0, result->GetNumResults());
1209 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1210 // Unlinked program.
1211 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1212 .WillOnce(SetArgPointee<2>(GL_FALSE))
1213 .RetiresOnSaturation();
1214 cmd.Init(client_program_id_,
1215 kBucketId,
1216 kSharedMemoryId,
1217 kSharedMemoryOffset);
1218 result->size = 0;
1219 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1220 EXPECT_EQ(0, result->GetNumResults());
1221 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1224 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadParamsFails) {
1225 const uint32 kBucketId = 123;
1226 const char kName0[] = "Cow";
1227 const char kName1[] = "Chicken";
1228 const char* kNames[] = { kName0, kName1 };
1229 const size_t kCount = arraysize(kNames);
1230 const char kValidStrEnd = 0;
1231 const GLuint kIndices[] = { 1, 2 };
1232 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1233 GetUniformIndices::Result* result =
1234 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1235 GetUniformIndices cmd;
1236 cmd.Init(client_program_id_,
1237 kBucketId,
1238 kSharedMemoryId,
1239 kSharedMemoryOffset);
1240 EXPECT_CALL(*gl_, GetUniformIndices(kServiceProgramId, kCount, _, _))
1241 .WillOnce(SetArrayArgument<3>(kIndices, kIndices + kCount))
1242 .RetiresOnSaturation();
1243 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1244 .WillOnce(SetArgPointee<2>(GL_TRUE))
1245 .RetiresOnSaturation();
1246 EXPECT_CALL(*gl_, GetError())
1247 .WillOnce(Return(GL_NO_ERROR))
1248 .WillOnce(Return(GL_INVALID_VALUE))
1249 .RetiresOnSaturation();
1250 decoder_->set_unsafe_es3_apis_enabled(true);
1251 result->size = 0;
1252 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1253 EXPECT_EQ(0, result->GetNumResults());
1254 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1257 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesResultNotInitFails) {
1258 const uint32 kBucketId = 123;
1259 const char kName0[] = "Cow";
1260 const char kName1[] = "Chicken";
1261 const char* kNames[] = { kName0, kName1 };
1262 const size_t kCount = arraysize(kNames);
1263 const char kValidStrEnd = 0;
1264 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1265 GetUniformIndices::Result* result =
1266 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1267 decoder_->set_unsafe_es3_apis_enabled(true);
1268 GetUniformIndices cmd;
1269 result->size = 1976; // Any value other than 0.
1270 cmd.Init(kInvalidClientId,
1271 kBucketId,
1272 kSharedMemoryId,
1273 kSharedMemoryOffset);
1274 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1277 TEST_P(GLES2DecoderWithShaderTest, GetUniformIndicesBadSharedMemoryFails) {
1278 const uint32 kBucketId = 123;
1279 const char kName0[] = "Cow";
1280 const char kName1[] = "Chicken";
1281 const char* kNames[] = { kName0, kName1 };
1282 const size_t kCount = arraysize(kNames);
1283 const char kValidStrEnd = 0;
1284 SetBucketAsCStrings(kBucketId, kCount, kNames, kCount, kValidStrEnd);
1285 GetUniformIndices::Result* result =
1286 static_cast<GetUniformIndices::Result*>(shared_memory_address_);
1287 decoder_->set_unsafe_es3_apis_enabled(true);
1288 GetUniformIndices cmd;
1289 cmd.Init(client_program_id_,
1290 kBucketId,
1291 kInvalidSharedMemoryId,
1292 kSharedMemoryOffset);
1293 result->size = 0;
1294 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1295 cmd.Init(client_program_id_,
1296 kBucketId,
1297 kSharedMemoryId,
1298 kInvalidSharedMemoryOffset);
1299 result->size = 0;
1300 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1303 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivSucceeds) {
1304 const uint32 kBucketId = 123;
1305 const GLuint kIndices[] = { 1, 2 };
1306 const GLint kResults[] = { 1976, 321 };
1307 const size_t kCount = arraysize(kIndices);
1308 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1309 GetActiveUniformsiv::Result* result =
1310 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1311 GetActiveUniformsiv cmd;
1312 cmd.Init(client_program_id_,
1313 kBucketId,
1314 GL_UNIFORM_TYPE,
1315 kSharedMemoryId,
1316 kSharedMemoryOffset);
1317 EXPECT_CALL(*gl_,
1318 GetActiveUniformsiv(
1319 kServiceProgramId, kCount, _, GL_UNIFORM_TYPE, _))
1320 .WillOnce(SetArrayArgument<4>(kResults, kResults + kCount))
1321 .RetiresOnSaturation();
1322 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1323 .WillOnce(SetArgPointee<2>(GL_TRUE))
1324 .RetiresOnSaturation();
1325 EXPECT_CALL(*gl_, GetError())
1326 .WillOnce(Return(GL_NO_ERROR))
1327 .WillOnce(Return(GL_NO_ERROR))
1328 .RetiresOnSaturation();
1329 decoder_->set_unsafe_es3_apis_enabled(true);
1330 result->size = 0;
1331 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1332 EXPECT_EQ(kCount, static_cast<size_t>(result->GetNumResults()));
1333 for (size_t ii = 0; ii < kCount; ++ii) {
1334 EXPECT_EQ(kResults[ii], result->GetData()[ii]);
1336 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1337 decoder_->set_unsafe_es3_apis_enabled(false);
1338 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1341 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadProgramFails) {
1342 const uint32 kBucketId = 123;
1343 const GLuint kIndices[] = { 1, 2 };
1344 const size_t kCount = arraysize(kIndices);
1345 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1346 GetActiveUniformsiv::Result* result =
1347 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1348 decoder_->set_unsafe_es3_apis_enabled(true);
1349 GetActiveUniformsiv cmd;
1350 // None-existant program
1351 cmd.Init(kInvalidClientId,
1352 kBucketId,
1353 GL_UNIFORM_TYPE,
1354 kSharedMemoryId,
1355 kSharedMemoryOffset);
1356 result->size = 0;
1357 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1358 EXPECT_EQ(0, result->GetNumResults());
1359 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1360 // Unlinked program.
1361 cmd.Init(client_program_id_,
1362 kBucketId,
1363 GL_UNIFORM_TYPE,
1364 kSharedMemoryId,
1365 kSharedMemoryOffset);
1366 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1367 .WillOnce(SetArgPointee<2>(GL_FALSE))
1368 .RetiresOnSaturation();
1369 result->size = 0;
1370 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1371 EXPECT_EQ(0, result->GetNumResults());
1372 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1375 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadParamsFails) {
1376 const uint32 kBucketId = 123;
1377 const GLuint kIndices[] = { 1, 2 };
1378 const GLint kResults[] = { 1976, 321 };
1379 const size_t kCount = arraysize(kIndices);
1380 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1381 GetActiveUniformsiv::Result* result =
1382 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1383 GetActiveUniformsiv cmd;
1384 cmd.Init(client_program_id_,
1385 kBucketId,
1386 GL_UNIFORM_TYPE,
1387 kSharedMemoryId,
1388 kSharedMemoryOffset);
1389 EXPECT_CALL(*gl_,
1390 GetActiveUniformsiv(
1391 kServiceProgramId, kCount, _, GL_UNIFORM_TYPE, _))
1392 .WillOnce(SetArrayArgument<4>(kResults, kResults + kCount))
1393 .RetiresOnSaturation();
1394 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1395 .WillOnce(SetArgPointee<2>(GL_TRUE))
1396 .RetiresOnSaturation();
1397 EXPECT_CALL(*gl_, GetError())
1398 .WillOnce(Return(GL_NO_ERROR))
1399 .WillOnce(Return(GL_INVALID_VALUE))
1400 .RetiresOnSaturation();
1401 decoder_->set_unsafe_es3_apis_enabled(true);
1402 result->size = 0;
1403 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1404 EXPECT_EQ(0, result->GetNumResults());
1405 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1408 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivResultNotInitFails) {
1409 const uint32 kBucketId = 123;
1410 const GLuint kIndices[] = { 1, 2 };
1411 const size_t kCount = arraysize(kIndices);
1412 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1413 GetActiveUniformsiv::Result* result =
1414 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1415 GetActiveUniformsiv cmd;
1416 cmd.Init(client_program_id_,
1417 kBucketId,
1418 GL_UNIFORM_TYPE,
1419 kSharedMemoryId,
1420 kSharedMemoryOffset);
1421 decoder_->set_unsafe_es3_apis_enabled(true);
1422 result->size = 1976; // Any value other than 0.
1423 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1426 TEST_P(GLES2DecoderWithShaderTest, GetActiveUniformsivBadSharedMemoryFails) {
1427 const uint32 kBucketId = 123;
1428 const GLuint kIndices[] = { 1, 2 };
1429 const size_t kCount = arraysize(kIndices);
1430 SetBucketData(kBucketId, kIndices, sizeof(GLuint) * kCount);
1431 GetActiveUniformsiv::Result* result =
1432 static_cast<GetActiveUniformsiv::Result*>(shared_memory_address_);
1433 GetActiveUniformsiv cmd;
1434 decoder_->set_unsafe_es3_apis_enabled(true);
1435 result->size = 0;
1436 cmd.Init(client_program_id_,
1437 kBucketId,
1438 GL_UNIFORM_TYPE,
1439 kInvalidSharedMemoryId,
1440 kSharedMemoryOffset);
1441 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1442 result->size = 0;
1443 cmd.Init(client_program_id_,
1444 kBucketId,
1445 GL_UNIFORM_TYPE,
1446 kSharedMemoryId,
1447 kInvalidSharedMemoryOffset);
1448 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1451 TEST_P(GLES2DecoderWithShaderTest, GetShaderInfoLogValidArgs) {
1452 const uint32 kBucketId = 123;
1453 const char kSource0[] = "void main() { gl_Position = vec4(1.0); }";
1454 const char* kSource[] = {kSource0};
1455 const char kValidStrEnd = 0;
1456 SetBucketAsCStrings(kBucketId, 1, kSource, 1, kValidStrEnd);
1457 ShaderSourceBucket bucket_cmd;
1458 bucket_cmd.Init(client_shader_id_, kBucketId);
1459 EXPECT_EQ(error::kNoError, ExecuteCmd(bucket_cmd));
1460 ClearSharedMemory();
1462 const char* kInfo = "hello";
1463 CompileShader compile_cmd;
1464 GetShaderInfoLog cmd;
1465 EXPECT_CALL(*gl_, ShaderSource(kServiceShaderId, 1, _, _));
1466 EXPECT_CALL(*gl_, CompileShader(kServiceShaderId));
1467 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_COMPILE_STATUS, _))
1468 .WillOnce(SetArgPointee<2>(GL_FALSE))
1469 .RetiresOnSaturation();
1470 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_INFO_LOG_LENGTH, _))
1471 .WillOnce(SetArgPointee<2>(strlen(kInfo) + 1))
1472 .RetiresOnSaturation();
1473 EXPECT_CALL(*gl_, GetShaderInfoLog(kServiceShaderId, strlen(kInfo) + 1, _, _))
1474 .WillOnce(DoAll(SetArgPointee<2>(strlen(kInfo)),
1475 SetArrayArgument<3>(kInfo, kInfo + strlen(kInfo) + 1)));
1476 compile_cmd.Init(client_shader_id_);
1477 cmd.Init(client_shader_id_, kBucketId);
1478 EXPECT_EQ(error::kNoError, ExecuteCmd(compile_cmd));
1479 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1480 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1481 ASSERT_TRUE(bucket != NULL);
1482 EXPECT_EQ(strlen(kInfo) + 1, bucket->size());
1483 EXPECT_EQ(0,
1484 memcmp(bucket->GetData(0, bucket->size()), kInfo, bucket->size()));
1485 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1488 TEST_P(GLES2DecoderWithShaderTest, GetShaderInfoLogInvalidArgs) {
1489 const uint32 kBucketId = 123;
1490 GetShaderInfoLog cmd;
1491 cmd.Init(kInvalidClientId, kBucketId);
1492 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1493 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1496 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingSucceeds) {
1497 const GLuint kIndex = 1;
1498 const uint32 kBucketId = 123;
1499 const char kName[] = "HolyCow";
1500 const GLsizei kBufferSize = static_cast<GLsizei>(strlen(kName) + 1);
1501 const GLsizei kSize = 2;
1502 const GLenum kType = GL_FLOAT_VEC2;
1503 GetTransformFeedbackVarying cmd;
1504 typedef GetTransformFeedbackVarying::Result Result;
1505 Result* result = static_cast<Result*>(shared_memory_address_);
1506 result->success = 0;
1507 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1508 .WillOnce(SetArgPointee<2>(GL_TRUE))
1509 .RetiresOnSaturation();
1510 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId,
1511 GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, _))
1512 .WillOnce(SetArgPointee<2>(kBufferSize))
1513 .RetiresOnSaturation();
1514 EXPECT_CALL(*gl_, GetError())
1515 .WillOnce(Return(GL_NO_ERROR))
1516 .WillOnce(Return(GL_NO_ERROR))
1517 .RetiresOnSaturation();
1518 EXPECT_CALL(*gl_,
1519 GetTransformFeedbackVarying(
1520 kServiceProgramId, kIndex, _, _, _, _, _))
1521 .WillOnce(DoAll(SetArgPointee<3>(kBufferSize - 1),
1522 SetArgPointee<4>(kSize),
1523 SetArgPointee<5>(kType),
1524 SetArrayArgument<6>(kName, kName + kBufferSize)))
1525 .RetiresOnSaturation();
1526 cmd.Init(client_program_id_,
1527 kIndex,
1528 kBucketId,
1529 shared_memory_id_,
1530 shared_memory_offset_);
1531 decoder_->set_unsafe_es3_apis_enabled(true);
1532 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1533 EXPECT_NE(0, result->success);
1534 EXPECT_EQ(kSize, static_cast<GLsizei>(result->size));
1535 EXPECT_EQ(kType, static_cast<GLenum>(result->type));
1536 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1537 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1538 ASSERT_TRUE(bucket != NULL);
1539 EXPECT_EQ(
1540 0, memcmp(bucket->GetData(0, bucket->size()), kName, bucket->size()));
1541 decoder_->set_unsafe_es3_apis_enabled(false);
1542 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1545 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingNotInitFails) {
1546 const GLuint kIndex = 1;
1547 const uint32 kBucketId = 123;
1548 GetTransformFeedbackVarying cmd;
1549 typedef GetTransformFeedbackVarying::Result Result;
1550 Result* result = static_cast<Result*>(shared_memory_address_);
1551 result->success = 1;
1552 cmd.Init(client_program_id_,
1553 kIndex,
1554 kBucketId,
1555 shared_memory_id_,
1556 shared_memory_offset_);
1557 decoder_->set_unsafe_es3_apis_enabled(true);
1558 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1561 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingBadProgramFails) {
1562 const GLuint kIndex = 1;
1563 const uint32 kBucketId = 123;
1564 GetTransformFeedbackVarying cmd;
1565 typedef GetTransformFeedbackVarying::Result Result;
1566 Result* result = static_cast<Result*>(shared_memory_address_);
1567 result->success = 0;
1568 cmd.Init(kInvalidClientId,
1569 kIndex,
1570 kBucketId,
1571 shared_memory_id_,
1572 shared_memory_offset_);
1573 decoder_->set_unsafe_es3_apis_enabled(true);
1574 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1575 EXPECT_EQ(0, result->success);
1576 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1579 TEST_P(GLES2DecoderWithShaderTest, GetTransformFeedbackVaryingBadParamsFails) {
1580 const GLuint kIndex = 1;
1581 const uint32 kBucketId = 123;
1582 const GLsizei kBufferSize = 10;
1583 GetTransformFeedbackVarying cmd;
1584 typedef GetTransformFeedbackVarying::Result Result;
1585 Result* result = static_cast<Result*>(shared_memory_address_);
1586 result->success = 0;
1587 cmd.Init(client_program_id_,
1588 kIndex,
1589 kBucketId,
1590 shared_memory_id_,
1591 shared_memory_offset_);
1592 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
1593 .WillOnce(SetArgPointee<2>(GL_TRUE))
1594 .RetiresOnSaturation();
1595 EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId,
1596 GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, _))
1597 .WillOnce(SetArgPointee<2>(kBufferSize))
1598 .RetiresOnSaturation();
1599 EXPECT_CALL(*gl_, GetError())
1600 .WillOnce(Return(GL_NO_ERROR))
1601 .WillOnce(Return(GL_INVALID_VALUE))
1602 .RetiresOnSaturation();
1603 EXPECT_CALL(*gl_,
1604 GetTransformFeedbackVarying(
1605 kServiceProgramId, kIndex, _, _, _, _, _))
1606 .Times(1)
1607 .RetiresOnSaturation();
1608 decoder_->set_unsafe_es3_apis_enabled(true);
1609 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1610 EXPECT_EQ(0, result->success);
1611 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1614 TEST_P(GLES2DecoderWithShaderTest,
1615 GetTransformFeedbackVaryingBadSharedMemoryFails) {
1616 const GLuint kIndex = 1;
1617 const uint32 kBucketId = 123;
1618 GetTransformFeedbackVarying cmd;
1619 typedef GetTransformFeedbackVarying::Result Result;
1620 Result* result = static_cast<Result*>(shared_memory_address_);
1621 result->success = 0;
1622 decoder_->set_unsafe_es3_apis_enabled(true);
1623 cmd.Init(client_program_id_,
1624 kIndex,
1625 kBucketId,
1626 kInvalidSharedMemoryId,
1627 shared_memory_offset_);
1628 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1629 cmd.Init(client_program_id_,
1630 kIndex,
1631 kBucketId,
1632 shared_memory_id_,
1633 kInvalidSharedMemoryOffset);
1634 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1637 TEST_P(GLES2DecoderTest, CompileShaderValidArgs) {
1638 // ShaderSource should not actually call any GL calls yet.
1639 const uint32 kInBucketId = 123;
1640 const char kSource0[] = "void main() { gl_Position = vec4(1.0); }";
1641 const char* kSource[] = {kSource0};
1642 const char kValidStrEnd = 0;
1643 SetBucketAsCStrings(kInBucketId, 1, kSource, 1, kValidStrEnd);
1644 ShaderSourceBucket bucket_cmd;
1645 bucket_cmd.Init(client_shader_id_, kInBucketId);
1646 EXPECT_EQ(error::kNoError, ExecuteCmd(bucket_cmd));
1647 ClearSharedMemory();
1649 // Compile shader should not actually call any GL calls yet.
1650 CompileShader cmd;
1651 cmd.Init(client_shader_id_);
1652 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1654 // Getting the shader compilation state should trigger the actual GL calls.
1655 EXPECT_CALL(*gl_, ShaderSource(kServiceShaderId, 1, _, _));
1656 EXPECT_CALL(*gl_, CompileShader(kServiceShaderId));
1657 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_COMPILE_STATUS, _))
1658 .WillOnce(SetArgPointee<2>(GL_TRUE))
1659 .RetiresOnSaturation();
1660 EXPECT_CALL(*gl_, GetError())
1661 .WillOnce(Return(GL_NO_ERROR))
1662 .WillOnce(Return(GL_NO_ERROR))
1663 .RetiresOnSaturation();
1665 GetShaderiv::Result* result =
1666 static_cast<GetShaderiv::Result*>(shared_memory_address_);
1667 result->size = 0;
1668 GetShaderiv status_cmd;
1669 status_cmd.Init(client_shader_id_, GL_COMPILE_STATUS,
1670 kSharedMemoryId, kSharedMemoryOffset);
1671 EXPECT_EQ(error::kNoError, ExecuteCmd(status_cmd));
1672 EXPECT_EQ(GL_TRUE, *result->GetData());
1675 TEST_P(GLES2DecoderTest, CompileShaderInvalidArgs) {
1676 CompileShader cmd;
1677 cmd.Init(kInvalidClientId);
1678 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1679 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1680 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1681 cmd.Init(client_program_id_);
1682 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1683 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1684 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1687 TEST_P(GLES2DecoderTest, ShaderSourceBucketAndGetShaderSourceValidArgs) {
1688 const uint32 kInBucketId = 123;
1689 const uint32 kOutBucketId = 125;
1690 const char kSource0[] = "hello";
1691 const char* kSource[] = { kSource0 };
1692 const char kValidStrEnd = 0;
1693 SetBucketAsCStrings(kInBucketId, 1, kSource, 1, kValidStrEnd);
1694 ShaderSourceBucket cmd;
1695 cmd.Init(client_shader_id_, kInBucketId);
1696 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1697 ClearSharedMemory();
1698 GetShaderSource get_cmd;
1699 get_cmd.Init(client_shader_id_, kOutBucketId);
1700 EXPECT_EQ(error::kNoError, ExecuteCmd(get_cmd));
1701 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kOutBucketId);
1702 ASSERT_TRUE(bucket != NULL);
1703 EXPECT_EQ(sizeof(kSource0), bucket->size());
1704 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()),
1705 kSource0, bucket->size()));
1708 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1709 TEST_P(GLES2DecoderTest, ShaderSourceBucketWithProgramId) {
1710 const uint32 kBucketId = 123;
1711 const char kSource0[] = "hello";
1712 const char* kSource[] = { kSource0 };
1713 const char kValidStrEnd = 0;
1714 SetBucketAsCStrings(kBucketId, 1, kSource, 1, kValidStrEnd);
1715 ShaderSourceBucket cmd;
1716 cmd.Init(client_program_id_, kBucketId);
1717 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1718 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1720 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1722 TEST_P(GLES2DecoderTest, ShaderSourceStripComments) {
1723 const uint32 kInBucketId = 123;
1724 const char kSource0[] = "hello/*te\ast*/world//a\ab";
1725 const char* kSource[] = { kSource0 };
1726 const char kValidStrEnd = 0;
1727 SetBucketAsCStrings(kInBucketId, 1, kSource, 1, kValidStrEnd);
1728 ShaderSourceBucket cmd;
1729 cmd.Init(client_shader_id_, kInBucketId);
1730 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1731 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1734 TEST_P(GLES2DecoderWithShaderTest, Uniform1iValidArgs) {
1735 EXPECT_CALL(*gl_, Uniform1i(kUniform1RealLocation, 2));
1736 Uniform1i cmd;
1737 cmd.Init(kUniform1FakeLocation, 2);
1738 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1741 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivImmediateValidArgs) {
1742 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1743 EXPECT_CALL(*gl_,
1744 Uniform1iv(kUniform1RealLocation,
1746 reinterpret_cast<GLint*>(ImmediateDataAddress(&cmd))));
1747 GLint temp[1 * 2] = {
1750 cmd.Init(kUniform1FakeLocation, 1, &temp[0]);
1751 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1754 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivImmediateInvalidValidArgs) {
1755 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1756 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1757 GLint temp[1 * 2] = {
1760 cmd.Init(kUniform1FakeLocation, 2, &temp[0]);
1761 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1762 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1765 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivZeroCount) {
1766 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1767 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1768 GLint temp = 0;
1769 cmd.Init(kUniform1FakeLocation, 0, &temp);
1770 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1771 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1774 TEST_P(GLES2DecoderWithShaderTest, Uniform1iSamplerIsLmited) {
1775 EXPECT_CALL(*gl_, Uniform1i(_, _)).Times(0);
1776 Uniform1i cmd;
1777 cmd.Init(kUniform1FakeLocation, kNumTextureUnits);
1778 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1779 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1782 TEST_P(GLES2DecoderWithShaderTest, Uniform1ivSamplerIsLimited) {
1783 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1784 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1785 GLint temp[] = {kNumTextureUnits};
1786 cmd.Init(kUniform1FakeLocation, 1, &temp[0]);
1787 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(temp)));
1788 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1791 TEST_P(GLES2DecoderTest, BindAttribLocationBucket) {
1792 const uint32 kBucketId = 123;
1793 const GLint kLocation = 2;
1794 const char* kName = "testing";
1795 EXPECT_CALL(*gl_,
1796 BindAttribLocation(kServiceProgramId, kLocation, StrEq(kName)))
1797 .Times(1);
1798 SetBucketAsCString(kBucketId, kName);
1799 BindAttribLocationBucket cmd;
1800 cmd.Init(client_program_id_, kLocation, kBucketId);
1801 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1804 TEST_P(GLES2DecoderTest, BindAttribLocationBucketInvalidArgs) {
1805 const uint32 kBucketId = 123;
1806 const GLint kLocation = 2;
1807 const char* kName = "testing";
1808 EXPECT_CALL(*gl_, BindAttribLocation(_, _, _)).Times(0);
1809 BindAttribLocationBucket cmd;
1810 // check bucket does not exist.
1811 cmd.Init(client_program_id_, kLocation, kBucketId);
1812 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1813 // check bucket is empty.
1814 SetBucketAsCString(kBucketId, NULL);
1815 cmd.Init(client_program_id_, kLocation, kBucketId);
1816 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1817 // Check bad program id
1818 SetBucketAsCString(kBucketId, kName);
1819 cmd.Init(kInvalidClientId, kLocation, kBucketId);
1820 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1821 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1824 TEST_P(GLES2DecoderWithShaderTest, GetAttribLocation) {
1825 const uint32 kBucketId = 123;
1826 const char* kNonExistentName = "foobar";
1827 typedef GetAttribLocation::Result Result;
1828 Result* result = GetSharedMemoryAs<Result*>();
1829 SetBucketAsCString(kBucketId, kAttrib2Name);
1830 *result = -1;
1831 GetAttribLocation cmd;
1832 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1833 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1834 EXPECT_EQ(kAttrib2Location, *result);
1835 SetBucketAsCString(kBucketId, kNonExistentName);
1836 *result = -1;
1837 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1838 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1839 EXPECT_EQ(-1, *result);
1842 TEST_P(GLES2DecoderWithShaderTest, GetAttribLocationInvalidArgs) {
1843 const uint32 kBucketId = 123;
1844 typedef GetAttribLocation::Result Result;
1845 Result* result = GetSharedMemoryAs<Result*>();
1846 *result = -1;
1847 GetAttribLocation cmd;
1848 // Check no bucket
1849 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1850 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1851 EXPECT_EQ(-1, *result);
1852 // Check bad program id.
1853 SetBucketAsCString(kBucketId, kAttrib2Name);
1854 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1855 *result = -1;
1856 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1857 EXPECT_EQ(-1, *result);
1858 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1859 // Check bad memory
1860 cmd.Init(client_program_id_,
1861 kBucketId,
1862 kInvalidSharedMemoryId,
1863 kSharedMemoryOffset);
1864 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1865 cmd.Init(client_program_id_,
1866 kBucketId,
1867 kSharedMemoryId,
1868 kInvalidSharedMemoryOffset);
1869 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1872 TEST_P(GLES2DecoderWithShaderTest, GetFragDataLocation) {
1873 const uint32 kBucketId = 123;
1874 const GLint kLocation = 10;
1875 const char* kName = "color";
1876 typedef GetFragDataLocation::Result Result;
1877 Result* result = GetSharedMemoryAs<Result*>();
1878 SetBucketAsCString(kBucketId, kName);
1879 *result = -1;
1880 GetFragDataLocation cmd;
1881 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1882 EXPECT_CALL(*gl_, GetFragDataLocation(kServiceProgramId, StrEq(kName)))
1883 .WillOnce(Return(kLocation))
1884 .RetiresOnSaturation();
1885 decoder_->set_unsafe_es3_apis_enabled(true);
1886 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1887 EXPECT_EQ(kLocation, *result);
1888 decoder_->set_unsafe_es3_apis_enabled(false);
1889 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1892 TEST_P(GLES2DecoderWithShaderTest, GetFragDataLocationInvalidArgs) {
1893 const uint32 kBucketId = 123;
1894 typedef GetFragDataLocation::Result Result;
1895 Result* result = GetSharedMemoryAs<Result*>();
1896 *result = -1;
1897 GetFragDataLocation cmd;
1898 decoder_->set_unsafe_es3_apis_enabled(true);
1899 // Check no bucket
1900 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1901 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1902 EXPECT_EQ(-1, *result);
1903 // Check bad program id.
1904 const char* kName = "color";
1905 SetBucketAsCString(kBucketId, kName);
1906 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1907 *result = -1;
1908 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1909 EXPECT_EQ(-1, *result);
1910 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1911 // Check bad memory
1912 cmd.Init(client_program_id_,
1913 kBucketId,
1914 kInvalidSharedMemoryId,
1915 kSharedMemoryOffset);
1916 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1917 cmd.Init(client_program_id_,
1918 kBucketId,
1919 kSharedMemoryId,
1920 kInvalidSharedMemoryOffset);
1921 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1924 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlockIndex) {
1925 const uint32 kBucketId = 123;
1926 const GLuint kIndex = 10;
1927 const char* kName = "color";
1928 typedef GetUniformBlockIndex::Result Result;
1929 Result* result = GetSharedMemoryAs<Result*>();
1930 SetBucketAsCString(kBucketId, kName);
1931 *result = GL_INVALID_INDEX;
1932 GetUniformBlockIndex cmd;
1933 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1934 EXPECT_CALL(*gl_, GetUniformBlockIndex(kServiceProgramId, StrEq(kName)))
1935 .WillOnce(Return(kIndex))
1936 .RetiresOnSaturation();
1937 decoder_->set_unsafe_es3_apis_enabled(true);
1938 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1939 EXPECT_EQ(kIndex, *result);
1940 decoder_->set_unsafe_es3_apis_enabled(false);
1941 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
1944 TEST_P(GLES2DecoderWithShaderTest, GetUniformBlockIndexInvalidArgs) {
1945 const uint32 kBucketId = 123;
1946 typedef GetUniformBlockIndex::Result Result;
1947 Result* result = GetSharedMemoryAs<Result*>();
1948 *result = GL_INVALID_INDEX;
1949 GetUniformBlockIndex cmd;
1950 decoder_->set_unsafe_es3_apis_enabled(true);
1951 // Check no bucket
1952 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1953 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1954 EXPECT_EQ(GL_INVALID_INDEX, *result);
1955 // Check bad program id.
1956 const char* kName = "color";
1957 SetBucketAsCString(kBucketId, kName);
1958 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1959 *result = GL_INVALID_INDEX;
1960 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1961 EXPECT_EQ(GL_INVALID_INDEX, *result);
1962 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1963 // Check bad memory
1964 cmd.Init(client_program_id_,
1965 kBucketId,
1966 kInvalidSharedMemoryId,
1967 kSharedMemoryOffset);
1968 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1969 cmd.Init(client_program_id_,
1970 kBucketId,
1971 kSharedMemoryId,
1972 kInvalidSharedMemoryOffset);
1973 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1976 TEST_P(GLES2DecoderWithShaderTest, GetUniformLocation) {
1977 const uint32 kBucketId = 123;
1978 const char* kNonExistentName = "foobar";
1979 typedef GetUniformLocation::Result Result;
1980 Result* result = GetSharedMemoryAs<Result*>();
1981 SetBucketAsCString(kBucketId, kUniform2Name);
1982 *result = -1;
1983 GetUniformLocation cmd;
1984 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1985 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1986 EXPECT_EQ(kUniform2FakeLocation, *result);
1987 SetBucketAsCString(kBucketId, kNonExistentName);
1988 *result = -1;
1989 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
1990 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1991 EXPECT_EQ(-1, *result);
1994 TEST_P(GLES2DecoderWithShaderTest, GetUniformLocationInvalidArgs) {
1995 const uint32 kBucketId = 123;
1996 typedef GetUniformLocation::Result Result;
1997 Result* result = GetSharedMemoryAs<Result*>();
1998 *result = -1;
1999 GetUniformLocation cmd;
2000 // Check no bucket
2001 cmd.Init(client_program_id_, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2002 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2003 EXPECT_EQ(-1, *result);
2004 // Check bad program id.
2005 SetBucketAsCString(kBucketId, kUniform2Name);
2006 cmd.Init(kInvalidClientId, kBucketId, kSharedMemoryId, kSharedMemoryOffset);
2007 *result = -1;
2008 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2009 EXPECT_EQ(-1, *result);
2010 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2011 // Check bad memory
2012 cmd.Init(client_program_id_,
2013 kBucketId,
2014 kInvalidSharedMemoryId,
2015 kSharedMemoryOffset);
2016 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2017 cmd.Init(client_program_id_,
2018 kBucketId,
2019 kSharedMemoryId,
2020 kInvalidSharedMemoryOffset);
2021 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2024 TEST_P(GLES2DecoderWithShaderTest, UniformBlockBindingValidArgs) {
2025 EXPECT_CALL(*gl_, UniformBlockBinding(kServiceProgramId, 2, 3));
2026 SpecializedSetup<cmds::UniformBlockBinding, 0>(true);
2027 cmds::UniformBlockBinding cmd;
2028 cmd.Init(client_program_id_, 2, 3);
2029 decoder_->set_unsafe_es3_apis_enabled(true);
2030 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2031 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2032 decoder_->set_unsafe_es3_apis_enabled(false);
2033 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
2036 TEST_P(GLES2DecoderWithShaderTest, BindUniformLocationCHROMIUMBucket) {
2037 const uint32 kBucketId = 123;
2038 const GLint kLocation = 2;
2039 const char* kName = "testing";
2040 const char* kBadName1 = "gl_testing";
2041 const char* kBadName2 = "testing[1]";
2043 SetBucketAsCString(kBucketId, kName);
2044 BindUniformLocationCHROMIUMBucket cmd;
2045 cmd.Init(client_program_id_,
2046 kLocation,
2047 kBucketId);
2048 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2049 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2050 // check negative location
2051 SetBucketAsCString(kBucketId, kName);
2052 cmd.Init(client_program_id_, -1, kBucketId);
2053 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2054 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2055 // check highest location
2056 SetBucketAsCString(kBucketId, kName);
2057 GLint kMaxLocation =
2058 (kMaxFragmentUniformVectors + kMaxVertexUniformVectors) * 4 - 1;
2059 cmd.Init(client_program_id_,
2060 kMaxLocation,
2061 kBucketId);
2062 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2063 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2064 // check too high location
2065 SetBucketAsCString(kBucketId, kName);
2066 cmd.Init(client_program_id_,
2067 kMaxLocation + 1,
2068 kBucketId);
2069 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2070 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2071 // check bad name "gl_..."
2072 SetBucketAsCString(kBucketId, kBadName1);
2073 cmd.Init(client_program_id_,
2074 kLocation,
2075 kBucketId);
2076 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2077 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2078 // check bad name "name[1]" non zero
2079 SetBucketAsCString(kBucketId, kBadName2);
2080 cmd.Init(client_program_id_,
2081 kLocation,
2082 kBucketId);
2083 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2084 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2087 TEST_P(GLES2DecoderManualInitTest, ClearUniformsBeforeFirstProgramUse) {
2088 base::CommandLine command_line(0, NULL);
2089 command_line.AppendSwitchASCII(
2090 switches::kGpuDriverBugWorkarounds,
2091 base::IntToString(gpu::CLEAR_UNIFORMS_BEFORE_FIRST_PROGRAM_USE));
2092 InitState init;
2093 init.has_alpha = true;
2094 init.request_alpha = true;
2095 init.bind_generates_resource = true;
2096 InitDecoderWithCommandLine(init, &command_line);
2098 static AttribInfo attribs[] = {
2100 kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location,
2103 kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location,
2106 kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location,
2109 static UniformInfo uniforms[] = {
2110 {kUniform1Name, kUniform1Size, kUniform1Type, kUniform1FakeLocation,
2111 kUniform1RealLocation, kUniform1DesiredLocation},
2112 {kUniform2Name, kUniform2Size, kUniform2Type, kUniform2FakeLocation,
2113 kUniform2RealLocation, kUniform2DesiredLocation},
2114 {kUniform3Name, kUniform3Size, kUniform3Type, kUniform3FakeLocation,
2115 kUniform3RealLocation, kUniform3DesiredLocation},
2117 SetupShader(attribs,
2118 arraysize(attribs),
2119 uniforms,
2120 arraysize(uniforms),
2121 client_program_id_,
2122 kServiceProgramId,
2123 client_vertex_shader_id_,
2124 kServiceVertexShaderId,
2125 client_fragment_shader_id_,
2126 kServiceFragmentShaderId);
2127 TestHelper::SetupExpectationsForClearingUniforms(
2128 gl_.get(), uniforms, arraysize(uniforms));
2132 EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
2133 .Times(1)
2134 .RetiresOnSaturation();
2135 cmds::UseProgram cmd;
2136 cmd.Init(client_program_id_);
2137 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2141 // TODO(gman): DeleteProgram
2143 // TODO(gman): UseProgram
2145 // TODO(gman): DeleteShader
2147 } // namespace gles2
2148 } // namespace gpu