Commit 9064fc1b authored by Adrián Chaves's avatar Adrián Chaves

Simplify CMake code for tests

Also prepare for a progressive reorganization of tests into category-specific
subfolders (e.g. unittests, integration-tests, functional-tests).
parent 331ebd62
......@@ -19,10 +19,6 @@ if(CMAKE_COMPILER_IS_GNUCXX AND BUILD_COVERAGE AND BUILD_TESTS)
SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
endif()
if(BUILD_TESTS)
enable_testing()
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-W -Wall)
......@@ -55,9 +51,6 @@ find_package(Qt5 5.2.0 REQUIRED CONFIG COMPONENTS Core Test Network Concurrent D
find_package(LibArchive REQUIRED)
find_package(Sqlite REQUIRED)
find_package(PolkitQt5-1 REQUIRED)
if(BUILD_TESTS)
find_package(GMock REQUIRED)
endif(BUILD_TESTS)
# Define install directories
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/akabei" CACHE "Akabei data installation directory" STRING)
......
......@@ -114,7 +114,8 @@ install(FILES ${AKABEI_ARCHIVE_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR}/libarch
add_subdirectory(benchmarks)
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
enable_testing()
find_package(GMock REQUIRED)
add_subdirectory(tests)
endif(BUILD_TESTS)
set(CMAKE_AUTOMOC ON)
set(COMMON_TEST_LIBRARIES akabeicore Qt5::Test)
add_subdirectory(mocks)
#General test
set(akabei_test_SRCS
akabeitest.cpp
)
add_executable(akabei_test ${akabei_test_SRCS} ${akabei_test_MOC_SRCS})
target_link_libraries(akabei_test ${COMMON_TEST_LIBRARIES})
add_test(akabei akabei_test)
#Hook test
set(akabei_hook_test_SRCS
akabeihooktest.cpp
)
add_executable(akabei_hook_test ${akabei_hook_test_SRCS} ${akabei_hook_test_MOC_SRCS})
target_link_libraries(akabei_hook_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_hook_test akabei_hook_test)
#Group test
set(akabei_group_test_SRCS
akabeigrouptest.cpp
)
add_executable(akabei_group_test ${akabei_group_test_SRCS} ${akabei_group_test_MOC_SRCS})
target_link_libraries(akabei_group_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_group_test akabei_group_test)
#Error test
set(akabei_error_test_SRCS
akabeierrortest.cpp
)
add_executable(akabei_error_test ${akabei_error_test_SRCS} ${akabei_error_test_MOC_SRCS})
target_link_libraries(akabei_error_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_error_test akabei_error_test)
#MD5SUM test
set(akabei_md5sum_test_SRCS
akabeimd5sumtest.cpp
)
add_executable(akabei_md5sum_test ${akabei_md5sum_test_SRCS} ${akabei_md5sum_test_MOC_SRCS})
target_link_libraries(akabei_md5sum_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_md5sum_test akabei_md5sum_test)
#MD5SUM test
set(akabei_sqlite_test_SRCS
akabeisqlitetest.cpp
)
# Base function to add a test, called from category-specific functions defined
# in subfolders.
function(_add_test name target file)
add_executable(${target} ${file}.cpp)
target_link_libraries(${target} ${ARGN} ${COMMON_TEST_LIBRARIES})
add_test(${name} ${target})
endfunction(_add_test)
# Adds a test that have not yet been moved into a category-specific subfolder
# (unittests, integration, functional, etc.).
function(_add_uncategorized_test name)
_add_test(uncategorized_${name}
${name}_uncategorized_test
akabei${name}test
${ARGN})
endfunction(_add_uncategorized_test)
# TODO: Review the following tests, improve them, and move them into the
# corresponding category-specific subfolder.
_add_uncategorized_test(archivehandler)
_add_uncategorized_test(error)
_add_uncategorized_test(group)
_add_uncategorized_test(hook)
_add_uncategorized_test(md5sum)
_add_uncategorized_test(permissions)
_add_uncategorized_test(polkitarchivehandler
dbusmock filesystemmock polkitmock)
_add_uncategorized_test(polkitsqliteconnection)
_add_uncategorized_test(sqlite)
_add_uncategorized_test(version)
add_executable(akabei_sqlite_test ${akabei_sqlite_test_SRCS} ${akabei_sqlite_test_MOC_SRCS})
target_include_directories(akabei_sqlite_test PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/build)
target_link_libraries(akabei_sqlite_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_sqlite_test akabei_sqlite_test)
#ArchiveHandler test
set(akabei_archive_handler_test_SRCS
akabeiarchivehandlertest.cpp
)
add_executable(akabei_archive_handler_test ${akabei_archive_handler_test_SRCS} ${akabei_archive_handler_test_MOC_SRCS})
target_link_libraries(akabei_archive_handler_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_archive_handler_test akabei_archive_handler_test)
#Version test
set(akabei_version_test_SRCS akabeiversiontest.cpp)
add_executable(akabei_version_test ${akabei_version_test_SRCS} ${akabei_version_test_MOC_SRCS})
target_link_libraries(akabei_version_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_version_test akabei_version_test)
#PolKitArchiveHandler test
set(akabei_polkit_archive_handler_test_SRCS
akabeipolkitarchivehandlertest.cpp
)
add_executable(akabei_polkit_archive_handler_test ${akabei_polkit_archive_handler_test_SRCS} ${akabei_polkit_archive_handler_test_MOC_SRCS})
target_link_libraries(akabei_polkit_archive_handler_test
dbusmock filesystemmock polkitmock ${COMMON_TEST_LIBRARIES})
add_test(akabei_polkit_archive_handler_test akabei_polkit_archive_handler_test)
#PolKitSQLiteConnection test
set(akabei_polkit_sqliteconnection_test_SRCS
akabeipolkitsqliteconnectiontest.cpp
)
add_executable(akabei_polkit_sqliteconnection_test ${akabei_polkit_sqliteconnection_test_SRCS} ${akabei_polkit_sqliteconnection_test_MOC_SRCS})
target_include_directories(akabei_polkit_sqliteconnection_test PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/build)
target_link_libraries(akabei_polkit_sqliteconnection_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_polkit_sqliteconnection_test akabei_polkit_sqliteconnection_test)
#Permissions test
set(akabei_permissions_test_SRCS
akabeipermissionstest.cpp
)
add_executable(akabei_permissions_test ${akabei_permissions_test_SRCS} ${akabei_permissions_test_MOC_SRCS})
target_link_libraries(akabei_permissions_test ${COMMON_TEST_LIBRARIES})
add_test(akabei_permissions_test akabei_permissions_test)
add_executable(sqliteresourcetest sqliteresourcetest.cpp)
target_link_libraries(sqliteresourcetest ${COMMON_TEST_LIBRARIES})
add_test(sqliteresourcetest sqliteresourcetest)
add_subdirectory(mocks)
add_subdirectory(unittests)
/* This file is part of the Chakra project
Copyright (C) 2011 Lukas Appelhans
This program 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 2 of the License, or (at your option) any later version.
*/
#include "akabeitest.h"
#include <QDebug>
AkabeiTest::AkabeiTest()
: QObject(0)
{
}
AkabeiTest::~AkabeiTest()
{
}
void AkabeiTest::simpleTest()
{
qDebug() << "BLABLABLAAAAAAAAAAAA";
}
QTEST_MAIN(AkabeiTest)
/* This file is part of the KDE project
Copyright (C) 2011 Lukas Appelhans <l.appelhans@gmx.de>
This program 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 2 of the License, or (at your option) any later version.
*/
#ifndef _AKABEITEST_H
#define _AKABEITEST_H
#include <QtTest/QtTest>
class AkabeiTest : public QObject
{
Q_OBJECT
public:
AkabeiTest();
~AkabeiTest();
private Q_SLOTS:
void simpleTest();
};
#endif
function(_add_unittest name)
_add_test(unit_${name} ${name}_unittest ${name} ${ARGN})
endfunction(_add_unittest)
_add_unittest(sqliteresource)
......@@ -10,7 +10,7 @@
#include <AbstractSQLiteConnection.h>
#include "common.h"
#include "../common.h"
class SQLiteResourceTest : public QObject
{
......@@ -141,4 +141,4 @@ private Q_SLOTS:
QTEST_MAIN(SQLiteResourceTest)
#include "sqliteresourcetest.moc"
#include "sqliteresource.moc"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment