74
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: unittests fro emailmru
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
//#include <XQSettingsManager.h>
|
|
19 |
//#include <XQCentralRepositoryUtils.h>
|
|
20 |
//#include <XQCentralRepositorySearchCriteria.h>
|
|
21 |
|
|
22 |
|
|
23 |
//#include "XQSettingsManager.h"
|
|
24 |
//#include "XQCentralRepositoryUtils.h"
|
|
25 |
//#include "XQCentralRepositorySearchCriteria.h"
|
|
26 |
|
|
27 |
#include "emailmru.h"
|
|
28 |
#include "unittest_emailmru.h"
|
|
29 |
|
|
30 |
/*!
|
|
31 |
Constructor
|
|
32 |
*/
|
|
33 |
TestEmailMru::TestEmailMru()
|
|
34 |
{
|
|
35 |
|
|
36 |
}
|
|
37 |
|
|
38 |
/*!
|
|
39 |
Destructor
|
|
40 |
*/
|
|
41 |
TestEmailMru::~TestEmailMru()
|
|
42 |
{
|
|
43 |
|
|
44 |
}
|
|
45 |
|
|
46 |
/*!
|
|
47 |
Called before testcase
|
|
48 |
*/
|
|
49 |
void TestEmailMru::initTestCase()
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
/*!
|
|
54 |
Called after testcase
|
|
55 |
*/
|
|
56 |
void TestEmailMru::cleanupTestCase()
|
|
57 |
{
|
|
58 |
}
|
|
59 |
|
|
60 |
/*!
|
|
61 |
Called before every function
|
|
62 |
*/
|
|
63 |
void TestEmailMru::init()
|
|
64 |
{
|
|
65 |
iMru = new EmailMRU();
|
|
66 |
}
|
|
67 |
|
|
68 |
/*!
|
|
69 |
Called after everyfunction
|
|
70 |
*/
|
|
71 |
void TestEmailMru::cleanup()
|
|
72 |
{
|
|
73 |
delete iMru;
|
|
74 |
iMru = NULL;
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
/*!
|
|
79 |
Test what happens when entry with same address
|
|
80 |
but different name is applied to MRU
|
|
81 |
*/
|
|
82 |
|
|
83 |
void TestEmailMru::testUpdateEntry()
|
|
84 |
{
|
|
85 |
// EmailMRU *mru = new EmailMRU();
|
|
86 |
iMru->reset();
|
|
87 |
bool success;
|
|
88 |
|
|
89 |
QString name = "n1";
|
|
90 |
QString addr = "a1";
|
|
91 |
iMru->updateMRU(name, addr);
|
|
92 |
|
|
93 |
QString name2 = "n2";
|
|
94 |
QString addr2 = "a2";
|
|
95 |
iMru->updateMRU(name2, addr2);
|
|
96 |
|
|
97 |
QString name3 = "n3";
|
|
98 |
QString addr3 = "a3";
|
|
99 |
iMru->updateMRU(name3, addr3);
|
|
100 |
|
|
101 |
/*
|
|
102 |
CenRep Should be:
|
|
103 |
|
|
104 |
"n1" : "a1"
|
|
105 |
"n2" : "a2"
|
|
106 |
"n3" : "a3";
|
|
107 |
|
|
108 |
*/
|
|
109 |
|
|
110 |
// Update A2
|
|
111 |
QString name4 = "n4";
|
|
112 |
QString addr4 = "a2";
|
|
113 |
iMru->updateMRU(name4, addr4);
|
|
114 |
|
|
115 |
/*
|
|
116 |
CenRep Should be:
|
|
117 |
|
|
118 |
"n1" : "a1"
|
|
119 |
"n3" : "a3"
|
|
120 |
"n4" : "a2"
|
|
121 |
|
|
122 |
*/
|
|
123 |
|
|
124 |
QString e_name;
|
|
125 |
QString e_addr;
|
|
126 |
|
|
127 |
success = iMru->getEntry(1, e_name, e_addr);
|
|
128 |
QCOMPARE(e_name, name);
|
|
129 |
QCOMPARE(e_addr, addr);
|
|
130 |
QCOMPARE(success, true);
|
|
131 |
|
|
132 |
success = iMru->getEntry(2, e_name, e_addr);
|
|
133 |
QCOMPARE(e_name, name3);
|
|
134 |
QCOMPARE(e_addr, addr3);
|
|
135 |
QCOMPARE(success, true);
|
|
136 |
|
|
137 |
success = iMru->getEntry(3, e_name, e_addr);
|
|
138 |
QCOMPARE(e_name, name4);
|
|
139 |
QCOMPARE(e_addr, addr4);
|
|
140 |
QCOMPARE(success, true);
|
|
141 |
|
|
142 |
e_name.clear();
|
|
143 |
e_addr.clear();
|
|
144 |
QString emptyString;
|
|
145 |
emptyString.clear();
|
|
146 |
|
|
147 |
success = iMru->getEntry(4, e_name, e_addr);
|
|
148 |
QCOMPARE(e_name, emptyString);
|
|
149 |
QCOMPARE(e_addr, emptyString);
|
|
150 |
QCOMPARE(success, false);
|
|
151 |
}
|
|
152 |
|
|
153 |
/*!
|
|
154 |
Test what happens when the MRU is filled and
|
|
155 |
yet still more entries are applied
|
|
156 |
*/
|
|
157 |
|
|
158 |
void TestEmailMru::testUpperLimit()
|
|
159 |
{
|
|
160 |
// EmailMRU *mru = new EmailMRU();
|
|
161 |
iMru->reset();
|
|
162 |
|
|
163 |
// first fill the MRU
|
|
164 |
for (qint32 i=0; i < emailAddressHistorySize; i++) {
|
|
165 |
QString name = "name";
|
|
166 |
QString addr = "addr";
|
|
167 |
QString num = QString::number(i);
|
|
168 |
name.append(num);
|
|
169 |
addr.append(num);
|
|
170 |
iMru->updateMRU(name, addr);
|
|
171 |
}
|
|
172 |
|
|
173 |
// next add one more pair, this should overwrite the
|
|
174 |
// first entries
|
|
175 |
QString e_name;
|
|
176 |
QString e_addr;
|
|
177 |
QString e_name_value = "expected_name";
|
|
178 |
QString e_addr_value = "expected_address";
|
|
179 |
iMru->updateMRU(e_name_value, e_addr_value);
|
|
180 |
|
|
181 |
iMru->getEntry(1, e_name, e_addr);
|
|
182 |
|
|
183 |
// finally compare if the first entries has been
|
|
184 |
// replaced
|
|
185 |
QCOMPARE(e_name, e_name_value);
|
|
186 |
QCOMPARE(e_addr, e_addr_value);
|
|
187 |
}
|
|
188 |
|
|
189 |
/*!
|
|
190 |
Provides data for testMruStrings
|
|
191 |
*/
|
|
192 |
void TestEmailMru::testMruStrings_data()
|
|
193 |
{
|
|
194 |
QTest::addColumn<QString>("display_name");
|
|
195 |
QTest::addColumn<QString>("email_address");
|
|
196 |
|
|
197 |
QTest::newRow("1") << "name1" << "name1.name1@gmail.com";
|
|
198 |
QTest::newRow("2") << "name2" << "name.name.name.namenamenmanamnamenmanemane2.name2@gmailmailmailamil.com";
|
|
199 |
QTest::newRow("3") << "näMeöÅ3" << "name3@gmail.com";
|
|
200 |
QTest::newRow("4") << "name4$&#/\\" << "name4.name4@gmail.com";
|
|
201 |
}
|
|
202 |
|
|
203 |
/*!
|
|
204 |
Check that name and address pairs are successfully
|
|
205 |
saved into mru database
|
|
206 |
*/
|
|
207 |
void TestEmailMru::testMruStrings()
|
|
208 |
{
|
|
209 |
QFETCH(QString, display_name);
|
|
210 |
QFETCH(QString, email_address);
|
|
211 |
|
|
212 |
// EmailMRU *mru = new EmailMRU();
|
|
213 |
iMru->reset();
|
|
214 |
iMru->updateMRU(display_name, email_address);
|
|
215 |
|
|
216 |
QString name;
|
|
217 |
QString address;
|
|
218 |
iMru->getEntry(1, name, address);
|
|
219 |
|
|
220 |
QCOMPARE(name, display_name);
|
|
221 |
QCOMPARE(address, email_address);
|
|
222 |
}
|
|
223 |
|
|
224 |
/*!
|
|
225 |
Reset mru database and verify that it is indeed empty
|
|
226 |
*/
|
|
227 |
void TestEmailMru::testReset()
|
|
228 |
{
|
|
229 |
// EmailMRU *mru = new EmailMRU();
|
|
230 |
iMru->reset();
|
|
231 |
bool success;
|
|
232 |
|
|
233 |
quint32 mruCount = iMru->entryCount();
|
|
234 |
|
|
235 |
QString e_name;
|
|
236 |
QString e_addr;
|
|
237 |
QString name = "n1";
|
|
238 |
QString addr = "a1";
|
|
239 |
iMru->updateMRU(name, addr);
|
|
240 |
|
|
241 |
mruCount = iMru->entryCount();
|
|
242 |
|
|
243 |
success = iMru->getEntry(1, e_name, e_addr);
|
|
244 |
QCOMPARE(e_name, name);
|
|
245 |
QCOMPARE(e_addr, addr);
|
|
246 |
QCOMPARE(success, true);
|
|
247 |
|
|
248 |
e_name.clear();
|
|
249 |
e_addr.clear();
|
|
250 |
QString emptyString;
|
|
251 |
emptyString.clear();
|
|
252 |
|
|
253 |
iMru->reset();
|
|
254 |
|
|
255 |
mruCount = iMru->entryCount();
|
|
256 |
|
|
257 |
success = iMru->getEntry(1, e_name, e_addr);
|
|
258 |
QCOMPARE(e_name, emptyString);
|
|
259 |
QCOMPARE(e_addr, emptyString);
|
|
260 |
QCOMPARE(success, false);
|
|
261 |
}
|
|
262 |
|
|
263 |
void TestEmailMru::testNameOrder()
|
|
264 |
{
|
|
265 |
int rVal = EmailMRU::nameOrder();
|
|
266 |
QVERIFY( rVal == 0 );
|
|
267 |
}
|
|
268 |
|
|
269 |
QTEST_MAIN( TestEmailMru );
|
|
270 |
|