File indexing completed on 2025-01-19 04:56:44

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Kevin Ottens <ervin@kde.org>
0003  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004  */
0005 
0006 
0007 #ifndef TESTLIB_AKONADIFAKEDATA_H
0008 #define TESTLIB_AKONADIFAKEDATA_H
0009 
0010 #include <QObject>
0011 
0012 #include <Akonadi/Collection>
0013 #include <Akonadi/Item>
0014 
0015 #include "testlib/akonadifakestoragebehavior.h"
0016 
0017 namespace Akonadi {
0018 class MonitorInterface;
0019 class StorageInterface;
0020 }
0021 
0022 namespace Utils {
0023 class DependencyManager;
0024 }
0025 
0026 namespace Testlib {
0027 
0028 class AkonadiFakeMonitor;
0029 
0030 class AkonadiFakeData
0031 {
0032 public:
0033     AkonadiFakeData();
0034     AkonadiFakeData(const AkonadiFakeData &other);
0035     ~AkonadiFakeData();
0036 
0037     AkonadiFakeData &operator=(const AkonadiFakeData &other);
0038 
0039     Akonadi::Collection::List collections() const;
0040     Akonadi::Collection::List childCollections(Akonadi::Collection::Id parentId) const;
0041     Akonadi::Collection collection(Akonadi::Collection::Id id) const;
0042     void createCollection(const Akonadi::Collection &collection);
0043     void modifyCollection(const Akonadi::Collection &collection);
0044     void removeCollection(const Akonadi::Collection &collection);
0045 
0046     QStringList contextsUids() const;
0047     Akonadi::Item::List contexts() const;
0048     Akonadi::Item contextItem(const QString &uid) const;
0049     void createContext(const Akonadi::Item &item);
0050     void modifyContext(const Akonadi::Item &item);
0051     void removeContext(const Akonadi::Item &item);
0052 
0053     Akonadi::Item::List items() const;
0054     Akonadi::Item::List childItems(Akonadi::Collection::Id parentId) const;
0055     Akonadi::Item::List contextItems(const QString& contextUid) const;
0056     Akonadi::Item item(Akonadi::Item::Id id) const;
0057     void createItem(const Akonadi::Item &item);
0058     void modifyItem(const Akonadi::Item &item);
0059     void removeItem(const Akonadi::Item &item);
0060 
0061     Akonadi::MonitorInterface *createMonitor();
0062     Akonadi::StorageInterface *createStorage();
0063     std::unique_ptr<Utils::DependencyManager> createDependencies();
0064 
0065     Akonadi::Collection::Id maxCollectionId() const;
0066     Akonadi::Item::Id maxItemId() const;
0067 
0068     Akonadi::Collection reconstructAncestors(const Akonadi::Collection &collection,
0069                                              const Akonadi::Collection &root = Akonadi::Collection::root()) const;
0070     Akonadi::Item reconstructItemDependencies(const Akonadi::Item &item,
0071                                               const Akonadi::Collection &root = Akonadi::Collection::root()) const;
0072 
0073     const AkonadiFakeStorageBehavior &storageBehavior() const;
0074     AkonadiFakeStorageBehavior &storageBehavior();
0075 
0076 private:
0077     QHash<Akonadi::Collection::Id, Akonadi::Collection> m_collections;
0078     QHash<Akonadi::Collection::Id, QList<Akonadi::Collection::Id>> m_childCollections;
0079 
0080     using ContextUid = QString;
0081     QHash<ContextUid, Akonadi::Item> m_contexts;
0082 
0083     QHash<Akonadi::Item::Id, Akonadi::Item> m_items;
0084     QHash<Akonadi::Collection::Id, QList<Akonadi::Item::Id>> m_childItems;
0085     QHash<ContextUid, QList<Akonadi::Item::Id>> m_contextItems;
0086 
0087     QScopedPointer<AkonadiFakeMonitor> m_monitor;
0088 
0089     AkonadiFakeStorageBehavior m_storageBehavior;
0090 };
0091 
0092 }
0093 
0094 #endif // TESTLIB_AKONADIFAKEDATA_H