Commit 8194c93a authored by Andreas Xavier's avatar Andreas Xavier
Browse files

Add default unittest setup to parley

This creates 2 stub unittests in the autotest directory so that devs
can easily add new unit tests of classes without doing the setup in
this patch.

It moves the definition of parley's include directories and
link libraries up into the root CMake file, so that they are visible
to the unittests and only need to be redefined in one location when a
dev makes a change elsewhere.

REVIEW: 118895
parent 75773865
......@@ -28,6 +28,44 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/config-parley.h
)
# Define link libs for parley executable and unittests
set( parley_LINK_LIBS
${LIBKDEEDU_KEDUVOCDOCUMENT_LIBRARIES}
${KDE4_KHTML_LIBS}
${KDE4_KNEWSTUFF3_LIBS}
${KDE4_PHONON_LIBS}
${KDE4_KCMUTILS_LIBRARY} #for the KPluginSelector
${KDE4_KROSSCORE_LIBS} ${KDE4_KROSSUI_LIBS} #for Kross
${QT_QTCORE_LIBRARY}
)
if(HAVE_LIBXSLT)
set( parley_LINK_LIBS ${parley_LINK_LIBS} ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES})
endif(HAVE_LIBXSLT)
if (X11_Xrender_FOUND)
set( parley_LINK_LIBS ${parley_LINK_LIBS} ${X11_LIBRARIES} ${X11_Xrender_LIB})
endif(X11_Xrender_FOUND)
#define the include libraries for both the parley executable and the autotests
set( parley_INCLUDE_DIRS
${LIBATTICA_INCLUDE_DIR}
# libkdeedu/keduvocdocument contains the library for reading and writing vocabulary files
${LIBKDEEDU_INCLUDE_DIR}
)
#### XSLT Support ####
# to transform the document xml to html or other
if(HAVE_LIBXSLT)
set( parley_INCLUDE_DIRS ${parley_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} ${LIBXSLT_INCLUDE_DIR} )
endif(HAVE_LIBXSLT)
#### End XSLT Support ####
add_subdirectory( autotests )
add_subdirectory( doc )
add_subdirectory( scripts_test )
add_subdirectory( src )
......@@ -36,6 +74,7 @@ add_subdirectory( plugins )
add_subdirectory( themes )
add_subdirectory( tipofday )
if(HAVE_LIBXSLT)
add_subdirectory( xslt )
endif(HAVE_LIBXSLT)
......
# To add a new unittest
# 1. Add its name to parley_unittests
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
set( unittest_INCLUDE_DIRS
../src
../src/practice
)
set(unittest_LINK_LIBS
${QT_QTTEST_LIBRARY}
)
set(parley_unittests
allpass1test
allpass2test
)
set(parley_unittests_helpers
parleyunittestutilities.cpp
)
macro(ADD_PARLEY_UNITTESTS)
foreach(_unittestname ${ARGN} )
kde4_add_unit_test(${_unittestname} ${_unittestname}.cpp ${parley_unittests_helpers} )
target_link_libraries( ${_unittestname} ${unittest_LINK_LIBS} parley_LIB ${parley_LINK_LIBS} )
endforeach(_unittestname ${argn} )
endmacro(ADD_PARLEY_UNITTESTS)
include_directories( ${unittest_INCLUDE_DIRS} ${parley_INCLUDE_DIRS} )
ADD_PARLEY_UNITTESTS( ${parley_unittests} )
/*
Copyright 2014 Andreas Xavier <andxav at zoho dot 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) any later version.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
#include "parleyunittestutilities.h"
#include "parleydocument.h"
#include <QtTest>
using namespace UnitTestUtilities;
/** This class is a unittest stub with 2 tests that always pass
*/
class AllPass1Test
: public QObject
{
Q_OBJECT
private slots: //must be private
/** Test that always passes*/
void testAlwaysPass1();
/** Test that always passes*/
void testAlwaysPass2();
};
void AllPass1Test::testAlwaysPass1()
{
QCOMPARE( true, true );
}
void AllPass1Test::testAlwaysPass2()
{
//This just forces these to link and test the CMake file
MinimalTempVocDoc tempfile;
KEduVocDocument *docWithLock = new KEduVocDocument();
int docError = docWithLock->open(tempfile.fileName());
QCOMPARE( docError, int( KEduVocDocument::NoError ) );
KUrl kurl = KUrl::fromPath(tempfile.fileName() );
ParleyDocument *doc = new ParleyDocument(0);
QCOMPARE( true, true );
}
QTEST_KDEMAIN_CORE( AllPass1Test )
#include "allpass1test.moc"
/*
Copyright 2014 Andreas Xavier <andxav at zoho dot 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) any later version.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
#include "parleyunittestutilities.h"
#include "parleydocument.h"
#include <QtTest>
/** This class is a unittest stub with 2 tests that always pass
*/
class AllPass2Test
: public QObject
{
Q_OBJECT
private slots: //must be private
/** Test that always passes*/
void testAlwaysPass1();
/** Test that always passes*/
void testAlwaysPass2();
};
void AllPass2Test::testAlwaysPass1()
{
QCOMPARE( true, true );
}
void AllPass2Test::testAlwaysPass2()
{
QCOMPARE( true, true );
}
QTEST_KDEMAIN_CORE( AllPass2Test )
#include "allpass2test.moc"
/*
Copyright 2014 Andreas Xavier <andxav at zoho dot 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) any later version.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
/**
@file This file collects some utility classes that are used in multiple unit tests
**/
#include "parleyunittestutilities.h"
using namespace UnitTestUtilities;
TemporaryVocDoc::TemporaryVocDoc()
{
this->setSuffix(".kvtml");
this->open();
this->close();
}
TemporaryVocDoc::~TemporaryVocDoc()
{
}
MinimalTempVocDoc::MinimalTempVocDoc()
{
const QString generator = QString::fromLatin1( "File Locking Unit Tests" );
const QString author = QString::fromLatin1( "File Locking Test" );
const QString lang = QString::fromLatin1( "File Locking Language Name" );
const QString locale = QString::fromLatin1( "en" ) ;
KEduVocIdentifier lang0;
lang0.setName( lang );
lang0.setLocale( locale);
KEduVocDocument *doc = new KEduVocDocument();
doc->setAuthor( author );
doc->appendIdentifier( lang0 );
KUrl filename = this->fileName();
doc->saveAs(filename, KEduVocDocument::Kvtml, generator);
delete doc;
}
/** Destructor*/
MinimalTempVocDoc::~MinimalTempVocDoc()
{
}
/*
Copyright 2014 Andreas Xavier <andxav at zoho dot 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) any later version.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
/**
@file This file collects some utility classes that are used in multiple unit tests
**/
#ifndef PARLEYUNITTESTUTILITIES_H
#define PARLEYUNITTESTUTILITIES_H
#include "parleydocument.h"
#include <KTemporaryFile>
#include <KUrl>
#include <qtest_kde.h>
#include <KDebug>
#include <QtTest>
namespace UnitTestUtilities
{
/** Class to manage creation/destruction of a kvtml temp doc*/
class TemporaryVocDoc : public KTemporaryFile
{
public :
/** Create the file, fix the suffix and instantiate it.*/
TemporaryVocDoc() ;
/** Destructor*/
~TemporaryVocDoc();
};
/** Creates a minimal doc that will save and load error free.*/
class MinimalTempVocDoc : public TemporaryVocDoc
{
public :
/** The minimal doc has generator, author, lang and local */
MinimalTempVocDoc();
/** Destructor*/
~MinimalTempVocDoc();
};
}
#endif //PARLEYUNITTESTUTILITIES_H
include_directories( ${LIBATTICA_INCLUDE_DIR} )
include_directories( ${parley_INCLUDE_DIRS} )
# installation of kconfig files .kcfg containing app settings
add_subdirectory( settings )
# libkdeedu/keduvocdocument contains the library for reading and writing vocabulary files
include_directories( ${LIBKDEEDU_INCLUDE_DIR} )
set(parley_SRCS
main.cpp
set(parley_LIB_SRCS
parleyactions.cpp
parleydocument.cpp
parleymainwindow.cpp
......@@ -106,7 +102,7 @@ set(parley_SRCS
welcomescreen/buttondelegate.cpp
)
kde4_add_ui_files(parley_SRCS
kde4_add_ui_files(parley_LIB_SRCS
configure-practice/generalpracticeoptions.ui
configure-practice/blockoptions.ui
configure-practice/thresholdoptions.ui
......@@ -139,7 +135,7 @@ kde4_add_ui_files(parley_SRCS
welcomescreen/welcomescreen.ui
)
kde4_add_kcfg_files(parley_SRCS
kde4_add_kcfg_files(parley_LIB_SRCS
settings/prefs.kcfgc
settings/documentsettings.kcfgc
settings/languagesettings.kcfgc
......@@ -148,40 +144,31 @@ kde4_add_kcfg_files(parley_SRCS
#### XSLT Support ####
# to transform the document xml to html or other
if(HAVE_LIBXSLT)
include_directories( ${LIBXML2_INCLUDE_DIR} ${LIBXSLT_INCLUDE_DIR} )
set(parley_SRCS ${parley_SRCS}
set(parley_LIB_SRCS ${parley_LIB_SRCS}
export/exportdialog.cpp
)
kde4_add_ui_files(parley_SRCS
kde4_add_ui_files(parley_LIB_SRCS
export/exportdialog.ui
)
endif(HAVE_LIBXSLT)
#### End XSLT Support ####
kde4_add_app_icon(parley_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/hi*-app-parley.png")
kde4_add_app_icon(parley_LIB_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/hi*-app-parley.png")
set(parley_SRCS
main.cpp
${parley_LIB_SRCS}
)
kde4_add_executable(parley ${parley_SRCS})
kde4_install_icons( ${ICON_INSTALL_DIR} )
target_link_libraries(
parley
${LIBKDEEDU_KEDUVOCDOCUMENT_LIBRARIES}
${KDE4_KHTML_LIBS}
${KDE4_KNEWSTUFF3_LIBS}
${KDE4_PHONON_LIBS}
${KDE4_KCMUTILS_LIBRARY} #for the KPluginSelector
${KDE4_KROSSCORE_LIBS} ${KDE4_KROSSUI_LIBS} #for Kross
${QT_QTCORE_LIBRARY}
)
if(HAVE_LIBXSLT)
target_link_libraries(parley ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES})
endif(HAVE_LIBXSLT)
#Library for the unit tests target
kde4_add_library(parley_LIB STATIC ${parley_LIB_SRCS})
if (X11_Xrender_FOUND)
target_link_libraries(parley ${X11_LIBRARIES} ${X11_Xrender_LIB})
endif(X11_Xrender_FOUND)
kde4_install_icons( ${ICON_INSTALL_DIR} )
target_link_libraries(parley ${parley_LINK_LIBS})
########### install files ###############
......@@ -200,5 +187,3 @@ install( FILES welcomescreen/welcomescreenui.rc DESTINATION ${DATA_INSTALL_DIR}
install( FILES statistics/statisticsui.rc DESTINATION ${DATA_INSTALL_DIR}/parley )
install( FILES practice/practiceui.rc DESTINATION ${DATA_INSTALL_DIR}/parley )
install( FILES practice/practicesummaryui.rc DESTINATION ${DATA_INSTALL_DIR}/parley )
Supports Markdown
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