Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / common / gles2_cmd_utils_unittest.cc
blob54ad3b5915244415c7f88b7e2c5822425016c556
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
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
7 #include <limits>
8 #include <GLES2/gl2.h>
9 #include <GLES2/gl2ext.h>
10 #include <GLES2/gl2extchromium.h>
11 #include <GLES3/gl3.h>
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace gpu {
16 namespace gles2 {
18 class GLES2UtilTest : public testing:: Test {
19 protected:
20 GLES2Util util_;
23 TEST_F(GLES2UtilTest, SafeMultiplyUint32) {
24 uint32_t result = 0;
25 EXPECT_TRUE(SafeMultiplyUint32(2u, 3u, &result));
26 EXPECT_EQ(6u, result);
27 EXPECT_FALSE(SafeMultiplyUint32(0x80000000u, 2u, &result));
28 EXPECT_EQ(0u, result);
29 EXPECT_TRUE(SafeMultiplyUint32(0x2u, 0x7FFFFFFFu, &result));
30 EXPECT_EQ(0xFFFFFFFEu, result);
31 EXPECT_FALSE(SafeMultiplyUint32(2u, 0x80000000u, &result));
32 EXPECT_EQ(0u, result);
35 TEST_F(GLES2UtilTest, SafeAddUint32) {
36 uint32_t result = 0;
37 EXPECT_TRUE(SafeAddUint32(2u, 3u, &result));
38 EXPECT_EQ(5u, result);
39 EXPECT_FALSE(SafeAddUint32(0x80000000u, 0x80000000u, &result));
40 EXPECT_EQ(0u, result);
41 EXPECT_TRUE(SafeAddUint32(0xFFFFFFFEu, 0x1u, &result));
42 EXPECT_EQ(0xFFFFFFFFu, result);
43 EXPECT_FALSE(SafeAddUint32(0xFFFFFFFEu, 0x2u, &result));
44 EXPECT_EQ(0u, result);
45 EXPECT_TRUE(SafeAddUint32(0x1u, 0xFFFFFFFEu, &result));
46 EXPECT_EQ(0xFFFFFFFFu, result);
47 EXPECT_FALSE(SafeAddUint32(0x2u, 0xFFFFFFFEu, &result));
48 EXPECT_EQ(0u, result);
51 TEST_F(GLES2UtilTest, SafeAddInt32) {
52 int32_t result = 0;
53 const int32_t kMax = std::numeric_limits<int32_t>::max();
54 const int32_t kMin = std::numeric_limits<int32_t>::min();
55 EXPECT_TRUE(SafeAddInt32(2, 3, &result));
56 EXPECT_EQ(5, result);
57 EXPECT_FALSE(SafeAddInt32(kMax, 1, &result));
58 EXPECT_EQ(0, result);
59 EXPECT_TRUE(SafeAddInt32(kMin + 1, -1, &result));
60 EXPECT_EQ(kMin, result);
61 EXPECT_FALSE(SafeAddInt32(kMin, -1, &result));
62 EXPECT_EQ(0, result);
63 EXPECT_TRUE(SafeAddInt32(kMax - 1, 1, &result));
64 EXPECT_EQ(kMax, result);
65 EXPECT_FALSE(SafeAddInt32(1, kMax, &result));
66 EXPECT_EQ(0, result);
67 EXPECT_TRUE(SafeAddInt32(-1, kMin + 1, &result));
68 EXPECT_EQ(kMin, result);
69 EXPECT_FALSE(SafeAddInt32(-1, kMin, &result));
70 EXPECT_EQ(0, result);
71 EXPECT_TRUE(SafeAddInt32(1, kMax - 1, &result));
72 EXPECT_EQ(kMax, result);
75 TEST_F(GLES2UtilTest, GLGetNumValuesReturned) {
76 EXPECT_EQ(0, util_.GLGetNumValuesReturned(GL_COMPRESSED_TEXTURE_FORMATS));
77 EXPECT_EQ(0, util_.GLGetNumValuesReturned(GL_SHADER_BINARY_FORMATS));
79 EXPECT_EQ(0, util_.num_compressed_texture_formats());
80 EXPECT_EQ(0, util_.num_shader_binary_formats());
82 util_.set_num_compressed_texture_formats(1);
83 util_.set_num_shader_binary_formats(2);
85 EXPECT_EQ(1, util_.GLGetNumValuesReturned(GL_COMPRESSED_TEXTURE_FORMATS));
86 EXPECT_EQ(2, util_.GLGetNumValuesReturned(GL_SHADER_BINARY_FORMATS));
88 EXPECT_EQ(1, util_.num_compressed_texture_formats());
89 EXPECT_EQ(2, util_.num_shader_binary_formats());
92 TEST_F(GLES2UtilTest, ComputeImageDataSizesFormats) {
93 const uint32_t kWidth = 16;
94 const uint32_t kHeight = 12;
95 uint32_t size;
96 uint32_t unpadded_row_size;
97 uint32_t padded_row_size;
98 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
99 kWidth, kHeight, 1, GL_RGB, GL_UNSIGNED_BYTE, 1,
100 &size, &unpadded_row_size, &padded_row_size));
101 EXPECT_EQ(kWidth * kHeight * 3, size);
102 EXPECT_EQ(kWidth * 3, padded_row_size);
103 EXPECT_EQ(padded_row_size, unpadded_row_size);
104 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
105 kWidth, kHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, &size,
106 &unpadded_row_size, &padded_row_size));
107 EXPECT_EQ(kWidth * kHeight * 4, size);
108 EXPECT_EQ(kWidth * 4, padded_row_size);
109 EXPECT_EQ(padded_row_size, unpadded_row_size);
110 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
111 kWidth, kHeight, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1, &size,
112 &unpadded_row_size, &padded_row_size));
113 EXPECT_EQ(kWidth * kHeight * 1, size);
114 EXPECT_EQ(kWidth * 1, padded_row_size);
115 EXPECT_EQ(padded_row_size, unpadded_row_size);
116 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
117 kWidth, kHeight, 1, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 1, &size,
118 &unpadded_row_size, &padded_row_size));
119 EXPECT_EQ(kWidth * kHeight * 2, size);
120 EXPECT_EQ(kWidth * 2, padded_row_size);
121 EXPECT_EQ(padded_row_size, unpadded_row_size);
122 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
123 kWidth, kHeight, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, 1, &size,
124 &unpadded_row_size, &padded_row_size));
125 EXPECT_EQ(kWidth * kHeight * 4, size);
126 EXPECT_EQ(kWidth * 4, padded_row_size);
127 EXPECT_EQ(padded_row_size, unpadded_row_size);
128 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
129 kWidth, kHeight, 1, GL_ALPHA, GL_UNSIGNED_BYTE, 1, &size,
130 &unpadded_row_size, &padded_row_size));
131 EXPECT_EQ(kWidth * kHeight * 1, size);
132 EXPECT_EQ(kWidth * 1, padded_row_size);
133 EXPECT_EQ(padded_row_size, unpadded_row_size);
134 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
135 kWidth, kHeight, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 1, &size,
136 &unpadded_row_size, &padded_row_size));
137 EXPECT_EQ(kWidth * kHeight * 2, size);
138 EXPECT_EQ(kWidth * 2, padded_row_size);
139 EXPECT_EQ(padded_row_size, unpadded_row_size);
140 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
141 kWidth, kHeight, 1, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, 1,
142 &size, &unpadded_row_size, &padded_row_size));
143 EXPECT_EQ(kWidth * kHeight * 4, size);
144 EXPECT_EQ(kWidth * 4, padded_row_size);
145 EXPECT_EQ(padded_row_size, unpadded_row_size);
146 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
147 kWidth, kHeight, 1, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, 1,
148 &size, &unpadded_row_size, &padded_row_size));
149 EXPECT_EQ(kWidth * kHeight * 3, size);
150 EXPECT_EQ(kWidth * 3, padded_row_size);
151 EXPECT_EQ(padded_row_size, unpadded_row_size);
152 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
153 kWidth, kHeight, 1, GL_RG, GL_UNSIGNED_BYTE, 1,
154 &size, &unpadded_row_size, &padded_row_size));
155 EXPECT_EQ(kWidth * kHeight * 2, size);
156 EXPECT_EQ(kWidth * 2, padded_row_size);
157 EXPECT_EQ(padded_row_size, unpadded_row_size);
158 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
159 kWidth, kHeight, 1, GL_RG_INTEGER, GL_UNSIGNED_BYTE, 1,
160 &size, &unpadded_row_size, &padded_row_size));
161 EXPECT_EQ(kWidth * kHeight * 2, size);
162 EXPECT_EQ(kWidth * 2, padded_row_size);
163 EXPECT_EQ(padded_row_size, unpadded_row_size);
164 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
165 kWidth, kHeight, 1, GL_RED, GL_UNSIGNED_BYTE, 1,
166 &size, &unpadded_row_size, &padded_row_size));
167 EXPECT_EQ(kWidth * kHeight * 1, size);
168 EXPECT_EQ(kWidth * 1, padded_row_size);
169 EXPECT_EQ(padded_row_size, unpadded_row_size);
170 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
171 kWidth, kHeight, 1, GL_RED_INTEGER, GL_UNSIGNED_BYTE, 1,
172 &size, &unpadded_row_size, &padded_row_size));
173 EXPECT_EQ(kWidth * kHeight * 1, size);
174 EXPECT_EQ(kWidth * 1, padded_row_size);
175 EXPECT_EQ(padded_row_size, unpadded_row_size);
178 TEST_F(GLES2UtilTest, ComputeImageDataSizeTypes) {
179 const uint32_t kWidth = 16;
180 const uint32_t kHeight = 12;
181 uint32_t size;
182 uint32_t unpadded_row_size;
183 uint32_t padded_row_size;
184 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
185 kWidth, kHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, &size,
186 &unpadded_row_size, &padded_row_size));
187 EXPECT_EQ(kWidth * kHeight * 4, size);
188 EXPECT_EQ(kWidth * 4, padded_row_size);
189 EXPECT_EQ(padded_row_size, unpadded_row_size);
190 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
191 kWidth, kHeight, 1, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 1, &size,
192 &unpadded_row_size, &padded_row_size));
193 EXPECT_EQ(kWidth * kHeight * 2, size);
194 EXPECT_EQ(kWidth * 2, padded_row_size);
195 EXPECT_EQ(padded_row_size, unpadded_row_size);
196 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
197 kWidth, kHeight, 1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 1, &size,
198 &unpadded_row_size, &padded_row_size));
199 EXPECT_EQ(kWidth * kHeight * 2, size);
200 EXPECT_EQ(kWidth * 2, padded_row_size);
201 EXPECT_EQ(padded_row_size, unpadded_row_size);
202 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
203 kWidth, kHeight, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 1, &size,
204 &unpadded_row_size, &padded_row_size));
205 EXPECT_EQ(kWidth * kHeight * 2, size);
206 EXPECT_EQ(kWidth * 2, padded_row_size);
207 EXPECT_EQ(padded_row_size, unpadded_row_size);
208 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
209 kWidth, kHeight, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 1, &size,
210 &unpadded_row_size, &padded_row_size));
211 EXPECT_EQ(kWidth * kHeight * 4, size);
212 EXPECT_EQ(kWidth * 4, padded_row_size);
213 EXPECT_EQ(padded_row_size, unpadded_row_size);
214 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
215 kWidth, kHeight, 1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, 1, &size,
216 &unpadded_row_size, &padded_row_size));
217 EXPECT_EQ(kWidth * kHeight * 4, size);
218 EXPECT_EQ(kWidth * 4, padded_row_size);
219 EXPECT_EQ(padded_row_size, unpadded_row_size);
220 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
221 kWidth, kHeight, 1, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 1, &size,
222 &unpadded_row_size, &padded_row_size));
223 EXPECT_EQ(kWidth * kHeight * 4, size);
224 EXPECT_EQ(kWidth * 4, padded_row_size);
225 EXPECT_EQ(padded_row_size, unpadded_row_size);
226 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
227 kWidth, kHeight, 1, GL_RGBA, GL_UNSIGNED_INT_5_9_9_9_REV, 1, &size,
228 &unpadded_row_size, &padded_row_size));
229 EXPECT_EQ(kWidth * kHeight * 4, size);
230 EXPECT_EQ(kWidth * 4, padded_row_size);
231 EXPECT_EQ(padded_row_size, unpadded_row_size);
232 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
233 kWidth, kHeight, 1, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
234 1, &size, &unpadded_row_size, &padded_row_size));
235 EXPECT_EQ(kWidth * kHeight * 8, size);
236 EXPECT_EQ(kWidth * 8, padded_row_size);
237 EXPECT_EQ(padded_row_size, unpadded_row_size);
238 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
239 kWidth, kHeight, 1, GL_RGBA, GL_HALF_FLOAT,
240 1, &size, &unpadded_row_size, &padded_row_size));
241 EXPECT_EQ(kWidth * kHeight * 8, size);
242 EXPECT_EQ(kWidth * 8, padded_row_size);
243 EXPECT_EQ(padded_row_size, unpadded_row_size);
244 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
245 kWidth, kHeight, 1, GL_RGBA, GL_HALF_FLOAT_OES,
246 1, &size, &unpadded_row_size, &padded_row_size));
247 EXPECT_EQ(kWidth * kHeight * 8, size);
248 EXPECT_EQ(kWidth * 8, padded_row_size);
249 EXPECT_EQ(padded_row_size, unpadded_row_size);
252 TEST_F(GLES2UtilTest, ComputeImageDataSizesUnpackAlignment) {
253 const uint32_t kWidth = 19;
254 const uint32_t kHeight = 12;
255 uint32_t size;
256 uint32_t unpadded_row_size;
257 uint32_t padded_row_size;
258 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
259 kWidth, kHeight, 1, GL_RGB, GL_UNSIGNED_BYTE, 1, &size,
260 &unpadded_row_size, &padded_row_size));
261 EXPECT_EQ(kWidth * kHeight * 3, size);
262 EXPECT_EQ(kWidth * 3, unpadded_row_size);
263 EXPECT_EQ(kWidth * 3, padded_row_size);
264 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
265 kWidth, kHeight, 1, GL_RGB, GL_UNSIGNED_BYTE, 2, &size,
266 &unpadded_row_size, &padded_row_size));
267 EXPECT_EQ((kWidth * 3 + 1) * (kHeight - 1) +
268 kWidth * 3, size);
269 EXPECT_EQ(kWidth * 3, unpadded_row_size);
270 EXPECT_EQ(kWidth * 3 + 1, padded_row_size);
271 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
272 kWidth, kHeight, 1, GL_RGB, GL_UNSIGNED_BYTE, 4, &size,
273 &unpadded_row_size, &padded_row_size));
274 EXPECT_EQ((kWidth * 3 + 3) * (kHeight - 1) +
275 kWidth * 3, size);
276 EXPECT_EQ(kWidth * 3, unpadded_row_size);
277 EXPECT_EQ(kWidth * 3 + 3, padded_row_size);
278 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
279 kWidth, kHeight, 1, GL_RGB, GL_UNSIGNED_BYTE, 8, &size,
280 &unpadded_row_size, &padded_row_size));
281 EXPECT_EQ((kWidth * 3 + 7) * (kHeight - 1) +
282 kWidth * 3, size);
283 EXPECT_EQ(kWidth * 3, unpadded_row_size);
284 EXPECT_EQ(kWidth * 3 + 7, padded_row_size);
287 TEST_F(GLES2UtilTest, ComputeImageDataSizeDepth) {
288 const uint32_t kWidth = 19;
289 const uint32_t kHeight = 12;
290 const uint32_t kDepth = 3;
291 uint32_t size;
292 uint32_t unpadded_row_size;
293 uint32_t padded_row_size;
294 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
295 kWidth, kHeight, kDepth, GL_RGB, GL_UNSIGNED_BYTE, 1, &size,
296 &unpadded_row_size, &padded_row_size));
297 EXPECT_EQ(kWidth * kHeight * kDepth * 3, size);
298 EXPECT_EQ(kWidth * 3, padded_row_size);
299 EXPECT_EQ(padded_row_size, unpadded_row_size);
300 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
301 kWidth, kHeight, kDepth, GL_RGB, GL_UNSIGNED_BYTE, 2, &size,
302 &unpadded_row_size, &padded_row_size));
303 EXPECT_EQ((kWidth * 3 + 1) * (kHeight * kDepth - 1) +
304 kWidth * 3, size);
305 EXPECT_EQ(kWidth * 3, unpadded_row_size);
306 EXPECT_EQ(kWidth * 3 + 1, padded_row_size);
307 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
308 kWidth, kHeight, kDepth, GL_RGB, GL_UNSIGNED_BYTE, 4, &size,
309 &unpadded_row_size, &padded_row_size));
310 EXPECT_EQ((kWidth * 3 + 3) * (kHeight * kDepth - 1) +
311 kWidth * 3, size);
312 EXPECT_EQ(kWidth * 3, unpadded_row_size);
313 EXPECT_EQ(kWidth * 3 + 3, padded_row_size);
314 EXPECT_TRUE(GLES2Util::ComputeImageDataSizes(
315 kWidth, kHeight, kDepth, GL_RGB, GL_UNSIGNED_BYTE, 8, &size,
316 &unpadded_row_size, &padded_row_size));
317 EXPECT_EQ((kWidth * 3 + 7) * (kHeight * kDepth - 1) +
318 kWidth * 3, size);
319 EXPECT_EQ(kWidth * 3, unpadded_row_size);
320 EXPECT_EQ(kWidth * 3 + 7, padded_row_size);
323 TEST_F(GLES2UtilTest, RenderbufferBytesPerPixel) {
324 EXPECT_EQ(1u, GLES2Util::RenderbufferBytesPerPixel(GL_STENCIL_INDEX8));
325 EXPECT_EQ(2u, GLES2Util::RenderbufferBytesPerPixel(GL_RGBA4));
326 EXPECT_EQ(2u, GLES2Util::RenderbufferBytesPerPixel(GL_RGB565));
327 EXPECT_EQ(2u, GLES2Util::RenderbufferBytesPerPixel(GL_RGB5_A1));
328 EXPECT_EQ(2u, GLES2Util::RenderbufferBytesPerPixel(GL_DEPTH_COMPONENT16));
329 EXPECT_EQ(4u, GLES2Util::RenderbufferBytesPerPixel(GL_RGB));
330 EXPECT_EQ(4u, GLES2Util::RenderbufferBytesPerPixel(GL_RGBA));
331 EXPECT_EQ(
332 4u, GLES2Util::RenderbufferBytesPerPixel(GL_DEPTH24_STENCIL8_OES));
333 EXPECT_EQ(4u, GLES2Util::RenderbufferBytesPerPixel(GL_RGB8_OES));
334 EXPECT_EQ(4u, GLES2Util::RenderbufferBytesPerPixel(GL_RGBA8_OES));
335 EXPECT_EQ(
336 4u, GLES2Util::RenderbufferBytesPerPixel(GL_DEPTH_COMPONENT24_OES));
337 EXPECT_EQ(0u, GLES2Util::RenderbufferBytesPerPixel(-1));
340 TEST_F(GLES2UtilTest, GetChannelsForCompressedFormat) {
341 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(GL_ETC1_RGB8_OES));
342 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
343 GL_COMPRESSED_RGB_S3TC_DXT1_EXT));
344 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
345 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT));
346 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
347 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT));
348 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
349 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT));
350 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(GL_ATC_RGB_AMD));
351 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
352 GL_ATC_RGBA_EXPLICIT_ALPHA_AMD));
353 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
354 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD));
355 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
356 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG));
357 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
358 GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG));
359 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
360 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG));
361 EXPECT_EQ(0u, GLES2Util::GetChannelsForFormat(
362 GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG));
365 namespace {
367 void CheckParseUniformName(
368 const char* name,
369 bool expected_success,
370 size_t expected_array_pos,
371 int expected_index,
372 bool expected_getting_array) {
373 int index = 1234;
374 size_t array_pos = 1244;
375 bool getting_array = false;
376 bool success = GLES2Util::ParseUniformName(
377 name, &array_pos, &index, &getting_array);
378 EXPECT_EQ(expected_success, success);
379 if (success) {
380 EXPECT_EQ(expected_array_pos, array_pos);
381 EXPECT_EQ(expected_index, index);
382 EXPECT_EQ(expected_getting_array, getting_array);
386 } // anonymous namespace
388 TEST_F(GLES2UtilTest, ParseUniformName) {
389 CheckParseUniformName("u_name", true, std::string::npos, 0, false);
390 CheckParseUniformName("u_name[]", false, std::string::npos, 0, false);
391 CheckParseUniformName("u_name]", false, std::string::npos, 0, false);
392 CheckParseUniformName("u_name[0a]", false, std::string::npos, 0, false);
393 CheckParseUniformName("u_name[a0]", false, std::string::npos, 0, false);
394 CheckParseUniformName("u_name[0a0]", false, std::string::npos, 0, false);
395 CheckParseUniformName("u_name[0]", true, 6u, 0, true);
396 CheckParseUniformName("u_name[2]", true, 6u, 2, true);
397 CheckParseUniformName("u_name[02]", true, 6u, 2, true);
398 CheckParseUniformName("u_name[20]", true, 6u, 20, true);
399 CheckParseUniformName("u_name[020]", true, 6u, 20, true);
400 CheckParseUniformName("u_name[0][0]", true, 9u, 0, true);
401 CheckParseUniformName("u_name[3][2]", true, 9u, 2, true);
402 CheckParseUniformName("u_name[03][02]", true, 10u, 2, true);
403 CheckParseUniformName("u_name[30][20]", true, 10u, 20, true);
404 CheckParseUniformName("u_name[030][020]", true, 11u, 20, true);
405 CheckParseUniformName("", false, std::string::npos, 0, false);
408 } // namespace gles2
409 } // namespace gpu