File indexing completed on 2025-01-19 04:56:42
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Bensi Mario <mbensi@ipsquad.net> 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 #include <Akonadi/Item> 0009 #include <KCalendarCore/Todo> 0010 #include "domain/task.h" 0011 #include "akonadi/akonadiserializer.h" 0012 0013 class SerializerBenchmark : public QObject 0014 { 0015 Q_OBJECT 0016 0017 Akonadi::Item createTestItem(); 0018 private slots: 0019 void deserialize(); 0020 void checkPayloadAndDeserialize(); 0021 void deserializeAndDestroy(); 0022 void checkPayload(); 0023 }; 0024 0025 Akonadi::Item SerializerBenchmark::createTestItem() 0026 { 0027 KCalendarCore::Todo::Ptr todo(new KCalendarCore::Todo); 0028 todo->setSummary(QStringLiteral("summary")); 0029 todo->setDescription(QStringLiteral("content")); 0030 todo->setCompleted(false); 0031 todo->setDtStart(QDate(2013, 11, 24).startOfDay()); 0032 todo->setDtDue(QDate(2014, 03, 01).startOfDay()); 0033 todo->setRelatedTo(QStringLiteral("5")); 0034 0035 // ... as payload of an item 0036 Akonadi::Item item; 0037 item.setMimeType(QStringLiteral("application/x-vnd.akonadi.calendar.todo")); 0038 item.setPayload<KCalendarCore::Todo::Ptr>(todo); 0039 0040 return item; 0041 } 0042 0043 void SerializerBenchmark::deserialize() 0044 { 0045 Akonadi::Item item = createTestItem(); 0046 Akonadi::Serializer serializer; 0047 0048 Domain::Task::Ptr task(new Domain::Task); 0049 QBENCHMARK { 0050 task = serializer.createTaskFromItem(item); 0051 } 0052 } 0053 0054 void SerializerBenchmark::checkPayloadAndDeserialize() 0055 { 0056 Akonadi::Item item = createTestItem(); 0057 Akonadi::Serializer serializer; 0058 Domain::Task::Ptr task(new Domain::Task); 0059 QBENCHMARK { 0060 if (!item.hasPayload<KCalendarCore::Todo::Ptr>()) 0061 return; 0062 0063 auto todoCheck = item.payload<KCalendarCore::Todo::Ptr>(); 0064 if (todoCheck->relatedTo() != QLatin1StringView("5")) { 0065 return; 0066 } 0067 0068 task = serializer.createTaskFromItem(item); 0069 } 0070 } 0071 0072 void SerializerBenchmark::deserializeAndDestroy() 0073 { 0074 Akonadi::Item item = createTestItem(); 0075 Akonadi::Serializer serializer; 0076 0077 QBENCHMARK { 0078 auto task = serializer.createTaskFromItem(item); 0079 } 0080 } 0081 0082 void SerializerBenchmark::checkPayload() 0083 { 0084 Akonadi::Item item = createTestItem(); 0085 QBENCHMARK { 0086 if (!item.hasPayload<KCalendarCore::Todo::Ptr>()) 0087 return; 0088 0089 auto todoCheck = item.payload<KCalendarCore::Todo::Ptr>(); 0090 if (todoCheck->relatedTo() != QLatin1StringView("5")) { 0091 return; 0092 } 0093 } 0094 } 0095 0096 ZANSHIN_TEST_MAIN(SerializerBenchmark) 0097 #include "serializerTest.moc"