File indexing completed on 2024-11-10 04:40:10

0001 /*
0002     SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "../collectionutils.h"
0008 #include "collection.h"
0009 #include "qtest_akonadi.h"
0010 
0011 using namespace Akonadi;
0012 
0013 class CollectionUtilsTest : public QObject
0014 {
0015     Q_OBJECT
0016 private Q_SLOTS:
0017     void testHasValidHierarchicalRID_data()
0018     {
0019         QTest::addColumn<Collection>("collection");
0020         QTest::addColumn<bool>("isHRID");
0021 
0022         QTest::newRow("empty") << Collection() << false;
0023         QTest::newRow("root") << Collection::root() << true;
0024         Collection c;
0025         c.setParentCollection(Collection::root());
0026         QTest::newRow("one level not ok") << c << false;
0027         c.setRemoteId(QStringLiteral("r1"));
0028         QTest::newRow("one level ok") << c << true;
0029         Collection c2;
0030         c2.setParentCollection(c);
0031         QTest::newRow("two level not ok") << c2 << false;
0032         c2.setRemoteId(QStringLiteral("r2"));
0033         QTest::newRow("two level ok") << c2 << true;
0034         c2.parentCollection().setRemoteId(QString());
0035         QTest::newRow("mid RID missing") << c2 << false;
0036     }
0037 
0038     void testHasValidHierarchicalRID()
0039     {
0040         QFETCH(Collection, collection);
0041         QFETCH(bool, isHRID);
0042         QCOMPARE(CollectionUtils::hasValidHierarchicalRID(collection), isHRID);
0043     }
0044 
0045     void testPersistentParentCollection()
0046     {
0047         Collection col1(1);
0048         Collection col2(2);
0049         Collection col3(3);
0050 
0051         col2.setParentCollection(col3);
0052         col1.setParentCollection(col2);
0053 
0054         Collection assigned = col1;
0055         QCOMPARE(assigned.parentCollection(), col2);
0056         QCOMPARE(assigned.parentCollection().parentCollection(), col3);
0057 
0058         Collection copied(col1);
0059         QCOMPARE(copied.parentCollection(), col2);
0060         QCOMPARE(copied.parentCollection().parentCollection(), col3);
0061     }
0062 };
0063 
0064 QTEST_AKONADIMAIN(CollectionUtilsTest)
0065 
0066 #include "collectionutilstest.moc"