1 /*-------------------------------------------------------------------------
2 * drawElements Internal Test Module
3 * ---------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Miscellaneous framework tests.
22 *//*--------------------------------------------------------------------*/
24 #include "ditFrameworkTests.hpp"
25 #include "tcuFloatFormat.hpp"
26 #include "tcuTestLog.hpp"
27 #include "tcuCommandLine.hpp"
41 enum Expected { NO_MATCH, MATCH_GROUP, MATCH_CASE, EXPECTED_LAST };
47 const char* getMatchCaseExpectedDesc (MatchCase::Expected expected)
49 static const char* descs[] =
55 return de::getSizedArrayElement<MatchCase::EXPECTED_LAST>(descs, expected);
58 class CaseListParserCase : public tcu::TestCase
61 CaseListParserCase (tcu::TestContext& testCtx, const char* name, const char* caseList, const MatchCase* subCases, int numSubCases)
62 : tcu::TestCase (testCtx, name, "")
63 , m_caseList (caseList)
64 , m_subCases (subCases)
65 , m_numSubCases (numSubCases)
69 IterateResult iterate (void)
71 TestLog& log = m_testCtx.getLog();
72 tcu::CommandLine cmdLine;
75 log << TestLog::Message << "Input:\n\"" << m_caseList << "\"" << TestLog::EndMessage;
85 if (!cmdLine.parse(DE_LENGTH_OF_ARRAY(argv), argv))
86 TCU_FAIL("Failed to parse case list");
89 for (int subCaseNdx = 0; subCaseNdx < m_numSubCases; subCaseNdx++)
91 const MatchCase& curCase = m_subCases[subCaseNdx];
95 log << TestLog::Message << "Checking \"" << curCase.path << "\""
96 << ", expecting " << getMatchCaseExpectedDesc(curCase.expected)
97 << TestLog::EndMessage;
99 matchGroup = cmdLine.checkTestGroupName(curCase.path);
100 matchCase = cmdLine.checkTestCaseName(curCase.path);
102 if ((matchGroup == (curCase.expected == MatchCase::MATCH_GROUP)) &&
103 (matchCase == (curCase.expected == MatchCase::MATCH_CASE)))
105 log << TestLog::Message << " pass" << TestLog::EndMessage;
109 log << TestLog::Message << " FAIL!" << TestLog::EndMessage;
112 m_testCtx.setTestResult((numPass == m_numSubCases) ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
113 (numPass == m_numSubCases) ? "All passed" : "Unexpected match result");
119 const char* const m_caseList;
120 const MatchCase* const m_subCases;
121 const int m_numSubCases;
124 class NegativeCaseListCase : public tcu::TestCase
127 NegativeCaseListCase (tcu::TestContext& testCtx, const char* name, const char* caseList)
128 : tcu::TestCase (testCtx, name, "")
129 , m_caseList (caseList)
133 IterateResult iterate (void)
135 TestLog& log = m_testCtx.getLog();
136 tcu::CommandLine cmdLine;
138 log << TestLog::Message << "Input:\n\"" << m_caseList << "\"" << TestLog::EndMessage;
148 if (cmdLine.parse(DE_LENGTH_OF_ARRAY(argv), argv))
149 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Parsing passed, should have failed");
151 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Parsing failed as expected");
158 const char* const m_caseList;
161 class TrieParserTests : public tcu::TestCaseGroup
164 TrieParserTests (tcu::TestContext& testCtx)
165 : tcu::TestCaseGroup(testCtx, "trie", "Test case trie parser tests")
172 static const char* const caseList = "{test}";
173 static const MatchCase subCases[] =
175 { "test", MatchCase::MATCH_CASE },
176 { "test.cd", MatchCase::NO_MATCH },
178 addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
181 static const char* const caseList = "{a{b}}";
182 static const MatchCase subCases[] =
184 { "a", MatchCase::MATCH_GROUP },
185 { "b", MatchCase::NO_MATCH },
186 { "a.b", MatchCase::MATCH_CASE },
187 { "a.a", MatchCase::NO_MATCH },
189 addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
192 static const char* const caseList = "{a{b,c}}";
193 static const MatchCase subCases[] =
195 { "a", MatchCase::MATCH_GROUP },
196 { "b", MatchCase::NO_MATCH },
197 { "a.b", MatchCase::MATCH_CASE },
198 { "a.a", MatchCase::NO_MATCH },
199 { "a.c", MatchCase::MATCH_CASE },
201 addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
204 static const char* const caseList = "{a{b},c{d,e}}";
205 static const MatchCase subCases[] =
207 { "a", MatchCase::MATCH_GROUP },
208 { "b", MatchCase::NO_MATCH },
209 { "a.b", MatchCase::MATCH_CASE },
210 { "a.c", MatchCase::NO_MATCH },
211 { "a.d", MatchCase::NO_MATCH },
212 { "a.e", MatchCase::NO_MATCH },
213 { "c", MatchCase::MATCH_GROUP },
214 { "c.b", MatchCase::NO_MATCH },
215 { "c.d", MatchCase::MATCH_CASE },
216 { "c.e", MatchCase::MATCH_CASE },
218 addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
221 static const char* const caseList = "{a,c{d,e}}";
222 static const MatchCase subCases[] =
224 { "a", MatchCase::MATCH_CASE },
225 { "b", MatchCase::NO_MATCH },
226 { "a.b", MatchCase::NO_MATCH },
227 { "a.c", MatchCase::NO_MATCH },
228 { "a.d", MatchCase::NO_MATCH },
229 { "a.e", MatchCase::NO_MATCH },
230 { "c", MatchCase::MATCH_GROUP },
231 { "c.b", MatchCase::NO_MATCH },
232 { "c.d", MatchCase::MATCH_CASE },
233 { "c.e", MatchCase::MATCH_CASE },
235 addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
238 static const char* const caseList = "{c{d,e},a}";
239 static const MatchCase subCases[] =
241 { "a", MatchCase::MATCH_CASE },
242 { "b", MatchCase::NO_MATCH },
243 { "a.b", MatchCase::NO_MATCH },
244 { "a.c", MatchCase::NO_MATCH },
245 { "a.d", MatchCase::NO_MATCH },
246 { "a.e", MatchCase::NO_MATCH },
247 { "c", MatchCase::MATCH_GROUP },
248 { "c.b", MatchCase::NO_MATCH },
249 { "c.d", MatchCase::MATCH_CASE },
250 { "c.e", MatchCase::MATCH_CASE },
252 addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
255 static const char* const caseList = "{test}\r";
256 static const MatchCase subCases[] =
258 { "test", MatchCase::MATCH_CASE },
259 { "test.cd", MatchCase::NO_MATCH },
261 addChild(new CaseListParserCase(m_testCtx, "trailing_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
264 static const char* const caseList = "{test}\n";
265 static const MatchCase subCases[] =
267 { "test", MatchCase::MATCH_CASE },
268 { "test.cd", MatchCase::NO_MATCH },
270 addChild(new CaseListParserCase(m_testCtx, "trailing_lf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
273 static const char* const caseList = "{test}\r\n";
274 static const MatchCase subCases[] =
276 { "test", MatchCase::MATCH_CASE },
277 { "test.cd", MatchCase::NO_MATCH },
279 addChild(new CaseListParserCase(m_testCtx, "trailing_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
283 addChild(new NegativeCaseListCase(m_testCtx, "empty_string", ""));
284 addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n"));
285 addChild(new NegativeCaseListCase(m_testCtx, "empty_root", "{}"));
286 addChild(new NegativeCaseListCase(m_testCtx, "empty_group", "{test{}}"));
287 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_1", "{{}}"));
288 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_2", "{{test}}"));
289 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_1", "{"));
290 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_2", "{test"));
291 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_3", "{test,"));
292 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_4", "{test{a}"));
293 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_5", "{a,b"));
294 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_1", "{test{"));
295 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_2", "{test{a"));
296 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_3", "{test{a,"));
297 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_4", "{test{a,b"));
298 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_1", "{a,,b}"));
299 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_2", "{,b}"));
300 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_3", "{a,}"));
301 addChild(new NegativeCaseListCase(m_testCtx, "no_separator", "{a{b}c}"));
302 addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_1", "{a.b}"));
303 addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_2", "{a[]}"));
304 addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_1", "{a}}"));
305 addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_2", "{a}x"));
306 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_1", "{\na}"));
307 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_2", "{a\n,b}"));
308 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_3", "{a,\nb}"));
309 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_4", "{a{b\n}}"));
310 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_5", "{a{b}\n}"));
314 class ListParserTests : public tcu::TestCaseGroup
317 ListParserTests (tcu::TestContext& testCtx)
318 : tcu::TestCaseGroup(testCtx, "list", "Test case list parser tests")
325 static const char* const caseList = "test";
326 static const MatchCase subCases[] =
328 { "test", MatchCase::MATCH_CASE },
329 { "test.cd", MatchCase::NO_MATCH },
331 addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
334 static const char* const caseList = "a.b";
335 static const MatchCase subCases[] =
337 { "a", MatchCase::MATCH_GROUP },
338 { "b", MatchCase::NO_MATCH },
339 { "a.b", MatchCase::MATCH_CASE },
340 { "a.a", MatchCase::NO_MATCH },
342 addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
345 static const char* const caseList = "a.b\na.c";
346 static const MatchCase subCases[] =
348 { "a", MatchCase::MATCH_GROUP },
349 { "b", MatchCase::NO_MATCH },
350 { "a.b", MatchCase::MATCH_CASE },
351 { "a.a", MatchCase::NO_MATCH },
352 { "a.c", MatchCase::MATCH_CASE },
354 addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
357 static const char* const caseList = "a.b\na.c";
358 static const MatchCase subCases[] =
360 { "a", MatchCase::MATCH_GROUP },
361 { "b", MatchCase::NO_MATCH },
362 { "a.b", MatchCase::MATCH_CASE },
363 { "a.a", MatchCase::NO_MATCH },
364 { "a.c", MatchCase::MATCH_CASE },
366 addChild(new CaseListParserCase(m_testCtx, "separator_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
369 static const char* const caseList = "a.b\ra.c";
370 static const MatchCase subCases[] =
372 { "a", MatchCase::MATCH_GROUP },
373 { "b", MatchCase::NO_MATCH },
374 { "a.b", MatchCase::MATCH_CASE },
375 { "a.a", MatchCase::NO_MATCH },
376 { "a.c", MatchCase::MATCH_CASE },
378 addChild(new CaseListParserCase(m_testCtx, "separator_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
381 static const char* const caseList = "a.b\r\na.c";
382 static const MatchCase subCases[] =
384 { "a", MatchCase::MATCH_GROUP },
385 { "b", MatchCase::NO_MATCH },
386 { "a.b", MatchCase::MATCH_CASE },
387 { "a.a", MatchCase::NO_MATCH },
388 { "a.c", MatchCase::MATCH_CASE },
390 addChild(new CaseListParserCase(m_testCtx, "separator_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
393 static const char* const caseList = "a.b\na.c\n";
394 static const MatchCase subCases[] =
396 { "a", MatchCase::MATCH_GROUP },
397 { "b", MatchCase::NO_MATCH },
398 { "a.b", MatchCase::MATCH_CASE },
399 { "a.a", MatchCase::NO_MATCH },
400 { "a.c", MatchCase::MATCH_CASE },
402 addChild(new CaseListParserCase(m_testCtx, "end_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
405 static const char* const caseList = "a.b\na.c\r";
406 static const MatchCase subCases[] =
408 { "a", MatchCase::MATCH_GROUP },
409 { "b", MatchCase::NO_MATCH },
410 { "a.b", MatchCase::MATCH_CASE },
411 { "a.a", MatchCase::NO_MATCH },
412 { "a.c", MatchCase::MATCH_CASE },
414 addChild(new CaseListParserCase(m_testCtx, "end_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
417 static const char* const caseList = "a.b\na.c\r\n";
418 static const MatchCase subCases[] =
420 { "a", MatchCase::MATCH_GROUP },
421 { "b", MatchCase::NO_MATCH },
422 { "a.b", MatchCase::MATCH_CASE },
423 { "a.a", MatchCase::NO_MATCH },
424 { "a.c", MatchCase::MATCH_CASE },
426 addChild(new CaseListParserCase(m_testCtx, "end_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
429 static const char* const caseList = "a.b\nc.d\nc.e";
430 static const MatchCase subCases[] =
432 { "a", MatchCase::MATCH_GROUP },
433 { "b", MatchCase::NO_MATCH },
434 { "a.b", MatchCase::MATCH_CASE },
435 { "a.c", MatchCase::NO_MATCH },
436 { "a.d", MatchCase::NO_MATCH },
437 { "a.e", MatchCase::NO_MATCH },
438 { "c", MatchCase::MATCH_GROUP },
439 { "c.b", MatchCase::NO_MATCH },
440 { "c.d", MatchCase::MATCH_CASE },
441 { "c.e", MatchCase::MATCH_CASE },
443 addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
446 static const char* const caseList = "a\nc.d\nc.e";
447 static const MatchCase subCases[] =
449 { "a", MatchCase::MATCH_CASE },
450 { "b", MatchCase::NO_MATCH },
451 { "a.b", MatchCase::NO_MATCH },
452 { "a.c", MatchCase::NO_MATCH },
453 { "a.d", MatchCase::NO_MATCH },
454 { "a.e", MatchCase::NO_MATCH },
455 { "c", MatchCase::MATCH_GROUP },
456 { "c.b", MatchCase::NO_MATCH },
457 { "c.d", MatchCase::MATCH_CASE },
458 { "c.e", MatchCase::MATCH_CASE },
460 addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
463 static const char* const caseList = "c.d\nc.e\na";
464 static const MatchCase subCases[] =
466 { "a", MatchCase::MATCH_CASE },
467 { "b", MatchCase::NO_MATCH },
468 { "a.b", MatchCase::NO_MATCH },
469 { "a.c", MatchCase::NO_MATCH },
470 { "a.d", MatchCase::NO_MATCH },
471 { "a.e", MatchCase::NO_MATCH },
472 { "c", MatchCase::MATCH_GROUP },
473 { "c.b", MatchCase::NO_MATCH },
474 { "c.d", MatchCase::MATCH_CASE },
475 { "c.e", MatchCase::MATCH_CASE },
477 addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
480 static const char* const caseList = "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.x";
481 static const MatchCase subCases[] =
483 { "a", MatchCase::MATCH_GROUP },
484 { "b", MatchCase::NO_MATCH },
485 { "a.b", MatchCase::MATCH_GROUP },
486 { "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.x", MatchCase::MATCH_CASE },
488 addChild(new CaseListParserCase(m_testCtx, "long_name", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
491 static const char* const caseList =
497 static const MatchCase subCases[] =
499 { "a", MatchCase::MATCH_GROUP },
500 { "a.b", MatchCase::MATCH_GROUP },
501 { "a.b.c.d.e", MatchCase::MATCH_CASE },
502 { "a.b.c.d.g", MatchCase::MATCH_CASE },
503 { "x.y", MatchCase::MATCH_GROUP },
504 { "x.y.z", MatchCase::MATCH_CASE },
505 { "a.b.c.f", MatchCase::MATCH_CASE },
506 { "a.b.c.x", MatchCase::MATCH_CASE },
508 addChild(new CaseListParserCase(m_testCtx, "partial_prefix", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
511 static const char* const caseList =
514 static const MatchCase subCases[] =
516 { "a", MatchCase::MATCH_GROUP },
517 { "a.a", MatchCase::MATCH_GROUP },
518 { "a.b.c.d", MatchCase::MATCH_CASE },
519 { "a.b.c.d", MatchCase::MATCH_CASE },
521 addChild(new CaseListParserCase(m_testCtx, "reparenting", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
525 addChild(new NegativeCaseListCase(m_testCtx, "empty_string", ""));
526 addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n"));
527 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name", ".test"));
528 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name", "test."));
532 class CaseListParserTests : public tcu::TestCaseGroup
535 CaseListParserTests (tcu::TestContext& testCtx)
536 : tcu::TestCaseGroup(testCtx, "case_list_parser", "Test case list parser tests")
542 addChild(new TrieParserTests(m_testCtx));
543 addChild(new ListParserTests(m_testCtx));
547 class CommonFrameworkTests : public tcu::TestCaseGroup
550 CommonFrameworkTests (tcu::TestContext& testCtx)
551 : tcu::TestCaseGroup(testCtx, "common", "Tests for the common utility framework")
557 addChild(new SelfCheckCase(m_testCtx, "float_format","tcu::FloatFormat_selfTest()",
558 tcu::FloatFormat_selfTest));
559 addChild(new CaseListParserTests(m_testCtx));
565 FrameworkTests::FrameworkTests (tcu::TestContext& testCtx)
566 : tcu::TestCaseGroup(testCtx, "framework", "Miscellaneous framework tests")
570 FrameworkTests::~FrameworkTests (void)
574 void FrameworkTests::init (void)
576 addChild(new CommonFrameworkTests(m_testCtx));