Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: gpu/command_buffer/service/test_helper.cc

Issue 10389077: Consolidate GPU unit test expectiation functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix license Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/service/test_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/test_helper.h" 5 #include "gpu/command_buffer/service/test_helper.h"
6 6
7 #include "base/string_number_conversions.h"
7 #include "base/string_tokenizer.h" 8 #include "base/string_tokenizer.h"
8 #include "gpu/command_buffer/common/gl_mock.h" 9 #include "gpu/command_buffer/common/gl_mock.h"
9 #include "gpu/command_buffer/common/types.h" 10 #include "gpu/command_buffer/common/types.h"
10 #include "gpu/command_buffer/service/gl_utils.h" 11 #include "gpu/command_buffer/service/gl_utils.h"
12 #include "gpu/command_buffer/service/program_manager.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 14
13 #include <string.h> 15 #include <string.h>
14 16
15 using ::testing::_; 17 using ::testing::_;
16 using ::testing::DoAll; 18 using ::testing::DoAll;
17 using ::testing::InSequence; 19 using ::testing::InSequence;
18 using ::testing::MatcherCast; 20 using ::testing::MatcherCast;
19 using ::testing::Pointee; 21 using ::testing::Pointee;
20 using ::testing::Return; 22 using ::testing::Return;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 218
217 void TestHelper::SetupFeatureInfoInitExpectations( 219 void TestHelper::SetupFeatureInfoInitExpectations(
218 ::gfx::MockGLInterface* gl, const char* extensions) { 220 ::gfx::MockGLInterface* gl, const char* extensions) {
219 InSequence sequence; 221 InSequence sequence;
220 222
221 EXPECT_CALL(*gl, GetString(GL_EXTENSIONS)) 223 EXPECT_CALL(*gl, GetString(GL_EXTENSIONS))
222 .WillOnce(Return(reinterpret_cast<const uint8*>(extensions))) 224 .WillOnce(Return(reinterpret_cast<const uint8*>(extensions)))
223 .RetiresOnSaturation(); 225 .RetiresOnSaturation();
224 } 226 }
225 227
228 void TestHelper::SetupExpectationsForClearingUniforms(
229 ::gfx::MockGLInterface* gl, UniformInfo* uniforms, size_t num_uniforms) {
230 for (size_t ii = 0; ii < num_uniforms; ++ii) {
231 const UniformInfo& info = uniforms[ii];
232 switch (info.type) {
233 case GL_FLOAT:
234 EXPECT_CALL(*gl, Uniform1fv(info.real_location, info.size, _))
235 .Times(1)
236 .RetiresOnSaturation();
237 break;
238 case GL_FLOAT_VEC2:
239 EXPECT_CALL(*gl, Uniform2fv(info.real_location, info.size, _))
240 .Times(1)
241 .RetiresOnSaturation();
242 break;
243 case GL_FLOAT_VEC3:
244 EXPECT_CALL(*gl, Uniform3fv(info.real_location, info.size, _))
245 .Times(1)
246 .RetiresOnSaturation();
247 break;
248 case GL_FLOAT_VEC4:
249 EXPECT_CALL(*gl, Uniform4fv(info.real_location, info.size, _))
250 .Times(1)
251 .RetiresOnSaturation();
252 break;
253 case GL_INT:
254 case GL_BOOL:
255 case GL_SAMPLER_2D:
256 case GL_SAMPLER_CUBE:
257 case GL_SAMPLER_EXTERNAL_OES:
258 case GL_SAMPLER_3D_OES:
259 case GL_SAMPLER_2D_RECT_ARB:
260 EXPECT_CALL(*gl, Uniform1iv(info.real_location, info.size, _))
261 .Times(1)
262 .RetiresOnSaturation();
263 break;
264 case GL_INT_VEC2:
265 case GL_BOOL_VEC2:
266 EXPECT_CALL(*gl, Uniform2iv(info.real_location, info.size, _))
267 .Times(1)
268 .RetiresOnSaturation();
269 break;
270 case GL_INT_VEC3:
271 case GL_BOOL_VEC3:
272 EXPECT_CALL(*gl, Uniform3iv(info.real_location, info.size, _))
273 .Times(1)
274 .RetiresOnSaturation();
275 break;
276 case GL_INT_VEC4:
277 case GL_BOOL_VEC4:
278 EXPECT_CALL(*gl, Uniform4iv(info.real_location, info.size, _))
279 .Times(1)
280 .RetiresOnSaturation();
281 break;
282 case GL_FLOAT_MAT2:
283 EXPECT_CALL(*gl, UniformMatrix2fv(
284 info.real_location, info.size, false, _))
285 .Times(1)
286 .RetiresOnSaturation();
287 break;
288 case GL_FLOAT_MAT3:
289 EXPECT_CALL(*gl, UniformMatrix3fv(
290 info.real_location, info.size, false, _))
291 .Times(1)
292 .RetiresOnSaturation();
293 break;
294 case GL_FLOAT_MAT4:
295 EXPECT_CALL(*gl, UniformMatrix4fv(
296 info.real_location, info.size, false, _))
297 .Times(1)
298 .RetiresOnSaturation();
299 break;
300 default:
301 NOTREACHED();
302 break;
303 }
304 }
305 }
306
307 void TestHelper::SetupShader(
308 ::gfx::MockGLInterface* gl,
309 AttribInfo* attribs, size_t num_attribs,
310 UniformInfo* uniforms, size_t num_uniforms,
311 GLuint service_id) {
312 InSequence s;
313
314 EXPECT_CALL(*gl,
315 LinkProgram(service_id))
316 .Times(1)
317 .RetiresOnSaturation();
318 EXPECT_CALL(*gl,
319 GetProgramiv(service_id, GL_LINK_STATUS, _))
320 .WillOnce(SetArgumentPointee<2>(1))
321 .RetiresOnSaturation();
322 EXPECT_CALL(*gl,
323 GetProgramiv(service_id, GL_INFO_LOG_LENGTH, _))
324 .WillOnce(SetArgumentPointee<2>(0))
325 .RetiresOnSaturation();
326 EXPECT_CALL(*gl,
327 GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTES, _))
328 .WillOnce(SetArgumentPointee<2>(num_attribs))
329 .RetiresOnSaturation();
330 size_t max_attrib_len = 0;
331 for (size_t ii = 0; ii < num_attribs; ++ii) {
332 size_t len = strlen(attribs[ii].name) + 1;
333 max_attrib_len = std::max(max_attrib_len, len);
334 }
335 EXPECT_CALL(*gl,
336 GetProgramiv(service_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
337 .WillOnce(SetArgumentPointee<2>(max_attrib_len))
338 .RetiresOnSaturation();
339 for (size_t ii = 0; ii < num_attribs; ++ii) {
340 const AttribInfo& info = attribs[ii];
341 EXPECT_CALL(*gl,
342 GetActiveAttrib(service_id, ii,
343 max_attrib_len, _, _, _, _))
344 .WillOnce(DoAll(
345 SetArgumentPointee<3>(strlen(info.name)),
346 SetArgumentPointee<4>(info.size),
347 SetArgumentPointee<5>(info.type),
348 SetArrayArgument<6>(info.name,
349 info.name + strlen(info.name) + 1)))
350 .RetiresOnSaturation();
351 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
352 EXPECT_CALL(*gl, GetAttribLocation(service_id, StrEq(info.name)))
353 .WillOnce(Return(info.location))
354 .RetiresOnSaturation();
355 }
356 }
357 EXPECT_CALL(*gl,
358 GetProgramiv(service_id, GL_ACTIVE_UNIFORMS, _))
359 .WillOnce(SetArgumentPointee<2>(num_uniforms))
360 .RetiresOnSaturation();
361 size_t max_uniform_len = 0;
362 for (size_t ii = 0; ii < num_uniforms; ++ii) {
363 size_t len = strlen(uniforms[ii].name) + 1;
364 max_uniform_len = std::max(max_uniform_len, len);
365 }
366 EXPECT_CALL(*gl,
367 GetProgramiv(service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
368 .WillOnce(SetArgumentPointee<2>(max_uniform_len))
369 .RetiresOnSaturation();
370 for (size_t ii = 0; ii < num_uniforms; ++ii) {
371 const UniformInfo& info = uniforms[ii];
372 EXPECT_CALL(*gl,
373 GetActiveUniform(service_id, ii,
374 max_uniform_len, _, _, _, _))
375 .WillOnce(DoAll(
376 SetArgumentPointee<3>(strlen(info.name)),
377 SetArgumentPointee<4>(info.size),
378 SetArgumentPointee<5>(info.type),
379 SetArrayArgument<6>(info.name,
380 info.name + strlen(info.name) + 1)))
381 .RetiresOnSaturation();
382 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
383 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(info.name)))
384 .WillOnce(Return(info.real_location))
385 .RetiresOnSaturation();
386 if (info.size > 1) {
387 std::string base_name = info.name;
388 size_t array_pos = base_name.rfind("[0]");
389 if (base_name.size() > 3 && array_pos == base_name.size() - 3) {
390 base_name = base_name.substr(0, base_name.size() - 3);
391 }
392 for (GLsizei jj = 1; jj < info.size; ++jj) {
393 std::string element_name(
394 std::string(base_name) + "[" + base::IntToString(jj) + "]");
395 EXPECT_CALL(*gl, GetUniformLocation(service_id, StrEq(element_name)))
396 .WillOnce(Return(info.real_location + jj * 2))
397 .RetiresOnSaturation();
398 }
399 }
400 }
401 }
402 }
403
404
226 } // namespace gles2 405 } // namespace gles2
227 } // namespace gpu 406 } // namespace gpu
228 407
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/test_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698