summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/imapresource/tests/imapmailtest.cpp85
-rw-r--r--tests/mailtest.cpp58
-rw-r--r--tests/mailtest.h1
3 files changed, 85 insertions, 59 deletions
diff --git a/examples/imapresource/tests/imapmailtest.cpp b/examples/imapresource/tests/imapmailtest.cpp
index e1dee0d..cab529b 100644
--- a/examples/imapresource/tests/imapmailtest.cpp
+++ b/examples/imapresource/tests/imapmailtest.cpp
@@ -1,11 +1,32 @@
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 */
1#include <QtTest> 19#include <QtTest>
2#include <QTcpSocket> 20#include <QTcpSocket>
21#include <KMime/Message>
3 22
4#include <tests/mailtest.h> 23#include <tests/mailtest.h>
5 24
6#include "common/test.h" 25#include "common/test.h"
7#include "common/domain/applicationdomaintype.h" 26#include "common/domain/applicationdomaintype.h"
8#include "common/secretstore.h" 27#include "common/secretstore.h"
28#include "common/resourcecontrol.h"
29#include "common/store.h"
9 30
10using namespace Sink; 31using namespace Sink;
11using namespace Sink::ApplicationDomain; 32using namespace Sink::ApplicationDomain;
@@ -42,6 +63,70 @@ protected:
42 Sink::SecretStore::instance().insert(resource.identifier(), "doe"); 63 Sink::SecretStore::instance().insert(resource.identifier(), "doe");
43 return resource; 64 return resource;
44 } 65 }
66
67private slots:
68
69 void testBogusMessageAppend()
70 {
71 using namespace Sink;
72 using namespace Sink::ApplicationDomain;
73
74 auto folder = Folder::create(mResourceInstanceIdentifier);
75 folder.setName("bogusfolder");
76 VERIFYEXEC(Store::create(folder));
77
78 Mail bogusMail;
79 {
80 auto mail = Mail::create(mResourceInstanceIdentifier);
81 mail.setMimeMessage("Bogus message: \0 this doesn't make any sense and contains NUL.");
82 mail.setFolder(folder);
83
84 VERIFYEXEC(Store::create(mail));
85
86 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
87 auto mails = Store::read<Mail>(Query().request<Mail::Folder>().request<Mail::Subject>().request<Mail::MimeMessage>());
88 QCOMPARE(mails.size(), 1);
89 bogusMail = mails.at(0);
90
91 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
92 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, false)));
93 //The cache will be off by one (because we failed to replay)
94 // VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::CacheIntegrityInspection(folder)));
95 }
96
97
98 //Ensure we can still append further messages:
99 {
100 auto mail = Mail::create(mResourceInstanceIdentifier);
101 {
102 auto message = KMime::Message::Ptr::create();
103 message->subject(true)->fromUnicodeString("Subject", "utf8");
104 message->assemble();
105 mail.setMimeMessage(message->encodedContent(true));
106 }
107 mail.setFolder(folder);
108 VERIFYEXEC(Store::create(mail));
109
110 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
111 auto mails = Store::read<Mail>(Query().request<Mail::Folder>().request<Mail::Subject>().request<Mail::MimeMessage>());
112 QCOMPARE(mails.size(), 2);
113
114 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
115 //The mail is still not available, because we'll end up trying to replay the bogus mail again.
116 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, false)));
117
118 //Fix the situation by deleting the bogus mail and retrying to sync.
119 VERIFYEXEC(Store::remove(bogusMail));
120 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
121 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
122
123 //This will fail because we still try to resync the previous mail
124 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true)));
125 //The cache will be off by one (because we failed to replay)
126 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::CacheIntegrityInspection(folder)));
127 }
128
129 }
45}; 130};
46 131
47QTEST_MAIN(ImapMailTest) 132QTEST_MAIN(ImapMailTest)
diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp
index 8e20fae..9b70309 100644
--- a/tests/mailtest.cpp
+++ b/tests/mailtest.cpp
@@ -475,61 +475,3 @@ void MailTest::testModifyMailToTrash()
475 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true))); 475 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true)));
476} 476}
477 477
478void MailTest::testBogusMessageAppend()
479{
480 auto folder = Folder::create(mResourceInstanceIdentifier);
481 folder.setName("bogusfolder");
482 VERIFYEXEC(Store::create(folder));
483
484 Mail bogusMail;
485 {
486 auto mail = Mail::create(mResourceInstanceIdentifier);
487 mail.setMimeMessage("Bogus message: \0 this doesn't make any sense and contains NUL.");
488 mail.setFolder(folder);
489
490 VERIFYEXEC(Store::create(mail));
491
492 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
493 auto mails = Store::read<Mail>(Query().request<Mail::Folder>().request<Mail::Subject>().request<Mail::MimeMessage>());
494 QCOMPARE(mails.size(), 1);
495 bogusMail = mails.at(0);
496
497 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
498 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, false)));
499 //The cache will be off by one (because we failed to replay)
500 // VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::CacheIntegrityInspection(folder)));
501 }
502
503
504 //Ensure we can still append further messages:
505 {
506 auto mail = Mail::create(mResourceInstanceIdentifier);
507 {
508 auto message = KMime::Message::Ptr::create();
509 message->subject(true)->fromUnicodeString("Subject", "utf8");
510 message->assemble();
511 mail.setMimeMessage(message->encodedContent(true));
512 }
513 mail.setFolder(folder);
514 VERIFYEXEC(Store::create(mail));
515
516 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
517 auto mails = Store::read<Mail>(Query().request<Mail::Folder>().request<Mail::Subject>().request<Mail::MimeMessage>());
518 QCOMPARE(mails.size(), 2);
519
520 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
521 //The mail is still not available, because we'll end up trying to replay the bogus mail again.
522 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, false)));
523
524 //Fix the situation by deleting the bogus mail and retrying to sync.
525 VERIFYEXEC(Store::remove(bogusMail));
526 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
527 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
528
529 //This will fail because we still try to resync the previous mail
530 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true)));
531 //The cache will be off by one (because we failed to replay)
532 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::CacheIntegrityInspection(folder)));
533 }
534
535}
diff --git a/tests/mailtest.h b/tests/mailtest.h
index 757da1b..b827188 100644
--- a/tests/mailtest.h
+++ b/tests/mailtest.h
@@ -53,7 +53,6 @@ private slots:
53 void testModifyMailToDraft(); 53 void testModifyMailToDraft();
54 54
55 void testModifyMailToTrash(); 55 void testModifyMailToTrash();
56 void testBogusMessageAppend();
57}; 56};
58 57
59} 58}