Commit 1beac2a0 authored by Jörg Ehrichs's avatar Jörg Ehrichs
Browse files

Refactor common Unit-Tests to use ctest/kde_add_unit_test

To compile the unit-tests add -DKDE4_BUILD_TESTS=ON to the cmake call

run "ctest" to execute unit test
parent 207c3dcf
......@@ -2,8 +2,15 @@ cmake_minimum_required(VERSION 2.6)
project(wacomtablet)
## set this to false to disable automatic test execution
set(ENABLE_TESTING false)
#--------------------------------------------------------------------------
# CTest setup
#--------------------------------------------------------------------------
ENABLE_TESTING()
include(CTest)
include(CTestConfig.cmake)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake COPYONLY)
# search packages used by KDE
find_package(KDE4 REQUIRED)
......@@ -21,19 +28,19 @@ find_package(XorgWacom REQUIRED)
macro_log_feature(XORGWACOM_FOUND "Xorg-Wacom" "Xorg input wacom driver" "http://linuxwacom.sourceforge.net" TRUE "" "The driver/header files are missing")
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS} -DQT_STRICT_ITERATORS )
add_definitions( ${QT_DEFINITIONS} ${KDE4_DEFINITIONS} -DQT_STRICT_ITERATORS )
add_definitions( -DQT_NO_CAST_FROM_ASCII )
add_definitions( -DQT_NO_CAST_TO_ASCII )
add_definitions( -DDISABLE_NEPOMUK_LEGACY )
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
add_definitions( -DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS )
#include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} ${LIBWACOM_INCLUDE_DIRS})
include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})
include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} )
add_subdirectory( src )
add_subdirectory( data )
add_subdirectory( images )
add_subdirectory( doc )
add_subdirectory( tests )
add_subdirectory( autotests )
macro_display_feature_log()
## This file should be placed in the root directory of your project.
## Then modify the CMakeLists.txt file in the root directory of your
## project to incorporate the testing dashboard.
## # The following are required to uses Dart and the Cdash dashboard
## ENABLE_TESTING()
## INCLUDE(CTest)
set(CTEST_PROJECT_NAME "wacomtablet")
set(CTEST_NIGHTLY_START_TIME "00:00:00 UTC")
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=wacomtablet")
set(CTEST_DROP_SITE_CDASH TRUE)
# This file contains all the specific settings that will be used
# when running 'make Experimental'
# Change the maximum warnings that will be displayed
# on the report page (default 50)
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 1000)
# Errors that will be ignored
set(CTEST_CUSTOM_ERROR_EXCEPTION
${CTEST_CUSTOM_ERROR_EXCEPTION}
"ICECC"
"Segmentation fault"
"GConf Error"
"Client failed to connect to the D-BUS daemon"
"Failed to connect to socket"
"qlist.h.*increases required alignment of target type"
"qmap.h.*increases required alignment of target type"
"qhash.h.*increases required alignment of target type"
)
# No coverage for these files (auto-generated, unit tests, etc)
set(CTEST_CUSTOM_COVERAGE_EXCLUDE ".moc$" "moc_" "ui_" "qrc_")
......@@ -42,16 +42,16 @@ Dependencies:
#################################################################
# build debian package
debuild -us -uc -b
$ debuild -us -uc -b
#################################################################
# or install with
mkdir build
cd build
cmake ../ -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` -DCMAKE_BUILD_TYPE=release
make
make install
$ mkdir build
$ cd build
$ cmake ../ -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` -DCMAKE_BUILD_TYPE=release
$ make
$ make install
#################################################################
# start with
......@@ -65,6 +65,28 @@ Afterwards you get a notice when you plugin your device and can configure it via
$ kcmshell4 kcm_wacomtablet
or have a look in the system settings where the keyboard and mouse settings are
#################################################################
# execute unit tests
To run the unit-test add the KDE4_BUILD_TESTS=ON variable to the cmake call
$ mkdir build
$ cd build
$ cmake ../ -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` -DKDE4_BUILD_TESTS=ON
$ make
execute all tests via:
$ ctest
or a single one via
$ cd /build/autotests/common/property
$ ./Property.shell
you can find the testresults in
build/Testing/Temporary/LastTest.log
##################################################################
# Add missing tablet devices
......
if(KDE4_BUILD_TESTS)
include_directories( ${CMAKE_SOURCE_DIR}/src )
# Add Tests
add_subdirectory( common/buttonshortcut )
add_subdirectory( common/deviceinformation )
add_subdirectory( common/deviceprofile )
add_subdirectory( common/deviceprofileconfigadaptor )
add_subdirectory( common/deviceproperty )
add_subdirectory( common/enum )
add_subdirectory( common/profilemanager )
add_subdirectory( common/property )
add_subdirectory( common/propertyset )
add_subdirectory( common/tabletinformation )
add_subdirectory( common/tabletprofile )
add_subdirectory( common/tabletprofileconfigadaptor )
endif()
kde4_add_unit_test(Common.ButtonShortcut
testbuttonshortcut.cpp
)
target_link_libraries(Common.ButtonShortcut
# include static libs
wacom_common
# include general qt/kde libs
${QT_QTTEST_LIBRARY}
)
......@@ -17,14 +17,44 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QString>
#include <QMap>
#include "common/buttonshortcut.h"
#include "buttonshortcut.h"
#include "testbuttonshortcut.moc"
#include <QtTest>
#include <KDE/KDebug>
#include <qtest_kde.h>
using namespace Wacom;
/**
* @file testbuttonshortcut.cpp
*
* @test UnitTest for the button shortcut testing
*/
class TestButtonShortcut: public QObject
{
Q_OBJECT
private slots:
void testAssignment();
void testButton();
void testInvalidKeyStrokes();
void testKeyStrokes();
void testModifier();
void testQKeySequences();
void testEmpty();
private:
void assertButton (const ButtonShortcut& shortcut, int buttonNumber) const;
void assertEquals (const ButtonShortcut& shortcut1, const ButtonShortcut& shortcut2) const;
void assertKeySequence (const ButtonShortcut& shortcut, const QString& sequence, bool sequenceIsQKeySeq, bool isModifier) const;
void assertKeyStroke (const Wacom::ButtonShortcut& shortcut, const QString& sequence, bool isQKeySequence) const;
void assertModifier (const ButtonShortcut& shortcut, const QString& sequence) const;
void assertUnset (const ButtonShortcut& shortcut) const;
};
QTEST_KDEMAIN_CORE(TestButtonShortcut)
void TestButtonShortcut::assertButton(const ButtonShortcut& shortcut, int buttonNumber) const
{
QVERIFY(shortcut.isSet());
......@@ -39,7 +69,6 @@ void TestButtonShortcut::assertButton(const ButtonShortcut& shortcut, int button
QVERIFY(shortcut.toQKeySequenceString().isEmpty());
}
void TestButtonShortcut::assertEquals(const ButtonShortcut& shortcut1, const ButtonShortcut& shortcut2) const
{
QVERIFY(shortcut1 == shortcut2);
......@@ -54,7 +83,6 @@ void TestButtonShortcut::assertEquals(const ButtonShortcut& shortcut1, const But
QCOMPARE(shortcut2.toQKeySequenceString(), shortcut2.toQKeySequenceString());
}
void TestButtonShortcut::assertKeySequence(const ButtonShortcut& shortcut, const QString& sequence, bool sequenceIsQKeySeq, bool isModifier) const
{
QVERIFY(shortcut.isSet());
......@@ -78,19 +106,16 @@ void TestButtonShortcut::assertKeySequence(const ButtonShortcut& shortcut, const
}
}
void TestButtonShortcut::assertKeyStroke(const ButtonShortcut& shortcut, const QString& sequence, bool isQKeySequence) const
{
assertKeySequence(shortcut, sequence, isQKeySequence, false);
}
void TestButtonShortcut::assertModifier(const ButtonShortcut& shortcut, const QString& sequence) const
{
assertKeySequence(shortcut, sequence, false, true);
}
void TestButtonShortcut::assertUnset(const ButtonShortcut& shortcut) const
{
QVERIFY(!shortcut.isSet());
......@@ -103,7 +128,6 @@ void TestButtonShortcut::assertUnset(const ButtonShortcut& shortcut) const
QVERIFY(shortcut.toQKeySequenceString().isEmpty());
}
void TestButtonShortcut::testAssignment()
{
ButtonShortcut buttonShortcut;
......@@ -363,4 +387,4 @@ void TestButtonShortcut::testQKeySequences()
}
}
#include "testbuttonshortcut.moc"
......@@ -22,8 +22,8 @@
#include <QString>
#include "commontestutils.h"
#include "deviceproperty.h"
#include "devicetype.h"
#include "src/common/deviceproperty.h"
#include "src/common/devicetype.h"
using namespace Wacom;
......
......@@ -20,10 +20,10 @@
#ifndef COMMONTESTUTILS_H
#define COMMONTESTUTILS_H
#include "deviceinformation.h"
#include "deviceprofile.h"
#include "devicetype.h"
#include "tabletinformation.h"
#include "src/common/deviceinformation.h"
#include "src/common/deviceprofile.h"
#include "src/common/devicetype.h"
#include "src/common/tabletinformation.h"
#include <QtCore/QString>
......
kde4_add_unit_test(Common.DeviceInformation
testdeviceinformation.cpp
../commontestutils.cpp
)
target_link_libraries(Common.DeviceInformation
# include static libs
wacom_common
# include general qt/kde libs
${QT_QTTEST_LIBRARY}
)
......@@ -17,13 +17,34 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "commontestutils.h"
#include "deviceinformation.h"
#include "autotests/common/commontestutils.h"
#include "src/common/deviceinformation.h"
#include "testdeviceinformation.moc"
#include <QtTest>
#include <KDE/KDebug>
#include <qtest_kde.h>
using namespace Wacom;
/**
* @file testdeviceinformation.cpp
*
* @test UnitTest for the device information
*/
class TestDeviceInformation: public QObject
{
Q_OBJECT
private slots:
void testCompare();
void testConstructor();
void testCopy();
void testSetter();
};
QTEST_KDEMAIN_CORE(TestDeviceInformation)
void TestDeviceInformation::testCompare()
{
DeviceType expectedType = DeviceType::Pad;
......@@ -86,8 +107,6 @@ void TestDeviceInformation::testCompare()
QVERIFY (actualDevice != expectedDevice);
}
void TestDeviceInformation::testConstructor()
{
DeviceType expectedType = DeviceType::Pad;
......@@ -105,8 +124,6 @@ void TestDeviceInformation::testConstructor()
QVERIFY (deviceInfo.getVendorId() == 0);
}
void TestDeviceInformation::testCopy()
{
DeviceType expectedType = DeviceType::Pad;
......@@ -128,8 +145,6 @@ void TestDeviceInformation::testCopy()
CommonTestUtils::assertValues (actual2Info, expectedType, expectedName);
}
void TestDeviceInformation::testSetter()
{
DeviceType expectedType = DeviceType::Stylus;
......@@ -141,3 +156,6 @@ void TestDeviceInformation::testSetter()
CommonTestUtils::assertValues(deviceInfo, expectedType, expectedName);
}
#include "testdeviceinformation.moc"
kde4_add_unit_test(Common.DeviceProfile
testdeviceprofile.cpp
../commontestutils.cpp
)
target_link_libraries(Common.DeviceProfile
# include static libs
wacom_common
# include general qt/kde libs
${QT_QTTEST_LIBRARY}
)
......@@ -17,12 +17,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "deviceprofile.h"
#include "commontestutils.h"
#include "testdeviceprofile.moc"
#include "autotests/common/commontestutils.h"
#include "src/common/deviceprofile.h"
#include <QtTest>
#include <KDE/KDebug>
#include <qtest_kde.h>
using namespace Wacom;
/**
* @file testdeviceprofile.cpp
*
* @test UnitTest for the device profiles
*/
class TestDeviceProfile: public QObject
{
Q_OBJECT
private slots:
void testConstructor();
void testSetter();
void testCopy();
};
QTEST_KDEMAIN_CORE(TestDeviceProfile)
void TestDeviceProfile::testConstructor()
{
DeviceProfile profile1;
......@@ -54,3 +75,5 @@ void TestDeviceProfile::testSetter()
CommonTestUtils::assertValues(profile);
}
#include "testdeviceprofile.moc"
kde4_add_unit_test(Common.DeviceProfileConfigAdaptor
testdeviceprofileconfigadaptor.cpp
../commontestutils.cpp
)
target_link_libraries(Common.DeviceProfileConfigAdaptor
# include static libs
wacom_common
# include general qt/kde libs
${QT_QTTEST_LIBRARY}
)
......@@ -17,6 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "autotests/common/commontestutils.h"
#include "src/common/deviceprofile.h"
#include "src/common/deviceprofileconfigadaptor.h"
#include <KDE/KSharedConfig>
#include <KDE/KConfigGroup>
......@@ -24,14 +28,28 @@
#include <QString>
#include <QTemporaryFile>
#include "deviceprofile.h"
#include "deviceprofileconfigadaptor.h"
#include <QtTest>
#include <KDE/KDebug>
#include "commontestutils.h"
#include "testdeviceprofileconfigadaptor.moc"
#include <qtest_kde.h>
using namespace Wacom;
/**
* @file testdeviceprofileconfigadaptor.cpp
*
* @test UnitTest for the device profiles config adaptor
*/
class TestDeviceProfileConfigAdaptor: public QObject
{
Q_OBJECT
private slots:
void testConfig();
};
QTEST_KDEMAIN_CORE(TestDeviceProfileConfigAdaptor)
void TestDeviceProfileConfigAdaptor::testConfig()
{
QTemporaryFile tempFile(QDir::tempPath() + QDir::separator() + QLatin1String("testdeviceprofileconfigadaptorrc_XXXXXX"));
......@@ -59,3 +77,6 @@ void TestDeviceProfileConfigAdaptor::testConfig()
CommonTestUtils::assertValues(readProfile);
}
#include "testdeviceprofileconfigadaptor.moc"
kde4_add_unit_test(Common.DeviceProperty
testdeviceproperty.cpp
)
target_link_libraries(Common.DeviceProperty
# include static libs
wacom_common
# include general qt/kde libs
${QT_QTTEST_LIBRARY}
)
......@@ -17,16 +17,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QString>
#include "src/common/deviceproperty.h"
#include "deviceproperty.h"
#include "testdeviceproperty.moc"
#include <QtTest>
#include <KDE/KDebug>
#include <qtest_kde.h>
using namespace Wacom;
/**
* @file testdeviceproperty.cpp
*
* @test UnitTest for the device properties
*/
class TestDeviceProperty: public QObject
{
Q_OBJECT
private slots:
void test();
};
QTEST_KDEMAIN_CORE(TestDeviceProperty)
void TestDeviceProperty::test()
{
// very basic test to make sure instanciation works
// the real unit tests can be found in TestPropertySet
QCOMPARE(DeviceProperty::Button1.key(), QLatin1String("Button1"));
}
#include "testdeviceproperty.moc"
kde4_add_unit_test(Common.Enum
testenum.cpp
)
target_link_libraries(Common.Enum
# include static libs
wacom_common
# include general qt/kde libs
${QT_QTTEST_LIBRARY}
)
......@@ -17,11 +17,38 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "enum.h"
#include "testenum.moc"
#include "src/common/enum.h"
#include <QtTest>
#include <KDE/KDebug>
#include <qtest_kde.h>
using namespace Wacom;
/**
* @file testenum.cpp
*
* @test UnitTest for the device properties
*/
class TestEnum: public QObject
{
Q_OBJECT
private slots:
void testCompare();
void testConstructor();
void testFind();
void testIterator();
void testKey();
void testKeys();
void testList();
void testOperator();
void testSize();
};
QTEST_KDEMAIN_CORE(TestEnum)
/*
* Forward Declarations, Typedefs & Helper classes.
*/
......@@ -78,9 +105,7 @@ const EnumTest EnumTest::VAL01_PRIO99(QLatin1String("VAL01_PRIO99"));
const EnumTest EnumTest::VAL01_PRIO50(QLatin1String("VAL01_PRIO50"));
/*
* UNIT TESTS
*/
void TestEnum::testCompare()
{
......@@ -228,3 +253,4 @@ void TestEnum::testSize()
QCOMPARE(EnumTest::list().size(), count);
}