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 "tcuEither.hpp"
27 #include "tcuTestLog.hpp"
28 #include "tcuCommandLine.hpp"
42 enum Expected { NO_MATCH, MATCH_GROUP, MATCH_CASE, EXPECTED_LAST };
48 const char* getMatchCaseExpectedDesc (MatchCase::Expected expected)
50 static const char* descs[] =
56 return de::getSizedArrayElement<MatchCase::EXPECTED_LAST>(descs, expected);
59 class CaseListParserCase : public tcu::TestCase
62 CaseListParserCase (tcu::TestContext& testCtx, const char* name, const char* caseList, const MatchCase* subCases, int numSubCases)
63 : tcu::TestCase (testCtx, name, "")
64 , m_caseList (caseList)
65 , m_subCases (subCases)
66 , m_numSubCases (numSubCases)
70 IterateResult iterate (void)
72 TestLog& log = m_testCtx.getLog();
73 tcu::CommandLine cmdLine;
76 log << TestLog::Message << "Input:\n\"" << m_caseList << "\"" << TestLog::EndMessage;
86 if (!cmdLine.parse(DE_LENGTH_OF_ARRAY(argv), argv))
87 TCU_FAIL("Failed to parse case list");
90 for (int subCaseNdx = 0; subCaseNdx < m_numSubCases; subCaseNdx++)
92 const MatchCase& curCase = m_subCases[subCaseNdx];
96 log << TestLog::Message << "Checking \"" << curCase.path << "\""
97 << ", expecting " << getMatchCaseExpectedDesc(curCase.expected)
98 << TestLog::EndMessage;
100 matchGroup = cmdLine.checkTestGroupName(curCase.path);
101 matchCase = cmdLine.checkTestCaseName(curCase.path);
103 if ((matchGroup == (curCase.expected == MatchCase::MATCH_GROUP)) &&
104 (matchCase == (curCase.expected == MatchCase::MATCH_CASE)))
106 log << TestLog::Message << " pass" << TestLog::EndMessage;
110 log << TestLog::Message << " FAIL!" << TestLog::EndMessage;
113 m_testCtx.setTestResult((numPass == m_numSubCases) ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
114 (numPass == m_numSubCases) ? "All passed" : "Unexpected match result");
120 const char* const m_caseList;
121 const MatchCase* const m_subCases;
122 const int m_numSubCases;
125 class NegativeCaseListCase : public tcu::TestCase
128 NegativeCaseListCase (tcu::TestContext& testCtx, const char* name, const char* caseList)
129 : tcu::TestCase (testCtx, name, "")
130 , m_caseList (caseList)
134 IterateResult iterate (void)
136 TestLog& log = m_testCtx.getLog();
137 tcu::CommandLine cmdLine;
139 log << TestLog::Message << "Input:\n\"" << m_caseList << "\"" << TestLog::EndMessage;
149 if (cmdLine.parse(DE_LENGTH_OF_ARRAY(argv), argv))
150 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Parsing passed, should have failed");
152 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Parsing failed as expected");
159 const char* const m_caseList;
162 class TrieParserTests : public tcu::TestCaseGroup
165 TrieParserTests (tcu::TestContext& testCtx)
166 : tcu::TestCaseGroup(testCtx, "trie", "Test case trie parser tests")
173 static const char* const caseList = "{test}";
174 static const MatchCase subCases[] =
176 { "test", MatchCase::MATCH_CASE },
177 { "test.cd", MatchCase::NO_MATCH },
179 addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
182 static const char* const caseList = "{a{b}}";
183 static const MatchCase subCases[] =
185 { "a", MatchCase::MATCH_GROUP },
186 { "b", MatchCase::NO_MATCH },
187 { "a.b", MatchCase::MATCH_CASE },
188 { "a.a", MatchCase::NO_MATCH },
190 addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
193 static const char* const caseList = "{a{b,c}}";
194 static const MatchCase subCases[] =
196 { "a", MatchCase::MATCH_GROUP },
197 { "b", MatchCase::NO_MATCH },
198 { "a.b", MatchCase::MATCH_CASE },
199 { "a.a", MatchCase::NO_MATCH },
200 { "a.c", MatchCase::MATCH_CASE },
202 addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
205 static const char* const caseList = "{a{b},c{d,e}}";
206 static const MatchCase subCases[] =
208 { "a", MatchCase::MATCH_GROUP },
209 { "b", MatchCase::NO_MATCH },
210 { "a.b", MatchCase::MATCH_CASE },
211 { "a.c", MatchCase::NO_MATCH },
212 { "a.d", MatchCase::NO_MATCH },
213 { "a.e", MatchCase::NO_MATCH },
214 { "c", MatchCase::MATCH_GROUP },
215 { "c.b", MatchCase::NO_MATCH },
216 { "c.d", MatchCase::MATCH_CASE },
217 { "c.e", MatchCase::MATCH_CASE },
219 addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
222 static const char* const caseList = "{a,c{d,e}}";
223 static const MatchCase subCases[] =
225 { "a", MatchCase::MATCH_CASE },
226 { "b", MatchCase::NO_MATCH },
227 { "a.b", MatchCase::NO_MATCH },
228 { "a.c", MatchCase::NO_MATCH },
229 { "a.d", MatchCase::NO_MATCH },
230 { "a.e", MatchCase::NO_MATCH },
231 { "c", MatchCase::MATCH_GROUP },
232 { "c.b", MatchCase::NO_MATCH },
233 { "c.d", MatchCase::MATCH_CASE },
234 { "c.e", MatchCase::MATCH_CASE },
236 addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
239 static const char* const caseList = "{c{d,e},a}";
240 static const MatchCase subCases[] =
242 { "a", MatchCase::MATCH_CASE },
243 { "b", MatchCase::NO_MATCH },
244 { "a.b", MatchCase::NO_MATCH },
245 { "a.c", MatchCase::NO_MATCH },
246 { "a.d", MatchCase::NO_MATCH },
247 { "a.e", MatchCase::NO_MATCH },
248 { "c", MatchCase::MATCH_GROUP },
249 { "c.b", MatchCase::NO_MATCH },
250 { "c.d", MatchCase::MATCH_CASE },
251 { "c.e", MatchCase::MATCH_CASE },
253 addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
256 static const char* const caseList = "{test}\r";
257 static const MatchCase subCases[] =
259 { "test", MatchCase::MATCH_CASE },
260 { "test.cd", MatchCase::NO_MATCH },
262 addChild(new CaseListParserCase(m_testCtx, "trailing_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
265 static const char* const caseList = "{test}\n";
266 static const MatchCase subCases[] =
268 { "test", MatchCase::MATCH_CASE },
269 { "test.cd", MatchCase::NO_MATCH },
271 addChild(new CaseListParserCase(m_testCtx, "trailing_lf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
274 static const char* const caseList = "{test}\r\n";
275 static const MatchCase subCases[] =
277 { "test", MatchCase::MATCH_CASE },
278 { "test.cd", MatchCase::NO_MATCH },
280 addChild(new CaseListParserCase(m_testCtx, "trailing_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
284 addChild(new NegativeCaseListCase(m_testCtx, "empty_string", ""));
285 addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n"));
286 addChild(new NegativeCaseListCase(m_testCtx, "empty_root", "{}"));
287 addChild(new NegativeCaseListCase(m_testCtx, "empty_group", "{test{}}"));
288 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_1", "{{}}"));
289 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_2", "{{test}}"));
290 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_1", "{"));
291 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_2", "{test"));
292 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_3", "{test,"));
293 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_4", "{test{a}"));
294 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_5", "{a,b"));
295 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_1", "{test{"));
296 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_2", "{test{a"));
297 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_3", "{test{a,"));
298 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_4", "{test{a,b"));
299 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_1", "{a,,b}"));
300 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_2", "{,b}"));
301 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_3", "{a,}"));
302 addChild(new NegativeCaseListCase(m_testCtx, "no_separator", "{a{b}c}"));
303 addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_1", "{a.b}"));
304 addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_2", "{a[]}"));
305 addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_1", "{a}}"));
306 addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_2", "{a}x"));
307 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_1", "{\na}"));
308 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_2", "{a\n,b}"));
309 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_3", "{a,\nb}"));
310 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_4", "{a{b\n}}"));
311 addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_5", "{a{b}\n}"));
315 class ListParserTests : public tcu::TestCaseGroup
318 ListParserTests (tcu::TestContext& testCtx)
319 : tcu::TestCaseGroup(testCtx, "list", "Test case list parser tests")
326 static const char* const caseList = "test";
327 static const MatchCase subCases[] =
329 { "test", MatchCase::MATCH_CASE },
330 { "test.cd", MatchCase::NO_MATCH },
332 addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
335 static const char* const caseList = "a.b";
336 static const MatchCase subCases[] =
338 { "a", MatchCase::MATCH_GROUP },
339 { "b", MatchCase::NO_MATCH },
340 { "a.b", MatchCase::MATCH_CASE },
341 { "a.a", MatchCase::NO_MATCH },
343 addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
346 static const char* const caseList = "a.b\na.c";
347 static const MatchCase subCases[] =
349 { "a", MatchCase::MATCH_GROUP },
350 { "b", MatchCase::NO_MATCH },
351 { "a.b", MatchCase::MATCH_CASE },
352 { "a.a", MatchCase::NO_MATCH },
353 { "a.c", MatchCase::MATCH_CASE },
355 addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
358 static const char* const caseList = "a.b\na.c";
359 static const MatchCase subCases[] =
361 { "a", MatchCase::MATCH_GROUP },
362 { "b", MatchCase::NO_MATCH },
363 { "a.b", MatchCase::MATCH_CASE },
364 { "a.a", MatchCase::NO_MATCH },
365 { "a.c", MatchCase::MATCH_CASE },
367 addChild(new CaseListParserCase(m_testCtx, "separator_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
370 static const char* const caseList = "a.b\ra.c";
371 static const MatchCase subCases[] =
373 { "a", MatchCase::MATCH_GROUP },
374 { "b", MatchCase::NO_MATCH },
375 { "a.b", MatchCase::MATCH_CASE },
376 { "a.a", MatchCase::NO_MATCH },
377 { "a.c", MatchCase::MATCH_CASE },
379 addChild(new CaseListParserCase(m_testCtx, "separator_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
382 static const char* const caseList = "a.b\r\na.c";
383 static const MatchCase subCases[] =
385 { "a", MatchCase::MATCH_GROUP },
386 { "b", MatchCase::NO_MATCH },
387 { "a.b", MatchCase::MATCH_CASE },
388 { "a.a", MatchCase::NO_MATCH },
389 { "a.c", MatchCase::MATCH_CASE },
391 addChild(new CaseListParserCase(m_testCtx, "separator_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
394 static const char* const caseList = "a.b\na.c\n";
395 static const MatchCase subCases[] =
397 { "a", MatchCase::MATCH_GROUP },
398 { "b", MatchCase::NO_MATCH },
399 { "a.b", MatchCase::MATCH_CASE },
400 { "a.a", MatchCase::NO_MATCH },
401 { "a.c", MatchCase::MATCH_CASE },
403 addChild(new CaseListParserCase(m_testCtx, "end_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
406 static const char* const caseList = "a.b\na.c\r";
407 static const MatchCase subCases[] =
409 { "a", MatchCase::MATCH_GROUP },
410 { "b", MatchCase::NO_MATCH },
411 { "a.b", MatchCase::MATCH_CASE },
412 { "a.a", MatchCase::NO_MATCH },
413 { "a.c", MatchCase::MATCH_CASE },
415 addChild(new CaseListParserCase(m_testCtx, "end_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
418 static const char* const caseList = "a.b\na.c\r\n";
419 static const MatchCase subCases[] =
421 { "a", MatchCase::MATCH_GROUP },
422 { "b", MatchCase::NO_MATCH },
423 { "a.b", MatchCase::MATCH_CASE },
424 { "a.a", MatchCase::NO_MATCH },
425 { "a.c", MatchCase::MATCH_CASE },
427 addChild(new CaseListParserCase(m_testCtx, "end_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
430 static const char* const caseList = "a.b\nc.d\nc.e";
431 static const MatchCase subCases[] =
433 { "a", MatchCase::MATCH_GROUP },
434 { "b", MatchCase::NO_MATCH },
435 { "a.b", MatchCase::MATCH_CASE },
436 { "a.c", MatchCase::NO_MATCH },
437 { "a.d", MatchCase::NO_MATCH },
438 { "a.e", MatchCase::NO_MATCH },
439 { "c", MatchCase::MATCH_GROUP },
440 { "c.b", MatchCase::NO_MATCH },
441 { "c.d", MatchCase::MATCH_CASE },
442 { "c.e", MatchCase::MATCH_CASE },
444 addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
447 static const char* const caseList = "a\nc.d\nc.e";
448 static const MatchCase subCases[] =
450 { "a", MatchCase::MATCH_CASE },
451 { "b", MatchCase::NO_MATCH },
452 { "a.b", MatchCase::NO_MATCH },
453 { "a.c", MatchCase::NO_MATCH },
454 { "a.d", MatchCase::NO_MATCH },
455 { "a.e", MatchCase::NO_MATCH },
456 { "c", MatchCase::MATCH_GROUP },
457 { "c.b", MatchCase::NO_MATCH },
458 { "c.d", MatchCase::MATCH_CASE },
459 { "c.e", MatchCase::MATCH_CASE },
461 addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
464 static const char* const caseList = "c.d\nc.e\na";
465 static const MatchCase subCases[] =
467 { "a", MatchCase::MATCH_CASE },
468 { "b", MatchCase::NO_MATCH },
469 { "a.b", MatchCase::NO_MATCH },
470 { "a.c", MatchCase::NO_MATCH },
471 { "a.d", MatchCase::NO_MATCH },
472 { "a.e", MatchCase::NO_MATCH },
473 { "c", MatchCase::MATCH_GROUP },
474 { "c.b", MatchCase::NO_MATCH },
475 { "c.d", MatchCase::MATCH_CASE },
476 { "c.e", MatchCase::MATCH_CASE },
478 addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
481 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";
482 static const MatchCase subCases[] =
484 { "a", MatchCase::MATCH_GROUP },
485 { "b", MatchCase::NO_MATCH },
486 { "a.b", MatchCase::MATCH_GROUP },
487 { "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 },
489 addChild(new CaseListParserCase(m_testCtx, "long_name", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
492 static const char* const caseList =
498 static const MatchCase subCases[] =
500 { "a", MatchCase::MATCH_GROUP },
501 { "a.b", MatchCase::MATCH_GROUP },
502 { "a.b.c.d.e", MatchCase::MATCH_CASE },
503 { "a.b.c.d.g", MatchCase::MATCH_CASE },
504 { "x.y", MatchCase::MATCH_GROUP },
505 { "x.y.z", MatchCase::MATCH_CASE },
506 { "a.b.c.f", MatchCase::MATCH_CASE },
507 { "a.b.c.x", MatchCase::MATCH_CASE },
509 addChild(new CaseListParserCase(m_testCtx, "partial_prefix", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
512 static const char* const caseList =
515 static const MatchCase subCases[] =
517 { "a", MatchCase::MATCH_GROUP },
518 { "a.a", MatchCase::MATCH_GROUP },
519 { "a.b.c.d", MatchCase::MATCH_CASE },
520 { "a.b.c.d", MatchCase::MATCH_CASE },
522 addChild(new CaseListParserCase(m_testCtx, "reparenting", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
526 addChild(new NegativeCaseListCase(m_testCtx, "empty_string", ""));
527 addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n"));
528 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name", ".test"));
529 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name", "test."));
533 class CaseListParserTests : public tcu::TestCaseGroup
536 CaseListParserTests (tcu::TestContext& testCtx)
537 : tcu::TestCaseGroup(testCtx, "case_list_parser", "Test case list parser tests")
543 addChild(new TrieParserTests(m_testCtx));
544 addChild(new ListParserTests(m_testCtx));
548 class CommonFrameworkTests : public tcu::TestCaseGroup
551 CommonFrameworkTests (tcu::TestContext& testCtx)
552 : tcu::TestCaseGroup(testCtx, "common", "Tests for the common utility framework")
558 addChild(new SelfCheckCase(m_testCtx, "float_format","tcu::FloatFormat_selfTest()",
559 tcu::FloatFormat_selfTest));
560 addChild(new SelfCheckCase(m_testCtx, "either","tcu::Either_selfTest()",
561 tcu::Either_selfTest));
567 FrameworkTests::FrameworkTests (tcu::TestContext& testCtx)
568 : tcu::TestCaseGroup(testCtx, "framework", "Miscellaneous framework tests")
572 FrameworkTests::~FrameworkTests (void)
576 void FrameworkTests::init (void)
578 addChild(new CommonFrameworkTests (m_testCtx));
579 addChild(new CaseListParserTests (m_testCtx));