• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.14
  • kdepim
  • libkdepim
  • addressline
  • autotests
baloocompletionemailtest.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 
19 */
20 
21 #include "baloocompletionemailtest.h"
22 #include "../addresslineedit/baloocompletionemail.h"
23 #include <qtest_kde.h>
24 #include <QDebug>
25 
26 BalooCompletionEmailTest::BalooCompletionEmailTest(QObject *parent)
27  : QObject(parent)
28 {
29 
30 }
31 
32 BalooCompletionEmailTest::~BalooCompletionEmailTest()
33 {
34 
35 }
36 
37 void BalooCompletionEmailTest::returnEmptyListWhenEmailListIsEmpty()
38 {
39  KPIM::BalooCompletionEmail completion;
40  QVERIFY(completion.cleanupEmailList().isEmpty());
41 }
42 
43 void BalooCompletionEmailTest::shouldReturnSameListWhenNotExclude()
44 {
45  KPIM::BalooCompletionEmail completion;
46  QStringList emailList;
47  emailList << QLatin1String("foo");
48  emailList << QLatin1String("foo2");
49  emailList << QLatin1String("foo3");
50  emailList << QLatin1String("foo4");
51  emailList << QLatin1String("foo5");
52  emailList << QLatin1String("foo6");
53  completion.setEmailList(emailList);
54  QCOMPARE(completion.cleanupEmailList(), emailList);
55 }
56 
57 void BalooCompletionEmailTest::shouldReturnSameListIfBlackListDoesntInterceptEmail()
58 {
59  KPIM::BalooCompletionEmail completion;
60  QStringList emailList;
61  emailList << QLatin1String("foo");
62  emailList << QLatin1String("foo2");
63  emailList << QLatin1String("foo3");
64  emailList << QLatin1String("foo4");
65  emailList << QLatin1String("foo5");
66  emailList << QLatin1String("foo6");
67  completion.setEmailList(emailList);
68 
69  QStringList blackList;
70  blackList << QLatin1String("bla");
71  blackList << QLatin1String("bla2");
72  blackList << QLatin1String("bla3");
73  blackList << QLatin1String("bla4");
74  completion.setBlackList(blackList);
75  QCOMPARE(completion.cleanupEmailList(), emailList);
76 }
77 
78 void BalooCompletionEmailTest::shouldReturnUniqueEmail()
79 {
80  KPIM::BalooCompletionEmail completion;
81  QStringList emailList;
82  emailList << QLatin1String("foo");
83  emailList << QLatin1String("foo");
84  emailList << QLatin1String("foo1");
85  emailList << QLatin1String("foo");
86  emailList << QLatin1String("foo1");
87  emailList << QLatin1String("foo2");
88  completion.setEmailList(emailList);
89  QCOMPARE(completion.cleanupEmailList(), (QStringList() << QLatin1String("foo") << QLatin1String("foo1") << QLatin1String("foo2") ) );
90 }
91 
92 void BalooCompletionEmailTest::shouldReturnEmptyListWhenAllBlackListed()
93 {
94  KPIM::BalooCompletionEmail completion;
95  QStringList emailList;
96  emailList << QLatin1String("foo");
97  emailList << QLatin1String("foo2");
98  emailList << QLatin1String("foo3");
99  emailList << QLatin1String("foo4");
100  emailList << QLatin1String("foo5");
101  emailList << QLatin1String("foo6");
102  completion.setEmailList(emailList);
103  completion.setBlackList(emailList);
104  QVERIFY(completion.cleanupEmailList().isEmpty());
105 }
106 
107 void BalooCompletionEmailTest::shouldExcludeDomain()
108 {
109  KPIM::BalooCompletionEmail completion;
110  QStringList emailList;
111  emailList << QLatin1String("foo@kde.org");
112  emailList << QLatin1String("foo2@kde.org");
113  emailList << QLatin1String("foo3@kde.org");
114  emailList << QLatin1String("foo4@kde.org");
115  emailList << QLatin1String("foo5@kde.org");
116  emailList << QLatin1String("foo6@kde.org");
117  completion.setEmailList(emailList);
118  completion.setExcludeDomain(QStringList() << QLatin1String("kde.org"));
119  QVERIFY(completion.cleanupEmailList().isEmpty());
120 
121  const QString newAddress = QLatin1String("foo6@linux.org");
122  emailList << newAddress;
123  completion.setEmailList(emailList);
124  QCOMPARE(completion.cleanupEmailList(), (QStringList() << newAddress) );
125 
126  completion.setExcludeDomain(QStringList() << QLatin1String("kde.org") << QLatin1String("linux.org") );
127  QVERIFY(completion.cleanupEmailList().isEmpty());
128 }
129 
130 void BalooCompletionEmailTest::shouldReturnEmailListWhenDomainListIsNotNull()
131 {
132  KPIM::BalooCompletionEmail completion;
133  QStringList emailList;
134  emailList << QLatin1String("foo@kde.org");
135  emailList << QLatin1String("foo2@kde.org");
136  emailList << QLatin1String("foo3@kde.org");
137  emailList << QLatin1String("foo4@kde.org");
138  emailList << QLatin1String("foo5@kde.org");
139  emailList << QLatin1String("foo6@kde.org");
140  emailList.sort();
141  completion.setEmailList(emailList);
142  completion.setExcludeDomain(QStringList() << QLatin1String(""));
143  QCOMPARE(completion.cleanupEmailList(), emailList);
144 }
145 
146 void BalooCompletionEmailTest::shouldDontDuplicateEmailWhenUseCase()
147 {
148  KPIM::BalooCompletionEmail completion;
149  QStringList emailList;
150  emailList << QLatin1String("foo");
151  emailList << QLatin1String("foo2");
152  emailList << QLatin1String("foo3");
153  emailList << QLatin1String("foo4");
154  emailList << QLatin1String("foo5");
155  emailList << QLatin1String("foo6");
156 
157  QStringList caseEmailList;
158  caseEmailList << QLatin1String("Foo");
159  caseEmailList << QLatin1String("fOo2");
160  caseEmailList << QLatin1String("FOo3");
161  completion.setEmailList((QStringList() << emailList<<caseEmailList));
162  QCOMPARE(completion.cleanupEmailList(), emailList);
163 }
164 
165 void BalooCompletionEmailTest::shouldExcludeDuplicateEntryWithDisplayName()
166 {
167  KPIM::BalooCompletionEmail completion;
168  QStringList emailList;
169  emailList << QLatin1String("John Doe <doe@example.com>");
170  emailList << QLatin1String("\"John Doe\" <doe@example.com>");
171  emailList << QLatin1String("\"\'John Doe\'\" <doe@example.com>");
172  completion.setEmailList(emailList);
173  QCOMPARE(completion.cleanupEmailList().count(), 1);
174 }
175 
176 void BalooCompletionEmailTest::shouldExcludeDuplicateEntryWithDisplayNameAddAddressWithDifferentCase()
177 {
178  KPIM::BalooCompletionEmail completion;
179  QStringList emailList;
180  emailList << QLatin1String("John Doe <doe@example.com>");
181  emailList << QLatin1String("\"John Doe\" <doe@example.com>");
182  emailList << QLatin1String("\"\'John Doe\'\" <doe@example.com>");
183  emailList << QLatin1String("John Doe <Doe@example.com>");
184  emailList << QLatin1String("John Doe <DOE@example.com>");
185  emailList << QLatin1String("John Doe <dOE@example.com>");
186  completion.setEmailList(emailList);
187  QCOMPARE(completion.cleanupEmailList().count(), 1);
188 
189 }
190 
191 void BalooCompletionEmailTest::shouldExcludeDuplicateEntryWithDifferentDisplayNameAddAddressWithDifferentCase()
192 {
193  KPIM::BalooCompletionEmail completion;
194  QStringList emailList;
195  emailList << QLatin1String("John Doe <doe@example.com>");
196  emailList << QLatin1String("\"John Doe\" <doe@example.com>");
197  emailList << QLatin1String("\"\'John Doe\'\" <doe@example.com>");
198  emailList << QLatin1String("John Doe <doe@example.com>");
199  emailList << QLatin1String("Doe John <Doe@example.com>");
200  emailList << QLatin1String("John <DOE@example.com>");
201  emailList << QLatin1String("Doe <dOE@example.com>");
202  completion.setEmailList(emailList);
203  QCOMPARE(completion.cleanupEmailList().count(), 1);
204 }
205 
206 QTEST_KDEMAIN(BalooCompletionEmailTest, NoGUI)
KPIM::BalooCompletionEmail::setEmailList
void setEmailList(const QStringList &lst)
Definition: baloocompletionemail.cpp:32
baloocompletionemailtest.h
BalooCompletionEmailTest::~BalooCompletionEmailTest
~BalooCompletionEmailTest()
Definition: baloocompletionemailtest.cpp:32
KPIM::BalooCompletionEmail::setExcludeDomain
void setExcludeDomain(const QStringList &lst)
Definition: baloocompletionemail.cpp:37
QList::count
int count(const T &value) const
BalooCompletionEmailTest::BalooCompletionEmailTest
BalooCompletionEmailTest(QObject *parent=0)
Definition: baloocompletionemailtest.cpp:26
QObject
QList::isEmpty
bool isEmpty() const
QString
QStringList
BalooCompletionEmailTest
Definition: baloocompletionemailtest.h:26
QLatin1String
KPIM::BalooCompletionEmail::setBlackList
void setBlackList(const QStringList &lst)
Definition: baloocompletionemail.cpp:42
KPIM::BalooCompletionEmail
Definition: baloocompletionemail.h:26
QStringList::sort
void sort()
KPIM::BalooCompletionEmail::cleanupEmailList
QStringList cleanupEmailList()
Definition: baloocompletionemail.cpp:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal