From 42a2faf4113ce9a1289454f634ffa1edd40e7a8d Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sat, 12 Jul 2014 16:21:08 +0200 Subject: [PATCH] Tests: Simplify the cmake file Now that the dependeny to the main window is removed from the DBBrowserDB class we can get rid of all the dialogs and widget related stuff in the cmake file used for the unit test project. Because our Application class depends on the main window, too, the code for the CSV tests is changed to use Qt's standard QApplication class. --- src/tests/TestImport.cpp | 4 +- tests/CMakeLists.txt | 164 +++++++-------------------------------- 2 files changed, 28 insertions(+), 140 deletions(-) diff --git a/src/tests/TestImport.cpp b/src/tests/TestImport.cpp index 981f8911..b35e02f6 100644 --- a/src/tests/TestImport.cpp +++ b/src/tests/TestImport.cpp @@ -1,7 +1,7 @@ #include #include +#include -#include "Application.h" #include "TestImport.h" #include "../sqlitedb.h" @@ -17,7 +17,7 @@ void TestImport::csvImport() // Init basic application int argcount = 1; const char* appname = "sqlb-unittests"; - Application app(argcount, const_cast(&appname)); + QApplication app(argcount, const_cast(&appname)); // Create temporary CSV file QTemporaryFile file; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 917b813b..72161a5c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,174 +8,62 @@ if(NOT CMAKE_BUILD_TYPE) endif() set(ANTLR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libs/antlr-2.7.7) -set(QHEXEDIT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libs/qhexedit) -set(QCUSTOMPLOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libs/qcustomplot-source) - add_subdirectory(${ANTLR_DIR} ${CMAKE_CURRENT_BINARY_DIR}/antlr) -add_subdirectory(${QHEXEDIT_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qcustomplot-source) -add_subdirectory(${QCUSTOMPLOT_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qhexedit) if(USE_QT5) find_package(Qt5Widgets REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) else() - find_package(Qt4 COMPONENTS QtTest QtCore QtGui QtNetwork REQUIRED) + find_package(Qt4 COMPONENTS QtCore QtTest QtGui REQUIRED) include(${QT_USE_FILE}) add_definitions(${QT_DEFINITIONS}) endif() -set(SQLB_HDR - ../src/gen_version.h - ../src/sqlitedb.h - ../src/sqlitetypes.h - ../src/grammar/sqlite3TokenTypes.hpp - ../src/grammar/Sqlite3Lexer.hpp - ../src/grammar/Sqlite3Parser.hpp -) - -set(SQLB_MOC_HDR - ../src/AboutDialog.h - ../src/CreateIndexDialog.h - ../src/EditDialog.h - ../src/EditTableDialog.h - ../src/ExportCsvDialog.h - ../src/ExtendedTableWidget.h - ../src/FilterTableHeader.h - ../src/ImportCsvDialog.h - ../src/MainWindow.h - ../src/PreferencesDialog.h - ../src/SQLiteSyntaxHighlighter.h - ../src/SqlExecutionArea.h - ../src/VacuumDialog.h - ../src/sqlitetablemodel.h - ../src/sqltextedit.h - ../src/DbStructureModel.h - ../src/Application.h - ../src/tests/TestImport.h - ../src/tests/testsqlobjects.h -) +# add extra library path for MacOS +if(APPLE) + find_library(LIBSQLITE sqlite3 HINTS /usr/local/lib /usr/local/opt/sqlite/lib) + set(ADDITIONAL_INCLUDE_PATHS /usr/local/include /usr/local/opt/sqlite/include) +else(APPLE) + find_library(LIBSQLITE sqlite3) +endif(APPLE) set(SQLB_SRC - ../src/AboutDialog.cpp - ../src/CreateIndexDialog.cpp - ../src/EditDialog.cpp - ../src/EditTableDialog.cpp - ../src/ExportCsvDialog.cpp - ../src/ExtendedTableWidget.cpp - ../src/FilterTableHeader.cpp - ../src/ImportCsvDialog.cpp - ../src/MainWindow.cpp - ../src/PreferencesDialog.cpp - ../src/SQLiteSyntaxHighlighter.cpp - ../src/SqlExecutionArea.cpp - ../src/VacuumDialog.cpp ../src/sqlitedb.cpp ../src/sqlitetablemodel.cpp ../src/sqlitetypes.cpp - ../src/sqltextedit.cpp - ../src/DbStructureModel.cpp - ../src/Application.cpp ../src/grammar/Sqlite3Lexer.cpp ../src/grammar/Sqlite3Parser.cpp ../src/tests/TestImport.cpp ../src/tests/testsqlobjects.cpp - ../src/tests/TestMain.cpp -) + ../src/tests/TestMain.cpp) -set(SQLB_FORMS - ../src/AboutDialog.ui - ../src/CreateIndexDialog.ui - ../src/EditDialog.ui - ../src/EditTableDialog.ui - ../src/ExportCsvDialog.ui - ../src/ImportCsvDialog.ui - ../src/MainWindow.ui - ../src/PreferencesDialog.ui - ../src/SqlExecutionArea.ui - ../src/VacuumDialog.ui -) +set(SQLB_HDR + ../src/grammar/sqlite3TokenTypes.hpp + ../src/grammar/Sqlite3Lexer.hpp + ../src/grammar/Sqlite3Parser.hpp + ../src/sqlitetypes.h) -set(SQLB_RESOURCES - ../src/icons/icons.qrc -) +set(SQLB_MOC_HDR + ../src/sqlitedb.h + ../src/sqlitetablemodel.h + ../src/tests/TestImport.h + ../src/tests/testsqlobjects.h) -if(USE_QT5) - qt5_wrap_ui(SQLB_FORM_HDR ${SQLB_FORMS}) - qt5_add_resources(SQLB_RESOURCES_RCC ${SQLB_RESOURCES}) -else() +if(NOT USE_QT5) QT4_WRAP_CPP(SQLB_MOC ${SQLB_MOC_HDR}) - QT4_WRAP_UI(SQLB_FORM_HDR ${SQLB_FORMS}) - QT4_ADD_RESOURCES(SQLB_RESOURCES_RCC ${SQLB_RESOURCES}) endif() -# get git version hash -file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/../src/gen_version.h - "#ifndef __GEN_VERSIONS_H__\n" - "#define __GEN_VERSIONS_H__\n" - "#define APP_VERSION \"master_git\"\n" - "#define MAJOR_VERSION 999\n" - "#define MINOR_VERSION 0\n" - "#define PATCH_VERSION 0\n" - "#endif\n") +include_directories(${ANTLR_DIR} ../src) -#icon and correct libs/subsystem for windows -if(WIN32) - #enable version check for windows - add_definitions(-DCHECKNEWVERSION) - - IF( MINGW ) - # resource compilation for MinGW - ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sqlbicon.o - COMMAND windres -I${CMAKE_CURRENT_SOURCE_DIR} -i${CMAKE_CURRENT_SOURCE_DIR}/src/winapp.rc -o ${CMAKE_CURRENT_BINARY_DIR}/sqlbicon.o ) - set(SQLB_SRC ${SQLB_SRC} ${CMAKE_CURRENT_BINARY_DIR}/sqlbicon.o) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-subsystem,windows") - set(WIN32_STATIC_LINK -Wl,-Bstatic -lssl -lcrypto -lws2_32) - set(ADDITIONAL_LIBS lcms lzma) - ELSE( MINGW ) - set(SQLB_SRC ${SQLB_SRC} ${CMAKE_CURRENT_SOURCE_DIR}src/winapp.rc) - ENDIF( MINGW ) -endif(WIN32) - -# add extra library path for MacOS -if(APPLE) - find_library(LIBSQLITE sqlite3 HINTS /usr/local/lib /usr/local/opt/sqlite/lib) - set(ADDITIONAL_INCLUDE_PATHS /usr/local/include /usr/local/opt/sqlite/include) -else(APPLE) - find_library(LIBSQLITE sqlite3) -endif(APPLE) - -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} - ${ANTLR_DIR} - ${QHEXEDIT_DIR} - ${QCUSTOMPLOT_DIR} - ${ADDITIONAL_INCLUDE_PATHS} - ../src) - -add_executable(${PROJECT_NAME} - ${SQLB_HDR} - ${SQLB_SRC} - ${SQLB_FORM_HDR} - ${SQLB_MOC} - ${SQLB_RESOURCES_RCC}) +add_executable(${PROJECT_NAME} ${SQLB_MOC} ${SQLB_HDR} ${SQLB_SRC}) if(USE_QT5) - qt5_use_modules(${PROJECT_NAME} Gui Widgets Network Test PrintSupport) + qt5_use_modules(${PROJECT_NAME} Test Widgets Gui) set(QT_LIBRARIES "") endif() -add_dependencies(${PROJECT_NAME} antlr qhexedit qcustomplot) -link_directories( - ${CMAKE_CURRENT_BINARY_DIR}/${ANTLR_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/${QHEXEDIT_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/${QCUSTOMPLOT_DIR}) +add_dependencies(${PROJECT_NAME} antlr) +target_link_libraries(${PROJECT_NAME} antlr ${QT_LIBRARIES} ${LIBSQLITE}) -target_link_libraries(${PROJECT_NAME} - antlr - qhexedit - qcustomplot - ${QT_LIBRARIES} - ${WIN32_STATIC_LINK} - ${LIBSQLITE} - ${ADDITIONAL_LIBS}) +MESSAGE(STATUS "Build type is ${CMAKE_BUILD_TYPE}")