1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkCommonFlagsConfig.h"
9#include "SkColorSpace_Base.h"
10#include "Test.h"
11#include <initializer_list>
12
13using sk_gpu_test::GrContextFactory;
14
15namespace {
16// The code
17//   SkCommandLineFlags::StringArray FLAGS_config1 = make_string_array({"a", "b"})
18// can be used to construct string array that one gets with command line flags.
19// For example, the call above is equivalent of
20//   DEFINE_string(config1, "a b", "");
21// in cases where the default command line flag value ("a b") is used.
22// make_string_array can be used to construct StringArray strings that have spaces in
23// them.
24SkCommandLineFlags::StringArray make_string_array(std::initializer_list<const char*> strings) {
25    SkTArray<SkString> array;
26    for (auto& s : strings) {
27        array.push_back(SkString(s));
28    }
29    return SkCommandLineFlags::StringArray(array);
30}
31}
32DEF_TEST(ParseConfigs_Gpu, reporter) {
33    // Parses a normal config and returns correct "tag".
34    // Simple GL config works
35    SkCommandLineFlags::StringArray config1 = make_string_array({"gl"});
36    SkCommandLineConfigArray configs;
37    ParseConfigs(config1, &configs);
38
39    REPORTER_ASSERT(reporter, configs.count() == 1);
40    REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl"));
41    REPORTER_ASSERT(reporter, configs[0]->getViaParts().count() == 0);
42#if SK_SUPPORT_GPU
43    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
44    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType()
45                    == GrContextFactory::kGL_ContextType);
46    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false);
47    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseInstanced() == false);
48    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false);
49    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
50    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
51    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr);
52#endif
53}
54
55DEF_TEST(ParseConfigs_OutParam, reporter) {
56    // Clears the out parameter.
57    SkCommandLineFlags::StringArray config1 = make_string_array({"gles"});
58    SkCommandLineConfigArray configs;
59    ParseConfigs(config1, &configs);
60    REPORTER_ASSERT(reporter, configs.count() == 1);
61    REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gles"));
62
63    SkCommandLineFlags::StringArray config2 = make_string_array({"8888"});
64    ParseConfigs(config2, &configs);
65    REPORTER_ASSERT(reporter, configs.count() == 1);
66    REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
67
68    SkCommandLineFlags::StringArray config3 = make_string_array({"gl"});
69    ParseConfigs(config3, &configs);
70    REPORTER_ASSERT(reporter, configs.count() == 1);
71    REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl"));
72}
73
74DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
75    // Parses all default configs and returns correct "tag".
76
77    SkCommandLineFlags::StringArray config1 = make_string_array({
78        "565",
79        "8888",
80        "debuggl",
81        "gl",
82        "gldft",
83        "nullgl",
84        "glmsaa8",
85        "glmsaa4",
86        "nonrendering",
87        "nullgl",
88        "gles",
89        "glnvpr8",
90        "glnvpr4",
91        "glnvprdit8",
92        "glesnvprdit4",
93        "pdf",
94        "skp",
95        "svg",
96        "xps",
97        "angle_d3d11_es2",
98        "angle_gl_es2",
99        "commandbuffer",
100        "mesa",
101        "hwui",
102        "glf16",
103        "glessrgb",
104        "gl",
105        "glnvpr4",
106        "glnvprdit4",
107        "glsrgb",
108        "glmsaa4",
109        "vk",
110        "glinst",
111        "glinst4",
112        "glinstdit4",
113        "glinst8",
114        "glinstdit8",
115        "glesinst",
116        "glesinst4",
117        "glesinstdit4",
118        "glwide",
119        "glnarrow",
120        "glnostencils",
121        "mock",
122        "mtl",
123        "gl4444",
124        "gl565"
125    });
126
127    SkCommandLineConfigArray configs;
128    ParseConfigs(config1, &configs);
129
130    auto srgbColorSpace = SkColorSpace::MakeSRGB();
131
132    REPORTER_ASSERT(reporter, configs.count() == config1.count());
133    for (int i = 0; i < config1.count(); ++i) {
134        REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
135        REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
136    }
137#if SK_SUPPORT_GPU
138    REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
139    REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
140    REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
141    REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
142    REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText());
143    REPORTER_ASSERT(reporter, configs[5]->asConfigGpu());
144    REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8);
145    REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4);
146    REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu());
147    REPORTER_ASSERT(reporter, configs[9]->asConfigGpu());
148    REPORTER_ASSERT(reporter, configs[10]->asConfigGpu());
149    REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8);
150    REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR());
151    REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText());
152    REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4);
153    REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
154    REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
155    REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 8);
156    REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
157    REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseDIText());
158    REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 4);
159    REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
160    REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
161    REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
162    REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
163    REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
164    REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
165    REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
166    REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
167    REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorSpace());
168    REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorSpace()->gammaIsLinear());
169    const SkMatrix44* srgbXYZ = as_CSB(srgbColorSpace)->toXYZD50();
170    SkASSERT(srgbXYZ);
171    const SkMatrix44* config25XYZ =
172            as_CSB(configs[24]->asConfigGpu()->getColorSpace())->toXYZD50();
173    SkASSERT(config25XYZ);
174    REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ);
175    REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
176    REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
177    REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
178    REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorSpace());
179    REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorSpace()->gammaIsLinear());
180    const SkMatrix44* config41XYZ =
181            as_CSB(configs[40]->asConfigGpu()->getColorSpace())->toXYZD50();
182    SkASSERT(config41XYZ);
183    REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ);
184    REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() ==
185                              GrContextFactory::kGL_ContextType);
186    REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
187    REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace());
188    REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()->gammaIsLinear());
189    REPORTER_ASSERT(reporter, *as_CSB(configs[41]->asConfigGpu()->getColorSpace())->toXYZD50() !=
190                    *as_CSB(srgbColorSpace)->toXYZD50());
191    REPORTER_ASSERT(reporter, configs[42]->asConfigGpu()->getContextType() ==
192                              GrContextFactory::kGL_ContextType);
193    REPORTER_ASSERT(reporter, SkToBool(configs[42]->asConfigGpu()->getContextOverrides() &
194                              SkCommandLineConfigGpu::ContextOverrides::kAvoidStencilBuffers));
195    REPORTER_ASSERT(reporter, configs[43]->asConfigGpu()->getContextType() ==
196                              GrContextFactory::kMock_ContextType);
197    REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getUseInstanced());
198    REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() ==
199                              GrContextFactory::kGL_ContextType);
200    REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced());
201    REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getSamples() == 4);
202    REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
203                              GrContextFactory::kGL_ContextType);
204    REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced());
205    REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseDIText());
206    REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getSamples() == 4);
207    REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
208                              GrContextFactory::kGL_ContextType);
209    REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseInstanced());
210    REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 8);
211    REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() ==
212                              GrContextFactory::kGL_ContextType);
213    REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced());
214    REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseDIText());
215    REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 8);
216    REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() ==
217                              GrContextFactory::kGLES_ContextType);
218    REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced());
219    REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() ==
220                              GrContextFactory::kGLES_ContextType);
221    REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced());
222    REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getSamples() == 4);
223    REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() ==
224                              GrContextFactory::kGLES_ContextType);
225    REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced());
226    REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseDIText());
227    REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4);
228    REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
229    REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
230    REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
231    REPORTER_ASSERT(reporter, configs[45]->asConfigGpu()->getContextType() ==
232                              GrContextFactory::kGL_ContextType);
233    REPORTER_ASSERT(reporter, configs[45]->asConfigGpu()->getColorType() == kARGB_4444_SkColorType);
234    REPORTER_ASSERT(reporter, configs[45]->asConfigGpu()->getAlphaType() == kPremul_SkAlphaType);
235    REPORTER_ASSERT(reporter, configs[46]->asConfigGpu()->getContextType() ==
236                              GrContextFactory::kGL_ContextType);
237    REPORTER_ASSERT(reporter, configs[46]->asConfigGpu()->getColorType() == kRGB_565_SkColorType);
238    REPORTER_ASSERT(reporter, configs[46]->asConfigGpu()->getAlphaType() == kOpaque_SkAlphaType);
239#if SK_MESA
240    REPORTER_ASSERT(reporter, configs[23]->asConfigGpu());
241#else
242    REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
243#endif
244    REPORTER_ASSERT(reporter, configs[26]->asConfigGpu());
245    REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
246    REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4);
247    REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getUseNVPR());
248    REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
249    REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4);
250    REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR());
251    REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseDIText());
252    REPORTER_ASSERT(reporter, configs[29]->asConfigGpu());
253    REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType()  == kRGBA_8888_SkColorType);
254    REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
255    REPORTER_ASSERT(reporter, configs[30]->asConfigGpu());
256    REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getSamples() == 4);
257#ifdef SK_VULKAN
258    REPORTER_ASSERT(reporter, configs[31]->asConfigGpu());
259#endif
260#endif
261}
262
263DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
264    SkCommandLineFlags::StringArray config1 = make_string_array({
265        "gpu[api=gl,nvpr=true,dit=false]",
266        "gpu[api=angle_d3d9_es2]",
267        "gpu[api=angle_gl_es3]",
268        "gpu[api=mesa,samples=77]",
269        "gpu[dit=true,api=commandbuffer]",
270        "gpu[api=gles]",
271        "gpu[api=gl]",
272        "gpu[api=vulkan]",
273        "gpu[api=metal]",
274        "gpu[api=mock]",
275    });
276
277    SkCommandLineConfigArray configs;
278    ParseConfigs(config1, &configs);
279    REPORTER_ASSERT(reporter, configs.count() == config1.count());
280    for (int i = 0; i < config1.count(); ++i) {
281        REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
282    }
283#if SK_SUPPORT_GPU
284    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
285                    GrContextFactory::kGL_ContextType);
286    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
287    REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
288    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
289    REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
290                    GrContextFactory::kANGLE_D3D9_ES2_ContextType);
291    REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
292    REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
293                    GrContextFactory::kANGLE_GL_ES3_ContextType);
294    REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
295#if SK_MESA
296    REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() ==
297                    GrContextFactory::kMESA_ContextType);
298#else
299    REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
300#endif
301    REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
302                    GrContextFactory::kCommandBuffer_ContextType);
303    REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
304                    GrContextFactory::kGLES_ContextType);
305    REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
306    REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
307    REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
308    REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
309                              GrContextFactory::kGL_ContextType);
310    REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
311    REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
312    REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
313#ifdef SK_VULKAN
314    REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
315                              GrContextFactory::kVulkan_ContextType);
316    REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
317    REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
318    REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
319#endif
320#ifdef SK_METAL
321    REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
322                              GrContextFactory::kMetal_ContextType);
323    REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR());
324    REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText());
325    REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0);
326#endif
327    REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() ==
328                   GrContextFactory::kMock_ContextType);
329#endif
330}
331
332DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
333    SkCommandLineFlags::StringArray config1 = make_string_array({
334        "gpu[api=gl,nvpr=1]", // Number as bool.
335        "gpu[api=gl,]", // Trailing in comma.
336        "gpu[api=angle_glu]", // Unknown api.
337        "gpu[api=,samples=0]", // Empty api.
338        "gpu[api=gl,samples=true]", // Value true as a number.
339        "gpu[api=gl,samples=0,samples=0]", // Duplicate option key.
340        "gpu[,api=gl,samples=0]", // Leading comma.
341        "gpu[samples=54", // Missing closing parenthesis.
342        ",,",
343        "gpu[]", // Missing required api specifier
344        "gpu[samples=4]", // Missing required api specifier
345        "gpu[", // Missing bracket.
346        "samples=54" // No backend.
347        "gpu[nvpr=true ]", // Space.
348    });
349
350    SkCommandLineConfigArray configs;
351    ParseConfigs(config1, &configs);
352    REPORTER_ASSERT(reporter, configs.count() == config1.count());
353    for (int i = 0; i < config1.count(); ++i) {
354        REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
355        REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
356#if SK_SUPPORT_GPU
357        REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
358#endif
359    }
360}
361
362DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
363    // These just list explicitly some properties of the system.
364    SkCommandLineFlags::StringArray config1 = make_string_array({
365        // Options are not canonized -> two same configs have a different tag.
366        "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]",
367        "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", ""
368        "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]"
369    });
370    SkCommandLineConfigArray configs;
371    ParseConfigs(config1, &configs);
372    REPORTER_ASSERT(reporter, configs.count() == config1.count());
373    for (int i = 0; i < config1.count(); ++i) {
374        REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
375#if SK_SUPPORT_GPU
376        REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
377        REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
378#else
379        REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
380#endif
381    }
382}
383
384#if SK_SUPPORT_GPU
385DEF_TEST(ParseConfigs_ViaParsing, reporter) {
386    SkCommandLineFlags::StringArray config1 = make_string_array({
387        "a-b-c-8888",
388        "zz-qq-gpu",
389        "a-angle_gl_es2"
390    });
391
392    SkCommandLineConfigArray configs;
393    ParseConfigs(config1, &configs);
394    const struct {
395        const char* backend;
396        const char* vias[3];
397    } expectedConfigs[] = {
398        {"8888", {"a", "b", "c"}},
399        {"gpu", {"zz", "qq", nullptr}},
400        {"gpu", { "a", nullptr, nullptr }}
401    };
402    for (int i = 0; i < config1.count(); ++i) {
403        REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
404        REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
405        for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
406            if (!expectedConfigs[i].vias[j]) {
407                REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
408                break;
409            }
410            REPORTER_ASSERT(reporter,
411                            configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
412        }
413    }
414}
415#endif
416
417DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
418    SkCommandLineFlags::StringArray config1 = make_string_array({
419        "zz-qq-gpu[api=gles]",
420        "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
421        "a-gpu[api=gl",
422        "abc-def-angle_gl_es2[api=gles]",
423    });
424
425    SkCommandLineConfigArray configs;
426    ParseConfigs(config1, &configs);
427    const struct {
428        const char* backend;
429        const char* vias[3];
430    } expectedConfigs[] = {
431#if SK_SUPPORT_GPU
432        {"gpu", {"zz", "qq", nullptr}},
433        {"gpu", {"abc", "nbc", "cbs"}},
434#else
435        {"gpu[api=gles]", {"zz", "qq", nullptr}},
436        {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
437#endif
438        {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
439                                                 // form but via still works as expected.
440        {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}}  // This is not extended form.
441                                                             // angle_gl_es2 is an api type not a
442                                                             // backend.
443    };
444    for (int i = 0; i < config1.count(); ++i) {
445        REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
446        REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
447        for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
448            if (!expectedConfigs[i].vias[j]) {
449                REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
450                                static_cast<int>(j));
451                break;
452            }
453            REPORTER_ASSERT(reporter,
454                            configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
455        }
456    }
457#if SK_SUPPORT_GPU
458    REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
459    REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
460    REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
461    REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
462#endif
463}
464