Akonadi

aktest.h
1 /*
2  SPDX-FileCopyrightText: 2011 Volker Krause <[email protected]>
3  SPDX-FileCopyrightText: 2014 Daniel Vr├ítil <[email protected]>
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 
52 inline void akTestSetInstanceIdentifier(const QString &instanceId)
53 {
54  Akonadi::Instance::setIdentifier(instanceId);
55 }
56 
57 #include <private/protocol_p.h>
58 
59 namespace QTest
60 {
61 template<> char *toString(const Akonadi::Protocol::ItemChangeNotificationPtr &msg)
62 {
63  return qstrdup(qPrintable(Akonadi::Protocol::debugString(msg)));
64 }
65 }
66 
67 namespace AkTest
68 {
69 enum NtfField {
70  NtfType = (1 << 0),
71  NtfOperation = (1 << 1),
72  NtfSession = (1 << 2),
73  NtfEntities = (1 << 3),
74  NtfResource = (1 << 5),
75  NtfCollection = (1 << 6),
76  NtfDestResource = (1 << 7),
77  NtfDestCollection = (1 << 8),
78  NtfAddedFlags = (1 << 9),
79  NtfRemovedFlags = (1 << 10),
80  NtfAddedTags = (1 << 11),
81  NtfRemovedTags = (1 << 12),
82 
83  NtfFlags = NtfAddedFlags | NtfRemovedTags,
84  NtfTags = NtfAddedTags | NtfRemovedTags,
85  NtfAll = NtfType | NtfOperation | NtfSession | NtfEntities | NtfResource | NtfCollection | NtfDestResource | NtfDestCollection | NtfFlags | NtfTags
86 };
87 using NtfFields = QFlags<NtfField>;
88 
89 bool compareNotifications(const Akonadi::Protocol::ItemChangeNotificationPtr &actual,
90  const Akonadi::Protocol::ItemChangeNotificationPtr &expected,
91  const NtfFields fields = NtfAll)
92 {
93  if (fields & NtfOperation) {
94  AKCOMPARE(actual->operation(), expected->operation());
95  }
96  if (fields & NtfSession) {
97  AKCOMPARE(actual->sessionId(), expected->sessionId());
98  }
99  if (fields & NtfEntities) {
100  AKCOMPARE(actual->items(), expected->items());
101  }
102  if (fields & NtfResource) {
103  AKCOMPARE(actual->resource(), expected->resource());
104  }
105  if (fields & NtfCollection) {
106  AKCOMPARE(actual->parentCollection(), expected->parentCollection());
107  }
108  if (fields & NtfDestResource) {
109  AKCOMPARE(actual->destinationResource(), expected->destinationResource());
110  }
111  if (fields & NtfDestCollection) {
112  AKCOMPARE(actual->parentDestCollection(), expected->parentDestCollection());
113  }
114  if (fields & NtfAddedFlags) {
115  AKCOMPARE(actual->addedFlags(), expected->addedFlags());
116  }
117  if (fields & NtfRemovedFlags) {
118  AKCOMPARE(actual->removedFlags(), expected->removedFlags());
119  }
120  if (fields & NtfAddedTags) {
121  AKCOMPARE(actual->addedTags(), expected->addedTags());
122  }
123  if (fields & NtfRemovedTags) {
124  AKCOMPARE(actual->removedTags(), expected->removedTags());
125  }
126 
127  return true;
128 }
129 }
130 
char * toString(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.