sl@0
|
1 |
// Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <s32cont.h>
|
sl@0
|
17 |
#include <s32file.h>
|
sl@0
|
18 |
#include <s32crypt.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include <pbe.h>
|
sl@0
|
21 |
#include "UP_STD.H"
|
sl@0
|
22 |
|
sl@0
|
23 |
const TInt KTestCleanupStack=0x20;
|
sl@0
|
24 |
|
sl@0
|
25 |
// This is a path specification and should not be used as is
|
sl@0
|
26 |
_LIT(KFileLocationSpec, "Z:\\STOR-TST\\T_SPAGE.DAT");
|
sl@0
|
27 |
_LIT(KPageFilePath, "C:\\TestSTOR\\T_SPAGEFILE.PAG");
|
sl@0
|
28 |
_LIT(KPageFilePathOnly, "C:\\TestSTOR\\");
|
sl@0
|
29 |
|
sl@0
|
30 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
31 |
LOCAL_D RTest TheTest(_L("t_storpage"));
|
sl@0
|
32 |
LOCAL_D RFs TheFs;
|
sl@0
|
33 |
LOCAL_D CFileStore* TheStore;
|
sl@0
|
34 |
|
sl@0
|
35 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
36 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
37 |
//Tests macros and functions.
|
sl@0
|
38 |
//If (!aValue) then the test will be panicked, the test data files will be deleted.
|
sl@0
|
39 |
static void Check(TInt aValue, TInt aLine)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
if(!aValue)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
TheTest.Printf(_L("*** Boolean expression evaluated to false!\r\n"));
|
sl@0
|
44 |
TheTest(EFalse, aLine);
|
sl@0
|
45 |
}
|
sl@0
|
46 |
}
|
sl@0
|
47 |
//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
|
sl@0
|
48 |
static void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
if(aValue != aExpected)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
53 |
TheTest(EFalse, aLine);
|
sl@0
|
54 |
}
|
sl@0
|
55 |
}
|
sl@0
|
56 |
//Use these to test conditions.
|
sl@0
|
57 |
#define TEST(arg) ::Check((arg), __LINE__)
|
sl@0
|
58 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
59 |
|
sl@0
|
60 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
61 |
|
sl@0
|
62 |
/**
|
sl@0
|
63 |
@SYMTestCaseID SYSLIB-STORE-CT-1178
|
sl@0
|
64 |
@SYMTestCaseDesc TPagedSet functionality test
|
sl@0
|
65 |
@SYMTestPriority High
|
sl@0
|
66 |
@SYMTestActions Tests for insert,delete,contains,with and without duplicates operations
|
sl@0
|
67 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
68 |
@SYMREQ REQ0000
|
sl@0
|
69 |
*/
|
sl@0
|
70 |
LOCAL_C void test1L(MPagePool& aPagePool)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
const TInt KEntryCount=200;
|
sl@0
|
73 |
|
sl@0
|
74 |
TPagedSet<TInt32> set;
|
sl@0
|
75 |
set.Connect(&aPagePool);
|
sl@0
|
76 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1178 Insertion & Deletion "));
|
sl@0
|
77 |
|
sl@0
|
78 |
TInt32 it=0;
|
sl@0
|
79 |
set.InsertL(it);
|
sl@0
|
80 |
TEST2(set.Count(), 1);
|
sl@0
|
81 |
TRAPD(r,set.InsertL(it));
|
sl@0
|
82 |
TEST2(r, KErrAlreadyExists);
|
sl@0
|
83 |
TEST2(set.Count(), 1);
|
sl@0
|
84 |
TEST(set.ContainsL(it));
|
sl@0
|
85 |
set.DeleteL(it);
|
sl@0
|
86 |
TEST2(set.Count(), 0);
|
sl@0
|
87 |
TRAP(r,set.DeleteL(it));
|
sl@0
|
88 |
TEST2(r, KErrNotFound);
|
sl@0
|
89 |
TEST2(set.Count(), 0);
|
sl@0
|
90 |
TEST(!set.ContainsL(it));
|
sl@0
|
91 |
|
sl@0
|
92 |
TheTest.Next(_L("No duplicates"));
|
sl@0
|
93 |
TInt ii;
|
sl@0
|
94 |
for (ii=0;ii<KEntryCount;++ii)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
it=ii;
|
sl@0
|
97 |
set.InsertL(it);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
for (ii=0;ii<KEntryCount;++ii)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
it=ii;
|
sl@0
|
102 |
TEST(set.ContainsL(it));
|
sl@0
|
103 |
}
|
sl@0
|
104 |
TEST2(set.Count(), KEntryCount);
|
sl@0
|
105 |
|
sl@0
|
106 |
TheTest.Next(_L("Empty the set"));
|
sl@0
|
107 |
set.ClearL();
|
sl@0
|
108 |
TEST2(set.Count(), 0);
|
sl@0
|
109 |
for (ii=0;ii<KEntryCount;++ii)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
it=ii;
|
sl@0
|
112 |
TEST(!set.ContainsL(it));
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
TheTest.End();
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
struct TTest
|
sl@0
|
119 |
{
|
sl@0
|
120 |
inline TTest() {Mem::FillZ(this,sizeof(*this));}
|
sl@0
|
121 |
TUint32 iVal;
|
sl@0
|
122 |
TUint32 iPadding[14];
|
sl@0
|
123 |
};
|
sl@0
|
124 |
|
sl@0
|
125 |
/**
|
sl@0
|
126 |
@SYMTestCaseID SYSLIB-STORE-CT-1179
|
sl@0
|
127 |
@SYMTestCaseDesc Tests for large set of TUint32
|
sl@0
|
128 |
@SYMTestPriority High
|
sl@0
|
129 |
@SYMTestActions Tests for inserting,contains,iteration,deletion operations
|
sl@0
|
130 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
131 |
@SYMREQ REQ0000
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
LOCAL_C void test2L(MPagePool& aPagePool)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
const TInt KEntryCount=500;
|
sl@0
|
136 |
|
sl@0
|
137 |
TPagedSet<TTest> set;
|
sl@0
|
138 |
set.Connect(&aPagePool);
|
sl@0
|
139 |
TTest item;
|
sl@0
|
140 |
|
sl@0
|
141 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1179 Add items "));
|
sl@0
|
142 |
TUint32 jj=0;
|
sl@0
|
143 |
TInt32 ii;
|
sl@0
|
144 |
for (ii=KEntryCount;ii>0;--ii)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
jj=(jj+17)%KEntryCount;
|
sl@0
|
147 |
item.iVal=jj;
|
sl@0
|
148 |
set.InsertL(item);
|
sl@0
|
149 |
}
|
sl@0
|
150 |
TEST2(set.Count(), KEntryCount);
|
sl@0
|
151 |
|
sl@0
|
152 |
TheTest.Next(_L("Check contents"));
|
sl@0
|
153 |
for (ii=0;ii<KEntryCount;++ii)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
item.iVal=ii;
|
sl@0
|
156 |
TEST(set.ContainsL(item));
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
TheTest.Next(_L("Iterate over items"));
|
sl@0
|
160 |
TUint8 *checkMap=(TUint8*)User::AllocLC(KEntryCount);
|
sl@0
|
161 |
Mem::FillZ(checkMap,KEntryCount);
|
sl@0
|
162 |
TPagedSetIter<TTest> iter(set);
|
sl@0
|
163 |
if (iter.ResetL())
|
sl@0
|
164 |
do ++checkMap[iter.AtL().iVal]; while (iter.NextL());
|
sl@0
|
165 |
for (ii=0;ii<KEntryCount;++ii)
|
sl@0
|
166 |
TEST2(checkMap[ii], 1);
|
sl@0
|
167 |
CleanupStack::PopAndDestroy();
|
sl@0
|
168 |
|
sl@0
|
169 |
TheTest.Next(_L("Delete items"));
|
sl@0
|
170 |
jj=0;
|
sl@0
|
171 |
for (ii=KEntryCount;ii>KEntryCount/2;--ii)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
jj=(jj+17)%KEntryCount;
|
sl@0
|
174 |
item.iVal=jj;
|
sl@0
|
175 |
set.DeleteL(item);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
TEST2(set.Count(), KEntryCount/2);
|
sl@0
|
178 |
|
sl@0
|
179 |
TheTest.Next(_L("Check contents"));
|
sl@0
|
180 |
for (;ii>0;--ii)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
jj=(jj+17)%KEntryCount;
|
sl@0
|
183 |
item.iVal=jj;
|
sl@0
|
184 |
TEST(set.ContainsL(item));
|
sl@0
|
185 |
}
|
sl@0
|
186 |
jj=0;
|
sl@0
|
187 |
for (ii=KEntryCount;ii>KEntryCount/2;--ii)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
jj=(jj+17)%KEntryCount;
|
sl@0
|
190 |
item.iVal=jj;
|
sl@0
|
191 |
TEST(!set.ContainsL(item));
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
TheTest.Next(_L("Delete items"));
|
sl@0
|
195 |
for (;ii>1;--ii)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
jj=(jj+17)%KEntryCount;
|
sl@0
|
198 |
item.iVal=jj;
|
sl@0
|
199 |
set.DeleteL(item);
|
sl@0
|
200 |
}
|
sl@0
|
201 |
TEST2(set.Count(), 1);
|
sl@0
|
202 |
|
sl@0
|
203 |
TheTest.Next(_L("Check contents"));
|
sl@0
|
204 |
jj=(jj+17)%KEntryCount;
|
sl@0
|
205 |
TPagedSetBiIter<TTest> biter(set);
|
sl@0
|
206 |
TEST(biter.FirstL());
|
sl@0
|
207 |
TEST2(biter.AtL().iVal, jj);
|
sl@0
|
208 |
TEST(!biter.NextL());
|
sl@0
|
209 |
TEST(biter.LastL());
|
sl@0
|
210 |
TEST2(biter.AtL().iVal ,jj);
|
sl@0
|
211 |
TEST(!biter.PreviousL());
|
sl@0
|
212 |
TPagedSetRIter<TTest> riter(set);
|
sl@0
|
213 |
TEST(riter.ResetL());
|
sl@0
|
214 |
TEST2(riter.AtL().iVal, jj);
|
sl@0
|
215 |
TEST(!riter.NextL());
|
sl@0
|
216 |
|
sl@0
|
217 |
item.iVal=jj;
|
sl@0
|
218 |
set.DeleteL(item);
|
sl@0
|
219 |
TEST(!iter.ResetL());
|
sl@0
|
220 |
TEST2(set.Count(), 0);
|
sl@0
|
221 |
|
sl@0
|
222 |
TheTest.End();
|
sl@0
|
223 |
}
|
sl@0
|
224 |
|
sl@0
|
225 |
/**
|
sl@0
|
226 |
@SYMTestCaseID SYSLIB-STORE-CT-1180
|
sl@0
|
227 |
@SYMTestCaseDesc Streaming tests
|
sl@0
|
228 |
@SYMTestPriority High
|
sl@0
|
229 |
@SYMTestActions Tests for read and write operations on the streams
|
sl@0
|
230 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
231 |
@SYMREQ REQ0000
|
sl@0
|
232 |
*/
|
sl@0
|
233 |
LOCAL_C void test3L(RStorePagePool& aPool)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
const TInt KEntryCount=1000;
|
sl@0
|
236 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1180 Build set and stream out "));
|
sl@0
|
237 |
aPool.Create(*TheStore);
|
sl@0
|
238 |
TBool rc = aPool.HasAvailable();
|
sl@0
|
239 |
TEST(!rc);
|
sl@0
|
240 |
rc = aPool.IsEmpty();
|
sl@0
|
241 |
TEST(rc);
|
sl@0
|
242 |
TStorePagePoolToken token2(TStorePagePoolToken::EEmpty);
|
sl@0
|
243 |
token2 = aPool.Token();
|
sl@0
|
244 |
rc = token2.IsEmpty();
|
sl@0
|
245 |
TEST(rc);
|
sl@0
|
246 |
rc = token2.HasAvailable();
|
sl@0
|
247 |
TEST(!rc);
|
sl@0
|
248 |
|
sl@0
|
249 |
TPagedSet<TInt32> set1;
|
sl@0
|
250 |
set1.Connect(&aPool);
|
sl@0
|
251 |
|
sl@0
|
252 |
TInt ii;
|
sl@0
|
253 |
for (ii=0;ii<KEntryCount;ii++)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
TInt32 it=ii;
|
sl@0
|
256 |
set1.InsertL(it);
|
sl@0
|
257 |
}
|
sl@0
|
258 |
aPool.FlushL();
|
sl@0
|
259 |
|
sl@0
|
260 |
RStoreWriteStream out;
|
sl@0
|
261 |
TStreamId id=out.CreateLC(*TheStore);
|
sl@0
|
262 |
out<<aPool.Token();
|
sl@0
|
263 |
out<<set1.Token();
|
sl@0
|
264 |
out.CommitL();
|
sl@0
|
265 |
CleanupStack::PopAndDestroy(); // out
|
sl@0
|
266 |
aPool.Close();
|
sl@0
|
267 |
//
|
sl@0
|
268 |
TheTest.Next(_L("Stream in and test set"));
|
sl@0
|
269 |
RStoreReadStream in;
|
sl@0
|
270 |
in.OpenLC(*TheStore,id);
|
sl@0
|
271 |
TStorePagePoolToken ptoken;
|
sl@0
|
272 |
in>>ptoken;
|
sl@0
|
273 |
aPool.Open(*TheStore,ptoken);
|
sl@0
|
274 |
TEST(!aPool.IsDirty());
|
sl@0
|
275 |
TPagedSetToken token;
|
sl@0
|
276 |
in>>token;
|
sl@0
|
277 |
TPagedSet<TInt32> set2(token);
|
sl@0
|
278 |
set2.Connect(&aPool);
|
sl@0
|
279 |
TEST(set2.IsIntact());
|
sl@0
|
280 |
CleanupStack::PopAndDestroy(); // in
|
sl@0
|
281 |
|
sl@0
|
282 |
TEST2(set2.Count(), KEntryCount);
|
sl@0
|
283 |
for (ii=0;ii<KEntryCount;ii++)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
TInt32 it=ii;
|
sl@0
|
286 |
set2.DeleteL(it);
|
sl@0
|
287 |
}
|
sl@0
|
288 |
TEST2(set2.Count(), 0);
|
sl@0
|
289 |
aPool.FlushL();
|
sl@0
|
290 |
aPool.Discard();
|
sl@0
|
291 |
aPool.ReclaimAllL();
|
sl@0
|
292 |
aPool.Close();
|
sl@0
|
293 |
TheTest.End();
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
/**
|
sl@0
|
297 |
@SYMTestCaseID PDS-STORE-CT-4009
|
sl@0
|
298 |
@SYMTestCaseDesc RFilePagePool tests
|
sl@0
|
299 |
@SYMTestPriority High
|
sl@0
|
300 |
@SYMTestActions Tests for creating and opening RFilePagePool
|
sl@0
|
301 |
@SYMTestExpectedResults RFilePagePool needs to be correctly created, replaced and opened.
|
sl@0
|
302 |
@SYMDEF DEF135804
|
sl@0
|
303 |
*/
|
sl@0
|
304 |
LOCAL_C void test4L()
|
sl@0
|
305 |
{
|
sl@0
|
306 |
RFilePagePool testPage;
|
sl@0
|
307 |
TFileName tempPageFileName;
|
sl@0
|
308 |
RFs fs;
|
sl@0
|
309 |
TInt err;
|
sl@0
|
310 |
fs.Connect();
|
sl@0
|
311 |
err = fs.MkDirAll(KPageFilePathOnly);
|
sl@0
|
312 |
TEST(err==KErrNone||err==KErrAlreadyExists);
|
sl@0
|
313 |
err = fs.Delete(KPageFilePath);
|
sl@0
|
314 |
TEST(err==KErrNone||err==KErrNotFound);
|
sl@0
|
315 |
CPageCache* pcache = CPageCache::NewLC(2);
|
sl@0
|
316 |
//creating file
|
sl@0
|
317 |
TheTest.Printf(_L("Creating file for the page pool"));
|
sl@0
|
318 |
err = testPage.Create(fs, KPageFilePath, EFileWrite);
|
sl@0
|
319 |
TEST2(err, KErrNone);
|
sl@0
|
320 |
testPage.Set(*pcache);
|
sl@0
|
321 |
TheTest.Printf(_L("-> File created -> Closing "));
|
sl@0
|
322 |
testPage.Close();
|
sl@0
|
323 |
TheTest.Printf(_L("-> Closed "));
|
sl@0
|
324 |
//opening file, file should be present after successful creation
|
sl@0
|
325 |
TheTest.Printf(_L("Opening file for the page pool"));
|
sl@0
|
326 |
err = testPage.Open(fs,KPageFilePath, EFileWrite);
|
sl@0
|
327 |
TEST2(err, KErrNone);
|
sl@0
|
328 |
testPage.Set(*pcache);
|
sl@0
|
329 |
TheTest.Printf(_L("-> File opened -> Closing "));
|
sl@0
|
330 |
testPage.Close();
|
sl@0
|
331 |
TheTest.Printf(_L("-> Closed "));
|
sl@0
|
332 |
//try to replace already existing file
|
sl@0
|
333 |
//file should exist after successful creation
|
sl@0
|
334 |
TheTest.Printf(_L("Replacing file for the page pool"));
|
sl@0
|
335 |
err = testPage.Replace(fs, KPageFilePath, EFileWrite);
|
sl@0
|
336 |
TEST2(err, KErrNone);
|
sl@0
|
337 |
testPage.Set(*pcache);
|
sl@0
|
338 |
TheTest.Printf(_L("-> File replaced -> Closing "));
|
sl@0
|
339 |
testPage.Close();
|
sl@0
|
340 |
TheTest.Printf(_L("-> Closed "));
|
sl@0
|
341 |
//try to create temp file with unique name
|
sl@0
|
342 |
TheTest.Printf(_L("Creating temp unique file "));
|
sl@0
|
343 |
err = testPage.Temp(fs, KPageFilePathOnly, tempPageFileName, EFileWrite);
|
sl@0
|
344 |
TEST2(err, KErrNone);
|
sl@0
|
345 |
testPage.Set(*pcache);
|
sl@0
|
346 |
TheTest.Printf(_L("-> File created -> Closing "));
|
sl@0
|
347 |
testPage.Close();
|
sl@0
|
348 |
TheTest.Printf(_L("-> Closed "));
|
sl@0
|
349 |
//if file was propertly created we should be able to open it
|
sl@0
|
350 |
TheTest.Printf(_L("Opening temp unique file "));
|
sl@0
|
351 |
err = testPage.Open(fs, tempPageFileName, EFileWrite);
|
sl@0
|
352 |
TEST2(err, KErrNone);
|
sl@0
|
353 |
TheTest.Printf(_L("-> File opened -> Releasing "));
|
sl@0
|
354 |
testPage.Release();
|
sl@0
|
355 |
TheTest.Printf(_L("-> Released "));
|
sl@0
|
356 |
|
sl@0
|
357 |
//open and flush temp file
|
sl@0
|
358 |
RFilePagePool testPage2(*pcache);
|
sl@0
|
359 |
err = testPage2.Open(fs, tempPageFileName, EFileWrite);
|
sl@0
|
360 |
TEST2(err, KErrNone);
|
sl@0
|
361 |
err = testPage2.Flush();
|
sl@0
|
362 |
TEST2(err, KErrNone);
|
sl@0
|
363 |
TRAP(err, testPage2.FlushL());
|
sl@0
|
364 |
TEST2(err, KErrNone);
|
sl@0
|
365 |
|
sl@0
|
366 |
RFile& file = const_cast<RFile&>(testPage2.File());
|
sl@0
|
367 |
TFileName testIsSameFile;
|
sl@0
|
368 |
file.FullName(testIsSameFile);
|
sl@0
|
369 |
TEST2( testIsSameFile.Compare(tempPageFileName), 0);
|
sl@0
|
370 |
testPage2.Detach();
|
sl@0
|
371 |
file.Close();
|
sl@0
|
372 |
|
sl@0
|
373 |
//attach and detach file
|
sl@0
|
374 |
file.Open(fs, testIsSameFile, EFileWrite|EFileShareReadersOrWriters);
|
sl@0
|
375 |
testPage2.Attach(file);
|
sl@0
|
376 |
testPage2.Detach();
|
sl@0
|
377 |
file.Close();
|
sl@0
|
378 |
testPage2.Close();
|
sl@0
|
379 |
|
sl@0
|
380 |
CleanupStack::PopAndDestroy(pcache);
|
sl@0
|
381 |
fs.Close();
|
sl@0
|
382 |
}
|
sl@0
|
383 |
|
sl@0
|
384 |
/**
|
sl@0
|
385 |
* Struct needed in test5()
|
sl@0
|
386 |
*/
|
sl@0
|
387 |
struct SCachePage
|
sl@0
|
388 |
{
|
sl@0
|
389 |
TCachePage iPage[1];
|
sl@0
|
390 |
TUint8 iData[KPoolPageSize];
|
sl@0
|
391 |
};
|
sl@0
|
392 |
/**
|
sl@0
|
393 |
* Class specially created to test protected API from RFilePagePool
|
sl@0
|
394 |
*/
|
sl@0
|
395 |
class RFilePagePoolTestClass: public RFilePagePool
|
sl@0
|
396 |
{
|
sl@0
|
397 |
public:
|
sl@0
|
398 |
void CallProtectedWriteL(SCachePage& page)
|
sl@0
|
399 |
{
|
sl@0
|
400 |
TPageChange change=page.iPage[0].iChange;
|
sl@0
|
401 |
WriteL(page.iPage[0].iRef,&page.iPage[1],change);
|
sl@0
|
402 |
}
|
sl@0
|
403 |
void CallProtectedReadL(SCachePage& page)
|
sl@0
|
404 |
{
|
sl@0
|
405 |
ReadL(page.iPage[0].iRef,&page.iPage[1]);
|
sl@0
|
406 |
}
|
sl@0
|
407 |
TPageRef CallProtectedExtendL(SCachePage& page)
|
sl@0
|
408 |
{
|
sl@0
|
409 |
ExtendL(&page.iPage[1],EPageReclaimable);
|
sl@0
|
410 |
return page.iPage[0].iRef;
|
sl@0
|
411 |
}
|
sl@0
|
412 |
};
|
sl@0
|
413 |
|
sl@0
|
414 |
/**
|
sl@0
|
415 |
@SYMTestCaseID PDS-STORE-CT-4010
|
sl@0
|
416 |
@SYMTestCaseDesc RFilePagePool protected API tests
|
sl@0
|
417 |
@SYMTestPriority High
|
sl@0
|
418 |
@SYMTestActions Tests for read and write and extend operations
|
sl@0
|
419 |
@SYMTestExpectedResults Cache pages should be properly written and properly read from RFilePagePoolTestClass
|
sl@0
|
420 |
@SYMDEF DEF135804
|
sl@0
|
421 |
*/
|
sl@0
|
422 |
LOCAL_C void test5L()
|
sl@0
|
423 |
{
|
sl@0
|
424 |
SCachePage page;
|
sl@0
|
425 |
page.iPage[0].iRef = 1;
|
sl@0
|
426 |
page.iPage[0].iChange=EPageNoChange;
|
sl@0
|
427 |
|
sl@0
|
428 |
RFilePagePoolTestClass fpp;
|
sl@0
|
429 |
RFs fs;
|
sl@0
|
430 |
fs.Connect();
|
sl@0
|
431 |
fs.MkDirAll(KPageFilePathOnly);
|
sl@0
|
432 |
fs.Delete(KPageFilePath);
|
sl@0
|
433 |
CPageCache* pcache = CPageCache::NewLC(2);
|
sl@0
|
434 |
//creating file
|
sl@0
|
435 |
TheTest.Printf(_L("Creating file "));
|
sl@0
|
436 |
TInt err = fpp.Create(fs, KPageFilePath, EFileWrite);
|
sl@0
|
437 |
TEST2(err, KErrNone);
|
sl@0
|
438 |
fpp.Set(*pcache);
|
sl@0
|
439 |
TheTest.Printf(_L("-> File created -> Testing protected API "));
|
sl@0
|
440 |
TRAP(err, fpp.CallProtectedWriteL(page));
|
sl@0
|
441 |
TEST2(err, KErrNone);
|
sl@0
|
442 |
TheTest.Printf(_L("-> CallProtectedWriteL() done "));
|
sl@0
|
443 |
TRAP(err, fpp.CallProtectedReadL(page));
|
sl@0
|
444 |
TEST2(err, KErrNone);
|
sl@0
|
445 |
TheTest.Printf(_L("-> CallProtectedReadL() done "));
|
sl@0
|
446 |
TRAP(err, fpp.CallProtectedExtendL(page));
|
sl@0
|
447 |
TEST2(err, KErrNone);
|
sl@0
|
448 |
TheTest.Printf(_L("-> CallProtectedExtendL() done -> Closing"));
|
sl@0
|
449 |
fpp.Close();
|
sl@0
|
450 |
TheTest.Printf(_L("-> Closed "));
|
sl@0
|
451 |
CleanupStack::PopAndDestroy(pcache);
|
sl@0
|
452 |
fs.Close();
|
sl@0
|
453 |
}
|
sl@0
|
454 |
|
sl@0
|
455 |
const TInt KCachePages=16;
|
sl@0
|
456 |
|
sl@0
|
457 |
LOCAL_C void testallL(RStorePagePool& aPool)
|
sl@0
|
458 |
{
|
sl@0
|
459 |
TheTest.Start(_L("Connecting page pool"));
|
sl@0
|
460 |
aPool.Set(*CPageCache::NewLC(KCachePages));
|
sl@0
|
461 |
aPool.Create(*TheStore);
|
sl@0
|
462 |
TheTest.Next(_L("Basic operations"));
|
sl@0
|
463 |
test1L(aPool);
|
sl@0
|
464 |
TheTest.Next(_L("Large set TUint32"));
|
sl@0
|
465 |
test2L(aPool);
|
sl@0
|
466 |
aPool.Discard();
|
sl@0
|
467 |
aPool.ReclaimAllL();
|
sl@0
|
468 |
aPool.Close();
|
sl@0
|
469 |
TheTest.Next(_L("Tokens and streaming"));
|
sl@0
|
470 |
test3L(aPool);
|
sl@0
|
471 |
CleanupStack::PopAndDestroy(); //cache
|
sl@0
|
472 |
TheTest.Next(_L("PDS-STORE-CT-4009: RFilePagePool tests"));
|
sl@0
|
473 |
test4L();
|
sl@0
|
474 |
TheTest.Next(_L("PDS-STORE-CT-4010: RFilePagePool protected API tests"));
|
sl@0
|
475 |
test5L();
|
sl@0
|
476 |
TheTest.End();
|
sl@0
|
477 |
}
|
sl@0
|
478 |
|
sl@0
|
479 |
/**
|
sl@0
|
480 |
@SYMTestCaseID PDS-STORE-CT-4021
|
sl@0
|
481 |
@SYMTestCaseDesc RStorePagePool protected API tests
|
sl@0
|
482 |
@SYMTestPriority High
|
sl@0
|
483 |
@SYMTestActions Tests for different constructors
|
sl@0
|
484 |
@SYMTestExpectedResults Objects must be created successfully
|
sl@0
|
485 |
@SYMDEF DEF135804
|
sl@0
|
486 |
*/
|
sl@0
|
487 |
LOCAL_C void testconstructionL(CPBEncryptSet* aKey)
|
sl@0
|
488 |
{
|
sl@0
|
489 |
TheTest.Next(_L("PDS-STORE-CT-4021: RStorePagePool protected API tests"));
|
sl@0
|
490 |
CPageCache* pcache = CPageCache::NewLC(KCachePages);
|
sl@0
|
491 |
TStorePagePoolToken token;
|
sl@0
|
492 |
RStorePagePool poolcached(*pcache);
|
sl@0
|
493 |
poolcached.Create(*TheStore);
|
sl@0
|
494 |
test1L(poolcached);
|
sl@0
|
495 |
poolcached.Discard();
|
sl@0
|
496 |
poolcached.ReclaimAllL();
|
sl@0
|
497 |
poolcached.Close();
|
sl@0
|
498 |
RStorePagePool poolstream(*TheStore);
|
sl@0
|
499 |
poolstream.Set(*pcache);
|
sl@0
|
500 |
test1L(poolstream);
|
sl@0
|
501 |
poolstream.Discard();
|
sl@0
|
502 |
poolstream.ReclaimAllL();
|
sl@0
|
503 |
poolstream.Close();
|
sl@0
|
504 |
RStorePagePool poolstreamtoken(*TheStore, token);
|
sl@0
|
505 |
poolstreamtoken.Set(*pcache);
|
sl@0
|
506 |
test1L(poolstreamtoken);
|
sl@0
|
507 |
poolstreamtoken.Close();
|
sl@0
|
508 |
RSecureStorePagePool securepoolcached( *pcache, *aKey );
|
sl@0
|
509 |
securepoolcached.Create(*TheStore);
|
sl@0
|
510 |
test1L(securepoolcached);
|
sl@0
|
511 |
securepoolcached.Discard();
|
sl@0
|
512 |
securepoolcached.ReclaimAllL();
|
sl@0
|
513 |
securepoolcached.Close();
|
sl@0
|
514 |
|
sl@0
|
515 |
|
sl@0
|
516 |
CleanupStack::PopAndDestroy();
|
sl@0
|
517 |
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
LOCAL_C void doMainL()
|
sl@0
|
521 |
{
|
sl@0
|
522 |
TheTest.Start(_L("Store PagePool"));
|
sl@0
|
523 |
TParsePtrC parse(KFileLocationSpec);
|
sl@0
|
524 |
|
sl@0
|
525 |
TheStore=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
|
sl@0
|
526 |
TheStore->SetTypeL(TheStore->Layout());
|
sl@0
|
527 |
RStorePagePool pool1;
|
sl@0
|
528 |
testallL(pool1);
|
sl@0
|
529 |
TheTest.Next(_L("Secure PagePool"));
|
sl@0
|
530 |
|
sl@0
|
531 |
CPBEncryptSet* key = CPBEncryptSet::NewLC(_L("the password"));
|
sl@0
|
532 |
RSecureStorePagePool pool2(*key);
|
sl@0
|
533 |
testallL(pool2);
|
sl@0
|
534 |
|
sl@0
|
535 |
|
sl@0
|
536 |
testconstructionL(key);
|
sl@0
|
537 |
|
sl@0
|
538 |
CleanupStack::PopAndDestroy(key);
|
sl@0
|
539 |
TheStore->CommitL();
|
sl@0
|
540 |
CleanupStack::PopAndDestroy(); // store
|
sl@0
|
541 |
}
|
sl@0
|
542 |
|
sl@0
|
543 |
//
|
sl@0
|
544 |
// Prepare the test directory.
|
sl@0
|
545 |
//
|
sl@0
|
546 |
LOCAL_C void setupTestDirectory()
|
sl@0
|
547 |
{
|
sl@0
|
548 |
TInt r=TheFs.Connect();
|
sl@0
|
549 |
TEST2(r, KErrNone);
|
sl@0
|
550 |
//
|
sl@0
|
551 |
TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));
|
sl@0
|
552 |
TParse parse;
|
sl@0
|
553 |
parse.Set(drive.Name(), &KFileLocationSpec, NULL);
|
sl@0
|
554 |
|
sl@0
|
555 |
r=TheFs.MkDir(parse.DriveAndPath());
|
sl@0
|
556 |
TEST(r==KErrNone||r==KErrAlreadyExists);
|
sl@0
|
557 |
r=TheFs.SetSessionPath(parse.DriveAndPath());
|
sl@0
|
558 |
TEST2(r, KErrNone);
|
sl@0
|
559 |
}
|
sl@0
|
560 |
|
sl@0
|
561 |
//
|
sl@0
|
562 |
// Initialise the cleanup stack.
|
sl@0
|
563 |
//
|
sl@0
|
564 |
LOCAL_C void setupCleanup()
|
sl@0
|
565 |
{
|
sl@0
|
566 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
567 |
TEST(TheTrapCleanup!=NULL);
|
sl@0
|
568 |
TRAPD(r,\
|
sl@0
|
569 |
{\
|
sl@0
|
570 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
571 |
CleanupStack::PushL((TAny*)1);\
|
sl@0
|
572 |
TEST2(r, KErrNone);\
|
sl@0
|
573 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
574 |
});
|
sl@0
|
575 |
TEST2(r, KErrNone);
|
sl@0
|
576 |
}
|
sl@0
|
577 |
|
sl@0
|
578 |
|
sl@0
|
579 |
|
sl@0
|
580 |
LOCAL_C void DeleteTestFiles()
|
sl@0
|
581 |
{
|
sl@0
|
582 |
|
sl@0
|
583 |
RFs fs;
|
sl@0
|
584 |
TInt err = fs.Connect();
|
sl@0
|
585 |
if(err == KErrNone)
|
sl@0
|
586 |
{
|
sl@0
|
587 |
CDir* dir;
|
sl@0
|
588 |
fs.GetDir(KPageFilePathOnly, KEntryAttNormal , ESortNone, dir);
|
sl@0
|
589 |
for(TInt i=0; i< dir->Count();i++)
|
sl@0
|
590 |
{
|
sl@0
|
591 |
CDir& rdir = *dir;
|
sl@0
|
592 |
TFileName tf (KPageFilePathOnly);
|
sl@0
|
593 |
tf.Append(rdir[i].iName);
|
sl@0
|
594 |
err = fs.Delete( tf );
|
sl@0
|
595 |
if (err != KErrNone)
|
sl@0
|
596 |
{
|
sl@0
|
597 |
RDebug::Print(_L("Error %d deleting file \"%S\".\n"), err, &(rdir[i].iName));
|
sl@0
|
598 |
}
|
sl@0
|
599 |
else
|
sl@0
|
600 |
RDebug::Print(_L("File \"%S\" removed.\n"), &(rdir[i].iName));
|
sl@0
|
601 |
}
|
sl@0
|
602 |
delete dir;
|
sl@0
|
603 |
err = fs.RmDir(KPageFilePathOnly);
|
sl@0
|
604 |
if (err != KErrNone)
|
sl@0
|
605 |
{
|
sl@0
|
606 |
RDebug::Print(_L("Error %d deleting folder \"%S\".\n"), err, &KPageFilePathOnly);
|
sl@0
|
607 |
}
|
sl@0
|
608 |
fs.Close();
|
sl@0
|
609 |
}
|
sl@0
|
610 |
else
|
sl@0
|
611 |
{
|
sl@0
|
612 |
RDebug::Print(_L("Error %d connecting file session.\n"), err);
|
sl@0
|
613 |
}
|
sl@0
|
614 |
}
|
sl@0
|
615 |
|
sl@0
|
616 |
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
|
sl@0
|
617 |
{
|
sl@0
|
618 |
RFs fsSession;
|
sl@0
|
619 |
TInt err = fsSession.Connect();
|
sl@0
|
620 |
if(err == KErrNone)
|
sl@0
|
621 |
{
|
sl@0
|
622 |
TEntry entry;
|
sl@0
|
623 |
if(fsSession.Entry(aFullName, entry) == KErrNone)
|
sl@0
|
624 |
{
|
sl@0
|
625 |
RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
|
sl@0
|
626 |
err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
|
sl@0
|
627 |
if(err != KErrNone)
|
sl@0
|
628 |
{
|
sl@0
|
629 |
RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
|
sl@0
|
630 |
}
|
sl@0
|
631 |
err = fsSession.Delete(aFullName);
|
sl@0
|
632 |
if(err != KErrNone)
|
sl@0
|
633 |
{
|
sl@0
|
634 |
RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
|
sl@0
|
635 |
}
|
sl@0
|
636 |
}
|
sl@0
|
637 |
fsSession.Close();
|
sl@0
|
638 |
}
|
sl@0
|
639 |
else
|
sl@0
|
640 |
{
|
sl@0
|
641 |
RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
|
sl@0
|
642 |
}
|
sl@0
|
643 |
}
|
sl@0
|
644 |
|
sl@0
|
645 |
GLDEF_C TInt E32Main()
|
sl@0
|
646 |
{
|
sl@0
|
647 |
TheTest.Title();
|
sl@0
|
648 |
setupTestDirectory();
|
sl@0
|
649 |
setupCleanup();
|
sl@0
|
650 |
__UHEAP_MARK;
|
sl@0
|
651 |
//
|
sl@0
|
652 |
TRAPD(r,doMainL());
|
sl@0
|
653 |
TEST2(r, KErrNone);
|
sl@0
|
654 |
|
sl@0
|
655 |
//deletion of data files must be before call to .End() - DEF047652
|
sl@0
|
656 |
TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));
|
sl@0
|
657 |
TParse parse;
|
sl@0
|
658 |
parse.Set(drive.Name(), &KFileLocationSpec, NULL);
|
sl@0
|
659 |
::DeleteDataFile(parse.FullName());
|
sl@0
|
660 |
::DeleteTestFiles();
|
sl@0
|
661 |
|
sl@0
|
662 |
TheTest.End();
|
sl@0
|
663 |
//
|
sl@0
|
664 |
__UHEAP_MARKEND;
|
sl@0
|
665 |
|
sl@0
|
666 |
delete TheTrapCleanup;
|
sl@0
|
667 |
TheFs.Close();
|
sl@0
|
668 |
TheTest.Close();
|
sl@0
|
669 |
return 0;
|
sl@0
|
670 |
}
|
sl@0
|
671 |
|