Akonadi

aktest.h
1/*
2 SPDX-FileCopyrightText: 2011 Volker Krause <vkrause@kde.org>
3 SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "akapplication.h"
11#include "private/instance_p.h"
12
13#include <KCrash>
14
15#include <QTest>
16
17#define AKTEST_MAIN(TestObject) \
18 int main(int argc, char **argv) \
19 { \
20 qputenv("XDG_DATA_HOME", ".local-unit-test/share"); \
21 qputenv("XDG_CONFIG_HOME", ".config-unit-test"); \
22 AkCoreApplication app(argc, argv); \
23 KCrash::setDrKonqiEnabled(false); \
24 app.parseCommandLine(); \
25 TestObject tc; \
26 return QTest::qExec(&tc, argc, argv); \
27 }
28
29#define AKTEST_FAKESERVER_MAIN(TestObject) \
30 int main(int argc, char **argv) \
31 { \
32 AkCoreApplication app(argc, argv); \
33 KCrash::setDrKonqiEnabled(false); \
34 app.addCommandLineOptions(QCommandLineOption(QStringLiteral("no-cleanup"), QStringLiteral("Don't clean up the temporary runtime environment"))); \
35 app.parseCommandLine(); \
36 TestObject tc; \
37 return QTest::qExec(&tc, argc, argv); \
38 }
39
40#define AKCOMPARE(actual, expected) \
41 do { \
42 if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \
43 return false; \
44 } while (false)
45
46#define AKVERIFY(statement) \
47 do { \
48 if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) \
49 return false; \
50 } while (false)
51
52inline void akTestSetInstanceIdentifier(const QString &instanceId)
53{
54 Akonadi::Instance::setIdentifier(instanceId);
55}
56
57#include "private/protocol_p.h"
58
59namespace QTest
60{
61template<>
62char *toString(const Akonadi::Protocol::ItemChangeNotificationPtr &msg)
63{
64 return qstrdup(qPrintable(Akonadi::Protocol::debugString(msg)));
65}
66}
67
68namespace AkTest
69{
70enum NtfField {
71 NtfType = (1 << 0),
72 NtfOperation = (1 << 1),
73 NtfSession = (1 << 2),
74 NtfEntities = (1 << 3),
75 NtfResource = (1 << 5),
76 NtfCollection = (1 << 6),
77 NtfDestResource = (1 << 7),
78 NtfDestCollection = (1 << 8),
79 NtfAddedFlags = (1 << 9),
80 NtfRemovedFlags = (1 << 10),
81 NtfAddedTags = (1 << 11),
82 NtfRemovedTags = (1 << 12),
83
84 NtfFlags = NtfAddedFlags | NtfRemovedTags,
85 NtfTags = NtfAddedTags | NtfRemovedTags,
86 NtfAll = NtfType | NtfOperation | NtfSession | NtfEntities | NtfResource | NtfCollection | NtfDestResource | NtfDestCollection | NtfFlags | NtfTags
87};
88using NtfFields = QFlags<NtfField>;
89
90bool compareNotifications(const Akonadi::Protocol::ItemChangeNotificationPtr &actual,
91 const Akonadi::Protocol::ItemChangeNotificationPtr &expected,
92 const NtfFields fields = NtfAll)
93{
94 if (fields & NtfOperation) {
95 AKCOMPARE(actual->operation(), expected->operation());
96 }
97 if (fields & NtfSession) {
98 AKCOMPARE(actual->sessionId(), expected->sessionId());
99 }
100 if (fields & NtfEntities) {
101 AKCOMPARE(actual->items(), expected->items());
102 }
103 if (fields & NtfResource) {
104 AKCOMPARE(actual->resource(), expected->resource());
105 }
106 if (fields & NtfCollection) {
107 AKCOMPARE(actual->parentCollection(), expected->parentCollection());
108 }
109 if (fields & NtfDestResource) {
110 AKCOMPARE(actual->destinationResource(), expected->destinationResource());
111 }
112 if (fields & NtfDestCollection) {
113 AKCOMPARE(actual->parentDestCollection(), expected->parentDestCollection());
114 }
115 if (fields & NtfAddedFlags) {
116 AKCOMPARE(actual->addedFlags(), expected->addedFlags());
117 }
118 if (fields & NtfRemovedFlags) {
119 AKCOMPARE(actual->removedFlags(), expected->removedFlags());
120 }
121 if (fields & NtfAddedTags) {
122 AKCOMPARE(actual->addedTags(), expected->addedTags());
123 }
124 if (fields & NtfRemovedTags) {
125 AKCOMPARE(actual->removedTags(), expected->removedTags());
126 }
127
128 return true;
129}
130}
char * toString(QSizePolicy sp)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.