17 #include <s32page.h> |
17 #include <s32page.h> |
18 #include <s32mem.h> |
18 #include <s32mem.h> |
19 #include <e32test.h> |
19 #include <e32test.h> |
20 #include "U32STD.H" |
20 #include "U32STD.H" |
21 |
21 |
22 const TInt KTestCleanupStack=0x20; |
22 LOCAL_D RTest TheTest(_L("t_storset")); |
23 |
23 |
24 LOCAL_D CTrapCleanup* TheTrapCleanup; |
24 /////////////////////////////////////////////////////////////////////////////////////// |
25 LOCAL_D RTest test(_L("t_storset")); |
25 /////////////////////////////////////////////////////////////////////////////////////// |
|
26 //Test macros and functions |
|
27 void Check1(TInt aValue, TInt aLine) |
|
28 { |
|
29 if(!aValue) |
|
30 { |
|
31 TheTest.Printf(_L("*** Expression evaluated to false. Line %d\r\n"), aLine); |
|
32 TheTest(EFalse, aLine); |
|
33 } |
|
34 } |
|
35 void Check2(TInt aValue, TInt aExpected, TInt aLine) |
|
36 { |
|
37 if(aValue != aExpected) |
|
38 { |
|
39 TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
|
40 TheTest(EFalse, aLine); |
|
41 } |
|
42 } |
|
43 void Check3(TUint aValue, TUint aExpected, TInt aLine) |
|
44 { |
|
45 if(aValue != aExpected) |
|
46 { |
|
47 TheTest.Printf(_L("*** Line %d, Expected value: %u, got: %u\r\n"), aLine, aExpected, aValue); |
|
48 TheTest(EFalse, aLine); |
|
49 } |
|
50 } |
|
51 #define TEST(arg) ::Check1((arg), __LINE__) |
|
52 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
53 #define TEST3(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
54 |
|
55 /////////////////////////////////////////////////////////////////////////////////////// |
26 |
56 |
27 /** |
57 /** |
28 @SYMTestCaseID SYSLIB-STORE-CT-1121 |
58 @SYMTestCaseID SYSLIB-STORE-CT-1121 |
29 @SYMTestCaseDesc TPagedSet class functionality test |
59 @SYMTestCaseDesc TPagedSet class functionality test |
30 @SYMTestPriority High |
60 @SYMTestPriority High |
33 @SYMTestExpectedResults Test must not fail |
63 @SYMTestExpectedResults Test must not fail |
34 @SYMREQ REQ0000 |
64 @SYMREQ REQ0000 |
35 */ |
65 */ |
36 LOCAL_C void test1L() |
66 LOCAL_C void test1L() |
37 { |
67 { |
38 test.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1121 Insertion & Deletion ")); |
68 TheTest.Printf(_L("Basic operations\r\n")); |
39 |
69 |
40 const TInt KEntryCount=200; |
70 const TInt KEntryCount=200; |
41 TPagedSet<TInt32> set; |
71 TPagedSet<TInt32> set; |
42 set.Connect(CMemPagePool::NewLC()); |
72 set.Connect(CMemPagePool::NewLC()); |
43 //IsIntact() and IsDirty() test |
73 //IsIntact() and IsDirty() test |
|
74 TheTest.Printf(_L("IsIntact() and IsDirty() test\r\n")); |
44 TBool rc = set.IsIntact(); |
75 TBool rc = set.IsIntact(); |
45 test(rc); |
76 TEST(rc); |
46 rc = set.IsDirty(); |
77 rc = set.IsDirty(); |
47 test(!rc); |
78 TEST(!rc); |
48 set.MarkDirty(); |
79 set.MarkDirty(); |
49 rc = set.IsDirty(); |
80 rc = set.IsDirty(); |
50 test(rc); |
81 TEST(rc); |
51 //IsBroken() test |
82 //IsBroken() test |
|
83 TheTest.Printf(_L("IsBroken() test\r\n")); |
52 rc = set.IsBroken(); |
84 rc = set.IsBroken(); |
53 test(!rc); |
85 TEST(!rc); |
54 set.MarkBroken(); |
86 set.MarkBroken(); |
55 rc = set.IsBroken(); |
87 rc = set.IsBroken(); |
56 test(!rc);//Empty tree - cannot be marked as broken |
88 TEST(!rc);//Empty tree - cannot be marked as broken |
57 TInt yy = 10; |
89 TInt yy = 10; |
58 set.InsertL(yy); |
90 set.InsertL(yy); |
59 set.MarkBroken(); |
91 set.MarkBroken(); |
60 rc = set.IsBroken(); |
92 rc = set.IsBroken(); |
61 test(rc); |
93 TEST(rc); |
|
94 TheTest.Printf(_L("RepairL()test\r\n")); |
62 set.RepairL(); |
95 set.RepairL(); |
63 rc = set.IsBroken(); |
96 rc = set.IsBroken(); |
64 test(!rc); |
97 TEST(!rc); |
|
98 TheTest.Printf(_L("ClearL() test\r\n")); |
65 set.ClearL(); |
99 set.ClearL(); |
66 rc = set.IsBroken(); |
100 rc = set.IsBroken(); |
67 test(!rc); |
101 TEST(!rc); |
68 |
102 |
|
103 TheTest.Printf(_L("InsertL() and DeleteL() test\r\n")); |
69 TInt32 it=0; |
104 TInt32 it=0; |
70 //* test(set.InsertL(it)); |
105 //* TEST(set.InsertL(it)); |
71 set.InsertL(it); |
106 set.InsertL(it); |
72 test(set.Count()==1); |
107 TEST2(set.Count(), 1); |
73 //* test(!set.InsertL(it)); |
108 //* TEST(!set.InsertL(it)); |
74 test(set.Count()==1); |
109 TEST2(set.Count(), 1); |
75 test(set.ContainsL(it)); |
110 TEST(set.ContainsL(it)); |
76 //* test(set.DeleteL(it)); |
111 //* TEST(set.DeleteL(it)); |
77 set.DeleteL(it); |
112 set.DeleteL(it); |
78 test(set.Count()==0); |
113 TEST2(set.Count(), 0); |
79 //* test(!set.DeleteL(it)); |
114 //* TEST(!set.DeleteL(it)); |
80 //* test(set.Count()==0); |
115 //* TEST(set.Count()==0); |
81 test(!set.ContainsL(it)); |
116 TEST(!set.ContainsL(it)); |
82 |
117 |
83 //* test.Next(_L("Duplicates")); |
118 //* TheTest.Printf(_L("Duplicates")); |
84 TInt ii; |
119 TInt ii; |
85 //* for (ii=0;ii<KEntryCount;++ii) |
120 //* for (ii=0;ii<KEntryCount;++ii) |
86 //* test(set.InsertL(it,EAllowDuplicates)); |
121 //* TEST(set.InsertL(it,EAllowDuplicates)); |
87 //* test(set.Count()==KEntryCount); |
122 //* TEST2(set.Count(), KEntryCount); |
88 //* test(set.ContainsL(it)); |
123 //* TEST(set.ContainsL(it)); |
89 //* test(!set.InsertL(it)); |
124 //* TEST(!set.InsertL(it)); |
90 //* for (ii=0;ii<KEntryCount;++ii) |
125 //* for (ii=0;ii<KEntryCount;++ii) |
91 //* test(set.DeleteL(it)); |
126 //* TEST(set.DeleteL(it)); |
92 //* test(!set.ContainsL(it)); |
127 //* TEST(!set.ContainsL(it)); |
93 //* test(!set.DeleteL(it)); |
128 //* TEST(!set.DeleteL(it)); |
94 //* test(set.Count()==0); |
129 //* TEST2(set.Count(), 0); |
95 |
130 |
96 test.Next(_L("No duplicates")); |
131 TheTest.Printf(_L("No duplicates\r\n")); |
97 for (ii=0;ii<KEntryCount;++ii) |
132 for (ii=0;ii<KEntryCount;++ii) |
98 { |
133 { |
99 it=ii; |
134 it=ii; |
100 //* test(set.InsertL(it)); |
135 //* TEST(set.InsertL(it)); |
101 set.InsertL(it); |
136 set.InsertL(it); |
102 } |
137 } |
103 for (ii=0;ii<KEntryCount;++ii) |
138 for (ii=0;ii<KEntryCount;++ii) |
104 { |
139 { |
105 it=ii; |
140 it=ii; |
106 //* test(!set.InsertL(it)); |
141 //* TEST(!set.InsertL(it)); |
107 test(set.ContainsL(it)); |
142 TEST(set.ContainsL(it)); |
108 } |
143 } |
109 test(set.Count()==KEntryCount); |
144 TEST2(set.Count(), KEntryCount); |
110 |
145 |
111 test.Next(_L("Empty the set")); |
146 TheTest.Printf(_L("Empty the set\r\n")); |
112 set.ClearL(); |
147 set.ClearL(); |
113 test(set.Count()==0); |
148 TEST2(set.Count(), 0); |
114 for (ii=0;ii<KEntryCount;++ii) |
149 for (ii=0;ii<KEntryCount;++ii) |
115 { |
150 { |
116 it=ii; |
151 it=ii; |
117 test(!set.ContainsL(it)); |
152 TEST(!set.ContainsL(it)); |
118 } |
153 } |
119 |
154 |
120 test.End(); |
|
121 CleanupStack::PopAndDestroy(); |
155 CleanupStack::PopAndDestroy(); |
122 } |
156 } |
123 /** |
157 /** |
124 @SYMTestCaseID SYSLIB-STORE-CT-1122 |
158 @SYMTestCaseID SYSLIB-STORE-CT-1122 |
125 @SYMTestCaseDesc TPagedSet class functionality test with large (10000) set of TUint32. |
159 @SYMTestCaseDesc TPagedSet class functionality test with large (10000) set of TUint32. |
134 |
168 |
135 TPagedSet<TUint32> set; |
169 TPagedSet<TUint32> set; |
136 //* set.Connect(CMemPagePool::NewLC(),TBtree::EQosFastest); |
170 //* set.Connect(CMemPagePool::NewLC(),TBtree::EQosFastest); |
137 set.Connect(CMemPagePool::NewLC()); |
171 set.Connect(CMemPagePool::NewLC()); |
138 |
172 |
139 test.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1122 Add items ")); |
173 TheTest.Printf(_L("Add items\r\n")); |
140 TUint32 jj=0; |
174 TUint32 jj=0; |
141 TInt32 ii; |
175 TInt32 ii; |
142 for (ii=KEntryCount;ii>0;--ii) |
176 for (ii=KEntryCount;ii>0;--ii) |
143 { |
177 { |
144 jj=(jj+17)%KEntryCount; |
178 jj=(jj+17)%KEntryCount; |
145 //* test(set.InsertL(jj)); |
179 //* TEST(set.InsertL(jj)); |
146 set.InsertL(jj); |
180 set.InsertL(jj); |
147 } |
181 } |
148 test(set.Count()==KEntryCount); |
182 TEST2(set.Count(), KEntryCount); |
149 |
183 |
150 test.Next(_L("Check contents")); |
184 TheTest.Printf(_L("Check contents\r\n")); |
151 for (ii=0;ii<KEntryCount;++ii) |
185 for (ii=0;ii<KEntryCount;++ii) |
152 test(set.ContainsL(ii)); |
186 TEST(set.ContainsL(ii)); |
153 |
187 |
154 test.Next(_L("Iterate over items")); |
188 TheTest.Printf(_L("Iterate over items\r\n")); |
155 TUint8 *checkMap=(TUint8*)User::AllocLC(KEntryCount); |
189 TUint8 *checkMap=(TUint8*)User::AllocLC(KEntryCount); |
156 Mem::FillZ(checkMap,KEntryCount); |
190 Mem::FillZ(checkMap,KEntryCount); |
157 TPagedSetIter<TUint32> iter(set); |
191 TPagedSetIter<TUint32> iter(set); |
158 if (iter.ResetL()) |
192 if (iter.ResetL()) |
159 { |
193 { |
161 { |
195 { |
162 TUint32 data1 = iter.AtL(); |
196 TUint32 data1 = iter.AtL(); |
163 ++checkMap[data1]; |
197 ++checkMap[data1]; |
164 TUint32 data2; |
198 TUint32 data2; |
165 iter.ExtractAtL(data2); |
199 iter.ExtractAtL(data2); |
166 test(data1 == data2); |
200 TEST3(data1, data2); |
167 }while(iter.NextL()); |
201 }while(iter.NextL()); |
168 } |
202 } |
169 for (ii=0;ii<KEntryCount;++ii) |
203 for (ii=0;ii<KEntryCount;++ii) |
170 test(checkMap[ii]==1); |
204 TEST2(checkMap[ii], 1); |
171 CleanupStack::PopAndDestroy(); |
205 CleanupStack::PopAndDestroy(); |
172 |
206 |
173 test.Next(_L("Delete items")); |
207 TheTest.Printf(_L("Delete items\r\n")); |
174 jj=0; |
208 jj=0; |
175 for (ii=KEntryCount;ii>KEntryCount/2;--ii) |
209 for (ii=KEntryCount;ii>KEntryCount/2;--ii) |
176 { |
210 { |
177 jj=(jj+17)%KEntryCount; |
211 jj=(jj+17)%KEntryCount; |
178 //* test(set.DeleteL(jj)); |
212 //* TEST(set.DeleteL(jj)); |
179 set.DeleteL(jj); |
213 set.DeleteL(jj); |
180 } |
214 } |
181 test(set.Count()==KEntryCount/2); |
215 TEST2(set.Count(), KEntryCount/2); |
182 |
216 |
183 test.Next(_L("Check contents")); |
217 TheTest.Printf(_L("Check contents\r\n")); |
184 for (;ii>0;--ii) |
218 for (;ii>0;--ii) |
185 { |
219 { |
186 jj=(jj+17)%KEntryCount; |
220 jj=(jj+17)%KEntryCount; |
187 test(set.ContainsL(jj)); |
221 TEST(set.ContainsL(jj)); |
188 } |
222 } |
189 jj=0; |
223 jj=0; |
190 for (ii=KEntryCount;ii>KEntryCount/2;--ii) |
224 for (ii=KEntryCount;ii>KEntryCount/2;--ii) |
191 { |
225 { |
192 jj=(jj+17)%KEntryCount; |
226 jj=(jj+17)%KEntryCount; |
193 test(!set.ContainsL(jj)); |
227 TEST(!set.ContainsL(jj)); |
194 } |
228 } |
195 |
229 |
196 test.Next(_L("Delete items")); |
230 TheTest.Printf(_L("Delete items\r\n")); |
197 for (;ii>1;--ii) |
231 for (;ii>1;--ii) |
198 { |
232 { |
199 jj=(jj+17)%KEntryCount; |
233 jj=(jj+17)%KEntryCount; |
200 //* test(set.DeleteL(jj)); |
234 //* TEST(set.DeleteL(jj)); |
201 set.DeleteL(jj); |
235 set.DeleteL(jj); |
202 } |
236 } |
203 test(set.Count()==1); |
237 TEST2(set.Count(), 1); |
204 |
238 |
205 test.Next(_L("Check contents")); |
239 TheTest.Printf(_L("Check contents\r\n")); |
206 jj=(jj+17)%KEntryCount; |
240 jj=(jj+17)%KEntryCount; |
207 TPagedSetBiIter<TUint32> biter(set); |
241 TPagedSetBiIter<TUint32> biter(set); |
208 test(biter.FirstL()); |
242 TEST(biter.FirstL()); |
209 test(biter.AtL()==jj); |
243 TEST3(biter.AtL(), jj); |
210 TUint32 data; |
244 TUint32 data; |
211 biter.ExtractAtL(data); |
245 biter.ExtractAtL(data); |
212 test(data == jj); |
246 TEST3(data, jj); |
213 test(!biter.NextL()); |
247 TEST(!biter.NextL()); |
214 test(biter.LastL()); |
248 TEST(biter.LastL()); |
215 test(biter.AtL()==jj); |
249 TEST3(biter.AtL(), jj); |
216 test(!biter.PreviousL()); |
250 TEST(!biter.PreviousL()); |
217 TPagedSetRIter<TUint32> riter(set); |
251 TPagedSetRIter<TUint32> riter(set); |
218 test(riter.ResetL()); |
252 TEST(riter.ResetL()); |
219 test(riter.AtL()==jj); |
253 TEST3(riter.AtL(), jj); |
220 riter.ExtractAtL(data); |
254 riter.ExtractAtL(data); |
221 test(data == jj); |
255 TEST3(data, jj); |
222 test(!riter.NextL()); |
256 TEST(!riter.NextL()); |
223 |
257 |
224 //* test(set.DeleteL(jj)); |
258 //* TEST(set.DeleteL(jj)); |
225 set.DeleteL(jj); |
259 set.DeleteL(jj); |
226 test(!iter.ResetL()); |
260 TEST(!iter.ResetL()); |
227 test(set.Count()==0); |
261 TEST2(set.Count(), 0); |
228 |
|
229 test.End(); |
|
230 |
262 |
231 CleanupStack::PopAndDestroy(); |
263 CleanupStack::PopAndDestroy(); |
232 } |
264 } |
233 /** |
265 /** |
234 @SYMTestCaseID SYSLIB-STORE-CT-1123 |
266 @SYMTestCaseID SYSLIB-STORE-CT-1123 |
261 @SYMTestExpectedResults Test must not fail |
293 @SYMTestExpectedResults Test must not fail |
262 @SYMREQ REQ0000 |
294 @SYMREQ REQ0000 |
263 */ |
295 */ |
264 LOCAL_C void test3bL(RReadStream& aStream,MPagePool *aPool,TInt aCount) |
296 LOCAL_C void test3bL(RReadStream& aStream,MPagePool *aPool,TInt aCount) |
265 { |
297 { |
266 test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1124 ")); |
298 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1124")); |
267 TPagedSetToken token; |
299 TPagedSetToken token; |
268 aStream>>token; |
300 aStream>>token; |
269 TPagedSet<TInt32> set(token); |
301 TPagedSet<TInt32> set(token); |
270 //* set.Connect(aPool,TBtree::EQosFastest); |
302 //* set.Connect(aPool,TBtree::EQosFastest); |
271 set.Connect(aPool); |
303 set.Connect(aPool); |
272 |
304 |
273 test(set.Count()==aCount); |
305 TEST2(set.Count(), aCount); |
274 for (TInt ii=0;ii<aCount;ii++) |
306 for (TInt ii=0;ii<aCount;ii++) |
275 { |
307 { |
276 TInt32 it=ii; |
308 TInt32 it=ii; |
277 //* test(set.DeleteL(it)); |
309 //* TEST(set.DeleteL(it)); |
278 set.DeleteL(it); |
310 set.DeleteL(it); |
279 } |
311 } |
280 test(set.Count()==0); |
312 TEST2(set.Count(), 0); |
281 } |
313 } |
282 |
314 |
283 /** |
315 /** |
284 @SYMTestCaseID SYSLIB-STORE-CT-1125 |
316 @SYMTestCaseID SYSLIB-STORE-CT-1125 |
285 @SYMTestCaseDesc Streaming sets test |
317 @SYMTestCaseDesc Streaming sets test |
291 LOCAL_C void test3L() |
323 LOCAL_C void test3L() |
292 { |
324 { |
293 const TInt KEntryCount=1000; |
325 const TInt KEntryCount=1000; |
294 MPagePool *pool=CMemPagePool::NewLC(); |
326 MPagePool *pool=CMemPagePool::NewLC(); |
295 TUint8 stream[0x40]; |
327 TUint8 stream[0x40]; |
296 test.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1125 Build set and stream out ")); |
328 TheTest.Printf(_L("Build set and stream out\r\n")); |
297 RMemWriteStream out(stream,sizeof(stream)); |
329 RMemWriteStream out(stream,sizeof(stream)); |
298 test3aL(out,pool,KEntryCount); |
330 test3aL(out,pool,KEntryCount); |
299 test.Next(_L("Stream in and test set ")); |
331 TheTest.Printf(_L("Stream in and test set\r\n")); |
300 RMemReadStream in(stream,sizeof(stream)); |
332 RMemReadStream in(stream,sizeof(stream)); |
301 test3bL(in,pool,KEntryCount); |
333 test3bL(in,pool,KEntryCount); |
302 test.End(); |
|
303 CleanupStack::PopAndDestroy(); |
334 CleanupStack::PopAndDestroy(); |
304 } |
335 } |
305 |
336 |
306 class CPersistentStoreHelper: public CPersistentStore |
337 class CPersistentStoreHelper: public CPersistentStore |
307 { |
338 { |
308 virtual MStreamBuf* DoReadL(TStreamId /*anId*/) const |
339 private: |
|
340 virtual MStreamBuf* DoReadL(TStreamId) const |
309 { |
341 { |
310 return NULL; |
342 return NULL; |
311 } |
343 } |
312 virtual MStreamBuf* DoCreateL(TStreamId& /*anId*/) |
344 virtual MStreamBuf* DoCreateL(TStreamId&) |
313 { |
345 { |
314 return NULL; |
346 return NULL; |
315 } |
347 } |
316 void Help() |
|
317 { |
|
318 //just do nothing |
|
319 return; |
|
320 } |
|
321 }; |
348 }; |
|
349 |
|
350 void DoBiITerMultiSetTestL(TPagedSetBiIter<TInt32>& aIter, TInt aCount) |
|
351 { |
|
352 TInt count = 0; |
|
353 TBool rc = aIter.FirstL(); |
|
354 TEST(rc); |
|
355 ++count; |
|
356 while(aIter.NextL()) |
|
357 { |
|
358 ++count; |
|
359 } |
|
360 TEST2(count, aCount); |
|
361 |
|
362 count = 0; |
|
363 rc = aIter.LastL(); |
|
364 TEST(rc); |
|
365 ++count; |
|
366 while(aIter.PreviousL()) |
|
367 { |
|
368 ++count; |
|
369 } |
|
370 TEST2(count, aCount); |
|
371 } |
|
372 |
|
373 void DoRIterMultiSetTestL(TPagedSetRIter<TInt32> aIter, TInt aCount) |
|
374 { |
|
375 TInt count = 0; |
|
376 TBool rc = aIter.ResetL(); |
|
377 TEST(rc); |
|
378 ++count; |
|
379 while(aIter.NextL()) |
|
380 { |
|
381 ++count; |
|
382 } |
|
383 TEST2(count, aCount); |
|
384 } |
|
385 |
|
386 void DoRIterAnyMultiSetTestL(TPagedSetRIter<TAny> aIter, TInt aCount) |
|
387 { |
|
388 TInt count = 0; |
|
389 TBool rc = aIter.ResetL(); |
|
390 TEST(rc); |
|
391 ++count; |
|
392 while(aIter.NextL()) |
|
393 { |
|
394 ++count; |
|
395 } |
|
396 TEST2(count, aCount); |
|
397 } |
|
398 |
|
399 void DoIterMultiSetTestL(TPagedSetIter<TInt32> aIter, TInt aCount) |
|
400 { |
|
401 TInt count = 0; |
|
402 TBool rc = aIter.ResetL(); |
|
403 TEST(rc); |
|
404 ++count; |
|
405 while(aIter.NextL()) |
|
406 { |
|
407 ++count; |
|
408 } |
|
409 TEST2(count, aCount); |
|
410 } |
|
411 |
|
412 void DoIterAnyMultiSetTestL(TPagedSetIter<TAny> aIter, TInt aCount) |
|
413 { |
|
414 TInt count = 0; |
|
415 TBool rc = aIter.ResetL(); |
|
416 TEST(rc); |
|
417 ++count; |
|
418 while(aIter.NextL()) |
|
419 { |
|
420 ++count; |
|
421 } |
|
422 TEST2(count, aCount); |
|
423 } |
322 |
424 |
323 /** |
425 /** |
324 @SYMTestCaseID PDS-STORE-CT-4015 |
426 @SYMTestCaseID PDS-STORE-CT-4015 |
325 @SYMTestCaseDesc Test untested APIs of TPagedMultiset and TPagedSetToken |
427 @SYMTestCaseDesc Test untested APIs of TPagedMultiset and TPagedSetToken |
326 @SYMTestPriority High |
428 @SYMTestPriority High |
333 */ |
435 */ |
334 LOCAL_C void test4L() |
436 LOCAL_C void test4L() |
335 { |
437 { |
336 const TInt KEntryCount=200; |
438 const TInt KEntryCount=200; |
337 |
439 |
338 test.Start(_L(" @SYMTestCaseID:PDS-STORE-CT-4015 Test untested APIs ")); |
440 TheTest.Printf(_L("Test untested APIs\r\n")); |
339 |
441 |
340 TInt32 it=0; |
442 TInt32 it=0; |
341 TPagedMultiset<TInt32> set; |
443 TPagedMultiset<TInt32> set; |
342 set.Connect(CMemPagePool::NewLC()); |
444 set.Connect(CMemPagePool::NewLC()); |
343 test.Next(_L("Duplicates")); |
445 TheTest.Printf(_L("Duplicates\r\n")); |
344 TInt ii, err; |
446 TInt ii, err; |
345 for (ii=0;ii<KEntryCount;++ii) |
447 for (ii=0;ii<KEntryCount;++ii) |
346 { |
448 { |
347 TRAP(err, set.InsertL(it)); |
449 TRAP(err, set.InsertL(it)); |
348 test(err==KErrNone); |
450 TEST2(err, KErrNone); |
349 } |
451 } |
350 test(set.Count()==KEntryCount); |
452 TEST2(set.Count(), KEntryCount); |
351 TBool rc = set.IsEmpty(); |
453 TBool rc = set.IsEmpty(); |
352 test(!rc); |
454 TEST(!rc); |
|
455 |
|
456 TPagedSetBiIter<TInt32> biIter(set); |
|
457 DoBiITerMultiSetTestL(biIter, set.Count()); |
|
458 |
|
459 TPagedSetRIter<TInt32> rIter(set); |
|
460 DoRIterMultiSetTestL(rIter, set.Count()); |
|
461 TPagedSetRIter<TAny> rIter2(set); |
|
462 DoRIterAnyMultiSetTestL(rIter2, set.Count()); |
|
463 |
|
464 TPagedSetIter<TInt32> iter(set); |
|
465 DoIterMultiSetTestL(iter, set.Count()); |
|
466 TPagedSetIter<TAny> iter2(set); |
|
467 DoIterAnyMultiSetTestL(iter2, set.Count()); |
|
468 |
|
469 TPagedSetToken token = set.Token(); |
|
470 TPagedMultiset<TInt32> multiSet2(token); |
|
471 TEST2(multiSet2.Count(), set.Count()); |
|
472 TPagedMultiset<TAny> multiSet3(token, sizeof(TInt32)); |
|
473 TEST2(multiSet3.Count(), set.Count()); |
|
474 TPagedMultiset<TAny> multiSet4(sizeof(TInt32)); |
|
475 TEST2(multiSet4.Count(), 0); |
|
476 TPagedSet<TAny> set5(token, sizeof(TInt32)); |
|
477 TEST2(set5.Count(), set.Count()); |
|
478 TPagedSet<TAny> set6(sizeof(TInt32)); |
|
479 TEST2(set6.Count(), 0); |
|
480 |
353 set.MarkDirty(); |
481 set.MarkDirty(); |
354 set.MarkCurrent(); |
482 set.MarkCurrent(); |
355 TRAP(err, set.ContainsL(it)); |
483 TRAP(err, set.ContainsL(it)); |
356 test(err==KErrNone); |
484 TEST2(err, KErrNone); |
357 TRAP(err, set.InsertL(it)); |
485 TRAP(err, set.InsertL(it)); |
358 test(err==KErrNone); |
486 TEST2(err, KErrNone); |
359 |
487 |
360 for (ii=0;ii<KEntryCount;++ii) |
488 for (ii=0;ii<KEntryCount;++ii) |
361 { |
489 { |
362 TRAP(err, set.DeleteL(it)); |
490 TRAP(err, set.DeleteL(it)); |
363 test(err==KErrNone); |
491 TEST2(err, KErrNone); |
364 } |
492 } |
365 |
493 |
366 TRAP(err, set.ContainsL(it)); |
494 TRAP(err, set.ContainsL(it)); |
367 test(err==KErrNone); |
495 TEST2(err, KErrNone); |
368 TRAP(err, set.DeleteL(it)); |
496 TRAP(err, set.DeleteL(it)); |
369 test(err==KErrNone); |
497 TEST2(err, KErrNone); |
370 test(set.Count()==0); |
498 TEST2(set.Count(), 0); |
371 |
499 |
372 test.Next(_L("Calling MPagePool::Delete")); |
500 TheTest.Printf(_L("Calling MPagePool::Delete\r\n")); |
373 CMemPagePool* mpp = CMemPagePool::NewLC(); |
501 CMemPagePool* mpp = CMemPagePool::NewLC(); |
374 const TPageAbandonFunction& nopFunc = mpp->AcquireL(); |
502 const TPageAbandonFunction& nopFunc = mpp->AcquireL(); |
375 test(&nopFunc != NULL); |
503 TEST(&nopFunc != NULL); |
376 TAny* any = mpp->AllocL(); |
504 TAny* any = mpp->AllocL(); |
377 TPageRef pref; |
505 TPageRef pref; |
378 pref = mpp->AssignL(any, EPageReclaimable); |
506 pref = mpp->AssignL(any, EPageReclaimable); |
379 mpp->MPagePool::Delete(pref); |
507 mpp->MPagePool::Delete(pref); |
380 CleanupStack::PopAndDestroy(); |
508 CleanupStack::PopAndDestroy(); |
381 |
509 |
382 test.Next(_L("CPersistentStore DoSetRootL")); |
510 TheTest.Printf(_L("CPersistentStore::DoSetRootL\r\n")); |
383 CPersistentStoreHelper* ps = new (ELeave) CPersistentStoreHelper(); |
511 CPersistentStoreHelper* ps = new (ELeave) CPersistentStoreHelper(); |
384 CleanupStack::PushL(ps); |
512 CleanupStack::PushL(ps); |
385 ps->SetRootL(KNullStreamId); |
513 ps->SetRootL(KNullStreamId); |
386 CleanupStack::PopAndDestroy(); |
514 TRAP(err, ps->ExtendL()); |
387 |
515 TEST2(err, KErrNotSupported); |
388 test.Next(_L("HDirectStoreBuf::DoSeekL calls")); |
516 TRAP(err, ps->DeleteL(TStreamId(1u))); |
|
517 TEST2(err, KErrNotSupported); |
|
518 CleanupStack::PopAndDestroy(ps); |
|
519 |
|
520 TheTest.Printf(_L("HDirectStoreBuf::DoSeekL calls\r\n")); |
389 HBufC8* buf = HBufC8::NewLC(1024); |
521 HBufC8* buf = HBufC8::NewLC(1024); |
390 RDesWriteStream wts; |
522 RDesWriteStream wts; |
391 |
523 |
392 TPtr8 ptr(buf->Des()); |
524 TPtr8 ptr(buf->Des()); |
393 wts.Open(ptr); |
525 wts.Open(ptr); |
402 |
534 |
403 CEmbeddedStore* estor = CEmbeddedStore::FromLC(rts); |
535 CEmbeddedStore* estor = CEmbeddedStore::FromLC(rts); |
404 RStoreReadStream rstream; |
536 RStoreReadStream rstream; |
405 rstream.OpenL(*estor, id); |
537 rstream.OpenL(*estor, id); |
406 TStreamPos pos = rstream.Source()->SeekL(MStreamBuf::ERead, 5); |
538 TStreamPos pos = rstream.Source()->SeekL(MStreamBuf::ERead, 5); |
407 test(pos.Offset() == 5); |
539 TEST2(pos.Offset(), 5); |
408 rts.Close(); |
540 rts.Close(); |
409 rstream.Close(); |
541 rstream.Close(); |
410 CleanupStack::PopAndDestroy(2); |
542 CleanupStack::PopAndDestroy(2); |
411 |
543 |
412 test.Next(_L("Calling TEmpty Constructor")); |
544 TheTest.Printf(_L("Calling TEmpty Constructor\r\n")); |
413 TPagedSetToken set2(TBtreeToken::EEmpty); |
545 TPagedSetToken set3(TBtreeToken::EEmpty); |
414 test( set2.Count() == 0); |
546 TEST2( set3.Count(), 0); |
415 |
547 |
416 test.Next(_L("Set function")); |
548 TheTest.Printf(_L("Set function\r\n")); |
417 set.Set(set2); |
549 set.Set(set3); |
418 const TPagedSetToken& pst = set.Token(); |
550 const TPagedSetToken& pst = set.Token(); |
419 test(pst.Count() == set2.Count()); |
551 TEST2(pst.Count(), set3.Count()); |
420 |
552 |
421 test.End(); |
|
422 CleanupStack::PopAndDestroy(); |
553 CleanupStack::PopAndDestroy(); |
423 } |
554 } |
424 |
555 |
425 /** |
556 /** |
426 @SYMTestCaseID PDS-STORE-CT-4065 |
557 @SYMTestCaseID PDS-STORE-CT-4065 |
477 { |
608 { |
478 CMemPagePool* pool = CMemPagePool::NewLC(); |
609 CMemPagePool* pool = CMemPagePool::NewLC(); |
479 |
610 |
480 TBtreeToken token(TBtreeToken::EEmpty); |
611 TBtreeToken token(TBtreeToken::EEmpty); |
481 TBool rc = token.IsEmpty(); |
612 TBool rc = token.IsEmpty(); |
482 test(rc); |
613 TEST(rc); |
483 rc = token.IsIntact(); |
614 rc = token.IsIntact(); |
484 test(rc); |
615 TEST(rc); |
485 |
616 |
486 TBtreeFix<TTestEntry, TInt> bentry(token, EBtreeSecure); |
617 TBtreeFix<TTestEntry, TInt> bentry(token, EBtreeSecure); |
487 TBtreeKey bkey(sizeof(TInt)); |
618 TBtreeKey bkey(sizeof(TInt)); |
488 bentry.Connect(pool, &bkey); |
619 bentry.Connect(pool, &bkey); |
489 |
620 |
490 TBtreePos bpos; |
621 TBtreePos bpos; |
491 rc = bentry.FindL(bpos, 1); |
622 rc = bentry.FindL(bpos, 1); |
492 test(!rc); |
623 TEST(!rc); |
493 rc = bentry.InsertL(bpos, TTestEntry(1, 101)); |
624 rc = bentry.InsertL(bpos, TTestEntry(1, 101)); |
494 test(rc); |
625 TEST(rc); |
495 rc = bentry.FindL(bpos, 1); |
626 rc = bentry.FindL(bpos, 1); |
496 test(rc); |
627 TEST(rc); |
497 TTestEntry entry1 = bentry.AtL(bpos); |
628 TTestEntry entry1 = bentry.AtL(bpos); |
498 test(entry1.iKey == 1 && entry1.iData == 101); |
629 TEST(entry1.iKey == 1 && entry1.iData == 101); |
499 const void* key = bkey.Key(&entry1); |
630 const void* key = bkey.Key(&entry1); |
500 TInt keyVal = *((const TInt*)key); |
631 TInt keyVal = *((const TInt*)key); |
501 test.Printf(_L("keyVal=%d\n"), keyVal); |
632 TheTest.Printf(_L("keyVal=%d\r\n"), keyVal); |
502 |
633 |
503 rc = bentry.InsertL(bpos, TTestEntry(3, 103)); |
634 rc = bentry.InsertL(bpos, TTestEntry(3, 103)); |
504 test(rc); |
635 TEST(rc); |
505 rc = bentry.InsertL(bpos, TTestEntry(2, 102)); |
636 rc = bentry.InsertL(bpos, TTestEntry(2, 102)); |
506 test(rc); |
637 TEST(rc); |
507 |
638 |
508 rc = bentry.FindL(bpos, 2); |
639 rc = bentry.FindL(bpos, 2); |
509 test(rc); |
640 TEST(rc); |
510 TTestEntry entry2; |
641 TTestEntry entry2; |
511 bentry.ExtractAtL(bpos, entry2); |
642 bentry.ExtractAtL(bpos, entry2); |
512 test(entry2.iKey == 2 && entry2.iData == 102); |
643 TEST(entry2.iKey == 2 && entry2.iData == 102); |
513 |
644 |
514 rc = bentry.FindL(bpos, 3); |
645 rc = bentry.FindL(bpos, 3); |
515 test(rc); |
646 TEST(rc); |
516 TTestEntry entry3; |
647 TTestEntry entry3; |
517 bentry.ExtractAtL(bpos, entry3); |
648 bentry.ExtractAtL(bpos, entry3); |
518 test(entry3.iKey == 3 && entry3.iData == 103); |
649 TEST(entry3.iKey == 3 && entry3.iData == 103); |
519 |
650 |
520 //============================================== |
651 //============================================== |
521 |
652 |
522 TBtreeMark bmark; |
653 TBtreeMark bmark; |
523 if(bentry.ResetL(bmark)) |
654 if(bentry.ResetL(bmark)) |
524 { |
655 { |
525 do |
656 do |
526 { |
657 { |
527 TTestEntry entry = bentry.AtL(bmark); |
658 TTestEntry entry = bentry.AtL(bmark); |
528 test.Printf(_L("AtL(): entry.iKey=%d, entry.iData=%d\n"), entry.iKey, entry.iData); |
659 TheTest.Printf(_L("AtL(): entry.iKey=%d, entry.iData=%d\r\n"), entry.iKey, entry.iData); |
529 bentry.ExtractAtL(bmark, entry); |
660 bentry.ExtractAtL(bmark, entry); |
530 test.Printf(_L("ExtractAtL(): entry.iKey=%d, entry.iData=%d\n"), entry.iKey, entry.iData); |
661 TheTest.Printf(_L("ExtractAtL(): entry.iKey=%d, entry.iData=%d\r\n"), entry.iKey, entry.iData); |
531 }while(bentry.NextL(bmark)); |
662 }while(bentry.NextL(bmark)); |
532 } |
663 } |
533 |
664 |
534 rc = bentry.NextL(bmark); |
665 rc = bentry.NextL(bmark); |
535 test(!rc); |
666 TEST(!rc); |
536 |
667 |
537 //============================================== |
668 //============================================== |
538 |
669 |
539 rc = bentry.DeleteL(2); |
670 rc = bentry.DeleteL(2); |
540 test(rc); |
671 TEST(rc); |
541 rc = bentry.FindL(bpos, 2); |
672 rc = bentry.FindL(bpos, 2); |
542 test(!rc); |
673 TEST(!rc); |
543 rc = bentry.FindL(bpos, 3); |
674 rc = bentry.FindL(bpos, 3); |
544 test(rc); |
675 TEST(rc); |
545 TRAPD(err, bentry.DeleteAtL(bpos)); |
676 TRAPD(err, bentry.DeleteAtL(bpos)); |
546 test(err == KErrNone); |
677 TEST(err == KErrNone); |
547 rc = bentry.FindL(bpos, 3); |
678 rc = bentry.FindL(bpos, 3); |
548 test(!rc); |
679 TEST(!rc); |
549 |
680 |
550 bentry.MarkDirty(); |
681 bentry.MarkDirty(); |
551 rc = bentry.IsDirty(); |
682 rc = bentry.IsDirty(); |
552 test(rc); |
683 TEST(rc); |
553 bentry.MarkCurrent(); |
684 bentry.MarkCurrent(); |
554 rc = bentry.IsDirty(); |
685 rc = bentry.IsDirty(); |
555 test(!rc); |
686 TEST(!rc); |
556 |
687 |
557 bentry.ClearL(); |
688 bentry.ClearL(); |
558 CleanupStack::PopAndDestroy(pool); |
689 CleanupStack::PopAndDestroy(pool); |
559 } |
690 } |
560 |
691 |
561 LOCAL_C void doMainL() |
692 LOCAL_C void DoTestsL() |
562 { |
693 { |
563 test.Start(_L("Basic operations")); |
694 TheTest.Start(_L("@SYMTestCaseID:SYSLIB-STORE-CT-1121 Basic operations")); |
564 test1L(); |
695 test1L(); |
565 test.Next(_L("Large set TUint32")); |
696 TheTest.Next(_L("@SYMTestCaseID:SYSLIB-STORE-CT-1122 Large set TUint32")); |
566 test2L(); |
697 test2L(); |
567 test.Next(_L("Tokens and streaming")); |
698 TheTest.Next(_L("@SYMTestCaseID:SYSLIB-STORE-CT-1125 Tokens and streaming")); |
568 test3L(); |
699 test3L(); |
569 test.Next(_L("Forgotten API")); |
700 TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4015 Forgotten API")); |
570 test4L(); |
701 test4L(); |
571 test.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4065: TStreamPos test")); |
702 TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4065: TStreamPos test")); |
572 StreamPosTest(); |
703 StreamPosTest(); |
573 test.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4066: TBtreeFix test")); |
704 TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4066: TBtreeFix test")); |
574 BTreeFixTestL(); |
705 BTreeFixTestL(); |
575 test.End(); |
706 } |
576 } |
707 |
577 |
708 TInt E32Main() |
578 LOCAL_C void setupCleanup() |
709 { |
579 // |
710 TheTest.Title(); |
580 // Initialise the cleanup stack. |
711 |
581 // |
712 CTrapCleanup* tc = CTrapCleanup::New(); |
582 { |
713 TheTest(tc != NULL); |
583 TheTrapCleanup=CTrapCleanup::New(); |
714 |
584 test(TheTrapCleanup!=NULL); |
715 __UHEAP_MARK; |
585 TRAPD(r,\ |
716 |
586 {\ |
717 TRAPD(err, DoTestsL()); |
587 for (TInt i=KTestCleanupStack;i>0;i--)\ |
718 TEST2(err, KErrNone); |
588 CleanupStack::PushL((TAny*)1);\ |
719 |
589 test(r==KErrNone);\ |
720 __UHEAP_MARKEND; |
590 CleanupStack::Pop(KTestCleanupStack);\ |
721 |
591 }); |
722 User::Heap().Check(); |
592 test(r==KErrNone); |
723 |
593 } |
724 TheTest.End(); |
594 |
725 TheTest.Close(); |
595 GLDEF_C TInt E32Main() |
726 |
596 { |
727 delete tc; |
597 test.Title(); |
728 |
598 setupCleanup(); |
729 return KErrNone; |
599 __UHEAP_MARK; |
730 } |
600 // |
731 |
601 TRAPD(r,doMainL()); |
|
602 test(r==KErrNone); |
|
603 // |
|
604 __UHEAP_MARKEND; |
|
605 delete TheTrapCleanup; |
|
606 test.Close(); |
|
607 return 0; |
|
608 } |
|
609 |
|