File indexing completed on 2024-03-24 03:55:26
0001 /* 0002 This file is part of the kcalcore library. 0003 SPDX-FileCopyrightText: 2006 Allen Winter <winter@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "testattachment.h" 0009 #include "attachment.h" 0010 #include "event.h" 0011 0012 #include <QTest> 0013 QTEST_MAIN(AttachmentTest) 0014 0015 using namespace KCalendarCore; 0016 0017 void AttachmentTest::testValidity() 0018 { 0019 Attachment attachment(QStringLiteral("http://www.kde.org")); 0020 QCOMPARE(attachment.uri(), QStringLiteral("http://www.kde.org")); 0021 QCOMPARE(attachment.data(), QByteArray()); 0022 QVERIFY(attachment.decodedData().isEmpty()); 0023 QVERIFY(!attachment.isBinary()); 0024 0025 attachment.setDecodedData("foo"); 0026 QVERIFY(attachment.isBinary()); 0027 QCOMPARE(attachment.decodedData(), QByteArray("foo")); 0028 QCOMPARE(attachment.data(), QByteArray("Zm9v")); 0029 QCOMPARE(attachment.size(), 3U); 0030 0031 Attachment attachment2 = Attachment(QByteArray("Zm9v")); 0032 QCOMPARE(attachment2.size(), 3U); 0033 QCOMPARE(attachment2.decodedData(), QByteArray("foo")); 0034 attachment2.setDecodedData("123456"); 0035 QCOMPARE(attachment2.size(), 6U); 0036 0037 Attachment attachment3(attachment2); 0038 QCOMPARE(attachment3.size(), attachment2.size()); 0039 0040 QByteArray fred("jkajskldfasjfklasjfaskfaskfasfkasfjdasfkasjf"); 0041 Attachment attachment4(fred, QStringLiteral("image/nonsense")); 0042 QCOMPARE(fred, attachment4.data()); 0043 QVERIFY(attachment4.isBinary()); 0044 QByteArray ethel("a9fafafjafkasmfasfasffksjklfjau"); 0045 attachment4.setData(ethel); 0046 QCOMPARE(ethel, attachment4.data()); 0047 0048 Attachment attachment5(QStringLiteral("http://www.kde.org")); 0049 Attachment attachment6(QStringLiteral("http://www.kde.org")); 0050 QVERIFY(attachment5 == attachment6); 0051 attachment5.setUri(QStringLiteral("http://bugs.kde.org")); 0052 QVERIFY(attachment5 != attachment6); 0053 attachment5.setDecodedData("123456"); 0054 attachment6.setDecodedData("123456"); 0055 QVERIFY(attachment5 == attachment6); 0056 attachment6.setDecodedData("12345"); 0057 QVERIFY(attachment5 != attachment6); 0058 } 0059 0060 void AttachmentTest::testSerializer_data() 0061 { 0062 QTest::addColumn<KCalendarCore::Attachment>("attachment"); 0063 0064 Attachment nonInline(QStringLiteral("http://www.kde.org")); 0065 Attachment inlineAttachment(QByteArray("foo"), QStringLiteral("image/nonsense")); 0066 0067 QTest::newRow("inline") << inlineAttachment; 0068 QTest::newRow("not inline") << nonInline; 0069 } 0070 0071 void AttachmentTest::testSerializer() 0072 { 0073 QFETCH(KCalendarCore::Attachment, attachment); 0074 0075 QByteArray array; 0076 QDataStream stream(&array, QIODevice::WriteOnly); 0077 stream << attachment; // Serialize 0078 0079 Attachment attachment2(QStringLiteral("foo")); 0080 QVERIFY(attachment != attachment2); 0081 QDataStream stream2(&array, QIODevice::ReadOnly); 0082 stream2 >> attachment2; // deserialize 0083 QVERIFY(attachment == attachment2); 0084 } 0085 0086 #include "moc_testattachment.cpp"