Akonadi

aktest.h
1 /*
2  Copyright (c) 2011 Volker Krause <[email protected]>
3  Copyright (c) 2014 Daniel Vrátil <[email protected]>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #ifndef AKTEST_H
22 #define AKTEST_H
23 
24 #include "akapplication.h"
25 #include <private/instance_p.h>
26 
27 #include <KCrash/KCrash>
28 
29 #include <QTest>
30 
31 #define AKTEST_MAIN(TestObject) \
32  int main(int argc, char **argv) \
33  { \
34  qputenv("XDG_DATA_HOME", ".local-unit-test/share"); \
35  qputenv("XDG_CONFIG_HOME", ".config-unit-test"); \
36  AkCoreApplication app(argc, argv); \
37  KCrash::setDrKonqiEnabled(false); \
38  app.parseCommandLine(); \
39  TestObject tc; \
40  return QTest::qExec(&tc, argc, argv); \
41  }
42 
43 #define AKTEST_FAKESERVER_MAIN(TestObject) \
44  int main(int argc, char **argv) \
45  { \
46  AkCoreApplication app(argc, argv); \
47  KCrash::setDrKonqiEnabled(false); \
48  app.addCommandLineOptions(QCommandLineOption( \
49  QLatin1String("no-cleanup"), QLatin1String("Don't clean up the temporary runtime environment"))); \
50  app.parseCommandLine(); \
51  TestObject tc; \
52  return QTest::qExec(&tc, argc, argv); \
53  }
54 
55 #define AKCOMPARE(actual, expected) \
56  do {\
57  if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
58  return false;\
59  } while (false)
60 
61 #define AKVERIFY(statement) \
62  do {\
63  if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\
64  return false;\
65  } while (false)
66 
67 inline void akTestSetInstanceIdentifier(const QString &instanceId)
68 {
69  Akonadi::Instance::setIdentifier(instanceId);
70 }
71 
72 #include <private/protocol_p.h>
73 
74 namespace QTest
75 {
76 template<>
77 char *toString(const Akonadi::Protocol::ItemChangeNotificationPtr &msg)
78 {
79  return qstrdup(qPrintable(Akonadi::Protocol::debugString(msg)));
80 }
81 }
82 
83 namespace AkTest
84 {
85 enum NtfField {
86  NtfType = (1 << 0),
87  NtfOperation = (1 << 1),
88  NtfSession = (1 << 2),
89  NtfEntities = (1 << 3),
90  NtfResource = (1 << 5),
91  NtfCollection = (1 << 6),
92  NtfDestResource = (1 << 7),
93  NtfDestCollection = (1 << 8),
94  NtfAddedFlags = (1 << 9),
95  NtfRemovedFlags = (1 << 10),
96  NtfAddedTags = (1 << 11),
97  NtfRemovedTags = (1 << 12),
98 
99  NtfFlags = NtfAddedFlags | NtfRemovedTags,
100  NtfTags = NtfAddedTags | NtfRemovedTags,
101  NtfAll = NtfType | NtfOperation | NtfSession | NtfEntities |
102  NtfResource | NtfCollection | NtfDestResource |
103  NtfDestCollection | NtfFlags | NtfTags
104 };
105 typedef QFlags<NtfField> NtfFields;
106 
107 bool compareNotifications(const Akonadi::Protocol::ItemChangeNotificationPtr &actual,
108  const Akonadi::Protocol::ItemChangeNotificationPtr &expected,
109  const NtfFields fields = NtfAll)
110 {
111  if (fields & NtfOperation) {
112  AKCOMPARE(actual->operation(), expected->operation());
113  }
114  if (fields & NtfSession) {
115  AKCOMPARE(actual->sessionId(), expected->sessionId());
116  }
117  if (fields & NtfEntities) {
118  AKCOMPARE(actual->items(), expected->items());
119  }
120  if (fields & NtfResource) {
121  AKCOMPARE(actual->resource(), expected->resource());
122  }
123  if (fields & NtfCollection) {
124  AKCOMPARE(actual->parentCollection(), expected->parentCollection());
125  }
126  if (fields & NtfDestResource) {
127  AKCOMPARE(actual->destinationResource(), expected->destinationResource());
128  }
129  if (fields & NtfDestCollection) {
130  AKCOMPARE(actual->parentDestCollection(), expected->parentDestCollection());
131  }
132  if (fields & NtfAddedFlags) {
133  AKCOMPARE(actual->addedFlags(), expected->addedFlags());
134  }
135  if (fields & NtfRemovedFlags) {
136  AKCOMPARE(actual->removedFlags(), expected->removedFlags());
137  }
138  if (fields & NtfAddedTags) {
139  AKCOMPARE(actual->addedTags(), expected->addedTags());
140  }
141  if (fields & NtfRemovedTags) {
142  AKCOMPARE(actual->removedTags(), expected->removedTags());
143  }
144 
145  return true;
146 }
147 }
148 
149 #endif
Definition: aktest.h:83
char * toString(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue May 26 2020 22:46:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.