|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ctestimapsessioncreatesequenceset.h" |
|
17 |
|
18 #include "cimapsession.h" |
|
19 |
|
20 CTestImapSessionCreateSequenceSet::CTestImapSessionCreateSequenceSet() |
|
21 {} |
|
22 |
|
23 CTestImapSessionCreateSequenceSet::~CTestImapSessionCreateSequenceSet() |
|
24 { |
|
25 iUids.Reset(); |
|
26 } |
|
27 |
|
28 void CTestImapSessionCreateSequenceSet::SetupL() |
|
29 {} |
|
30 |
|
31 void CTestImapSessionCreateSequenceSet::TearDownL() |
|
32 { |
|
33 iUids.Reset(); |
|
34 } |
|
35 |
|
36 /** |
|
37 3 ==> 3 |
|
38 */ |
|
39 void CTestImapSessionCreateSequenceSet::TestSingleValueL() |
|
40 { |
|
41 INFO_PRINTF1(_L("TestSingleValueL: 3 ==> 3")); |
|
42 |
|
43 iUids.AppendL(3); |
|
44 |
|
45 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
46 |
|
47 _LIT8(KCompare, "3"); |
|
48 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
49 |
|
50 CleanupStack::PopAndDestroy(sequenceSet); |
|
51 INFO_PRINTF1(_L("Complete")); |
|
52 } |
|
53 |
|
54 /** |
|
55 1 2 ==> 1:2 |
|
56 */ |
|
57 void CTestImapSessionCreateSequenceSet::TestSingleShortRangeL() |
|
58 { |
|
59 INFO_PRINTF1(_L("TestSingleShortRangeL: 1 2 ==> 1:2")); |
|
60 |
|
61 iUids.AppendL(1); |
|
62 iUids.AppendL(2); |
|
63 |
|
64 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
65 |
|
66 _LIT8(KCompare, "1:2"); |
|
67 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
68 |
|
69 CleanupStack::PopAndDestroy(sequenceSet); |
|
70 INFO_PRINTF1(_L("Complete")); |
|
71 } |
|
72 |
|
73 /** |
|
74 1 2 3 4 5 ==> 1:5 |
|
75 */ |
|
76 void CTestImapSessionCreateSequenceSet::TestSingleMediumRangeL() |
|
77 { |
|
78 INFO_PRINTF1(_L("TestSingleMediumRangeL: 1 2 3 4 5 ==> 1:5")); |
|
79 |
|
80 iUids.AppendL(1); |
|
81 iUids.AppendL(2); |
|
82 iUids.AppendL(3); |
|
83 iUids.AppendL(4); |
|
84 iUids.AppendL(5); |
|
85 |
|
86 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
87 |
|
88 _LIT8(KCompare, "1:5"); |
|
89 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
90 |
|
91 CleanupStack::PopAndDestroy(sequenceSet); |
|
92 INFO_PRINTF1(_L("Complete")); |
|
93 } |
|
94 |
|
95 /** |
|
96 1 2 3 4 5 ... 100 ==> 1:100 |
|
97 */ |
|
98 void CTestImapSessionCreateSequenceSet::TestSingleLongRangeL() |
|
99 { |
|
100 INFO_PRINTF1(_L("TestSingleLongRangeL: 1 2 3 4 5 ... 100 ==> 1:100")); |
|
101 |
|
102 for (TUint i=1; i<=100; i++) |
|
103 { |
|
104 iUids.AppendL(i); |
|
105 } |
|
106 |
|
107 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
108 |
|
109 _LIT8(KCompare, "1:100"); |
|
110 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
111 |
|
112 CleanupStack::PopAndDestroy(sequenceSet); |
|
113 INFO_PRINTF1(_L("Complete")); |
|
114 } |
|
115 |
|
116 /** |
|
117 1 3 5 7 ==> 1,3,5,7 |
|
118 */ |
|
119 void CTestImapSessionCreateSequenceSet::TestIndividualValuesL() |
|
120 { |
|
121 INFO_PRINTF1(_L("TestIndividualValuesL: 1 3 5 7 ==> 1,3,5,7")); |
|
122 |
|
123 iUids.AppendL(1); |
|
124 iUids.AppendL(3); |
|
125 iUids.AppendL(5); |
|
126 iUids.AppendL(7); |
|
127 |
|
128 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
129 |
|
130 _LIT8(KCompare, "1,3,5,7"); |
|
131 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
132 |
|
133 CleanupStack::PopAndDestroy(sequenceSet); |
|
134 INFO_PRINTF1(_L("Complete")); |
|
135 } |
|
136 |
|
137 /** |
|
138 5 8 9 10 11 ==> 5,8:11 |
|
139 */ |
|
140 void CTestImapSessionCreateSequenceSet::TestSingleValueFollowedByRangeL() |
|
141 { |
|
142 INFO_PRINTF1(_L("TestSingleValueFollowedByRangeL: 5 8 9 10 11 ==> 5,8:11")); |
|
143 |
|
144 iUids.AppendL(5); |
|
145 iUids.AppendL(8); |
|
146 iUids.AppendL(9); |
|
147 iUids.AppendL(10); |
|
148 iUids.AppendL(11); |
|
149 |
|
150 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
151 |
|
152 _LIT8(KCompare, "5,8:11"); |
|
153 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
154 |
|
155 CleanupStack::PopAndDestroy(sequenceSet); |
|
156 INFO_PRINTF1(_L("Complete")); |
|
157 } |
|
158 |
|
159 /** |
|
160 This tests the example given in the insource documentation for CreateSequenceSetLC |
|
161 3 4 5 6 21 ==> 3:6,21 |
|
162 */ |
|
163 void CTestImapSessionCreateSequenceSet::TestRangeFollowedBySingleValueL() |
|
164 { |
|
165 INFO_PRINTF1(_L("TestRangeFollowedBySingleValueL: 3 4 5 6 21")); |
|
166 |
|
167 iUids.AppendL(3); |
|
168 iUids.AppendL(4); |
|
169 iUids.AppendL(5); |
|
170 iUids.AppendL(6); |
|
171 iUids.AppendL(21); |
|
172 |
|
173 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
174 |
|
175 _LIT8(KCompare, "3:6,21"); |
|
176 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
177 |
|
178 CleanupStack::PopAndDestroy(sequenceSet); |
|
179 INFO_PRINTF1(_L("Complete")); |
|
180 } |
|
181 |
|
182 /** |
|
183 1 3 4 6 ==> 1,3:4,6 |
|
184 */ |
|
185 void CTestImapSessionCreateSequenceSet::TestShortRangeSurroundedBySingleValuesL() |
|
186 { |
|
187 INFO_PRINTF1(_L("TestShortRangeSurroundedBySingleValuesL: 1 3 4 6 ==> 1,3:4,6")); |
|
188 |
|
189 iUids.AppendL(1); |
|
190 iUids.AppendL(3); |
|
191 iUids.AppendL(4); |
|
192 iUids.AppendL(6); |
|
193 |
|
194 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
195 |
|
196 _LIT8(KCompare, "1,3:4,6"); |
|
197 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
198 |
|
199 CleanupStack::PopAndDestroy(sequenceSet); |
|
200 INFO_PRINTF1(_L("Complete")); |
|
201 } |
|
202 |
|
203 /** |
|
204 1 3 4 5 6 10 ==> 1,3:6,10 |
|
205 */ |
|
206 void CTestImapSessionCreateSequenceSet::TestMediumRangeSurroundedBySingleValuesL() |
|
207 { |
|
208 INFO_PRINTF1(_L("TestMediumRangeSurroundedBySingleValuesL: 1 3 4 5 6 10 ==> 1,3:6,10")); |
|
209 |
|
210 iUids.AppendL(1); |
|
211 iUids.AppendL(3); |
|
212 iUids.AppendL(4); |
|
213 iUids.AppendL(5); |
|
214 iUids.AppendL(6); |
|
215 iUids.AppendL(10); |
|
216 |
|
217 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
218 |
|
219 _LIT8(KCompare, "1,3:6,10"); |
|
220 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
221 |
|
222 CleanupStack::PopAndDestroy(sequenceSet); |
|
223 INFO_PRINTF1(_L("Complete")); |
|
224 } |
|
225 |
|
226 /** |
|
227 5 6 7 8 11 15 16 17 18 ==> 5:8,11,15:18 |
|
228 */ |
|
229 void CTestImapSessionCreateSequenceSet::TestSingleValueSurroundedByRangesL() |
|
230 { |
|
231 INFO_PRINTF1(_L("TestSingleValueSurroundedByRangesL: 5 6 7 8 11 15 16 17 18 ==> 5:8,11,15:18")); |
|
232 |
|
233 TUint uids[] = { 5,6,7,8,11,15,16,17,18 }; |
|
234 TInt countUids = sizeof(uids) / sizeof(TUint); |
|
235 |
|
236 DoTestL(uids, countUids, _L8("5:8,11,15:18")); |
|
237 |
|
238 INFO_PRINTF1(_L("Complete")); |
|
239 } |
|
240 |
|
241 /** |
|
242 10 11 12 15 16 ==> 10:12,15:16 |
|
243 */ |
|
244 void CTestImapSessionCreateSequenceSet::TestTwoRangesL() |
|
245 { |
|
246 INFO_PRINTF1(_L("TestTwoRangesL: 10 11 12 15 16 ==> 10:12,15:16")); |
|
247 |
|
248 iUids.AppendL(10); |
|
249 iUids.AppendL(11); |
|
250 iUids.AppendL(12); |
|
251 iUids.AppendL(15); |
|
252 iUids.AppendL(16); |
|
253 |
|
254 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
255 |
|
256 _LIT8(KCompare, "10:12,15:16"); |
|
257 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
258 |
|
259 CleanupStack::PopAndDestroy(sequenceSet); |
|
260 INFO_PRINTF1(_L("Complete")); |
|
261 } |
|
262 |
|
263 /** |
|
264 1 2 3 5 6 7 10 11 12 13 ==> 1:3,5:7,10:13 |
|
265 */ |
|
266 void CTestImapSessionCreateSequenceSet::TestThreeRangesL() |
|
267 { |
|
268 INFO_PRINTF1(_L("TestThreeRangesL: 1 2 3 5 6 7 10 11 12 13 ==> 1:3,5:7,10:13")); |
|
269 |
|
270 TUint uids[] = { 1,2,3,5,6,7,10,11,12,13 }; |
|
271 TInt countUids = sizeof(uids) / sizeof(TUint); |
|
272 |
|
273 DoTestL(uids, countUids, _L8("1:3,5:7,10:13")); |
|
274 |
|
275 INFO_PRINTF1(_L("Complete")); |
|
276 } |
|
277 |
|
278 /** |
|
279 2,4,6,8,10,...,200 ==> 2,4,6,8,10,...,200 |
|
280 |
|
281 CImapSession::CreateSequenceSetLC() uses an expandable buffer to build the |
|
282 sequence set string. This test checks that the buffer does indeed expand |
|
283 when required. |
|
284 */ |
|
285 void CTestImapSessionCreateSequenceSet::TestLongResultStringL() |
|
286 { |
|
287 INFO_PRINTF1(_L("TestLongResultStringL: 2,4,6,8,10,...,200 ==> 2,4,6,8,10,...,200")); |
|
288 |
|
289 TBuf8<400> bufExpectedResult; |
|
290 |
|
291 iUids.AppendL(2); |
|
292 bufExpectedResult.Append(_L8("2")); |
|
293 |
|
294 for (TUint i=2; i<=100; i++) |
|
295 { |
|
296 iUids.AppendL(i*2); |
|
297 bufExpectedResult.AppendFormat(_L8(",%d"), i*2); |
|
298 } |
|
299 |
|
300 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
301 |
|
302 ASSERT_EQUALS((TDesC8&)*sequenceSet, (TDesC8&)bufExpectedResult); |
|
303 |
|
304 CleanupStack::PopAndDestroy(sequenceSet); |
|
305 INFO_PRINTF1(_L("Complete")); |
|
306 } |
|
307 |
|
308 /** |
|
309 10 11 12 15 16 ==> 10:12,15:16 |
|
310 */ |
|
311 void CTestImapSessionCreateSequenceSet::TestOutOfOrderSingleRangeL() |
|
312 { |
|
313 INFO_PRINTF1(_L("TestOutOfOrderSingleRangeL: 10 11 12 15 16 ==> 10:12,15:16")); |
|
314 |
|
315 iUids.AppendL(10); |
|
316 iUids.AppendL(11); |
|
317 iUids.AppendL(12); |
|
318 iUids.AppendL(15); |
|
319 iUids.AppendL(16); |
|
320 |
|
321 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
322 |
|
323 _LIT8(KCompare, "10:12,15:16"); |
|
324 ASSERT_EQUALS((TDesC8&)*sequenceSet, KCompare()); |
|
325 |
|
326 CleanupStack::PopAndDestroy(sequenceSet); |
|
327 INFO_PRINTF1(_L("Complete")); |
|
328 } |
|
329 |
|
330 /** |
|
331 16 10 3 7 14 5 15 4 12 13 6 ==> 3:7,12:16 |
|
332 */ |
|
333 void CTestImapSessionCreateSequenceSet::TestOutOfOrderMixedValuesL() |
|
334 { |
|
335 INFO_PRINTF1(_L("TestOutOfOrderMixedValuesL: 16 3 7 14 5 15 4 12 13 6 ==> 3:7,10,12:16")); |
|
336 |
|
337 TUint uids[] = { 16,10,3,7,14,5,15,4,12,13,6 }; |
|
338 TInt countUids = sizeof(uids) / sizeof(TUint); |
|
339 |
|
340 DoTestL(uids, countUids, _L8("3:7,10,12:16")); |
|
341 |
|
342 INFO_PRINTF1(_L("Complete")); |
|
343 } |
|
344 |
|
345 /** |
|
346 3 3 4 5 5 5 6 6 7 7 7 7 ==> 3:7 |
|
347 */ |
|
348 void CTestImapSessionCreateSequenceSet::TestDuplicatesSingleRangeL() |
|
349 { |
|
350 INFO_PRINTF1(_L("TestDuplicatesSingleRangeL: 3 3 4 5 5 5 6 6 7 7 7 7 ==> 3:7")); |
|
351 |
|
352 TUint uids[] = { 3,3,4,5,5,5,6,6,7,7,7,7 }; |
|
353 TInt countUids = sizeof(uids) / sizeof(TUint); |
|
354 |
|
355 DoTestL(uids, countUids, _L8("3:7")); |
|
356 |
|
357 INFO_PRINTF1(_L("Complete")); |
|
358 } |
|
359 |
|
360 /** |
|
361 12 12 15 15 16 20 21 21 22 22 30 30 30 ==> 12,15:16,20:22:30 |
|
362 */ |
|
363 void CTestImapSessionCreateSequenceSet::TestDuplicatesMixedValuesL() |
|
364 { |
|
365 INFO_PRINTF1(_L("TestDuplicatesMixedValuesL: 12 12 15 15 16 20 21 21 22 22 30 30 30 ==> 12,15:16,20:22:30")); |
|
366 |
|
367 TUint uids[] = { 12,12,15,15,16,20,21,21,22,22,30,30,30 }; |
|
368 TInt countUids = sizeof(uids) / sizeof(TUint); |
|
369 |
|
370 DoTestL(uids, countUids, _L8("12,15:16,20:22,30")); |
|
371 |
|
372 INFO_PRINTF1(_L("Complete")); |
|
373 } |
|
374 |
|
375 /** |
|
376 3 7 16 20 10 11 10 15 11 2 2 1 20 3 4 7 10 2 14 20 15 ==> 1:4,7,10:11,14:16,20 |
|
377 */ |
|
378 void CTestImapSessionCreateSequenceSet::TestDuplicatesAndOutOfOrderMixedValuesL() |
|
379 { |
|
380 INFO_PRINTF1(_L("TestDuplicatesAndOutOfOrderMixedValuesL: 3 7 16 20 10 11 10 15 11 2 2 1 20 3 4 7 10 2 14 20 15 ==> 1:4,7,10:11,14:16,20")); |
|
381 |
|
382 TUint uids[] = { 3,7,16,20,10,11,10,15,11,2,2,1,20,3,4,7,10,2,14,20,15 }; |
|
383 TInt countUids = sizeof(uids) / sizeof(TUint); |
|
384 |
|
385 DoTestL(uids, countUids, _L8("1:4,7,10:11,14:16,20")); |
|
386 |
|
387 INFO_PRINTF1(_L("Complete")); |
|
388 } |
|
389 |
|
390 |
|
391 void CTestImapSessionCreateSequenceSet::DoTestL(TUint* aUids, TInt aCountUids, const TDesC8& aExpectedResult) |
|
392 { |
|
393 for (TInt i = 0; i < aCountUids; i++) |
|
394 { |
|
395 iUids.AppendL(aUids[i]); |
|
396 } |
|
397 |
|
398 HBufC8* sequenceSet = CImapSession::CreateSequenceSetLC(iUids); |
|
399 ASSERT_EQUALS((TDesC8&)*sequenceSet, aExpectedResult); |
|
400 |
|
401 CleanupStack::PopAndDestroy(sequenceSet); |
|
402 } |
|
403 |
|
404 |
|
405 CTestSuite* CTestImapSessionCreateSequenceSet::CreateSuiteL(const TDesC& aName) |
|
406 // static |
|
407 { |
|
408 SUB_SUITE; |
|
409 ADD_TEST_STEP(TestSingleValueL); |
|
410 ADD_TEST_STEP(TestSingleShortRangeL); |
|
411 ADD_TEST_STEP(TestSingleMediumRangeL); |
|
412 ADD_TEST_STEP(TestSingleLongRangeL); |
|
413 ADD_TEST_STEP(TestIndividualValuesL); |
|
414 ADD_TEST_STEP(TestSingleValueFollowedByRangeL); |
|
415 ADD_TEST_STEP(TestRangeFollowedBySingleValueL); |
|
416 ADD_TEST_STEP(TestShortRangeSurroundedBySingleValuesL); |
|
417 ADD_TEST_STEP(TestMediumRangeSurroundedBySingleValuesL); |
|
418 ADD_TEST_STEP(TestSingleValueSurroundedByRangesL); |
|
419 ADD_TEST_STEP(TestTwoRangesL); |
|
420 ADD_TEST_STEP(TestThreeRangesL); |
|
421 ADD_TEST_STEP(TestLongResultStringL); |
|
422 ADD_TEST_STEP(TestOutOfOrderSingleRangeL); |
|
423 ADD_TEST_STEP(TestOutOfOrderMixedValuesL); |
|
424 ADD_TEST_STEP(TestDuplicatesSingleRangeL); |
|
425 ADD_TEST_STEP(TestDuplicatesMixedValuesL); |
|
426 ADD_TEST_STEP(TestDuplicatesAndOutOfOrderMixedValuesL); |
|
427 END_SUITE; |
|
428 } |
|
429 |