...
 
Commits (2)
......@@ -128,43 +128,48 @@ if(KF5DocTools_FOUND)
add_subdirectory(doc)
endif()
if(BUILD_TESTING AND NOT SAILFISHOS)
if (BUILD_TESTING AND NOT SAILFISHOS)
# Original tests
add_subdirectory(tests)
include(ECMCoverageOption)
set(BUILD_COVERAGE 1)
# Clean the coverage and generated HTML output
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/tests/coverage)
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/tests/html)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/coverage)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/html)
add_custom_target(coverage_wrappers
ALL)
# Custom target that will genrate initial content of the "merge_info.bash"
# script that is used to generate merged .info file once all tests have
# been run and executed and all their data are in appropriate .info files
# (per test)
add_custom_target(pre_generate_coverage_html
COMMAND echo -n "lcov" > ${CMAKE_BINARY_DIR}/tests/coverage/merge_info.bash)
add_subdirectory(tests)
# add_subdirectory(filesyncapp/daemon/tests/singleton_pool_test)e
# Add custom target on which all tests will depend, i.e. they will compile
# and execute before this target to produce all test result data
# (.gcno and .gcda)
add_custom_target(generate_coverage_html)
set(generate_coverage_html_deps "" CACHE string "List of unit tests to generate coverage for" FORCE)
# Add all tests (all *.cpp files that reisde in any test directory)
file(GLOB all_unit_tests */**/tests/*)
foreach(unit_test ${all_unit_tests})
message("Processing unit test ${unit_test}")
foreach (unit_test ${all_unit_tests})
message("Adding unit test ${unit_test}")
add_subdirectory(${unit_test})
endforeach()
message(" .......... ${generate_coverage_html_deps}")
endforeach ()
file(GLOB coverage_info "${CMAKE_BINARY_DIR}/tests/coverage")
message(${coverage_info})
#${CMAKE_BINARY_DIR}/tests/coverage
#$\(ls .\)
add_custom_target(generate_coverage_html
# Now last step is to mege all coverage data (.info) files and generate
# HTML output
add_custom_target(post_generate_coverage_html
ALL
DEPENDS coverage_wrappers
COMMAND lcov "${generate_coverage_html_deps}" --output-file "${CMAKE_BINARY_DIR}/tests/kdeconnect.info"
DEPENDS generate_coverage_html
COMMAND echo " --output-file ${CMAKE_BINARY_DIR}/tests/kdeconnect.info" >> ${CMAKE_BINARY_DIR}/tests/coverage/merge_info.bash
COMMAND chmod +x ${CMAKE_BINARY_DIR}/tests/coverage/merge_info.bash
COMMAND bash -c ${CMAKE_BINARY_DIR}/tests/coverage/merge_info.bash
COMMAND genhtml --legend -s -o "${CMAKE_BINARY_DIR}/tests/html" "${CMAKE_BINARY_DIR}/tests/kdeconnect.info")
# add_dependencies(generate_coverage_html singleton_pool_test_coverage_wrapper index_test_coverage_wrapper)
endif()
endif ()
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -7,26 +7,27 @@ function(kdeconnect_add_plugin)
kcoreaddons_add_plugin(${ARGN} INSTALL_NAMESPACE kdeconnect)
endfunction()
function(add_to_coverage test_name class_under_test)
# This function adds tested class to the coverage report, i.e. runs the test to
# generate an actual coverage data (.gcda) and then uses lcov to generate .info
# file for the tested class and lastly adds coverage target as a dependency for
# the "generate_coverage_html" target so this is build first; it also assumes
# that each tested class has an apropriate test in
# "tests/<TESTED_CLASS>_test/<TESTED_CLASS>_test.cpp" which itself can be
# anywhere in the hierarchy (e.g. plugins, standalone apps, etc.)
function(add_to_coverage class_under_test)
set(class_to_extract "*\\/${class_under_test}.*")
add_custom_target(${test_name}_coverage_wrapper
set(test_name ${class_under_test}_test)
set(coverage_target ${class_under_test}_coverage)
add_custom_target(${coverage_target}
DEPENDS ${test_name}
COMMAND echo "Running unit test ${test_name}"
DEPENDS pre_generate_coverage_html
COMMAND echo "Running unit test for ${CMAKE_BINARY_DIR}/bin/${test_name}"
COMMAND ${CMAKE_BINARY_DIR}/bin/${test_name}
COMMAND echo "Processing gcov data for the unit test ${test_name}"
COMMAND lcov --directory ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/ --capture --output-file ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/gcov.info
COMMAND lcov --extract ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/gcov.info ${class_to_extract} --output-file ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/${test_name}.info
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/${test_name}.info ${CMAKE_BINARY_DIR}/tests/coverage/
)
add_dependencies(coverage_wrappers "${test_name}_coverage_wrapper")
# add_custom_target(
# "coverage_for_${test_name}" ALL DEPENDS gen
# )
set(generate_coverage_html_deps "${generate_coverage_html_deps} --add-tracefile ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/${test_name}.info" CACHE string "List of unit tests to generate coverage for" FORCE)
# add_dependencies(generate_coverage_html "generate_coverage_for_${test_name}")
# message(" .......... ${generate_coverage_html_deps}")
COMMAND echo "Processing gcov data for ${coverage_target}"
COMMAND lcov --directory ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/ --capture --output-file ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${coverage_target}.dir/gcov.info
COMMAND lcov --extract ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${coverage_target}.dir/gcov.info ${class_to_extract} --output-file ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${coverage_target}.dir/${coverage_target}.info
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${coverage_target}.dir/${coverage_target}.info ${CMAKE_BINARY_DIR}/tests/coverage/
COMMAND echo -n " --add-tracefile ${CMAKE_BINARY_DIR}/tests/coverage/${coverage_target}.info" >> ${CMAKE_BINARY_DIR}/tests/coverage/merge_info.bash
)
add_dependencies(generate_coverage_html "${coverage_target}")
endfunction()
......@@ -10,7 +10,7 @@ add_executable(kdeconnect-filesync-daemon
executor.cpp
sync_operation.cpp
config.cpp
singleton_pool.cpp
singleton_pool.hpp
../interfaces/filesyncapp_interface.cpp
../interfaces/sync_result.cpp
../interfaces/json_types.cpp
......
......@@ -33,7 +33,7 @@
#include <QtCore/QJsonDocument>
#include "common.h"
#include "singleton_pool.h"
#include "singleton_pool.hpp"
namespace FileSync
{
......
......@@ -28,7 +28,7 @@
#include <QObject>
#include "sync_operation.h"
#include "singleton_pool.h"
#include "singleton_pool.hpp"
namespace FileSync
{
......
......@@ -28,7 +28,7 @@
#include <QtCore/QObject>
#include <QtCore/QFile>
#include "singleton_pool.h"
#include "singleton_pool.hpp"
namespace FileSync
{
......
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FILESYNC_SINGLETON_POOL_H
#define FILESYNC_SINGLETON_POOL_H
#ifndef FILESYNC_SINGLETON_POOL_HPP
#define FILESYNC_SINGLETON_POOL_HPP
#include <QString>
#include <QMap>
......@@ -114,4 +114,4 @@ namespace FileSync
template<class T>
QMap<QString, T *> *FileSync::SingletonPool<T>::s_instances = NULL;
#endif //FILESYNC_SINGLETON_POOL_H
#endif //FILESYNC_SINGLETON_POOL_HPP
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Test)
include_directories(
${KDEConnectCore_BINARY_DIR}
${CMAKE_SOURCE_DIR}
../../
)
set(kdeconnect_libraries
kdeconnectcore
kdeconnectinterfaces
KF5::I18n
KF5::KIOWidgets
Qt5::DBus
Qt5::Network
Qt5::Test
qca-qt5
pthread
)
ecm_add_test(
../../common.cpp
../../log.cpp
../../index.cpp
../../executor.cpp
../../daemon.cpp
../../sync_operation.cpp
../../config.cpp
../../sftp_mounter.cpp
../../../interfaces/filesyncapp_interface.cpp
../../../interfaces/sync_result.cpp
../../../interfaces/json_types.cpp
daemon_test.cpp LINK_LIBRARIES ${kdeconnect_libraries} TEST_NAME daemon_test)
add_to_coverage("daemon")
......@@ -18,4 +18,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "singleton_pool.h"
#include <QObject>
#include <QTest>
// Class under the test
#include "daemon.h"
namespace FileSync
{
class DaemonTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void test0()
{
}
};
}
QTEST_MAIN(FileSync::DaemonTest)
#include "daemon_test.moc"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Test)
include_directories(
${KDEConnectCore_BINARY_DIR}
${CMAKE_SOURCE_DIR}
../../
)
set(kdeconnect_libraries
kdeconnectcore
kdeconnectinterfaces
KF5::I18n
KF5::KIOWidgets
Qt5::DBus
Qt5::Network
Qt5::Test
qca-qt5
pthread
)
ecm_add_test(
../../common.cpp
../../log.cpp
../../index.cpp
../../executor.cpp
../../daemon.cpp
../../sync_operation.cpp
../../config.cpp
../../sftp_mounter.cpp
../../../interfaces/filesyncapp_interface.cpp
../../../interfaces/sync_result.cpp
../../../interfaces/json_types.cpp
executor_test.cpp LINK_LIBRARIES ${kdeconnect_libraries} TEST_NAME executor_test)
add_to_coverage("executor")
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@gmail.com>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QObject>
#include <QTest>
// Class under the test
#include "executor.h"
namespace FileSync
{
class ExecutorTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void test0()
{
}
};
}
QTEST_MAIN(FileSync::ExecutorTest)
#include "executor_test.moc"
......@@ -29,4 +29,4 @@ ecm_add_test(
../../index.cpp
index_test.cpp LINK_LIBRARIES ${kdeconnect_libraries} TEST_NAME index_test)
add_to_coverage("index_test" "index")
\ No newline at end of file
add_to_coverage("index")
\ No newline at end of file
......@@ -39,7 +39,6 @@ namespace FileSync
m_index = &Index::instance("testIndos");
......
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Test)
include_directories(
${KDEConnectCore_BINARY_DIR}
${CMAKE_SOURCE_DIR}
../../
)
set(kdeconnect_libraries
kdeconnectcore
KF5::I18n
KF5::KIOWidgets
Qt5::DBus
Qt5::Network
Qt5::Test
qca-qt5
pthread
)
ecm_add_test(
../../common.cpp
../../log.cpp
log_test.cpp LINK_LIBRARIES ${kdeconnect_libraries} TEST_NAME log_test)
add_to_coverage("log")
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@gmail.com>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QObject>
#include <QTest>
#include <QThread>
#include "singleton_pool.hpp"
namespace FileSync
{
class LogTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
/**
* Try to create and destroy single instance, and repeat verifying that
* second created instance is a different one
*/
void testCreateAndDestroyTwoInstances()
{
}
};
}
QTEST_MAIN(FileSync::LogTest)
#include "log_test.moc"
......@@ -26,4 +26,4 @@ ecm_add_test(
../../index.cpp
singleton_pool_test.cpp LINK_LIBRARIES ${kdeconnect_libraries} TEST_NAME singleton_pool_test)
add_to_coverage("singleton_pool_test" "singleton_pool")
add_to_coverage("singleton_pool")
......@@ -22,7 +22,7 @@
#include <QTest>
#include <QThread>
#include "singleton_pool.h"
#include "singleton_pool.hpp"
namespace FileSync
{
......@@ -127,31 +127,6 @@ namespace FileSync
QVERIFY(originalCTime0 != originalCTime1);
QVERIFY(originalCTime0 != originalCTime2);
QVERIFY(originalCTime1 != originalCTime2);
}
};
}
......
......@@ -27,7 +27,7 @@
#include <QDBusConnection>
#include <daemon.h>
#include <singleton_pool.h>
#include <singleton_pool.hpp>
#include <config.h>
#include <filesyncapp/interfaces/sync_result.h>
#include <filesyncapp/interfaces/json_types.h>
......