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/gencollection.h" 0008 0009 #include "akonadi/akonadiapplicationselectedattribute.h" 0010 #include <Akonadi/EntityDisplayAttribute> 0011 0012 #include <testlib/qtest_zanshin.h> 0013 0014 using namespace Testlib; 0015 0016 class GenCollectionTest : public QObject 0017 { 0018 Q_OBJECT 0019 private slots: 0020 void shouldImplicitlyConvertBackToCollection() 0021 { 0022 // GIVEN 0023 auto col = Akonadi::Collection(42); 0024 auto gen = GenCollection(col); 0025 0026 // WHEN 0027 Akonadi::Collection newCol = gen; 0028 0029 // THEN 0030 QCOMPARE(newCol, col); 0031 } 0032 0033 void shouldAllowToSetId() 0034 { 0035 // GIVEN 0036 Akonadi::Collection col = GenCollection().withId(42); 0037 0038 // THEN 0039 QCOMPARE(col.id(), 42LL); 0040 } 0041 0042 void shouldAllowToSetParent() 0043 { 0044 // GIVEN 0045 Akonadi::Collection col = GenCollection().withParent(42); 0046 0047 // THEN 0048 QCOMPARE(col.parentCollection().id(), 42LL); 0049 } 0050 0051 void shouldAllowToSetRootAsParent() 0052 { 0053 // GIVEN 0054 Akonadi::Collection col = GenCollection().withRootAsParent(); 0055 0056 // THEN 0057 QCOMPARE(col.parentCollection(), Akonadi::Collection::root()); 0058 } 0059 0060 void shouldAllowToSetName() 0061 { 0062 // GIVEN 0063 Akonadi::Collection col = GenCollection().withName(QStringLiteral("42")); 0064 0065 // THEN 0066 QCOMPARE(col.name(), QStringLiteral("42")); 0067 } 0068 0069 void shouldAllowToSetIcon() 0070 { 0071 // GIVEN 0072 Akonadi::Collection col = GenCollection().withIcon(QStringLiteral("42")); 0073 0074 // THEN 0075 QCOMPARE(col.attribute<Akonadi::EntityDisplayAttribute>()->iconName(), QStringLiteral("42")); 0076 } 0077 0078 void shouldAllowToSetSelected() 0079 { 0080 // GIVEN 0081 Akonadi::Collection col = GenCollection().selected(); 0082 0083 // THEN 0084 QVERIFY(!col.hasAttribute<Akonadi::ApplicationSelectedAttribute>()); 0085 0086 // WHEN 0087 col = GenCollection(col).selected(false); 0088 0089 // THEN 0090 QCOMPARE(col.attribute<Akonadi::ApplicationSelectedAttribute>()->isSelected(), false); 0091 } 0092 0093 void shouldAllowToSetTaskContent() 0094 { 0095 // GIVEN 0096 Akonadi::Collection col = GenCollection().withTaskContent(); 0097 0098 // THEN 0099 QVERIFY(col.contentMimeTypes().contains(QStringLiteral("application/x-vnd.akonadi.calendar.todo"))); 0100 0101 // WHEN 0102 col = GenCollection(col).withTaskContent(false); 0103 0104 // THEN 0105 QVERIFY(!col.contentMimeTypes().contains(QStringLiteral("application/x-vnd.akonadi.calendar.todo"))); 0106 } 0107 0108 void shouldAllowToSetNoteContent() 0109 { 0110 // GIVEN 0111 Akonadi::Collection col = GenCollection().withNoteContent(); 0112 0113 // THEN 0114 QVERIFY(col.contentMimeTypes().contains(QStringLiteral("text/x-vnd.akonadi.note"))); 0115 0116 // WHEN 0117 col = GenCollection(col).withNoteContent(false); 0118 0119 // THEN 0120 QVERIFY(!col.contentMimeTypes().contains(QStringLiteral("text/x-vnd.akonadi.note"))); 0121 } 0122 0123 void shouldAllowToSetNoteAndTaskContent() 0124 { 0125 // GIVEN 0126 Akonadi::Collection col = GenCollection().withTaskContent().withNoteContent(); 0127 0128 // THEN 0129 QVERIFY(col.contentMimeTypes().contains(QStringLiteral("application/x-vnd.akonadi.calendar.todo"))); 0130 QVERIFY(col.contentMimeTypes().contains(QStringLiteral("text/x-vnd.akonadi.note"))); 0131 0132 // WHEN 0133 col = GenCollection(col).withTaskContent(false).withNoteContent(false); 0134 0135 // THEN 0136 QVERIFY(!col.contentMimeTypes().contains(QStringLiteral("application/x-vnd.akonadi.calendar.todo"))); 0137 QVERIFY(!col.contentMimeTypes().contains(QStringLiteral("text/x-vnd.akonadi.note"))); 0138 } 0139 }; 0140 0141 ZANSHIN_TEST_MAIN(GenCollectionTest) 0142 0143 #include "gencollectiontest.moc"