From 2eb3810b66de3130f3e650627380c28a96acded7 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 13 Oct 2015 00:04:05 +0200 Subject: Moved test implementations to central location. --- tests/CMakeLists.txt | 4 +- tests/genericfacadebenchmark.cpp | 39 +------------ tests/genericfacadetest.cpp | 64 +-------------------- tests/genericresourcebenchmark.cpp | 27 +-------- tests/genericresourcetest.cpp | 17 +----- tests/pipelinetest.cpp | 13 +---- tests/testimplementations.cpp | 23 ++++++++ tests/testimplementations.h | 111 +++++++++++++++++++++++++++++++++++++ 8 files changed, 146 insertions(+), 152 deletions(-) create mode 100644 tests/testimplementations.cpp create mode 100644 tests/testimplementations.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b2201ff..5629cdb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,7 +10,7 @@ include_directories( macro(manual_tests) foreach(_testname ${ARGN}) - add_executable(${_testname} ${_testname}.cpp) + add_executable(${_testname} ${_testname}.cpp testimplementations.cpp) generate_flatbuffers(${_testname} calendar) qt5_use_modules(${_testname} Core Test Concurrent) target_link_libraries(${_testname} akonadi2common libhawd) @@ -19,7 +19,7 @@ endmacro(manual_tests) macro(auto_tests) foreach(_testname ${ARGN}) - add_executable(${_testname} ${_testname}.cpp) + add_executable(${_testname} ${_testname}.cpp testimplementations.cpp) generate_flatbuffers(${_testname} calendar) add_test(${_testname} ${_testname}) qt5_use_modules(${_testname} Core Test Concurrent) diff --git a/tests/genericfacadebenchmark.cpp b/tests/genericfacadebenchmark.cpp index 7cd6c75..3e98fce 100644 --- a/tests/genericfacadebenchmark.cpp +++ b/tests/genericfacadebenchmark.cpp @@ -2,6 +2,8 @@ #include +#include "testimplementations.h" + #include #include #include @@ -9,44 +11,7 @@ #include "event_generated.h" -class TestEventAdaptorFactory : public DomainTypeAdaptorFactory -{ -public: - TestEventAdaptorFactory() - : DomainTypeAdaptorFactory() - { - } - - virtual ~TestEventAdaptorFactory() {}; -}; - -class TestResourceAccess : public Akonadi2::ResourceAccessInterface -{ - Q_OBJECT -public: - virtual ~TestResourceAccess() {}; - KAsync::Job sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null(); } - KAsync::Job sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null(); } - KAsync::Job synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null(); } - -public Q_SLOTS: - void open() Q_DECL_OVERRIDE {} - void close() Q_DECL_OVERRIDE {} -}; - -class TestResourceFacade : public Akonadi2::GenericFacade -{ -public: - TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer > storage, const QSharedPointer resourceAccess) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create(), storage, resourceAccess) - { - } - virtual ~TestResourceFacade() - { - - } -}; class GenericFacadeBenchmark : public QObject { diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp index e9c1a94..ae6a685 100644 --- a/tests/genericfacadetest.cpp +++ b/tests/genericfacadetest.cpp @@ -2,6 +2,8 @@ #include +#include "testimplementations.h" + #include #include #include @@ -10,68 +12,6 @@ //Replace with something different #include "event_generated.h" -class TestEventAdaptorFactory : public DomainTypeAdaptorFactory -{ -public: - TestEventAdaptorFactory() - : DomainTypeAdaptorFactory() - { - } - - virtual ~TestEventAdaptorFactory() {}; -}; - -class TestEntityStorage : public EntityStorage -{ -public: - using EntityStorage::EntityStorage; - virtual qint64 read(const Akonadi2::Query &query, qint64 oldRevision, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE - { - for (const auto &res : mResults) { - resultProvider->add(res); - } - for (const auto &res : mModifications) { - resultProvider->modify(res); - } - for (const auto &res : mRemovals) { - resultProvider->remove(res); - } - return mLatestRevision; - } - - QList mResults; - QList mModifications; - QList mRemovals; - qint64 mLatestRevision; -}; - -class TestResourceAccess : public Akonadi2::ResourceAccessInterface -{ - Q_OBJECT -public: - virtual ~TestResourceAccess() {}; - KAsync::Job sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null(); } - KAsync::Job sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null(); } - KAsync::Job synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null(); } - -public Q_SLOTS: - void open() Q_DECL_OVERRIDE {} - void close() Q_DECL_OVERRIDE {} -}; - -class TestResourceFacade : public Akonadi2::GenericFacade -{ -public: - TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer > storage, const QSharedPointer resourceAccess) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create(), storage, resourceAccess) - { - - } - virtual ~TestResourceFacade() - { - - } -}; class GenericFacadeTest : public QObject { diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp index 50d0c67..1776c81 100644 --- a/tests/genericresourcebenchmark.cpp +++ b/tests/genericresourcebenchmark.cpp @@ -2,6 +2,8 @@ #include +#include "testimplementations.h" + #include "event_generated.h" #include "createentity_generated.h" #include "commands.h" @@ -15,31 +17,6 @@ #include "hawd/dataset.h" #include "hawd/formatter.h" -class TestResource : public Akonadi2::GenericResource -{ -public: - TestResource(const QByteArray &instanceIdentifier, QSharedPointer pipeline) - : Akonadi2::GenericResource(instanceIdentifier, pipeline) - { - } - - KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE - { - return KAsync::null(); - } -}; - -class TestEventAdaptorFactory : public DomainTypeAdaptorFactory -{ -public: - TestEventAdaptorFactory() - : DomainTypeAdaptorFactory() - { - } - - virtual ~TestEventAdaptorFactory() {}; -}; - static void removeFromDisk(const QString &name) { diff --git a/tests/genericresourcetest.cpp b/tests/genericresourcetest.cpp index fa6da22..60b1dab 100644 --- a/tests/genericresourcetest.cpp +++ b/tests/genericresourcetest.cpp @@ -2,6 +2,8 @@ #include +#include "testimplementations.h" + #include "event_generated.h" #include "entity_generated.h" #include "metadata_generated.h" @@ -12,21 +14,6 @@ #include "genericresource.h" #include "definitions.h" -class TestResource : public Akonadi2::GenericResource -{ -public: - TestResource(const QByteArray &instanceIdentifier, QSharedPointer pipeline) - : Akonadi2::GenericResource(instanceIdentifier, pipeline) - { - } - - KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE - { - return KAsync::null(); - } -}; - - static void removeFromDisk(const QString &name) { Akonadi2::Storage store(Akonadi2::storageLocation(), name, Akonadi2::Storage::ReadWrite); diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 4cff511..9aa7024 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -2,6 +2,8 @@ #include +#include "testimplementations.h" + #include "event_generated.h" #include "entity_generated.h" #include "metadata_generated.h" @@ -18,17 +20,6 @@ #include "log.h" #include "domainadaptor.h" -class TestEventAdaptorFactory : public DomainTypeAdaptorFactory -{ -public: - TestEventAdaptorFactory() - : DomainTypeAdaptorFactory() - { - } - - virtual ~TestEventAdaptorFactory() {}; -}; - static void removeFromDisk(const QString &name) { Akonadi2::Storage store(Akonadi2::Store::storageLocation(), name, Akonadi2::Storage::ReadWrite); diff --git a/tests/testimplementations.cpp b/tests/testimplementations.cpp new file mode 100644 index 0000000..1040956 --- /dev/null +++ b/tests/testimplementations.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 6 of version 3 of the license. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "testimplementations.h" + +#include "testimplementations.moc" diff --git a/tests/testimplementations.h b/tests/testimplementations.h new file mode 100644 index 0000000..eee78b0 --- /dev/null +++ b/tests/testimplementations.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 6 of version 3 of the license. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +//Replace with something different +#include "event_generated.h" + +class TestEventAdaptorFactory : public DomainTypeAdaptorFactory +{ +public: + TestEventAdaptorFactory() + : DomainTypeAdaptorFactory() + { + } + + virtual ~TestEventAdaptorFactory() {}; +}; + +class TestEntityStorage : public EntityStorage +{ +public: + using EntityStorage::EntityStorage; + virtual qint64 read(const Akonadi2::Query &query, qint64 oldRevision, const QSharedPointer > &resultProvider) Q_DECL_OVERRIDE + { + for (const auto &res : mResults) { + resultProvider->add(res); + } + for (const auto &res : mModifications) { + resultProvider->modify(res); + } + for (const auto &res : mRemovals) { + resultProvider->remove(res); + } + return mLatestRevision; + } + + QList mResults; + QList mModifications; + QList mRemovals; + qint64 mLatestRevision; +}; + +class TestResourceAccess : public Akonadi2::ResourceAccessInterface +{ + Q_OBJECT +public: + virtual ~TestResourceAccess() {}; + KAsync::Job sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null(); } + KAsync::Job sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null(); } + KAsync::Job synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null(); } + +public Q_SLOTS: + void open() Q_DECL_OVERRIDE {} + void close() Q_DECL_OVERRIDE {} +}; + +class TestResourceFacade : public Akonadi2::GenericFacade +{ +public: + TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer > storage, const QSharedPointer resourceAccess) + : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create(), storage, resourceAccess) + { + + } + virtual ~TestResourceFacade() + { + + } +}; + +class TestResource : public Akonadi2::GenericResource +{ +public: + TestResource(const QByteArray &instanceIdentifier, QSharedPointer pipeline) + : Akonadi2::GenericResource(instanceIdentifier, pipeline) + { + } + + KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE + { + return KAsync::null(); + } +}; -- cgit v1.2.3