File indexing completed on 2025-03-09 04:57:05
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 #include "testlib/akonadifakedata.h" 0008 #include "testlib/akonadifakedataxmlloader.h" 0009 #include <akonadi/akonadiserializer.h> 0010 0011 #include <KCalendarCore/Todo> 0012 0013 #include <testlib/qtest_zanshin.h> 0014 0015 using Akonadi::Serializer; 0016 0017 class AkonadiFakeDataXmlLoaderTest : public QObject 0018 { 0019 Q_OBJECT 0020 private slots: 0021 void shouldLoadFromXmlFile() 0022 { 0023 // GIVEN 0024 auto data = Testlib::AkonadiFakeData(); 0025 0026 // Put a first collection with an idea to make sure it isn't lost on loading 0027 auto searchCollection = Akonadi::Collection(1); 0028 searchCollection.setParentCollection(Akonadi::Collection::root()); 0029 searchCollection.setName(QStringLiteral("Search")); 0030 data.createCollection(searchCollection); 0031 0032 auto loader = Testlib::AkonadiFakeDataXmlLoader(&data); 0033 0034 // WHEN 0035 loader.load(SOURCE_DIR "/../akonadi/testenv/data/testdata.xml"); 0036 0037 // THEN 0038 QVERIFY(data.collections().size() > 1); 0039 QVERIFY(data.items().size() > 1); 0040 QVERIFY(data.contexts().size() > 1); 0041 0042 // Do a bit of sanity checking, no need to do much more than that as 0043 // the xml loading will be extensively used in the AkonadiFakeStorageTest 0044 // and AkonadiFakeData has quite a few asserts. 0045 0046 QCOMPARE(data.childCollections(Akonadi::Collection::root().id()).size(), 2); 0047 const auto res = data.childCollections(Akonadi::Collection::root().id()).at(1); 0048 QCOMPARE(res.id(), qint64(2)); 0049 0050 const auto children = data.childCollections(res.id()); 0051 QCOMPARE(children.size(), 5); 0052 QCOMPARE(children.at(0).name(), QStringLiteral("Calendar1")); 0053 QCOMPARE(children.at(0).id(), qint64(3)); 0054 QCOMPARE(children.at(0).remoteId(), QStringLiteral("{cdc229c7-a9b5-4d37-989d-a28e372be2a9}")); 0055 QCOMPARE(children.at(1).name(), QStringLiteral("Emails")); 0056 QCOMPARE(children.at(1).id(), qint64(4)); 0057 QCOMPARE(children.at(1).remoteId(), QStringLiteral("{14096930-7bfe-46ca-8fba-7c04d3b62ec8}")); 0058 QCOMPARE(children.at(2).name(), QStringLiteral("Contacts")); 0059 QCOMPARE(children.at(2).id(), qint64(5)); 0060 QCOMPARE(children.at(2).remoteId(), QStringLiteral("{36bf43ac-0988-4435-b602-d6c29e606630}")); 0061 QCOMPARE(children.at(3).name(), QStringLiteral("Destroy me!")); 0062 QCOMPARE(children.at(3).id(), qint64(6)); 0063 QCOMPARE(children.at(3).remoteId(), QStringLiteral("{1f78b360-a01b-4785-9187-75450190342c}")); 0064 QCOMPARE(children.at(4).name(), QStringLiteral("Change me!")); 0065 QCOMPARE(children.at(4).id(), qint64(7)); 0066 QCOMPARE(children.at(4).remoteId(), QStringLiteral("{28ef9f03-4ebc-4e33-970f-f379775894f9}")); 0067 0068 const auto firstContext = data.contexts().at(0); 0069 QCOMPARE(firstContext.remoteId(), "rid-online-context"); 0070 const auto contextAsTodo = firstContext.payload<KCalendarCore::Todo::Ptr>(); 0071 QCOMPARE(contextAsTodo->uid(), "online-context"); 0072 QCOMPARE(contextAsTodo->summary(), "Online"); 0073 QCOMPARE(contextAsTodo->customProperty(Serializer::customPropertyAppName(), Serializer::customPropertyIsContext()), "1"); 0074 } 0075 }; 0076 0077 ZANSHIN_TEST_MAIN(AkonadiFakeDataXmlLoaderTest) 0078 0079 #include "akonadifakedataxmlloadertest.moc"