From 27df9cfa4d7e9607dfdb32230888cd990d3a359f Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 2 May 2015 13:51:23 +0200 Subject: [PATCH] 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). --- src/tests/CMakeLists.txt | 94 ++++++++++++++++++++++++++++-------- src/tests/TestImport.cpp | 13 ++--- src/tests/TestImport.h | 6 --- src/tests/TestMain.cpp | 17 ------- src/tests/testsqlobjects.cpp | 2 + 5 files changed, 80 insertions(+), 52 deletions(-) delete mode 100644 src/tests/TestMain.cpp diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 997a0385..a9dd651e 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -5,7 +5,66 @@ else() add_definitions(${QT_DEFINITIONS}) endif() -set(SQLB_UNITTESTS_SRC +include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${ANTLR_DIR}" ..) + +# test-sqlobjects + +set(TESTSQLOBJECTS_SRC + ../sqlitedb.cpp + ../sqlitetablemodel.cpp + ../sqlitetypes.cpp + ../csvparser.cpp + ../grammar/Sqlite3Lexer.cpp + ../grammar/Sqlite3Parser.cpp + ../PreferencesDialog.cpp + testsqlobjects.cpp + ../FileDialog.cpp +) + +set(TESTSQLOBJECTS_HDR + ../grammar/sqlite3TokenTypes.hpp + ../grammar/Sqlite3Lexer.hpp + ../grammar/Sqlite3Parser.hpp + ../sqlitetypes.h) + +set(TESTSQLOBJECTS_FORMS + ../PreferencesDialog.ui) + +set(TESTSQLOBJECTS_MOC_HDR + ../sqlitedb.h + ../sqlitetablemodel.h + ../PreferencesDialog.h + testsqlobjects.h + ../FileDialog.h +) + +if(sqlcipher) + list(APPEND TESTSQLOBJECTS_SRC ../CipherDialog.cpp) + list(APPEND TESTSQLOBJECTS_FORMS ../CipherDialog.ui) + list(APPEND TESTSQLOBJECTS_MOC_HDR ../CipherDialog.h) +endif() + +if(USE_QT5) + QT5_WRAP_UI(TESTSQLOBJECTS_FORM_HDR ${TESTSQLOBJECTS_FORMS}) +else() + QT4_WRAP_CPP(TESTSQLOBJECTS_MOC ${TESTSQLOBJECTS_MOC_HDR}) + QT4_WRAP_UI(TESTSQLOBJECTS_FORM_HDR ${TESTSQLOBJECTS_FORMS}) +endif() + +add_executable(test-sqlobjects ${TESTSQLOBJECTS_MOC} ${TESTSQLOBJECTS_HDR} ${TESTSQLOBJECTS_SRC} ${TESTSQLOBJECTS_FORM_HDR}) + +if(USE_QT5) + qt5_use_modules(test-sqlobjects Test Widgets Gui) + set(QT_LIBRARIES "") +endif() + +add_dependencies(test-sqlobjects antlr) +target_link_libraries(test-sqlobjects antlr ${QT_LIBRARIES} ${LIBSQLITE}) +add_test(test-sqlobjects test-sqlobjects) + +# test-import + +set(TESTIMPORT_SRC ../sqlitedb.cpp ../sqlitetablemodel.cpp ../sqlitetypes.cpp @@ -14,52 +73,47 @@ set(SQLB_UNITTESTS_SRC ../grammar/Sqlite3Parser.cpp ../PreferencesDialog.cpp TestImport.cpp - testsqlobjects.cpp - TestMain.cpp ../FileDialog.cpp ) -set(SQLB_UNITTESTS_HDR +set(TESTIMPORT_HDR ../grammar/sqlite3TokenTypes.hpp ../grammar/Sqlite3Lexer.hpp ../grammar/Sqlite3Parser.hpp ../csvparser.h ../sqlitetypes.h) -set(SQLB_UNITTESTS_FORMS +set(TESTIMPORT_FORMS ../PreferencesDialog.ui) -set(SQLB_UNITTESTS_MOC_HDR +set(TESTIMPORT_MOC_HDR ../sqlitedb.h ../sqlitetablemodel.h ../PreferencesDialog.h TestImport.h - testsqlobjects.h ../FileDialog.h ) if(sqlcipher) - list(APPEND SQLB_UNITTESTS_SRC ../CipherDialog.cpp) - list(APPEND SQLB_UNITTESTS_FORMS ../CipherDialog.ui) - list(APPEND SQLB_UNITTESTS_MOC_HDR ../CipherDialog.h) + list(APPEND TESTIMPORT_SRC ../CipherDialog.cpp) + list(APPEND TESTIMPORT_FORMS ../CipherDialog.ui) + list(APPEND TESTIMPORT_MOC_HDR ../CipherDialog.h) endif() if(USE_QT5) - QT5_WRAP_UI(SQLB_UNITTESTS_FORM_HDR ${SQLB_UNITTESTS_FORMS}) + QT5_WRAP_UI(TESTIMPORT_FORM_HDR ${TESTIMPORT_FORMS}) else() - QT4_WRAP_CPP(SQLB_UNITTESTS_MOC ${SQLB_UNITTESTS_MOC_HDR}) - QT4_WRAP_UI(SQLB_UNITTESTS_FORM_HDR ${SQLB_UNITTESTS_FORMS}) + QT4_WRAP_CPP(TESTIMPORT_MOC ${TESTIMPORT_MOC_HDR}) + QT4_WRAP_UI(TESTIMPORT_FORM_HDR ${TESTIMPORT_FORMS}) endif() -include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${ANTLR_DIR}" ..) - -add_executable(sqlb-unittests ${SQLB_UNITTESTS_MOC} ${SQLB_UNITTESTS_HDR} ${SQLB_UNITTESTS_SRC} ${SQLB_UNITTESTS_FORM_HDR}) +add_executable(test-import ${TESTIMPORT_MOC} ${TESTIMPORT_HDR} ${TESTIMPORT_SRC} ${TESTIMPORT_FORM_HDR}) if(USE_QT5) - qt5_use_modules(sqlb-unittests Test Widgets Gui) + qt5_use_modules(test-import Test Widgets Gui) set(QT_LIBRARIES "") endif() -add_dependencies(sqlb-unittests antlr) -target_link_libraries(sqlb-unittests antlr ${QT_LIBRARIES} ${LIBSQLITE}) -add_test(sqlb-unittests sqlb-unittests) +add_dependencies(test-import antlr) +target_link_libraries(test-import antlr ${QT_LIBRARIES} ${LIBSQLITE}) +add_test(test-import test-import) diff --git a/src/tests/TestImport.cpp b/src/tests/TestImport.cpp index e6f3f8f9..17710a35 100644 --- a/src/tests/TestImport.cpp +++ b/src/tests/TestImport.cpp @@ -1,3 +1,5 @@ +// force QtCore-only main application by QTEST_MAIN +#undef QT_GUI_LIB #include #include #include @@ -7,23 +9,16 @@ #include "TestImport.h" #include "../sqlitedb.h" +QTEST_MAIN(TestImport) + Q_DECLARE_METATYPE(CSVParser::TCSVResult) TestImport::TestImport() { - // Init basic application - // The app needs to be initialized for the utf8 test - // to work - argcount = 1; - args[0] = new char[20]; - strcpy(args[0], "sqlb-unittests"); - app = new QCoreApplication(argcount, args); } TestImport::~TestImport() { - delete[] args[0]; - delete app; } void TestImport::csvImport() diff --git a/src/tests/TestImport.h b/src/tests/TestImport.h index e9edb3f9..18de5619 100644 --- a/src/tests/TestImport.h +++ b/src/tests/TestImport.h @@ -2,7 +2,6 @@ #define TESTIMPORT_H #include -#include class TestImport : public QObject { @@ -12,11 +11,6 @@ public: TestImport(); ~TestImport(); -private: - int argcount; - char *args[1]; // the size must match what 'argcount' is set to - QCoreApplication* app; - private slots: void csvImport(); void csvImport_data(); diff --git a/src/tests/TestMain.cpp b/src/tests/TestMain.cpp deleted file mode 100644 index f26741b6..00000000 --- a/src/tests/TestMain.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "tests/testsqlobjects.h" -#include "tests/TestImport.h" - -int main(int argc, char** argv) -{ - int status = 0; - { - TestTable tc; - status |= QTest::qExec(&tc, argc, argv); - } - { - TestImport tc; - status |= QTest::qExec(&tc, argc, argv); - } - return status; -} diff --git a/src/tests/testsqlobjects.cpp b/src/tests/testsqlobjects.cpp index b1e83b37..63ecaba2 100644 --- a/src/tests/testsqlobjects.cpp +++ b/src/tests/testsqlobjects.cpp @@ -3,6 +3,8 @@ #include +QTEST_APPLESS_MAIN(TestTable) + using namespace sqlb; void TestTable::sqlOutput()