diff options
Diffstat (limited to 'examples/imapresource/tests/imapmailsyncbenchmark.cpp')
-rw-r--r-- | examples/imapresource/tests/imapmailsyncbenchmark.cpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/examples/imapresource/tests/imapmailsyncbenchmark.cpp b/examples/imapresource/tests/imapmailsyncbenchmark.cpp new file mode 100644 index 0000000..c00e795 --- /dev/null +++ b/examples/imapresource/tests/imapmailsyncbenchmark.cpp | |||
@@ -0,0 +1,127 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | #include <QtTest> | ||
20 | #include <QTcpSocket> | ||
21 | |||
22 | #include <tests/mailsynctest.h> | ||
23 | #include "../imapresource.h" | ||
24 | #include "../imapserverproxy.h" | ||
25 | |||
26 | #include "common/test.h" | ||
27 | #include "common/domain/applicationdomaintype.h" | ||
28 | #include "common/store.h" | ||
29 | #include "common/resourcecontrol.h" | ||
30 | |||
31 | using namespace Sink; | ||
32 | using namespace Sink::ApplicationDomain; | ||
33 | |||
34 | SINK_DEBUG_AREA("ImapMailSyncBenchmark") | ||
35 | |||
36 | /** | ||
37 | * Test of complete system using the imap resource. | ||
38 | * | ||
39 | * This test requires the imap resource installed. | ||
40 | */ | ||
41 | class ImapMailSyncBenchmark : public QObject | ||
42 | { | ||
43 | Q_OBJECT | ||
44 | |||
45 | bool isBackendAvailable() | ||
46 | { | ||
47 | QTcpSocket socket; | ||
48 | socket.connectToHost("localhost", 993); | ||
49 | return socket.waitForConnected(200); | ||
50 | } | ||
51 | |||
52 | void resetTestEnvironment() | ||
53 | { | ||
54 | system("populatemailbox.sh"); | ||
55 | } | ||
56 | |||
57 | Sink::ApplicationDomain::SinkResource createResource() | ||
58 | { | ||
59 | auto resource = ApplicationDomain::ImapResource::create("account1"); | ||
60 | resource.setProperty("server", "localhost"); | ||
61 | resource.setProperty("port", 993); | ||
62 | resource.setProperty("username", "doe"); | ||
63 | resource.setProperty("password", "doe"); | ||
64 | return resource; | ||
65 | } | ||
66 | |||
67 | void removeResourceFromDisk(const QByteArray &identifier) | ||
68 | { | ||
69 | ::ImapResource::removeFromDisk(identifier); | ||
70 | } | ||
71 | |||
72 | QByteArray mResourceInstanceIdentifier; | ||
73 | QByteArrayList mCapabilities; | ||
74 | |||
75 | private slots: | ||
76 | |||
77 | void initTestCase() | ||
78 | { | ||
79 | Test::initTest(); | ||
80 | QVERIFY(isBackendAvailable()); | ||
81 | resetTestEnvironment(); | ||
82 | auto resource = createResource(); | ||
83 | QVERIFY(!resource.identifier().isEmpty()); | ||
84 | |||
85 | VERIFYEXEC(Store::create(resource)); | ||
86 | |||
87 | mResourceInstanceIdentifier = resource.identifier(); | ||
88 | mCapabilities = resource.getProperty("capabilities").value<QByteArrayList>(); | ||
89 | } | ||
90 | |||
91 | void cleanup() | ||
92 | { | ||
93 | //TODO the shutdown job fails if the resource is already shut down | ||
94 | // VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier)); | ||
95 | ResourceControl::shutdown(mResourceInstanceIdentifier).exec().waitForFinished(); | ||
96 | removeResourceFromDisk(mResourceInstanceIdentifier); | ||
97 | } | ||
98 | |||
99 | void init() | ||
100 | { | ||
101 | qDebug(); | ||
102 | qDebug() << "-----------------------------------------"; | ||
103 | qDebug(); | ||
104 | VERIFYEXEC(ResourceControl::start(mResourceInstanceIdentifier)); | ||
105 | } | ||
106 | |||
107 | void testSync() | ||
108 | { | ||
109 | Sink::Query query; | ||
110 | query.resources << mResourceInstanceIdentifier; | ||
111 | query.request<Folder::Name>().request<Folder::SpecialPurpose>(); | ||
112 | |||
113 | QTime time; | ||
114 | time.start(); | ||
115 | |||
116 | // Ensure all local data is processed | ||
117 | VERIFYEXEC(Store::synchronize(query)); | ||
118 | SinkLog() << "Sync took: " << Sink::Log::TraceTime(time.elapsed()); | ||
119 | |||
120 | VERIFYEXEC(ResourceControl::flushMessageQueue(query.resources)); | ||
121 | SinkLog() << "Total took: " << Sink::Log::TraceTime(time.elapsed()); | ||
122 | } | ||
123 | }; | ||
124 | |||
125 | QTEST_MAIN(ImapMailSyncBenchmark) | ||
126 | |||
127 | #include "imapmailsyncbenchmark.moc" | ||