File indexing completed on 2024-11-10 04:40:12
0001 /* 0002 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "itemserializertest.h" 0008 0009 #include "attributefactory.h" 0010 #include "item.h" 0011 #include "itemserializer_p.h" 0012 0013 #include <QTest> 0014 0015 #include <QStandardPaths> 0016 0017 using namespace Akonadi; 0018 0019 QTEST_MAIN(ItemSerializerTest) 0020 0021 void ItemSerializerTest::testEmptyPayload() 0022 { 0023 // should not crash 0024 QByteArray data; 0025 Item item; 0026 ItemSerializer::deserialize(item, Item::FullPayload, data, 0, ItemSerializer::Internal); 0027 QVERIFY(data.isEmpty()); 0028 } 0029 0030 void ItemSerializerTest::testDefaultSerializer_data() 0031 { 0032 QTest::addColumn<QByteArray>("serialized"); 0033 0034 QTest::newRow("null") << QByteArray(); 0035 QTest::newRow("empty") << QByteArray(""); 0036 QTest::newRow("nullbytei") << QByteArray("\0", 1); 0037 QTest::newRow("mixed") << QByteArray("\0\r\n\0bla", 7); 0038 } 0039 0040 void ItemSerializerTest::testDefaultSerializer() 0041 { 0042 // Avoid ItemSerializer from picking config from user's config, which affects how/whether 0043 // compresion is enabled or not. 0044 QStandardPaths::setTestModeEnabled(true); 0045 0046 QFETCH(QByteArray, serialized); 0047 Item item; 0048 item.setMimeType(QStringLiteral("application/octet-stream")); 0049 ItemSerializer::deserialize(item, Item::FullPayload, serialized, 0, ItemSerializer::Internal); 0050 0051 QVERIFY(item.hasPayload<QByteArray>()); 0052 QCOMPARE(item.payload<QByteArray>(), serialized); 0053 0054 QByteArray data; 0055 int version = 0; 0056 ItemSerializer::serialize(item, Item::FullPayload, data, version); 0057 QCOMPARE(data, serialized); 0058 QEXPECT_FAIL("null", "Serializer cannot distinguish null vs. empty", Continue); 0059 QCOMPARE(data.isNull(), serialized.isNull()); 0060 } 0061 0062 #include "moc_itemserializertest.cpp"