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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.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
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/gles2_cmd_decoder_unittest_base.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 InSequence s; 1153 InSequence s;
1154 1154
1155 EXPECT_CALL(*gl_, 1155 EXPECT_CALL(*gl_,
1156 AttachShader(program_service_id, vertex_shader_service_id)) 1156 AttachShader(program_service_id, vertex_shader_service_id))
1157 .Times(1) 1157 .Times(1)
1158 .RetiresOnSaturation(); 1158 .RetiresOnSaturation();
1159 EXPECT_CALL(*gl_, 1159 EXPECT_CALL(*gl_,
1160 AttachShader(program_service_id, fragment_shader_service_id)) 1160 AttachShader(program_service_id, fragment_shader_service_id))
1161 .Times(1) 1161 .Times(1)
1162 .RetiresOnSaturation(); 1162 .RetiresOnSaturation();
1163 EXPECT_CALL(*gl_, LinkProgram(program_service_id)) 1163 TestHelper::SetupShader(
1164 .Times(1) 1164 gl_.get(), attribs, num_attribs, uniforms, num_uniforms,
1165 .RetiresOnSaturation(); 1165 program_service_id);
1166 EXPECT_CALL(*gl_, GetProgramiv(program_service_id, GL_LINK_STATUS, _))
1167 .WillOnce(SetArgumentPointee<2>(GL_TRUE))
1168 .RetiresOnSaturation();
1169 EXPECT_CALL(*gl_,
1170 GetProgramiv(program_service_id, GL_INFO_LOG_LENGTH, _))
1171 .WillOnce(SetArgumentPointee<2>(0))
1172 .RetiresOnSaturation();
1173 EXPECT_CALL(*gl_,
1174 GetProgramiv(program_service_id, GL_ACTIVE_ATTRIBUTES, _))
1175 .WillOnce(SetArgumentPointee<2>(num_attribs))
1176 .RetiresOnSaturation();
1177 size_t max_attrib_len = 0;
1178 for (size_t ii = 0; ii < num_attribs; ++ii) {
1179 size_t len = strlen(attribs[ii].name) + 1;
1180 max_attrib_len = std::max(max_attrib_len, len);
1181 }
1182 EXPECT_CALL(*gl_,
1183 GetProgramiv(program_service_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
1184 .WillOnce(SetArgumentPointee<2>(max_attrib_len))
1185 .RetiresOnSaturation();
1186 for (size_t ii = 0; ii < num_attribs; ++ii) {
1187 const AttribInfo& info = attribs[ii];
1188 EXPECT_CALL(*gl_,
1189 GetActiveAttrib(program_service_id, ii, max_attrib_len, _, _, _, _))
1190 .WillOnce(DoAll(
1191 SetArgumentPointee<3>(strlen(info.name)),
1192 SetArgumentPointee<4>(info.size),
1193 SetArgumentPointee<5>(info.type),
1194 SetArrayArgument<6>(info.name,
1195 info.name + strlen(info.name) + 1)))
1196 .RetiresOnSaturation();
1197 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
1198 EXPECT_CALL(*gl_, GetAttribLocation(program_service_id,
1199 StrEq(info.name)))
1200 .WillOnce(Return(info.location))
1201 .RetiresOnSaturation();
1202 }
1203 }
1204 EXPECT_CALL(*gl_,
1205 GetProgramiv(program_service_id, GL_ACTIVE_UNIFORMS, _))
1206 .WillOnce(SetArgumentPointee<2>(num_uniforms))
1207 .RetiresOnSaturation();
1208 size_t max_uniform_len = 0;
1209 for (size_t ii = 0; ii < num_uniforms; ++ii) {
1210 size_t len = strlen(uniforms[ii].name) + 1;
1211 max_uniform_len = std::max(max_uniform_len, len);
1212 }
1213 EXPECT_CALL(*gl_,
1214 GetProgramiv(program_service_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
1215 .WillOnce(SetArgumentPointee<2>(max_uniform_len))
1216 .RetiresOnSaturation();
1217 for (size_t ii = 0; ii < num_uniforms; ++ii) {
1218 const UniformInfo& info = uniforms[ii];
1219 EXPECT_CALL(*gl_,
1220 GetActiveUniform(program_service_id, ii, max_uniform_len, _, _, _, _))
1221 .WillOnce(DoAll(
1222 SetArgumentPointee<3>(strlen(info.name)),
1223 SetArgumentPointee<4>(info.size),
1224 SetArgumentPointee<5>(info.type),
1225 SetArrayArgument<6>(info.name,
1226 info.name + strlen(info.name) + 1)))
1227 .RetiresOnSaturation();
1228 if (!ProgramManager::IsInvalidPrefix(info.name, strlen(info.name))) {
1229 EXPECT_CALL(*gl_, GetUniformLocation(program_service_id,
1230 StrEq(info.name)))
1231 .WillOnce(Return(info.real_location))
1232 .RetiresOnSaturation();
1233 if (info.size > 1) {
1234 std::string base_name = info.name;
1235 size_t array_pos = base_name.rfind("[0]");
1236 if (base_name.size() > 3 && array_pos == base_name.size() - 3) {
1237 base_name = base_name.substr(0, base_name.size() - 3);
1238 }
1239 for (GLsizei jj = 1; jj < info.size; ++jj) {
1240 std::string element_name(
1241 std::string(base_name) + "[" + base::IntToString(jj) + "]");
1242 EXPECT_CALL(*gl_, GetUniformLocation(program_service_id,
1243 StrEq(element_name)))
1244 .WillOnce(Return(info.real_location + jj * 2))
1245 .RetiresOnSaturation();
1246 }
1247 }
1248 }
1249 }
1250 } 1166 }
1251 1167
1252 DoCreateShader( 1168 DoCreateShader(
1253 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id); 1169 GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id);
1254 DoCreateShader( 1170 DoCreateShader(
1255 GL_FRAGMENT_SHADER, fragment_shader_client_id, 1171 GL_FRAGMENT_SHADER, fragment_shader_client_id,
1256 fragment_shader_service_id); 1172 fragment_shader_service_id);
1257 1173
1258 GetShaderInfo(vertex_shader_client_id)->SetStatus(true, "", NULL); 1174 GetShaderInfo(vertex_shader_client_id)->SetStatus(true, "", NULL);
1259 GetShaderInfo(fragment_shader_client_id)->SetStatus(true, "", NULL); 1175 GetShaderInfo(fragment_shader_client_id)->SetStatus(true, "", NULL);
1260 1176
1261 AttachShader attach_cmd; 1177 AttachShader attach_cmd;
1262 attach_cmd.Init(program_client_id, vertex_shader_client_id); 1178 attach_cmd.Init(program_client_id, vertex_shader_client_id);
1263 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd)); 1179 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1264 1180
1265 attach_cmd.Init(program_client_id, fragment_shader_client_id); 1181 attach_cmd.Init(program_client_id, fragment_shader_client_id);
1266 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd)); 1182 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
1267 1183
1268 LinkProgram link_cmd; 1184 LinkProgram link_cmd;
1269 link_cmd.Init(program_client_id); 1185 link_cmd.Init(program_client_id);
1270 1186
1271 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd)); 1187 EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
1272 1188
1273 // Assume the next command will be UseProgram. 1189 // Assume the next command will be UseProgram.
1274 SetupExpectationsForClearingUniforms(uniforms, num_uniforms); 1190 SetupExpectationsForClearingUniforms(uniforms, num_uniforms);
1275 } 1191 }
1276 1192
1277 void GLES2DecoderTestBase::SetupExpectationsForClearingUniforms(
1278 UniformInfo* uniforms, size_t num_uniforms) {
1279 for (size_t ii = 0; ii < num_uniforms; ++ii) {
1280 const UniformInfo& info = uniforms[ii];
1281 switch (info.type) {
1282 case GL_FLOAT:
1283 EXPECT_CALL(*gl_, Uniform1fv(info.real_location, info.size, _))
1284 .Times(1)
1285 .RetiresOnSaturation();
1286 break;
1287 case GL_FLOAT_VEC2:
1288 EXPECT_CALL(*gl_, Uniform2fv(info.real_location, info.size, _))
1289 .Times(1)
1290 .RetiresOnSaturation();
1291 break;
1292 case GL_FLOAT_VEC3:
1293 EXPECT_CALL(*gl_, Uniform3fv(info.real_location, info.size, _))
1294 .Times(1)
1295 .RetiresOnSaturation();
1296 break;
1297 case GL_FLOAT_VEC4:
1298 EXPECT_CALL(*gl_, Uniform4fv(info.real_location, info.size, _))
1299 .Times(1)
1300 .RetiresOnSaturation();
1301 break;
1302 case GL_INT:
1303 case GL_BOOL:
1304 case GL_SAMPLER_2D:
1305 case GL_SAMPLER_CUBE:
1306 case GL_SAMPLER_EXTERNAL_OES:
1307 case GL_SAMPLER_3D_OES:
1308 case GL_SAMPLER_2D_RECT_ARB:
1309 EXPECT_CALL(*gl_, Uniform1iv(info.real_location, info.size, _))
1310 .Times(1)
1311 .RetiresOnSaturation();
1312 break;
1313 case GL_INT_VEC2:
1314 case GL_BOOL_VEC2:
1315 EXPECT_CALL(*gl_, Uniform2iv(info.real_location, info.size, _))
1316 .Times(1)
1317 .RetiresOnSaturation();
1318 break;
1319 case GL_INT_VEC3:
1320 case GL_BOOL_VEC3:
1321 EXPECT_CALL(*gl_, Uniform3iv(info.real_location, info.size, _))
1322 .Times(1)
1323 .RetiresOnSaturation();
1324 break;
1325 case GL_INT_VEC4:
1326 case GL_BOOL_VEC4:
1327 EXPECT_CALL(*gl_, Uniform4iv(info.real_location, info.size, _))
1328 .Times(1)
1329 .RetiresOnSaturation();
1330 break;
1331 case GL_FLOAT_MAT2:
1332 EXPECT_CALL(*gl_, UniformMatrix2fv(
1333 info.real_location, info.size, false, _))
1334 .Times(1)
1335 .RetiresOnSaturation();
1336 break;
1337 case GL_FLOAT_MAT3:
1338 EXPECT_CALL(*gl_, UniformMatrix3fv(
1339 info.real_location, info.size, false, _))
1340 .Times(1)
1341 .RetiresOnSaturation();
1342 break;
1343 case GL_FLOAT_MAT4:
1344 EXPECT_CALL(*gl_, UniformMatrix4fv(
1345 info.real_location, info.size, false, _))
1346 .Times(1)
1347 .RetiresOnSaturation();
1348 break;
1349 default:
1350 NOTREACHED();
1351 break;
1352 }
1353 }
1354 }
1355
1356 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) { 1193 void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) {
1357 EXPECT_CALL(*gl_, EnableVertexAttribArray(index)) 1194 EXPECT_CALL(*gl_, EnableVertexAttribArray(index))
1358 .Times(1) 1195 .Times(1)
1359 .RetiresOnSaturation(); 1196 .RetiresOnSaturation();
1360 EnableVertexAttribArray cmd; 1197 EnableVertexAttribArray cmd;
1361 cmd.Init(index); 1198 cmd.Init(index);
1362 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 1199 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1363 } 1200 }
1364 1201
1365 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) { 1202 void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 num_vertices, buffer_id, GL_NO_ERROR); 1317 num_vertices, buffer_id, GL_NO_ERROR);
1481 } 1318 }
1482 1319
1483 void GLES2DecoderWithShaderTestBase::SetUp() { 1320 void GLES2DecoderWithShaderTestBase::SetUp() {
1484 GLES2DecoderTestBase::SetUp(); 1321 GLES2DecoderTestBase::SetUp();
1485 SetupDefaultProgram(); 1322 SetupDefaultProgram();
1486 } 1323 }
1487 1324
1488 } // namespace gles2 1325 } // namespace gles2
1489 } // namespace gpu 1326 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h ('k') | gpu/command_buffer/service/program_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698