Commit 4a0c8a10 authored by David Faure's avatar David Faure

More work on itiphandlertest:

- unittestenv for mysql-fs as the test framework expects
- port from kdehome to xdgconfig+xdglocal
- use proper way to export internal class when building tests
- use QFINDTESTDATA instead of a wrongly-escaped define

It passes!
parent da7daa17
......@@ -35,6 +35,11 @@ ecm_setup_version(${AKONADICALENDAR_LIB_VERSION} VARIABLE_PREFIX AKONADICALENDAR
configure_file(akonadi-calendar-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/src/akonadi-calendar-version.h @ONLY)
if(BUILD_TESTING)
set(AKONADI_CALENDAR_TESTS_EXPORT AKONADI_CALENDAR_EXPORT)
endif()
configure_file(akonadi-calendar_tests_export.h.in "${CMAKE_CURRENT_BINARY_DIR}/src/akonadi-calendar_tests_export.h" @ONLY)
########### Find packages ###########
find_package(KF5KIO ${KF5_VERSION} CONFIG REQUIRED)
......@@ -55,12 +60,6 @@ find_package(KF5AkonadiContact ${AKONADICONTACT_LIB_VERSION} CONFIG REQUIRED)
add_definitions(-DTRANSLATION_DOMAIN=\"libakonadi-calendar5\")
add_definitions("-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII")
# TODO: switch to more standard approach for export-class-if-building-autotests once the tests pass
set( PLEASE_TEST_INVITATIONS FALSE)
if ( PLEASE_TEST_INVITATIONS )
add_definitions( -DPLEASE_TEST_INVITATIONS )
endif()
add_subdirectory(src)
if (BUILD_TESTING)
......
#include "akonadi-calendar_export.h"
#define AKONADI_CALENDAR_TESTS_EXPORT @AKONADI_CALENDAR_TESTS_EXPORT@
......@@ -10,8 +10,6 @@ set( KDEPIMLIBS_RUN_ISOLATED_TESTS TRUE )
set( PREVIOUS_EXEC_OUTPUT_PATH ../../tests )
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
add_definitions(-DITIP_DATA_DIR="\\"${CMAKE_CURRENT_SOURCE_DIR}/itip_data\\"" )
set(common_sources unittestbase.cpp helper.cpp ${Akonadi-Calendar_BINARY_DIR}/src/akonadicalendar_debug.cpp ${Akonadi-Calendar_SOURCE_DIR}/src/utils_p.cpp)
set(common_libs "KF5::AkonadiCalendar;KF5::CalendarCore;KF5::Mime;KF5::IdentityManagement;KF5::AkonadiWidgets")
......@@ -24,9 +22,7 @@ add_akonadi_isolated_test_advanced( calendarbasetest.cpp "" "KF5::AkonadiCalenda
add_akonadi_isolated_test_advanced( fetchjobcalendartest.cpp "" "KF5::AkonadiCalendar" )
add_akonadi_isolated_test_advanced( etmcalendartest.cpp "" "KF5::AkonadiCalendar" )
add_akonadi_isolated_test_advanced( itiphandlertest.cpp "${common_sources}" "${common_libs};KF5::MailTransport")
add_akonadi_isolated_test_advanced( mailclienttest.cpp "" "KF5::AkonadiCalendar;KF5::Mime;KF5::MailTransport;KF5::IdentityManagement")
if ( PLEASE_TEST_INVITATIONS )
add_akonadi_isolated_test_advanced( itiphandlertest.cpp "${common_sources}" "${common_libs};KF5::MailTransport")
add_akonadi_isolated_test_advanced( mailclienttest.cpp "" "KF5::AkonadiCalendar;KF5::Mime;KF5::MailTransport;KF5::IdentityManagement")
endif()
endif()
......@@ -31,7 +31,8 @@ Akonadi::Collection Helper::fetchCollection()
Q_UNUSED(ret);
// Find our collection
Collection::List collections = job->collections();
const Collection::List collections = job->collections();
Q_ASSERT(!collections.isEmpty());
Collection collection = collections.first();
Q_ASSERT(collection.isValid());
......
......@@ -97,6 +97,8 @@ public:
void ITIPHandlerTest::initTestCase()
{
AkonadiTest::checkTestIsIsolated();
extern AKONADI_CALENDAR_TESTS_EXPORT bool akonadi_calendar_running_unittests;
akonadi_calendar_running_unittests = true;
m_pendingItipMessageSignal = 0;
m_pendingIncidenceChangerSignal = 0;
m_itipHandler = 0;
......@@ -634,7 +636,7 @@ void ITIPHandlerTest::createITIPHandler()
QString ITIPHandlerTest::icalData(const QString &data_filename)
{
QString absolutePath = QLatin1String(ITIP_DATA_DIR) + QLatin1Char('/') + data_filename;
QString absolutePath = QFINDTESTDATA(QStringLiteral("itip_data/") + data_filename);
return QString::fromLatin1(readFile(absolutePath));
}
......
......@@ -169,6 +169,7 @@ QByteArray UnitTestBase::readFile(const QString &filename)
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "File could not be opened for reading:" << filename;
return QByteArray();
}
......
<config>
<confighome>xdgconfig-mysql.fs</confighome>
<datahome>xdglocal</datahome>
<agent synchronize="true">akonadi_ical_resource</agent>
<envvar name="AKONADI_DISABLE_AGENT_AUTOSTART">true</envvar>
<envvar name="TESTRUNNER_DB_ENVIRONMENT">mysql</envvar>
</config>
<config>
<kdehome>kdehome</kdehome>
<confighome>xdgconfig-sqlite.db</confighome>
<datahome>xdglocal</datahome>
<agent synchronize="true">akonadi_ical_resource</agent>
......
<config>
<confighome>xdgconfig</confighome>
<datahome>xdglocal</datahome>
</config>
[General]
Path[$e]=$KDEHOME/std0.ics
\ No newline at end of file
[%General]
# This is a slightly adjusted version of the QSQLITE driver from Qt
# It is provided by akonadi itself
Driver=QSQLITE3
[Debug]
Tracer=null
[Search]
Manager=Dummy
[General]
Path[$e]=$XDG_DATA_HOME/std0.ics
......@@ -37,11 +37,8 @@
using namespace Akonadi;
using namespace KCalCore;
#ifdef PLEASE_TEST_INVITATIONS
# define RUNNING_UNIT_TESTS true
#else
# define RUNNING_UNIT_TESTS false
#endif
AKONADI_CALENDAR_TESTS_EXPORT bool akonadi_calendar_running_unittests = false;
static ITIPHandlerDialogDelegate::Action actionFromStatus(ITIPHandlerHelper::SendResult result)
{
......@@ -551,7 +548,7 @@ void IncidenceChanger::Private::handleInvitationsBeforeChange(const Change::Ptr
return;
}
if (RUNNING_UNIT_TESTS && !weAreOrganizer(newIncidence)) {
if (akonadi_calendar_running_unittests && !weAreOrganizer(newIncidence)) {
// This is a bit of a workaround when running tests. I don't want to show the
// "You're not organizer, do you want to modify event?" dialog in unit-tests, but want
// to emulate a "yes" and a "no" press.
......
......@@ -22,7 +22,7 @@
#ifndef AKONADI_MAILCLIENT_P_H
#define AKONADI_MAILCLIENT_P_H
#include "akonadi-calendar_export.h"
#include "akonadi-calendar_tests_export.h"
#include "itiphandler.h"
#include <kcalcore/incidencebase.h>
#include <kmime/kmime_message.h>
......@@ -51,15 +51,10 @@ class KJob;
namespace Akonadi
{
#ifdef PLEASE_TEST_INVITATIONS
#define EXPORT_MAILCLIENT AKONADI_CALENDAR_EXPORT
#else
#define EXPORT_MAILCLIENT
#endif
class ITIPHandlerComponentFactory;
class EXPORT_MAILCLIENT MailClient : public QObject
class AKONADI_CALENDAR_TESTS_EXPORT MailClient : public QObject
{
Q_OBJECT
......
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