-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
524b27f
commit 49a9f18
Showing
9 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,8 @@ qrc_*.cpp | |
moc_*.h | ||
ui_*.h | ||
build*/ | ||
cmake-build-*/ | ||
Makefile* | ||
*build-* | ||
|
||
# QtCreator | ||
*.autosave | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
#ifndef AUTOTEST_H | ||
#define AUTOTEST_H | ||
|
||
// see http://qtcreator.blogspot.de/2009/10/running-multiple-unit-tests.html | ||
|
||
#include <QTest> | ||
#include <QList> | ||
#include <QString> | ||
#include <QSharedPointer> | ||
|
||
namespace AutoTest | ||
{ | ||
typedef QList<QObject *> TestList; | ||
|
||
inline TestList &testList() | ||
{ | ||
static TestList list; | ||
return list; | ||
} | ||
|
||
inline bool findObject(QObject *object) | ||
{ | ||
TestList &list = testList(); | ||
if (list.contains(object)) { | ||
return true; | ||
} | ||
|
||
for (QObject *test : list) { | ||
if (test->objectName() == object->objectName()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
inline void addTest(QObject *object) | ||
{ | ||
TestList &list = testList(); | ||
if (!findObject(object)) { | ||
list.append(object); | ||
} | ||
} | ||
|
||
inline int run(int argc, char *argv[]) | ||
{ | ||
int ret = 0; | ||
|
||
for (QObject *test : testList()) { | ||
ret += QTest::qExec(test, argc, argv); | ||
} | ||
|
||
return ret; | ||
} | ||
} | ||
|
||
template<class T> | ||
class Test | ||
{ | ||
public: | ||
QSharedPointer<T> child; | ||
|
||
Test(const QString &name) | ||
: child(new T) | ||
{ | ||
child->setObjectName(name); | ||
AutoTest::addTest(child.data()); | ||
} | ||
}; | ||
|
||
#define DECLARE_TEST(className) static Test<className> t(#className); | ||
|
||
#endif //AUTOTEST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Test) | ||
|
||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/CutterTest.pro" | ||
"${CMAKE_CURRENT_BINARY_DIR}/CutterTest.pro" | ||
COPYONLY) # trigger reconfigure if CutterTest.pro changes | ||
parse_qmake_pro("${CMAKE_CURRENT_BINARY_DIR}/CutterTest.pro" CUTTER_TEST_PRO) | ||
set(TEST_SOURCE_FILES ${CUTTER_TEST_PRO_SOURCES}) | ||
set(TEST_HEADER_FILES ${CUTTER_TEST_PRO_HEADERS}) | ||
|
||
message(STATUS "sources from CutterTest.pro: ${TEST_SOURCE_FILES}") | ||
message(STATUS "headers from CutterTest.pro: ${TEST_HEADER_FILES}") | ||
|
||
add_executable(CutterTest ${TEST_SOURCE_FILES} ${TEST_HEADER_FILES}) | ||
qt5_use_modules(CutterTest Core Widgets Gui Test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
#include "CutterTest.h" | ||
|
||
void CutterTest::initTestCase() | ||
{ | ||
qDebug("CutterTest::initTestCase()"); | ||
} | ||
|
||
void CutterTest::cleanupTestCase() | ||
{ | ||
qDebug("CutterTest::cleanupTestCase()"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
#ifndef CUTTERTEST_H | ||
#define CUTTERTEST_H | ||
|
||
#include <QObject> | ||
|
||
class CutterTest: public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
protected slots: | ||
virtual void initTestCase(); | ||
virtual void cleanupTestCase(); | ||
}; | ||
|
||
#endif //CUTTERTEST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
QT += widgets testlib | ||
|
||
HEADERS = AutoTest.h \ | ||
CutterTest.h | ||
|
||
SOURCES = main.cpp \ | ||
TestHexdumpWidget.cpp \ | ||
CutterTest.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
#include <QtTest> | ||
|
||
#include "AutoTest.h" | ||
#include "CutterTest.h" | ||
|
||
class TestHexdumpWidget: public CutterTest | ||
{ | ||
Q_OBJECT | ||
private slots: | ||
void initTestCase() override; | ||
void toUpper(); | ||
}; | ||
|
||
void TestHexdumpWidget::initTestCase() | ||
{ | ||
qDebug("TestHexdumpWidget::initTestCase()"); | ||
} | ||
|
||
void TestHexdumpWidget::toUpper() | ||
{ | ||
QString str = "Hello"; | ||
QCOMPARE(str.toUpper(), QString("HELLO")); | ||
} | ||
|
||
DECLARE_TEST(TestHexdumpWidget) | ||
#include "TestHexdumpWidget.moc" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
#include "AutoTest.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
return AutoTest::run(argc, argv); | ||
} | ||
|