diff --git a/CMakeLists.txt b/CMakeLists.txt index a92bc2a63..7e41f99cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,8 @@ add_definitions( "-DQT_STRICT_ITERATORS" ) # build options option(BUILD_GUI "Build Tomahawk with GUI" ON) option(BUILD_RELEASE "Generate TOMAHAWK_VERSION without GIT info" OFF) +option(BUILD_TESTS "Build Tomahawk with unit tests" ON) + option(WITH_BREAKPAD "Build with breakpad integration" ON) option(WITH_CRASHREPORTER "Build with CrashReporter" ON) option(WITH_BINARY_ATTICA "Enable support for downloading binary resolvers automatically" ON) @@ -133,8 +135,11 @@ else() message(STATUS "Could not find Qt5, now searching for Qt4... you're better off this way!") set(NEEDED_QT4_COMPONENTS "QtCore" "QtXml" "QtNetwork") - if(BUILD_GUI) - list(APPEND NEEDED_QT4_COMPONENTS "QtGui" "QtWebkit" "QtUiTools" "QtSvg" ) + if( BUILD_GUI ) + list(APPEND NEEDED_QT4_COMPONENTS "QtGui" "QtWebkit" "QtUiTools" "QtSvg") + endif() + if( BUILD_TESTS ) + list(APPEND NEEDED_QT4_COMPONENTS "QtTest") endif() macro_optional_find_package(Qt4 4.7.0 COMPONENTS ${NEEDED_QT4_COMPONENTS} ) @@ -317,3 +322,8 @@ ADD_SUBDIRECTORY( thirdparty ) ADD_SUBDIRECTORY( src ) ADD_SUBDIRECTORY( src/libtomahawk ) ADD_SUBDIRECTORY( admin ) + +if( BUILD_TESTS ) + enable_testing() + add_subdirectory( tests ) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..50cfcdf1e --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,4 @@ +include_directories(${CMAKE_CURRENT_LIST_DIR}/../src) +include(tomahawk_add_test.cmake) + +tomahawk_add_test(Foo) diff --git a/tests/TestFoo.h b/tests/TestFoo.h new file mode 100644 index 000000000..fe44a10a6 --- /dev/null +++ b/tests/TestFoo.h @@ -0,0 +1,36 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + + +#ifndef TOMAHAWK_TESTFOO_H +#define TOMAHAWK_TESTFOO_H + +#include + +class TestFoo : public QObject +{ + Q_OBJECT + +private slots: + void testBar() + { + QVERIFY( true ); + } +}; + +#endif \ No newline at end of file diff --git a/tests/main.cpp.in b/tests/main.cpp.in new file mode 100644 index 000000000..56780f275 --- /dev/null +++ b/tests/main.cpp.in @@ -0,0 +1,35 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include +#include + +#include "Test@TOMAHAWK_TEST_CLASS@.h" +#include "moc_Test@TOMAHAWK_TEST_CLASS@.cpp" + +int main( int argc, char** argv) +{ + QCoreApplication app( argc, argv ); + + #define TEST( Type ) { \ + Type o; \ + if (int r = QTest::qExec( &o, argc, argv ) != 0) return r; } + + TEST( Test@TOMAHAWK_TEST_CLASS@ ); + return 0; +} \ No newline at end of file diff --git a/tests/tomahawk_add_test.cmake b/tests/tomahawk_add_test.cmake new file mode 100644 index 000000000..a0d6f96c7 --- /dev/null +++ b/tests/tomahawk_add_test.cmake @@ -0,0 +1,20 @@ +macro(tomahawk_add_test test_class) + include_directories(${QT_INCLUDES} "${PROJECT_SOURCE_DIR}/src" ${CMAKE_CURRENT_BINARY_DIR}) + + set(TOMAHAWK_TEST_CLASS ${test_class}) + set(TOMAHAWK_TEST_TARGET ${TOMAHAWK_TEST_CLASS}Test) + configure_file(main.cpp.in Test${TOMAHAWK_TEST_CLASS}.cpp) + configure_file(Test${TOMAHAWK_TEST_CLASS}.h Test${TOMAHAWK_TEST_CLASS}.h) + + add_executable(${TOMAHAWK_TEST_CLASS}Test Test${TOMAHAWK_TEST_CLASS}.cpp) + + set_target_properties(${TOMAHAWK_TEST_TARGET} PROPERTIES AUTOMOC ON) + + target_link_libraries(${TOMAHAWK_TEST_TARGET} + ${TOMAHAWK_LIBRARIES} + ${QT_QTTEST_LIBRARY} + ${QT_QTCORE_LIBRARY} + ) + + add_test(NAME ${TOMAHAWK_TEST_TARGET} COMMAND ${TOMAHAWK_TEST_TARGET}) +endmacro() \ No newline at end of file