File indexing completed on 2024-11-10 04:40:16
0001 /* 0002 SPDX-FileCopyrightText: 2015 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QObject> 0008 0009 #include "attributefactory.h" 0010 #include "qtest_akonadi.h" 0011 #include "tag.h" 0012 #include "tagattribute.h" 0013 #include "testattribute.h" 0014 0015 using namespace Akonadi; 0016 0017 // Tag tests not requiring a full Akonadi test environment 0018 // this is mainly to test memory management of attributes, so this is best used with valgrind/ASan 0019 class TagTestSimple : public QObject 0020 { 0021 Q_OBJECT 0022 0023 private Q_SLOTS: 0024 void testCustomAttributes(); 0025 void testTagAttribute(); 0026 }; 0027 0028 void TagTestSimple::testCustomAttributes() 0029 { 0030 Tag t2; 0031 { 0032 Tag t1; 0033 auto attr = new TestAttribute; 0034 attr->deserialize("hello"); 0035 t1.addAttribute(attr); 0036 t2 = t1; 0037 } 0038 QVERIFY(t2.hasAttribute("EXTRA")); 0039 auto attr = t2.attribute<TestAttribute>(); 0040 QCOMPARE(attr->serialized(), QByteArray("hello")); 0041 } 0042 0043 void TagTestSimple::testTagAttribute() 0044 { 0045 Tag t2; 0046 { 0047 Tag t1; 0048 auto attr = AttributeFactory::createAttribute("TAG"); 0049 t1.addAttribute(attr); 0050 t1.setName(QStringLiteral("hello")); 0051 t2 = t1; 0052 } 0053 QVERIFY(t2.hasAttribute<TagAttribute>()); 0054 auto attr = t2.attribute<TagAttribute>(); 0055 QVERIFY(attr); 0056 QCOMPARE(t2.name(), attr->displayName()); 0057 } 0058 0059 #include "tagtest_simple.moc" 0060 0061 QTEST_MAIN(TagTestSimple)