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)));
256 addChild(new NegativeCaseListCase(m_testCtx, "empty_string", ""));
257 addChild(new NegativeCaseListCase(m_testCtx, "empty_root", "{}"));
258 addChild(new NegativeCaseListCase(m_testCtx, "empty_group", "{test{}}"));
259 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_1", "{{}}"));
260 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_2", "{{test}}"));
261 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_1", "{"));
262 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_2", "{test"));
263 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_3", "{test,"));
264 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_4", "{test{a}"));
265 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_5", "{a,b"));
266 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_1", "{test{"));
267 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_2", "{test{a"));
268 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_3", "{test{a,"));
269 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_4", "{test{a,b"));
270 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_1", "{a,,b}"));
271 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_2", "{,b}"));
272 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_3", "{a,}"));
273 addChild(new NegativeCaseListCase(m_testCtx, "no_separator", "{a{b}c}"));
274 addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_1", "{a.b}"));
275 addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_2", "{a[]}"));
276 addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_1", "{a}}"));
277 addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_2", "{a}x"));
281 class ListParserTests : public tcu::TestCaseGroup
284 ListParserTests (tcu::TestContext& testCtx)
285 : tcu::TestCaseGroup(testCtx, "list", "Test case list parser tests")
292 static const char* const caseList = "test";
293 static const MatchCase subCases[] =
295 { "test", MatchCase::MATCH_CASE },
296 { "test.cd", MatchCase::NO_MATCH },
298 addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
301 static const char* const caseList = "a.b";
302 static const MatchCase subCases[] =
304 { "a", MatchCase::MATCH_GROUP },
305 { "b", MatchCase::NO_MATCH },
306 { "a.b", MatchCase::MATCH_CASE },
307 { "a.a", MatchCase::NO_MATCH },
309 addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
312 static const char* const caseList = "a.b\na.c";
313 static const MatchCase subCases[] =
315 { "a", MatchCase::MATCH_GROUP },
316 { "b", MatchCase::NO_MATCH },
317 { "a.b", MatchCase::MATCH_CASE },
318 { "a.a", MatchCase::NO_MATCH },
319 { "a.c", MatchCase::MATCH_CASE },
321 addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
324 static const char* const caseList = "a.b\na.c";
325 static const MatchCase subCases[] =
327 { "a", MatchCase::MATCH_GROUP },
328 { "b", MatchCase::NO_MATCH },
329 { "a.b", MatchCase::MATCH_CASE },
330 { "a.a", MatchCase::NO_MATCH },
331 { "a.c", MatchCase::MATCH_CASE },
333 addChild(new CaseListParserCase(m_testCtx, "separator_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
336 static const char* const caseList = "a.b\ra.c";
337 static const MatchCase subCases[] =
339 { "a", MatchCase::MATCH_GROUP },
340 { "b", MatchCase::NO_MATCH },
341 { "a.b", MatchCase::MATCH_CASE },
342 { "a.a", MatchCase::NO_MATCH },
343 { "a.c", MatchCase::MATCH_CASE },
345 addChild(new CaseListParserCase(m_testCtx, "separator_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
348 static const char* const caseList = "a.b\r\na.c";
349 static const MatchCase subCases[] =
351 { "a", MatchCase::MATCH_GROUP },
352 { "b", MatchCase::NO_MATCH },
353 { "a.b", MatchCase::MATCH_CASE },
354 { "a.a", MatchCase::NO_MATCH },
355 { "a.c", MatchCase::MATCH_CASE },
357 addChild(new CaseListParserCase(m_testCtx, "separator_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
360 static const char* const caseList = "a.b\na.c\n";
361 static const MatchCase subCases[] =
363 { "a", MatchCase::MATCH_GROUP },
364 { "b", MatchCase::NO_MATCH },
365 { "a.b", MatchCase::MATCH_CASE },
366 { "a.a", MatchCase::NO_MATCH },
367 { "a.c", MatchCase::MATCH_CASE },
369 addChild(new CaseListParserCase(m_testCtx, "end_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
372 static const char* const caseList = "a.b\na.c\r";
373 static const MatchCase subCases[] =
375 { "a", MatchCase::MATCH_GROUP },
376 { "b", MatchCase::NO_MATCH },
377 { "a.b", MatchCase::MATCH_CASE },
378 { "a.a", MatchCase::NO_MATCH },
379 { "a.c", MatchCase::MATCH_CASE },
381 addChild(new CaseListParserCase(m_testCtx, "end_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
384 static const char* const caseList = "a.b\na.c\r\n";
385 static const MatchCase subCases[] =
387 { "a", MatchCase::MATCH_GROUP },
388 { "b", MatchCase::NO_MATCH },
389 { "a.b", MatchCase::MATCH_CASE },
390 { "a.a", MatchCase::NO_MATCH },
391 { "a.c", MatchCase::MATCH_CASE },
393 addChild(new CaseListParserCase(m_testCtx, "end_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
396 static const char* const caseList = "a.b\nc.d\nc.e";
397 static const MatchCase subCases[] =
399 { "a", MatchCase::MATCH_GROUP },
400 { "b", MatchCase::NO_MATCH },
401 { "a.b", MatchCase::MATCH_CASE },
402 { "a.c", MatchCase::NO_MATCH },
403 { "a.d", MatchCase::NO_MATCH },
404 { "a.e", MatchCase::NO_MATCH },
405 { "c", MatchCase::MATCH_GROUP },
406 { "c.b", MatchCase::NO_MATCH },
407 { "c.d", MatchCase::MATCH_CASE },
408 { "c.e", MatchCase::MATCH_CASE },
410 addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
413 static const char* const caseList = "a\nc.d\nc.e";
414 static const MatchCase subCases[] =
416 { "a", MatchCase::MATCH_CASE },
417 { "b", MatchCase::NO_MATCH },
418 { "a.b", MatchCase::NO_MATCH },
419 { "a.c", MatchCase::NO_MATCH },
420 { "a.d", MatchCase::NO_MATCH },
421 { "a.e", MatchCase::NO_MATCH },
422 { "c", MatchCase::MATCH_GROUP },
423 { "c.b", MatchCase::NO_MATCH },
424 { "c.d", MatchCase::MATCH_CASE },
425 { "c.e", MatchCase::MATCH_CASE },
427 addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
430 static const char* const caseList = "c.d\nc.e\na";
431 static const MatchCase subCases[] =
433 { "a", MatchCase::MATCH_CASE },
434 { "b", MatchCase::NO_MATCH },
435 { "a.b", MatchCase::NO_MATCH },
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, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
447 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";
448 static const MatchCase subCases[] =
450 { "a", MatchCase::MATCH_GROUP },
451 { "b", MatchCase::NO_MATCH },
452 { "a.b", MatchCase::MATCH_GROUP },
453 { "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 },
455 addChild(new CaseListParserCase(m_testCtx, "long_name", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
458 static const char* const caseList =
464 static const MatchCase subCases[] =
466 { "a", MatchCase::MATCH_GROUP },
467 { "a.b", MatchCase::MATCH_GROUP },
468 { "a.b.c.d.e", MatchCase::MATCH_CASE },
469 { "a.b.c.d.g", MatchCase::MATCH_CASE },
470 { "x.y", MatchCase::MATCH_GROUP },
471 { "x.y.z", MatchCase::MATCH_CASE },
472 { "a.b.c.f", MatchCase::MATCH_CASE },
473 { "a.b.c.x", MatchCase::MATCH_CASE },
475 addChild(new CaseListParserCase(m_testCtx, "partial_prefix", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
478 static const char* const caseList =
481 static const MatchCase subCases[] =
483 { "a", MatchCase::MATCH_GROUP },
484 { "a.a", MatchCase::MATCH_GROUP },
485 { "a.b.c.d", MatchCase::MATCH_CASE },
486 { "a.b.c.d", MatchCase::MATCH_CASE },
488 addChild(new CaseListParserCase(m_testCtx, "reparenting", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
492 addChild(new NegativeCaseListCase(m_testCtx, "empty_string", ""));
493 addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n"));
494 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name", ".test"));
495 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name", "test."));
499 class CaseListParserTests : public tcu::TestCaseGroup
502 CaseListParserTests (tcu::TestContext& testCtx)
503 : tcu::TestCaseGroup(testCtx, "case_list_parser", "Test case list parser tests")
509 addChild(new TrieParserTests(m_testCtx));
510 addChild(new ListParserTests(m_testCtx));
514 class CommonFrameworkTests : public tcu::TestCaseGroup
517 CommonFrameworkTests (tcu::TestContext& testCtx)
518 : tcu::TestCaseGroup(testCtx, "common", "Tests for the common utility framework")
524 addChild(new SelfCheckCase(m_testCtx, "float_format","tcu::FloatFormat_selfTest()",
525 tcu::FloatFormat_selfTest));
526 addChild(new CaseListParserTests(m_testCtx));
532 FrameworkTests::FrameworkTests (tcu::TestContext& testCtx)
533 : tcu::TestCaseGroup(testCtx, "framework", "Miscellaneous framework tests")
537 FrameworkTests::~FrameworkTests (void)
541 void FrameworkTests::init (void)
543 addChild(new CommonFrameworkTests(m_testCtx));