File indexing completed on 2025-01-05 04:59:50
0001 /* 0002 * SPDX-FileCopyrightText: 2014 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/qtest_zanshin.h> 0008 0009 #include <memory> 0010 0011 #include "akonadi/akonadiapplicationselectedattribute.h" 0012 0013 class AkonadiApplicationSelectedAttributeTest : public QObject 0014 { 0015 Q_OBJECT 0016 private slots: 0017 void shouldHaveDefaultState() 0018 { 0019 // GIVEN 0020 Akonadi::ApplicationSelectedAttribute attr; 0021 0022 // THEN 0023 QCOMPARE(attr.isSelected(), true); 0024 QCOMPARE(attr.type(), QByteArray("ZanshinSelected")); 0025 } 0026 0027 void shouldBeCloneable() 0028 { 0029 // GIVEN 0030 Akonadi::ApplicationSelectedAttribute attr; 0031 attr.setSelected(false); 0032 0033 // WHEN 0034 auto clone = std::unique_ptr<Akonadi::ApplicationSelectedAttribute>(attr.clone()); 0035 0036 // THEN 0037 QCOMPARE(clone->isSelected(), attr.isSelected()); 0038 QCOMPARE(clone->type(), attr.type()); 0039 } 0040 0041 void shouldDeserialize_data() 0042 { 0043 QTest::addColumn<QByteArray>("data"); 0044 QTest::addColumn<bool>("selected"); 0045 0046 QTest::newRow("selected") << QByteArray("true") << true; 0047 QTest::newRow("deselected") << QByteArray("false") << false; 0048 QTest::newRow("malformed") << QByteArray("foo") << false; 0049 QTest::newRow("empty") << QByteArray() << false; 0050 } 0051 0052 void shouldDeserialize() 0053 { 0054 // GIVEN 0055 QFETCH(QByteArray, data); 0056 QFETCH(bool, selected); 0057 0058 Akonadi::ApplicationSelectedAttribute attr; 0059 0060 // WHEN 0061 attr.deserialize(data); 0062 0063 // THEN 0064 QCOMPARE(attr.isSelected(), selected); 0065 } 0066 0067 void shouldSerialize() 0068 { 0069 // GIVEN 0070 Akonadi::ApplicationSelectedAttribute attr; 0071 0072 // WHEN 0073 attr.setSelected(true); 0074 const QByteArray selectedData = attr.serialized(); 0075 0076 attr.setSelected(false); 0077 const QByteArray deselectedData = attr.serialized(); 0078 0079 // THEN 0080 QCOMPARE(selectedData, QByteArray("true")); 0081 QCOMPARE(deselectedData, QByteArray("false")); 0082 } 0083 }; 0084 0085 ZANSHIN_TEST_MAIN(AkonadiApplicationSelectedAttributeTest) 0086 0087 #include "akonadiapplicationselectedattributetest.moc"