Skip to content

Commit 27df9cf

Browse files
committed
tests: split sqlb-unittests
Instead of a single executable running different unit tests at the same time, split the sqlobjects and import parts out of it. While this currently duplicates the cmake boilerplate for each, it allows to finetune each properly (like build only the sources for it, in the future), and to call each separately. Add the QTEST_MAIN in each test, and remove the manual QCoreApplication handling in TestImport (handled by QTEST_MAIN).
1 parent 57f2622 commit 27df9cf

File tree

5 files changed

+80
-52
lines changed

5 files changed

+80
-52
lines changed

src/tests/CMakeLists.txt

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,115 @@ else()
55
add_definitions(${QT_DEFINITIONS})
66
endif()
77

8-
set(SQLB_UNITTESTS_SRC
8+
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${ANTLR_DIR}" ..)
9+
10+
# test-sqlobjects
11+
12+
set(TESTSQLOBJECTS_SRC
913
../sqlitedb.cpp
1014
../sqlitetablemodel.cpp
1115
../sqlitetypes.cpp
1216
../csvparser.cpp
1317
../grammar/Sqlite3Lexer.cpp
1418
../grammar/Sqlite3Parser.cpp
1519
../PreferencesDialog.cpp
16-
TestImport.cpp
1720
testsqlobjects.cpp
18-
TestMain.cpp
1921
../FileDialog.cpp
2022
)
2123

22-
set(SQLB_UNITTESTS_HDR
24+
set(TESTSQLOBJECTS_HDR
2325
../grammar/sqlite3TokenTypes.hpp
2426
../grammar/Sqlite3Lexer.hpp
2527
../grammar/Sqlite3Parser.hpp
26-
../csvparser.h
2728
../sqlitetypes.h)
2829

29-
set(SQLB_UNITTESTS_FORMS
30+
set(TESTSQLOBJECTS_FORMS
3031
../PreferencesDialog.ui)
3132

32-
set(SQLB_UNITTESTS_MOC_HDR
33+
set(TESTSQLOBJECTS_MOC_HDR
3334
../sqlitedb.h
3435
../sqlitetablemodel.h
3536
../PreferencesDialog.h
36-
TestImport.h
3737
testsqlobjects.h
3838
../FileDialog.h
3939
)
4040

4141
if(sqlcipher)
42-
list(APPEND SQLB_UNITTESTS_SRC ../CipherDialog.cpp)
43-
list(APPEND SQLB_UNITTESTS_FORMS ../CipherDialog.ui)
44-
list(APPEND SQLB_UNITTESTS_MOC_HDR ../CipherDialog.h)
42+
list(APPEND TESTSQLOBJECTS_SRC ../CipherDialog.cpp)
43+
list(APPEND TESTSQLOBJECTS_FORMS ../CipherDialog.ui)
44+
list(APPEND TESTSQLOBJECTS_MOC_HDR ../CipherDialog.h)
4545
endif()
4646

4747
if(USE_QT5)
48-
QT5_WRAP_UI(SQLB_UNITTESTS_FORM_HDR ${SQLB_UNITTESTS_FORMS})
48+
QT5_WRAP_UI(TESTSQLOBJECTS_FORM_HDR ${TESTSQLOBJECTS_FORMS})
4949
else()
50-
QT4_WRAP_CPP(SQLB_UNITTESTS_MOC ${SQLB_UNITTESTS_MOC_HDR})
51-
QT4_WRAP_UI(SQLB_UNITTESTS_FORM_HDR ${SQLB_UNITTESTS_FORMS})
50+
QT4_WRAP_CPP(TESTSQLOBJECTS_MOC ${TESTSQLOBJECTS_MOC_HDR})
51+
QT4_WRAP_UI(TESTSQLOBJECTS_FORM_HDR ${TESTSQLOBJECTS_FORMS})
5252
endif()
5353

54-
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${ANTLR_DIR}" ..)
54+
add_executable(test-sqlobjects ${TESTSQLOBJECTS_MOC} ${TESTSQLOBJECTS_HDR} ${TESTSQLOBJECTS_SRC} ${TESTSQLOBJECTS_FORM_HDR})
55+
56+
if(USE_QT5)
57+
qt5_use_modules(test-sqlobjects Test Widgets Gui)
58+
set(QT_LIBRARIES "")
59+
endif()
60+
61+
add_dependencies(test-sqlobjects antlr)
62+
target_link_libraries(test-sqlobjects antlr ${QT_LIBRARIES} ${LIBSQLITE})
63+
add_test(test-sqlobjects test-sqlobjects)
64+
65+
# test-import
66+
67+
set(TESTIMPORT_SRC
68+
../sqlitedb.cpp
69+
../sqlitetablemodel.cpp
70+
../sqlitetypes.cpp
71+
../csvparser.cpp
72+
../grammar/Sqlite3Lexer.cpp
73+
../grammar/Sqlite3Parser.cpp
74+
../PreferencesDialog.cpp
75+
TestImport.cpp
76+
../FileDialog.cpp
77+
)
78+
79+
set(TESTIMPORT_HDR
80+
../grammar/sqlite3TokenTypes.hpp
81+
../grammar/Sqlite3Lexer.hpp
82+
../grammar/Sqlite3Parser.hpp
83+
../csvparser.h
84+
../sqlitetypes.h)
85+
86+
set(TESTIMPORT_FORMS
87+
../PreferencesDialog.ui)
88+
89+
set(TESTIMPORT_MOC_HDR
90+
../sqlitedb.h
91+
../sqlitetablemodel.h
92+
../PreferencesDialog.h
93+
TestImport.h
94+
../FileDialog.h
95+
)
96+
97+
if(sqlcipher)
98+
list(APPEND TESTIMPORT_SRC ../CipherDialog.cpp)
99+
list(APPEND TESTIMPORT_FORMS ../CipherDialog.ui)
100+
list(APPEND TESTIMPORT_MOC_HDR ../CipherDialog.h)
101+
endif()
102+
103+
if(USE_QT5)
104+
QT5_WRAP_UI(TESTIMPORT_FORM_HDR ${TESTIMPORT_FORMS})
105+
else()
106+
QT4_WRAP_CPP(TESTIMPORT_MOC ${TESTIMPORT_MOC_HDR})
107+
QT4_WRAP_UI(TESTIMPORT_FORM_HDR ${TESTIMPORT_FORMS})
108+
endif()
55109

56-
add_executable(sqlb-unittests ${SQLB_UNITTESTS_MOC} ${SQLB_UNITTESTS_HDR} ${SQLB_UNITTESTS_SRC} ${SQLB_UNITTESTS_FORM_HDR})
110+
add_executable(test-import ${TESTIMPORT_MOC} ${TESTIMPORT_HDR} ${TESTIMPORT_SRC} ${TESTIMPORT_FORM_HDR})
57111

58112
if(USE_QT5)
59-
qt5_use_modules(sqlb-unittests Test Widgets Gui)
113+
qt5_use_modules(test-import Test Widgets Gui)
60114
set(QT_LIBRARIES "")
61115
endif()
62116

63-
add_dependencies(sqlb-unittests antlr)
64-
target_link_libraries(sqlb-unittests antlr ${QT_LIBRARIES} ${LIBSQLITE})
65-
add_test(sqlb-unittests sqlb-unittests)
117+
add_dependencies(test-import antlr)
118+
target_link_libraries(test-import antlr ${QT_LIBRARIES} ${LIBSQLITE})
119+
add_test(test-import test-import)

src/tests/TestImport.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// force QtCore-only main application by QTEST_MAIN
2+
#undef QT_GUI_LIB
13
#include <QTemporaryFile>
24
#include <QtTest/QTest>
35
#include <QCoreApplication>
@@ -7,23 +9,16 @@
79
#include "TestImport.h"
810
#include "../sqlitedb.h"
911

12+
QTEST_MAIN(TestImport)
13+
1014
Q_DECLARE_METATYPE(CSVParser::TCSVResult)
1115

1216
TestImport::TestImport()
1317
{
14-
// Init basic application
15-
// The app needs to be initialized for the utf8 test
16-
// to work
17-
argcount = 1;
18-
args[0] = new char[20];
19-
strcpy(args[0], "sqlb-unittests");
20-
app = new QCoreApplication(argcount, args);
2118
}
2219

2320
TestImport::~TestImport()
2421
{
25-
delete[] args[0];
26-
delete app;
2722
}
2823

2924
void TestImport::csvImport()

src/tests/TestImport.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define TESTIMPORT_H
33

44
#include <QObject>
5-
#include <QApplication>
65

76
class TestImport : public QObject
87
{
@@ -12,11 +11,6 @@ class TestImport : public QObject
1211
TestImport();
1312
~TestImport();
1413

15-
private:
16-
int argcount;
17-
char *args[1]; // the size must match what 'argcount' is set to
18-
QCoreApplication* app;
19-
2014
private slots:
2115
void csvImport();
2216
void csvImport_data();

src/tests/TestMain.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/tests/testsqlobjects.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <QtTest/QtTest>
55

6+
QTEST_APPLESS_MAIN(TestTable)
7+
68
using namespace sqlb;
79

810
void TestTable::sqlOutput()

0 commit comments

Comments
 (0)