diff --git a/autotests/libs/CMakeLists.txt b/autotests/libs/CMakeLists.txt index 51a8e3128..0c104d549 100644 --- a/autotests/libs/CMakeLists.txt +++ b/autotests/libs/CMakeLists.txt @@ -1,181 +1,181 @@ set(QT_REQUIRED_VERSION "5.8.0") find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Test DBus) include(ECMAddTests) if(${EXECUTABLE_OUTPUT_PATH}) set( PREVIOUS_EXEC_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH} ) else() set( PREVIOUS_EXEC_OUTPUT_PATH . ) endif() set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) set( TEST_RESULT_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/testresults ) file(MAKE_DIRECTORY ${TEST_RESULT_OUTPUT_PATH}) option(AKONADI_TESTS_XML "Use XML files for the test results, instead of plain text." FALSE) option(AKONADI_RUN_SQLITE_ISOLATED_TESTS "Run isolated tests with sqlite3 as backend" TRUE) option(AKONADI_RUN_MYSQL_ISOLATED_TESTS "Run isolated tests with MySQL as backend" TRUE) option(AKONADI_RUN_PGSQL_ISOLATED_TESTS "Run isolated tests with PostgreSQL as backend" TRUE) kde_enable_exceptions() include_directories( ${Boost_INCLUDE_DIR} ) # convenience macro to add akonadi qtestlib unit-tests macro(add_akonadi_test _source) set(_test ${_source} ${CMAKE_BINARY_DIR}/src/core/akonadicore_debug.cpp) get_filename_component(_name ${_source} NAME_WE) add_executable( ${_name} ${_test} ) add_test(NAME ${_name} COMMAND ${_name} ) ecm_mark_as_test(akonadi-${_name}) set_tests_properties(${_name} PROPERTIES ENVIRONMENT "QT_HASH_SEED=1;QT_NO_CPU_FEATURE=sse4.2") target_link_libraries(${_name} akonaditestfake Qt5::Test KF5::AkonadiPrivate KF5::DBusAddons KF5::I18n) endmacro() # convenience macro to add akonadi qtestlib unit-tests macro(add_akonadi_test_widgets _source) set(_test ${_source} ${CMAKE_BINARY_DIR}/src/widgets/akonadiwidgets_debug.cpp ${CMAKE_BINARY_DIR}/src/core/akonadicore_debug.cpp ) get_filename_component(_name ${_source} NAME_WE) add_executable( ${_name} ${_test} ) add_test(NAME ${_name} COMMAND ${_name} ) ecm_mark_as_test(akonadi-${_name}) set_tests_properties(${_name} PROPERTIES ENVIRONMENT "QT_HASH_SEED=1;QT_NO_CPU_FEATURE=sse4.2") target_link_libraries(${_name} akonaditestfake Qt5::Test KF5::AkonadiWidgets KF5::AkonadiPrivate KF5::DBusAddons) endmacro() include(../../KF5AkonadiMacros.cmake) # akonadi test fake library set(akonaditestfake_xml ${Akonadi_SOURCE_DIR}/src/interfaces/org.freedesktop.Akonadi.NotificationSource.xml) set_source_files_properties(${akonaditestfake_xml} PROPERTIES INCLUDE "protocol_p.h") qt5_add_dbus_interface( akonaditestfake_srcs ${akonaditestfake_xml} notificationsourceinterface ) add_library(akonaditestfake SHARED ${akonaditestfake_srcs} fakeakonadiservercommand.cpp fakesession.cpp fakemonitor.cpp fakeserverdata.cpp modelspy.cpp fakeentitycache.cpp inspectablemonitor.cpp inspectablechangerecorder.cpp ) generate_export_header(akonaditestfake BASE_NAME akonaditestfake) target_link_libraries(akonaditestfake Qt5::DBus KF5::AkonadiCore Qt5::Test Qt5::Widgets Qt5::Network KF5::DBusAddons KF5::AkonadiPrivate ) add_executable(akonadi-firstrun ../../src/core/firstrun.cpp firstrunner.cpp ${CMAKE_BINARY_DIR}/src/core/akonadicore_debug.cpp ) target_link_libraries( akonadi-firstrun Qt5::Test Qt5::Core KF5::AkonadiCore KF5::AkonadiPrivate KF5::DBusAddons KF5::ConfigCore Qt5::Widgets) # qtestlib unit tests add_akonadi_test(imapparsertest.cpp) # It need KIMAP add_akonadi_test(imapsettest.cpp) add_akonadi_test(itemhydratest.cpp) add_akonadi_test(itemtest.cpp) add_akonadi_test(itemserializertest.cpp) add_akonadi_test(mimetypecheckertest.cpp) add_akonadi_test(protocolhelpertest.cpp) add_akonadi_test(entitytreemodeltest.cpp) add_akonadi_test(monitornotificationtest.cpp) add_akonadi_test(collectionutilstest.cpp) add_akonadi_test(collectioncolorattributetest.cpp) add_akonadi_test(entitydisplayattributetest.cpp) add_akonadi_test(proxymodelstest.cpp) add_akonadi_test(newmailnotifierattributetest.cpp) add_akonadi_test(pop3resourceattributetest.cpp) add_akonadi_test_widgets(actionstatemanagertest.cpp) add_akonadi_test_widgets(conflictresolvedialogtest.cpp) add_akonadi_test(tagmodeltest.cpp) add_akonadi_test(statisticsproxymodeltest.cpp) add_akonadi_test(sharedvaluepooltest.cpp) add_akonadi_test(jobtest.cpp) add_akonadi_test(tagtest_simple.cpp) add_akonadi_test(cachepolicytest.cpp) # PORT FROM QJSON add_akonadi_test(searchquerytest.cpp) # qtestlib tests that need non-exported stuff from #add_executable( resourceschedulertest resourceschedulertest.cpp ../src/agentbase/resourcescheduler.cpp ) #add_test( resourceschedulertest resourceschedulertest ) #ecm_mark_as_test(akonadi-resourceschedulertest) #target_link_libraries(resourceschedulertest Qt5::Test KF5::AkonadiAgentBase) # testrunner tests add_akonadi_isolated_test(SOURCE testenvironmenttest.cpp) add_akonadi_isolated_test(SOURCE autoincrementtest.cpp) add_akonadi_isolated_test(SOURCE attributefactorytest.cpp) add_akonadi_isolated_test(SOURCE collectionpathresolvertest.cpp) add_akonadi_isolated_test(SOURCE collectionattributetest.cpp) add_akonadi_isolated_test(SOURCE itemfetchtest.cpp) add_akonadi_isolated_test(SOURCE itemappendtest.cpp) add_akonadi_isolated_test(SOURCE itemstoretest.cpp) add_akonadi_isolated_test(SOURCE itemdeletetest.cpp) add_akonadi_isolated_test(SOURCE entitycachetest.cpp) add_akonadi_isolated_test(SOURCE monitortest.cpp) #add_akonadi_isolated_test_advanced(monitorfiltertest.cpp "" "KF5::AkonadiPrivate") add_akonadi_isolated_test(SOURCE searchjobtest.cpp) add_akonadi_isolated_test(SOURCE changerecordertest.cpp) add_akonadi_isolated_test(SOURCE resourcetest.cpp) add_akonadi_isolated_test(SOURCE subscriptiontest.cpp) add_akonadi_isolated_test(SOURCE transactiontest.cpp) add_akonadi_isolated_test(SOURCE itemcopytest.cpp) add_akonadi_isolated_test(SOURCE itemmovetest.cpp) add_akonadi_isolated_test(SOURCE collectioncopytest.cpp) add_akonadi_isolated_test(SOURCE collectionmovetest.cpp) add_akonadi_isolated_test( SOURCE collectionsynctest.cpp ADDITIONAL_SOURCES ${CMAKE_BINARY_DIR}/src/core/akonadicore_debug.cpp LINK_LIBRARIES KF5::I18n ) add_akonadi_isolated_test(SOURCE itemsynctest.cpp) add_akonadi_isolated_test(SOURCE linktest.cpp) add_akonadi_isolated_test(SOURCE cachetest.cpp) # FIXME: This is very unstable on Jenkins #add_akonadi_isolated_test(servermanagertest.cpp) add_akonadi_isolated_test( SOURCE tagselectwidgettest.cpp LINK_LIBRARIES KF5::AkonadiWidgets ) # Having a benchmark is cool if you have any reference to compare against, but this # benchmark takes over 40 seconds and does not have any real value to us atm. Major # performance regressions would be spotted by devs anyway, so disabling for now. #add_akonadi_isolated_test(itembenchmark.cpp) #add_akonadi_isolated_test(collectioncreator.cpp) add_akonadi_isolated_test(SOURCE gidtest.cpp) add_akonadi_isolated_test(SOURCE lazypopulationtest.cpp) add_akonadi_isolated_test(SOURCE favoriteproxytest.cpp) add_akonadi_isolated_test( SOURCE itemsearchjobtest.cpp ADDITIONAL_SOURCES testsearchplugin/testsearchplugin.cpp) -add_akonadi_isolated_test(SOURCE tagtest.cpp) +add_akonadi_isolated_test(SOURCE tagtest.cpp ADDITIONAL_SOURCES ${CMAKE_BINARY_DIR}/src/core/akonadicore_debug.cpp) add_akonadi_isolated_test(SOURCE tagsynctest.cpp) add_akonadi_isolated_test(SOURCE relationtest.cpp) add_akonadi_isolated_test(SOURCE etmpopulationtest.cpp) diff --git a/src/core/tag.h b/src/core/tag.h index 795dbd8f4..3dd9f97eb 100644 --- a/src/core/tag.h +++ b/src/core/tag.h @@ -1,270 +1,270 @@ /* Copyright (c) 2014 Christian Mollekopf This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_TAG_H #define AKONADI_TAG_H #include "akonadicore_export.h" #include "attribute.h" +#include "akonadicore_debug.h" #include #include #include #include namespace Akonadi { class TagModifyJob; class TagPrivate; /** * An Akonadi Tag. */ class AKONADICORE_EXPORT Tag { public: typedef QVector List; typedef qint64 Id; /** * The PLAIN type has the following properties: * * gid == displayName * * immutable * * no hierarchy (no parent) * * PLAIN tags are general purpose tags that are easy to map by backends. */ static const char PLAIN[]; /** * The GENERIC type has the following properties: * * mutable * * gid is RFC 4122 compatible * * no hierarchy (no parent) * * GENERIC tags are general purpose tags, that are used, if you can change tag name. */ static const char GENERIC[]; Tag(); explicit Tag(Id id); /** * Creates a PLAIN tag */ explicit Tag(const QString &name); Tag(const Tag &other); ~Tag(); Tag &operator=(const Tag &); //Avoid slicing bool operator==(const Tag &) const; bool operator!=(const Tag &) const; static Tag fromUrl(const QUrl &url); /** * Adds an attribute to the entity. * * If an attribute of the same type name already exists, it is deleted and * replaced with the new one. * * @param attribute The new attribute. * * @note The entity takes the ownership of the attribute. */ void addAttribute(Attribute *attribute); /** * Removes and deletes the attribute of the given type @p name. */ void removeAttribute(const QByteArray &name); /** * Returns @c true if the entity has an attribute of the given type @p name, * false otherwise. */ bool hasAttribute(const QByteArray &name) const; /** * Returns a list of all attributes of the entity. */ Attribute::List attributes() const; /** * Removes and deletes all attributes of the entity. */ void clearAttributes(); /** * Returns the attribute of the given type @p name if available, 0 otherwise. */ Attribute *attribute(const QByteArray &name) const; /** * Describes the options that can be passed to access attributes. */ enum CreateOption { AddIfMissing ///< Creates the attribute if it is missing }; /** * Returns the attribute of the requested type. * If the entity has no attribute of that type yet, a new one * is created and added to the entity. * * @param option The create options. */ template inline T *attribute(CreateOption option); /** * Returns the attribute of the requested type or 0 if it is not available. */ template inline T *attribute() const; /** * Removes and deletes the attribute of the requested type. */ template inline void removeAttribute(); /** * Returns whether the entity has an attribute of the requested type. */ template inline bool hasAttribute() const; /** * Returns the url of the tag. */ QUrl url() const; /** * Sets the unique @p identifier of the tag. */ void setId(Id identifier); /** * Returns the unique identifier of the tag. */ Id id() const; void setGid(const QByteArray &gid); QByteArray gid() const; void setRemoteId(const QByteArray &remoteId); QByteArray remoteId() const; void setType(const QByteArray &type); QByteArray type() const; void setName(const QString &name); QString name() const; void setParent(const Tag &parent); Tag parent() const; bool isValid() const; /** * Returns true if the tag is immutable (cannot be modified after creation). * Note that the immutability does not affect the attributes. */ bool isImmutable() const; /** * Returns a GENERIC tag with the given name and a valid gid */ static Tag genericTag(const QString &name); private: //@cond PRIVATE friend class TagModifyJob; QSharedDataPointer d_ptr; //@endcond }; AKONADICORE_EXPORT uint qHash(const Akonadi::Tag &); template inline T *Tag::attribute(CreateOption option) { Q_UNUSED(option); const T dummy; if (hasAttribute(dummy.type())) { T *attr = dynamic_cast(attribute(dummy.type())); if (attr) { return attr; } //reuse 5250 qWarning() << "Found attribute of unknown type" << dummy.type() << ". Did you forget to call AttributeFactory::registerAttribute()?"; } T *attr = new T(); addAttribute(attr); return attr; } template inline T *Tag::attribute() const { const T dummy; if (hasAttribute(dummy.type())) { T *attr = dynamic_cast(attribute(dummy.type())); if (attr) { return attr; } - //Reuse 5250 - qWarning() << "Found attribute of unknown type" << dummy.type() + qCWarning(AKONADICORE_LOG) << "Found attribute of unknown type" << dummy.type() << ". Did you forget to call AttributeFactory::registerAttribute()?"; } return nullptr; } template inline void Tag::removeAttribute() { const T dummy; removeAttribute(dummy.type()); } template inline bool Tag::hasAttribute() const { const T dummy; return hasAttribute(dummy.type()); } } // namespace Akonadi AKONADICORE_EXPORT QDebug &operator<<(QDebug &debug, const Akonadi::Tag &tag); Q_DECLARE_METATYPE(Akonadi::Tag) Q_DECLARE_METATYPE(Akonadi::Tag::List) Q_DECLARE_METATYPE(QSet) Q_DECLARE_TYPEINFO(Akonadi::Tag, Q_MOVABLE_TYPE); #endif