From 37bc11e707d3f29fa81675bcc41610ab65c2b314 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 28 Sep 2021 15:12:48 +0200 Subject: Refactor QTEST*_MAIN() implementations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The various variants duplicated some rather complex code around varying setup in the middle. Rework in terms of a macro that defines main() and takes the setup code as a parameter. That setup code also had some common structure, so package that in a setup macro that takes the class to be used. Reworked various testlib selftests that were using QTEST_MAIN_IMPL(); change to use the new QTEST_MAIN_WRAPPER() and TEST_MAIN_SETUP(). These might be better dealt with by supporting a second form of the initMain() test-setup function in the test classes, that takes references for argc and argv, to let a test massage its command-line options. Change-Id: I7fb16b38d51c80ba2f5c9c82f3b7a37ffc636795 Reviewed-by: Tor Arne Vestbø --- .../benchlibcallgrind/tst_benchlibcallgrind.cpp | 7 ++----- .../selftests/benchlibcounting/tst_benchlibcounting.cpp | 9 +++------ .../benchlibtickcounter/tst_benchlibtickcounter.cpp | 9 +++------ .../selftests/commandlinedata/tst_commandlinedata.cpp | 9 +++------ tests/auto/testlib/selftests/counting/tst_counting.cpp | 17 ++++++++++------- .../selftests/printdatatags/tst_printdatatags.cpp | 9 +++------ .../tst_printdatatagswithglobaltags.cpp | 9 +++------ .../testlib/selftests/signaldumper/tst_signaldumper.cpp | 9 +++------ tests/auto/testlib/selftests/silent/tst_silent.cpp | 9 +++------ 9 files changed, 33 insertions(+), 54 deletions(-) (limited to 'tests/auto/testlib/selftests') diff --git a/tests/auto/testlib/selftests/benchlibcallgrind/tst_benchlibcallgrind.cpp b/tests/auto/testlib/selftests/benchlibcallgrind/tst_benchlibcallgrind.cpp index 353a7f5018..b3cf623375 100644 --- a/tests/auto/testlib/selftests/benchlibcallgrind/tst_benchlibcallgrind.cpp +++ b/tests/auto/testlib/selftests/benchlibcallgrind/tst_benchlibcallgrind.cpp @@ -78,8 +78,7 @@ void tst_BenchlibCallgrind::twoHundredMillionInstructions() #endif } -int main(int argc, char *argv[]) -{ +QTEST_MAIN_WRAPPER(tst_BenchlibCallgrind, std::vector args(argv, argv + argc); // Add the -callgrind argument unless (it's there anyway or) we're the // recursive invocation with -callgrindchild passed. @@ -92,9 +91,7 @@ int main(int argc, char *argv[]) argc = args.size(); argv = const_cast(&args[0]); } - - QTEST_MAIN_IMPL(tst_BenchlibCallgrind) -} + QTEST_MAIN_SETUP()) #undef HAVE_VALGRIND_H #include "tst_benchlibcallgrind.moc" diff --git a/tests/auto/testlib/selftests/benchlibcounting/tst_benchlibcounting.cpp b/tests/auto/testlib/selftests/benchlibcounting/tst_benchlibcounting.cpp index 40dd0bc25f..9903a1bd59 100644 --- a/tests/auto/testlib/selftests/benchlibcounting/tst_benchlibcounting.cpp +++ b/tests/auto/testlib/selftests/benchlibcounting/tst_benchlibcounting.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -59,14 +59,11 @@ void tst_BenchlibCounting::failingBenchmark() }; } -int main(int argc, char *argv[]) -{ +QTEST_MAIN_WRAPPER(tst_BenchlibCounting, std::vector args(argv, argv + argc); args.push_back("-eventcounter"); argc = args.size(); argv = const_cast(&args[0]); - - QTEST_MAIN_IMPL(tst_BenchlibCounting) -} + QTEST_MAIN_SETUP()) #include "tst_benchlibcounting.moc" diff --git a/tests/auto/testlib/selftests/benchlibtickcounter/tst_benchlibtickcounter.cpp b/tests/auto/testlib/selftests/benchlibtickcounter/tst_benchlibtickcounter.cpp index 8f1a06a3c3..97ac22bb94 100644 --- a/tests/auto/testlib/selftests/benchlibtickcounter/tst_benchlibtickcounter.cpp +++ b/tests/auto/testlib/selftests/benchlibtickcounter/tst_benchlibtickcounter.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -62,14 +62,11 @@ void tst_BenchlibTickCounter::threeBillionTicks() #endif } -int main(int argc, char *argv[]) -{ +QTEST_MAIN_WRAPPER(tst_BenchlibTickCounter, std::vector args(argv, argv + argc); args.push_back("-tickcounter"); argc = args.size(); argv = const_cast(&args[0]); - - QTEST_MAIN_IMPL(tst_BenchlibTickCounter) -} + QTEST_MAIN_SETUP()) #include "tst_benchlibtickcounter.moc" diff --git a/tests/auto/testlib/selftests/commandlinedata/tst_commandlinedata.cpp b/tests/auto/testlib/selftests/commandlinedata/tst_commandlinedata.cpp index 42746d8fab..9759436ef9 100644 --- a/tests/auto/testlib/selftests/commandlinedata/tst_commandlinedata.cpp +++ b/tests/auto/testlib/selftests/commandlinedata/tst_commandlinedata.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -63,16 +63,13 @@ void tst_DataTable::fiveTablePasses_data() const QTest::newRow("fiveTablePasses_data5") << true; } -int main(int argc, char *argv[]) -{ +QTEST_MAIN_WRAPPER(tst_DataTable, std::vector args(argv, argv + argc); args.push_back("fiveTablePasses"); args.push_back("fiveTablePasses:fiveTablePasses_data1"); args.push_back("-v2"); argc = int(args.size()); argv = const_cast(&args[0]); - - QTEST_MAIN_IMPL(tst_DataTable) -} + QTEST_MAIN_SETUP()) #include "tst_commandlinedata.moc" diff --git a/tests/auto/testlib/selftests/counting/tst_counting.cpp b/tests/auto/testlib/selftests/counting/tst_counting.cpp index 0831f88005..69cfc91b40 100644 --- a/tests/auto/testlib/selftests/counting/tst_counting.cpp +++ b/tests/auto/testlib/selftests/counting/tst_counting.cpp @@ -290,15 +290,18 @@ void tst_Counting::testSkipInCleanup() qDebug() << "This test function should execute and then QSKIP in cleanup()"; } -int main(int argc, char *argv[]) -{ #ifdef TESTLIB_VERBOSITY_ARG - std::vector args(argv, argv + argc); - args.push_back(QT_STRINGIFY(TESTLIB_VERBOSITY_ARG)); - argc = int(args.size()); +#define SETUP() \ + std::vector args(argv, argv + argc); \ + args.push_back(QT_STRINGIFY(TESTLIB_VERBOSITY_ARG)); \ + argc = int(args.size()); \ argv = const_cast(&args[0]); +#else +#define SETUP() #endif - QTEST_MAIN_IMPL(tst_Counting) -} +QTEST_MAIN_WRAPPER(tst_Counting, + SETUP() + QTEST_MAIN_SETUP()) + #include "tst_counting.moc" diff --git a/tests/auto/testlib/selftests/printdatatags/tst_printdatatags.cpp b/tests/auto/testlib/selftests/printdatatags/tst_printdatatags.cpp index d036c64d1f..a2f91896f4 100644 --- a/tests/auto/testlib/selftests/printdatatags/tst_printdatatags.cpp +++ b/tests/auto/testlib/selftests/printdatatags/tst_printdatatags.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -72,14 +72,11 @@ void tst_PrintDataTags::c() const { } -int main(int argc, char *argv[]) -{ +QTEST_MAIN_WRAPPER(tst_PrintDataTags, std::vector args(argv, argv + argc); args.push_back("-datatags"); argc = int(args.size()); argv = const_cast(&args[0]); - - QTEST_MAIN_IMPL(tst_PrintDataTags) -} + QTEST_MAIN_SETUP()) #include "tst_printdatatags.moc" diff --git a/tests/auto/testlib/selftests/printdatatagswithglobaltags/tst_printdatatagswithglobaltags.cpp b/tests/auto/testlib/selftests/printdatatagswithglobaltags/tst_printdatatagswithglobaltags.cpp index e94bec3b64..417df9aedb 100644 --- a/tests/auto/testlib/selftests/printdatatagswithglobaltags/tst_printdatatagswithglobaltags.cpp +++ b/tests/auto/testlib/selftests/printdatatagswithglobaltags/tst_printdatatagswithglobaltags.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -88,14 +88,11 @@ void tst_PrintDataTagsWithGlobalTags::c() const { } -int main(int argc, char *argv[]) -{ +QTEST_MAIN_WRAPPER(tst_PrintDataTagsWithGlobalTags, std::vector args(argv, argv + argc); args.push_back("-datatags"); argc = int(args.size()); argv = const_cast(&args[0]); - - QTEST_MAIN_IMPL(tst_PrintDataTagsWithGlobalTags) -} + QTEST_MAIN_SETUP()) #include "tst_printdatatagswithglobaltags.moc" diff --git a/tests/auto/testlib/selftests/signaldumper/tst_signaldumper.cpp b/tests/auto/testlib/selftests/signaldumper/tst_signaldumper.cpp index f83a3c42f6..6dee51b544 100644 --- a/tests/auto/testlib/selftests/signaldumper/tst_signaldumper.cpp +++ b/tests/auto/testlib/selftests/signaldumper/tst_signaldumper.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -424,14 +424,11 @@ void tst_Signaldumper::deletingSender() emit signalSlotOwner->signalWithoutParameters(); } -int main(int argc, char *argv[]) -{ +QTEST_MAIN_WRAPPER(tst_Signaldumper, std::vector args(argv, argv + argc); args.push_back("-vs"); argc = int(args.size()); argv = const_cast(&args[0]); - - QTEST_MAIN_IMPL(tst_Signaldumper) -} + QTEST_MAIN_SETUP()) #include "tst_signaldumper.moc" diff --git a/tests/auto/testlib/selftests/silent/tst_silent.cpp b/tests/auto/testlib/selftests/silent/tst_silent.cpp index 34b33e1391..87c610f269 100644 --- a/tests/auto/testlib/selftests/silent/tst_silent.cpp +++ b/tests/auto/testlib/selftests/silent/tst_silent.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -102,14 +102,11 @@ void tst_Silent::messages() qFatal("This is a fatal error message that should still appear in silent test output"); } -int main(int argc, char *argv[]) -{ +QTEST_MAIN_WRAPPER(tst_Silent, std::vector args(argv, argv + argc); args.push_back("-silent"); argc = int(args.size()); argv = const_cast(&args[0]); - - QTEST_MAIN_IMPL(tst_Silent) -} + QTEST_MAIN_SETUP()) #include "tst_silent.moc" -- cgit v1.2.3