Second try, with dirk's input on IRC.
On Mon, Apr 14, 2014 at 1:46 PM, Tomaz Canabrava <[email protected]> wrote: > > So - > CMake has a testing framework called CTest that can generate html reports > and it's easy to integrate a new test on it. I created this in cmake *only* > because it was what I had used before, tried to learn the docs for qmake + > tests and it was a bit frustrating / hard to do. > > > what this does right now: > 1 - compiles subsurface in small libraries > ( core, ui, profile ) > 2 - compiles tests that are linked to those libraries > 3 - run tests by running 'make test' > > make test will run > a few tests are failing, even using IS_FP_SAME, and the plan is to > increase the amount > of code tested to 100% over time ( we can also include the gcov tool to > get the percent of code that is tested. ) > > Tomaz > >
From 568d702bd69dbf9c9c9629f594fe20b62ed2096c Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 14 Apr 2014 14:32:06 -0300 Subject: [PATCH 3/3] Add a Readme.testing file with explanations on how to use the tests. Signed-off-by: Tomaz Canabrava <[email protected]> --- Readme.testing | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Readme.testing diff --git a/Readme.testing b/Readme.testing new file mode 100644 index 0000000..bc9997c --- /dev/null +++ b/Readme.testing @@ -0,0 +1,16 @@ +Testing subsurface: + +Right now to test subsurface you need to have the 'cmake' executable +to compile the source code of the tests and run them. + +1 - create a folder 'build-tests' on the project root directory +2 - run cmake ( cmake .. ) +3 - compile the software by invocking make +4 - run the tests by invocking make test +(optional 5) if the tests are failing, a better way to see what's +happening is to run ctest -V , this way the tests will still fail, +but more verbosically - easyer to track them down. + +to create a new test, just implement copy the one provided by +example in the tests folder and add the last three lines of the CMakeLists.txt file +adapted to your test. -- 1.9.2
From 56ec173d9471bb85bc6fc71874618b98e7f69474 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 14 Apr 2014 14:27:32 -0300 Subject: [PATCH 2/3] First test case implemented. This is just a stub test case to show how a test case should be implemented. every 'private slot' on the test classes will be automatically executed when you run 'make test' on the terminal, and a report will be generated with a failure / success. Signed-off-by: Tomaz Canabrava <[email protected]> --- CMakeLists.txt | 3 +++ tests/testunitconversion.cpp | 14 ++++++++++++++ tests/testunitconversion.h | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/testunitconversion.cpp create mode 100644 tests/testunitconversion.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 35736e6..35fc9ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,3 +114,6 @@ ADD_DEPENDENCIES(subsurface_interface subsurface_generated_ui) ADD_DEPENDENCIES(subsurface_generated_ui version) ENABLE_TESTING() +ADD_EXECUTABLE( TestUnitConversion tests/testunitconversion.cpp ) +TARGET_LINK_LIBRARIES( TestUnitConversion ${QT_LIBRARIES}) +ADD_TEST( NAME TestUnitConversion COMMAND TestUnitConversion) \ No newline at end of file diff --git a/tests/testunitconversion.cpp b/tests/testunitconversion.cpp new file mode 100644 index 0000000..54b7e1b --- /dev/null +++ b/tests/testunitconversion.cpp @@ -0,0 +1,14 @@ +#include "testunitconversion.h" +#include "dive.h" + +void TestUnitConversion::testUnitConversions() +{ + QCOMPARE(IS_FP_SAME(grams_to_lbs(1000), 2.20459), true); + QCOMPARE(lbs_to_grams(1), 454); + QCOMPARE(IS_FP_SAME(ml_to_cuft(1000), 0.0353147), true); + QCOMPARE(IS_FP_SAME(cuft_to_l(1), 28.3168), true); + QCOMPARE(IS_FP_SAME(mm_to_feet(1000), 3.28084), true); + QCOMPARE(feet_to_mm(1), (long unsigned int) 305); +} + +QTEST_MAIN(TestUnitConversion) \ No newline at end of file diff --git a/tests/testunitconversion.h b/tests/testunitconversion.h new file mode 100644 index 0000000..b8f0585 --- /dev/null +++ b/tests/testunitconversion.h @@ -0,0 +1,12 @@ +#ifndef TESTUNITCONVERSION_H +#define TESTUNITCONVERSION_H + +#include <QtTest> + +class TestUnitConversion : public QObject{ + Q_OBJECT +private slots: + void testUnitConversions(); +}; + +#endif \ No newline at end of file -- 1.9.2
From f058398850845ecb41807be033f40ca813a85fe6 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 14 Apr 2014 14:21:01 -0300 Subject: [PATCH 1/3] Add a CMake based buildsystem for the tests. This commit adds a CMake based buildsystem for the tests, it separated the subsurface sources in small libraries to make testing easyer ( subsurface core, subsurface ui, subsurface profile, etc. ) There's no test yet, this however produces a compiled and executable binary *on linux*. This file shouldn't be needed on any other platform as this is not the main build system, but the test build system. Signed-off-by: Tomaz Canabrava <[email protected]> --- CMakeLists.txt | 116 ++++++++++++++++++++++++++++++++++++++++++++ marbledata/FindMarble.cmake | 20 ++++++++ 2 files changed, 136 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 marbledata/FindMarble.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..35736e6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,116 @@ +project(Subsurface) +cmake_minimum_required(VERSION 2.8) + +#options +SET(SUBSURFACE_QT_VERSION "4") +SET(CMAKE_AUTOMOC ON) +SET(CMAKE_AUTOUIC ON) +SET(CMAKE_MODULE_PATH ${${PROJECT_NAME}_SOURCE_DIR}/marbledata) + +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 ") +endif() + +INCLUDE_DIRECTORIES( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR} qt-ui qt-ui/profile) +FIND_PACKAGE(PkgConfig) + +MACRO(pkg_config_library LIBNAME pcfile) + pkg_check_modules(${LIBNAME} ${pcfile}) + include_directories(${${LIBNAME}_INCLUDE_DIRS}) + link_directories(${${LIBNAME}_LIBRARY_DIRS}) + add_definitions(${${LIBNAME}_CFLAGS_OTHER}) + set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} ${${LIBNAME}_LIBRARIES}) +ENDMACRO() + +pkg_config_library(LIBXML libxml-2.0) +pkg_config_library(LIBSQLITE3 sqlite3) +pkg_config_library(LIBGIT2 libgit2) +pkg_config_library(LIBXSLT libxslt) + +STRING(COMPARE EQUAL "${${PROJECT_NAME}_SOURCE_DIR}" "${${PROJECT_NAME}_BINARY_DIR}" insource) +GET_FILENAME_COMPONENT(PARENTDIR ${${PROJECT_NAME}_SOURCE_DIR} PATH) +STRING(COMPARE EQUAL "${${PROJECT_NAME}_SOURCE_DIR}" "${PARENTDIR}" insourcesubdir) +IF(NOT (insource OR insourcedir)) + add_custom_target(link_marble_data ALL COMMAND rm -f marbledata && ln -s ${${PROJECT_NAME}_SOURCE_DIR}/marbledata ${${PROJECT_NAME}_BINARY_DIR}/marbledata) +ENDIF() + +#configure Qt version. +IF(${SUBSURFACE_QT_VERSION} MATCHES "4") + SET(QT_USE_QTNETWORK TRUE) + SET(QT_USE_QTXML TRUE) + SET(QT_USE_QTSVG TRUE) + SET(QT_USE_QTTEST TRUE) + SET(QT_USE_QTWEBKIT TRUE) + FIND_PACKAGE(Qt4 REQUIRED) + INCLUDE(${QT_USE_FILE}) + ADD_DEFINITIONS(${QT_DEFINITIONS}) + FIND_PACKAGE(Marble REQUIRED) + INCLUDE_DIRECTORIES(${MARBLE_INCLUDE_DIR}) +ELSEIF(${SUBSURFACE_QT_VERSION} MATCHES "5") + ADD_DEFINITIONS(-DNO_MARBLE) +ELSE() + message( FATAL_ERROR "Qt version should be 4 or 5" ) +ENDIF() + +# Generate the ssrf-config.h every 'make' +FILE(WRITE ${CMAKE_BINARY_DIR}/version.h.in "\#define VERSION_STRING \"4.1.\"@VERSION@\n") +FILE(WRITE ${CMAKE_BINARY_DIR}/version.cmake "EXECUTE_PROCESS( + COMMAND date +\"%s\" + OUTPUT_VARIABLE VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + CONFIGURE_FILE(\${SRC} \${DST} @ONLY) +") +ADD_CUSTOM_TARGET(version ALL COMMAND + ${CMAKE_COMMAND} -D SRC=${CMAKE_BINARY_DIR}/version.h.in + -D DST=${CMAKE_BINARY_DIR}/ssrf-version.h + -P ${CMAKE_BINARY_DIR}/version.cmake +) + +# compile the core library, in C. +FILE(GLOB SUBSURFACE_CORE_LIB_SRCS *.c) +LIST(REMOVE_ITEM SUBSURFACE_CORE_LIB_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/windows.c + ${CMAKE_CURRENT_SOURCE_DIR}/macos.c + ${CMAKE_CURRENT_SOURCE_DIR}/cochran.c +) + +FILE(GLOB SUBSURFACE_PROFILE_LIB_SRCS qt-ui/profile/*.cpp) +FILE(GLOB SUBSURFACE_UI qt-ui/*.ui) +FILE(GLOB SUBSURFACE_INTERFACE qt-ui/*.cpp) +FILE(GLOB SUBSURFACE_APP *.cpp ) +IF(NOT (CMAKE_SYSTEM_NAME MATCHES Android)) + LIST(REMOVE_ITEM SUBSURFACE_APP ${CMAKE_CURRENT_SOURCE_DIR}/android.cpp) +ENDIF() + +# to be replaced by QT_WRAP_UI on CMake 3. +IF(${SUBSURFACE_QT_VERSION} MATCHES "4") + QT4_WRAP_UI( SUBSURFACE_UI_HDRS ${SUBSURFACE_UI} ) + QT4_ADD_RESOURCES( SUBSURFACE_QRC_HRDS subsurface.qrc ) +ELSEIF(${SUBSURFACE_QT_VERSION} MATCHES "5") + QT5_WRAP_UI( SUBSURFACE_UI_HDRS ${SUBSURFACE_UI} ) +ENDIF() + +ADD_LIBRARY(subsurface_corelib STATIC ${SUBSURFACE_CORE_LIB_SRCS} ) +ADD_LIBRARY(subsurface_profile STATIC ${SUBSURFACE_PROFILE_LIB_SRCS}) +ADD_LIBRARY(subsurface_generated_ui STATIC ${SUBSURFACE_UI_HDRS}) +ADD_LIBRARY(subsurface_interface STATIC ${SUBSURFACE_INTERFACE}) +ADD_EXECUTABLE(subsurface ${SUBSURFACE_APP} ${SUBSURFACE_QRC_HRDS} ) + +target_link_libraries( subsurface + subsurface_generated_ui + subsurface_interface + subsurface_profile + subsurface_corelib + ${QT_LIBRARIES} + ${MARBLE_LIBRARIES} + ${SUBSURFACE_LINK_LIBRARIES} + -ldivecomputer + -lzip +) + +ADD_DEPENDENCIES(subsurface_profile subsurface_generated_ui) +ADD_DEPENDENCIES(subsurface_interface subsurface_generated_ui) +ADD_DEPENDENCIES(subsurface_generated_ui version) + +ENABLE_TESTING() diff --git a/marbledata/FindMarble.cmake b/marbledata/FindMarble.cmake new file mode 100644 index 0000000..99f017a --- /dev/null +++ b/marbledata/FindMarble.cmake @@ -0,0 +1,20 @@ +# - Try to find the Marble Library +# Once done this will define +# +# MARBLE_FOUND - system has Marble +# MARBLE_INCLUDE_DIR - the Marble include directory +# MARBLE_LIBRARIES +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +IF ( MARBLE_INCLUDE_DIR AND MARBLE_LIBRARIES ) + # in cache already + SET( MARBLE_FIND_QUIETLY TRUE ) +ENDIF ( MARBLE_INCLUDE_DIR AND MARBLE_LIBRARIES ) + +FIND_PATH( MARBLE_INCLUDE_DIR NAMES marble/MarbleModel.h ) +FIND_LIBRARY( MARBLE_LIBRARIES NAMES marblewidget ) + +INCLUDE( FindPackageHandleStandardArgs ) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( marble DEFAULT_MSG MARBLE_INCLUDE_DIR MARBLE_LIBRARIES ) -- 1.9.2
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
