Refactor QTEST*_MAIN() implementations
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ø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
b67c367e0e
commit
37bc11e707
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2019 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Copyright (C) 2020 Intel Corporation.
|
** Copyright (C) 2020 Intel Corporation.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
@ -612,84 +612,57 @@ struct QtCoverageScanner
|
|||||||
#define TESTLIB_SELFCOVERAGE_START(name)
|
#define TESTLIB_SELFCOVERAGE_START(name)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define QTEST_APPLESS_MAIN(TestObject) \
|
// Internal (but used by some testlib selftests to hack argc and argv).
|
||||||
|
// Tests should normally implement initMain() if they have set-up to do before
|
||||||
|
// instantiating the test class.
|
||||||
|
#define QTEST_MAIN_WRAPPER(TestObject, ...) \
|
||||||
int main(int argc, char *argv[]) \
|
int main(int argc, char *argv[]) \
|
||||||
{ \
|
{ \
|
||||||
TESTLIB_SELFCOVERAGE_START(TestObject) \
|
TESTLIB_SELFCOVERAGE_START(#TestObject) \
|
||||||
QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
|
QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
|
||||||
|
__VA_ARGS__ \
|
||||||
TestObject tc; \
|
TestObject tc; \
|
||||||
QTEST_SET_MAIN_SOURCE_PATH \
|
QTEST_SET_MAIN_SOURCE_PATH \
|
||||||
return QTest::qExec(&tc, argc, argv); \
|
return QTest::qExec(&tc, argc, argv); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For when you don't even want a QApplication:
|
||||||
|
#define QTEST_APPLESS_MAIN(TestObject) QTEST_MAIN_WRAPPER(TestObject)
|
||||||
|
|
||||||
#include <QtTest/qtestsystem.h>
|
#include <QtTest/qtestsystem.h>
|
||||||
|
|
||||||
#if defined(QT_NETWORK_LIB)
|
#if defined(QT_NETWORK_LIB)
|
||||||
# include <QtTest/qtest_network.h>
|
# include <QtTest/qtest_network.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Internal
|
||||||
|
#define QTEST_QAPP_SETUP(klaz) \
|
||||||
|
klaz app(argc, argv); \
|
||||||
|
app.setAttribute(Qt::AA_Use96Dpi, true);
|
||||||
|
|
||||||
#if defined(QT_WIDGETS_LIB)
|
#if defined(QT_WIDGETS_LIB)
|
||||||
|
|
||||||
# include <QtTest/qtest_widgets.h>
|
# include <QtTest/qtest_widgets.h>
|
||||||
|
|
||||||
# ifdef QT_KEYPAD_NAVIGATION
|
# ifdef QT_KEYPAD_NAVIGATION
|
||||||
# define QTEST_DISABLE_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeNone);
|
# define QTEST_DISABLE_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeNone);
|
||||||
# else
|
# else
|
||||||
# define QTEST_DISABLE_KEYPAD_NAVIGATION
|
# define QTEST_DISABLE_KEYPAD_NAVIGATION
|
||||||
# endif
|
# endif
|
||||||
|
// Internal
|
||||||
#define QTEST_MAIN_IMPL(TestObject) \
|
# define QTEST_MAIN_SETUP() QTEST_QAPP_SETUP(QApplication) QTEST_DISABLE_KEYPAD_NAVIGATION
|
||||||
TESTLIB_SELFCOVERAGE_START(#TestObject) \
|
|
||||||
QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
|
|
||||||
QApplication app(argc, argv); \
|
|
||||||
app.setAttribute(Qt::AA_Use96Dpi, true); \
|
|
||||||
QTEST_DISABLE_KEYPAD_NAVIGATION \
|
|
||||||
TestObject tc; \
|
|
||||||
QTEST_SET_MAIN_SOURCE_PATH \
|
|
||||||
return QTest::qExec(&tc, argc, argv);
|
|
||||||
|
|
||||||
#elif defined(QT_GUI_LIB)
|
#elif defined(QT_GUI_LIB)
|
||||||
|
|
||||||
# include <QtTest/qtest_gui.h>
|
# include <QtTest/qtest_gui.h>
|
||||||
|
// Internal
|
||||||
#define QTEST_MAIN_IMPL(TestObject) \
|
# define QTEST_MAIN_SETUP() QTEST_QAPP_SETUP(QGuiApplication)
|
||||||
TESTLIB_SELFCOVERAGE_START(#TestObject) \
|
|
||||||
QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
|
|
||||||
QGuiApplication app(argc, argv); \
|
|
||||||
app.setAttribute(Qt::AA_Use96Dpi, true); \
|
|
||||||
TestObject tc; \
|
|
||||||
QTEST_SET_MAIN_SOURCE_PATH \
|
|
||||||
return QTest::qExec(&tc, argc, argv);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
// Internal
|
||||||
#define QTEST_MAIN_IMPL(TestObject) \
|
# define QTEST_MAIN_SETUP() QTEST_QAPP_SETUP(QCoreApplication)
|
||||||
TESTLIB_SELFCOVERAGE_START(#TestObject) \
|
|
||||||
QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
|
|
||||||
QCoreApplication app(argc, argv); \
|
|
||||||
app.setAttribute(Qt::AA_Use96Dpi, true); \
|
|
||||||
TestObject tc; \
|
|
||||||
QTEST_SET_MAIN_SOURCE_PATH \
|
|
||||||
return QTest::qExec(&tc, argc, argv);
|
|
||||||
|
|
||||||
#endif // QT_GUI_LIB
|
#endif // QT_GUI_LIB
|
||||||
|
|
||||||
#define QTEST_MAIN(TestObject) \
|
// For most tests:
|
||||||
int main(int argc, char *argv[]) \
|
#define QTEST_MAIN(TestObject) QTEST_MAIN_WRAPPER(TestObject, QTEST_MAIN_SETUP())
|
||||||
{ \
|
|
||||||
QTEST_MAIN_IMPL(TestObject) \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// For command-line tests
|
||||||
#define QTEST_GUILESS_MAIN(TestObject) \
|
#define QTEST_GUILESS_MAIN(TestObject) \
|
||||||
int main(int argc, char *argv[]) \
|
QTEST_MAIN_WRAPPER(TestObject, QTEST_QAPP_SETUP(QCoreApplication))
|
||||||
{ \
|
|
||||||
TESTLIB_SELFCOVERAGE_START(#TestObject) \
|
|
||||||
QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
|
|
||||||
QCoreApplication app(argc, argv); \
|
|
||||||
app.setAttribute(Qt::AA_Use96Dpi, true); \
|
|
||||||
TestObject tc; \
|
|
||||||
QTEST_SET_MAIN_SOURCE_PATH \
|
|
||||||
return QTest::qExec(&tc, argc, argv); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,8 +78,7 @@ void tst_BenchlibCallgrind::twoHundredMillionInstructions()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
QTEST_MAIN_WRAPPER(tst_BenchlibCallgrind,
|
||||||
{
|
|
||||||
std::vector<const char*> args(argv, argv + argc);
|
std::vector<const char*> args(argv, argv + argc);
|
||||||
// Add the -callgrind argument unless (it's there anyway or) we're the
|
// Add the -callgrind argument unless (it's there anyway or) we're the
|
||||||
// recursive invocation with -callgrindchild passed.
|
// recursive invocation with -callgrindchild passed.
|
||||||
@ -92,9 +91,7 @@ int main(int argc, char *argv[])
|
|||||||
argc = args.size();
|
argc = args.size();
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
}
|
}
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
QTEST_MAIN_IMPL(tst_BenchlibCallgrind)
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef HAVE_VALGRIND_H
|
#undef HAVE_VALGRIND_H
|
||||||
#include "tst_benchlibcallgrind.moc"
|
#include "tst_benchlibcallgrind.moc"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** 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<const char*> args(argv, argv + argc);
|
std::vector<const char*> args(argv, argv + argc);
|
||||||
args.push_back("-eventcounter");
|
args.push_back("-eventcounter");
|
||||||
argc = args.size();
|
argc = args.size();
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
QTEST_MAIN_IMPL(tst_BenchlibCounting)
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "tst_benchlibcounting.moc"
|
#include "tst_benchlibcounting.moc"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -62,14 +62,11 @@ void tst_BenchlibTickCounter::threeBillionTicks()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
QTEST_MAIN_WRAPPER(tst_BenchlibTickCounter,
|
||||||
{
|
|
||||||
std::vector<const char*> args(argv, argv + argc);
|
std::vector<const char*> args(argv, argv + argc);
|
||||||
args.push_back("-tickcounter");
|
args.push_back("-tickcounter");
|
||||||
argc = args.size();
|
argc = args.size();
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
QTEST_MAIN_IMPL(tst_BenchlibTickCounter)
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "tst_benchlibtickcounter.moc"
|
#include "tst_benchlibtickcounter.moc"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** 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;
|
QTest::newRow("fiveTablePasses_data5") << true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
QTEST_MAIN_WRAPPER(tst_DataTable,
|
||||||
{
|
|
||||||
std::vector<const char*> args(argv, argv + argc);
|
std::vector<const char*> args(argv, argv + argc);
|
||||||
args.push_back("fiveTablePasses");
|
args.push_back("fiveTablePasses");
|
||||||
args.push_back("fiveTablePasses:fiveTablePasses_data1");
|
args.push_back("fiveTablePasses:fiveTablePasses_data1");
|
||||||
args.push_back("-v2");
|
args.push_back("-v2");
|
||||||
argc = int(args.size());
|
argc = int(args.size());
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
QTEST_MAIN_IMPL(tst_DataTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "tst_commandlinedata.moc"
|
#include "tst_commandlinedata.moc"
|
||||||
|
@ -290,15 +290,18 @@ void tst_Counting::testSkipInCleanup()
|
|||||||
qDebug() << "This test function should execute and then QSKIP in cleanup()";
|
qDebug() << "This test function should execute and then QSKIP in cleanup()";
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
#ifdef TESTLIB_VERBOSITY_ARG
|
#ifdef TESTLIB_VERBOSITY_ARG
|
||||||
std::vector<const char*> args(argv, argv + argc);
|
#define SETUP() \
|
||||||
args.push_back(QT_STRINGIFY(TESTLIB_VERBOSITY_ARG));
|
std::vector<const char*> args(argv, argv + argc); \
|
||||||
argc = int(args.size());
|
args.push_back(QT_STRINGIFY(TESTLIB_VERBOSITY_ARG)); \
|
||||||
|
argc = int(args.size()); \
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
|
#else
|
||||||
|
#define SETUP()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTEST_MAIN_IMPL(tst_Counting)
|
QTEST_MAIN_WRAPPER(tst_Counting,
|
||||||
}
|
SETUP()
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
|
|
||||||
#include "tst_counting.moc"
|
#include "tst_counting.moc"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** 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<const char*> args(argv, argv + argc);
|
std::vector<const char*> args(argv, argv + argc);
|
||||||
args.push_back("-datatags");
|
args.push_back("-datatags");
|
||||||
argc = int(args.size());
|
argc = int(args.size());
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
QTEST_MAIN_IMPL(tst_PrintDataTags)
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "tst_printdatatags.moc"
|
#include "tst_printdatatags.moc"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** 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<const char*> args(argv, argv + argc);
|
std::vector<const char*> args(argv, argv + argc);
|
||||||
args.push_back("-datatags");
|
args.push_back("-datatags");
|
||||||
argc = int(args.size());
|
argc = int(args.size());
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
QTEST_MAIN_IMPL(tst_PrintDataTagsWithGlobalTags)
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "tst_printdatatagswithglobaltags.moc"
|
#include "tst_printdatatagswithglobaltags.moc"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -424,14 +424,11 @@ void tst_Signaldumper::deletingSender()
|
|||||||
emit signalSlotOwner->signalWithoutParameters();
|
emit signalSlotOwner->signalWithoutParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
QTEST_MAIN_WRAPPER(tst_Signaldumper,
|
||||||
{
|
|
||||||
std::vector<const char*> args(argv, argv + argc);
|
std::vector<const char*> args(argv, argv + argc);
|
||||||
args.push_back("-vs");
|
args.push_back("-vs");
|
||||||
argc = int(args.size());
|
argc = int(args.size());
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
QTEST_MAIN_IMPL(tst_Signaldumper)
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "tst_signaldumper.moc"
|
#include "tst_signaldumper.moc"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** 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");
|
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<const char*> args(argv, argv + argc);
|
std::vector<const char*> args(argv, argv + argc);
|
||||||
args.push_back("-silent");
|
args.push_back("-silent");
|
||||||
argc = int(args.size());
|
argc = int(args.size());
|
||||||
argv = const_cast<char**>(&args[0]);
|
argv = const_cast<char**>(&args[0]);
|
||||||
|
QTEST_MAIN_SETUP())
|
||||||
QTEST_MAIN_IMPL(tst_Silent)
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "tst_silent.moc"
|
#include "tst_silent.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user