sl@0
|
1 |
// Copyright (c) 1995-2009 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 the License "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 |
// f32test\server\t_lock.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <f32file.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include "t_server.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
class RFileTest : public RFile
|
sl@0
|
24 |
{
|
sl@0
|
25 |
public:
|
sl@0
|
26 |
RFileTest(const TDesC& aName);
|
sl@0
|
27 |
RFileTest& Replace(const TDesC& aName);
|
sl@0
|
28 |
RFileTest& Open(const TDesC& aName);
|
sl@0
|
29 |
RFileTest& Lock(TInt aPos,TInt aLen=1);
|
sl@0
|
30 |
RFileTest& LockE(TInt aPos,TInt aLen=1);
|
sl@0
|
31 |
RFileTest& UnLock(TInt aPos,TInt aLen=1);
|
sl@0
|
32 |
RFileTest& UnLockE(TInt aPos,TInt aLen=1);
|
sl@0
|
33 |
RFileTest& LockEA(TInt aPos,TInt aLen=1);
|
sl@0
|
34 |
RFileTest& UnLockEA(TInt aPos,TInt aLen=1);
|
sl@0
|
35 |
RFileTest& Write(TInt aPos,TInt aLen=1);
|
sl@0
|
36 |
RFileTest& WriteE(TInt aPos,TInt aLen=1);
|
sl@0
|
37 |
RFileTest& Read(TInt aPos,TInt aLen=1);
|
sl@0
|
38 |
RFileTest& ReadE(TInt aPos,TInt aLen=1);
|
sl@0
|
39 |
RFileTest& Size(TInt aSize);
|
sl@0
|
40 |
RFileTest& SizeE(TInt aSize);
|
sl@0
|
41 |
private:
|
sl@0
|
42 |
TName iName;
|
sl@0
|
43 |
};
|
sl@0
|
44 |
|
sl@0
|
45 |
GLDEF_D RTest test(_L("T_LOCK"));
|
sl@0
|
46 |
LOCAL_D RFileTest Test1(_L("File 1"));
|
sl@0
|
47 |
LOCAL_D RFileTest Test2(_L("File 2"));
|
sl@0
|
48 |
LOCAL_D TBuf8<0x100> Pattern;
|
sl@0
|
49 |
LOCAL_D TBuf8<0x100> Buffer;
|
sl@0
|
50 |
|
sl@0
|
51 |
LOCAL_C void DoFormat()
|
sl@0
|
52 |
//
|
sl@0
|
53 |
// Format the ramdisk
|
sl@0
|
54 |
//
|
sl@0
|
55 |
{
|
sl@0
|
56 |
|
sl@0
|
57 |
TInt count;
|
sl@0
|
58 |
RFormat format;
|
sl@0
|
59 |
#if defined(__WINS__)
|
sl@0
|
60 |
TInt r=format.Open(TheFs,_L("Y:\\"),EHighDensity,count);
|
sl@0
|
61 |
#else
|
sl@0
|
62 |
TInt r=format.Open(TheFs,_L("C:\\"),EHighDensity,count);
|
sl@0
|
63 |
#endif
|
sl@0
|
64 |
test(r==KErrNone);
|
sl@0
|
65 |
while(count)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
r=format.Next(count);
|
sl@0
|
68 |
test(r==KErrNone);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
format.Close();
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
LOCAL_C void MakeTestDirectory()
|
sl@0
|
74 |
//
|
sl@0
|
75 |
// Format the ramdisk if it is corrupt
|
sl@0
|
76 |
//
|
sl@0
|
77 |
{
|
sl@0
|
78 |
|
sl@0
|
79 |
TPtrC testDir=_L("\\F32-TST\\");
|
sl@0
|
80 |
TInt r=TheFs.MkDir(testDir);
|
sl@0
|
81 |
if (r==KErrNone || r==KErrAlreadyExists)
|
sl@0
|
82 |
return;
|
sl@0
|
83 |
test.Next(_L("Formatting disk"));
|
sl@0
|
84 |
DoFormat();
|
sl@0
|
85 |
r=TheFs.MkDir(testDir);
|
sl@0
|
86 |
test(r==KErrNone);
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
RFileTest::RFileTest(const TDesC& aName)
|
sl@0
|
90 |
//
|
sl@0
|
91 |
// Constructor
|
sl@0
|
92 |
//
|
sl@0
|
93 |
: iName(aName)
|
sl@0
|
94 |
{}
|
sl@0
|
95 |
|
sl@0
|
96 |
RFileTest& RFileTest::Replace(const TDesC& aName)
|
sl@0
|
97 |
//
|
sl@0
|
98 |
// Replace a file.
|
sl@0
|
99 |
//
|
sl@0
|
100 |
{
|
sl@0
|
101 |
|
sl@0
|
102 |
test.Printf(_L("%S replace %S\n"),&iName,&aName);
|
sl@0
|
103 |
TInt r=RFile::Replace(TheFs,aName,EFileStream|EFileWrite|EFileShareAny);
|
sl@0
|
104 |
test(r==KErrNone);
|
sl@0
|
105 |
return(*this);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
RFileTest& RFileTest::Open(const TDesC& aName)
|
sl@0
|
109 |
//
|
sl@0
|
110 |
// Open a file.
|
sl@0
|
111 |
//
|
sl@0
|
112 |
{
|
sl@0
|
113 |
|
sl@0
|
114 |
test.Printf(_L("%S open %S\n"),&iName,&aName);
|
sl@0
|
115 |
TInt r=RFile::Open(TheFs,aName,EFileStream|EFileWrite|EFileShareAny);
|
sl@0
|
116 |
test(r==KErrNone);
|
sl@0
|
117 |
return(*this);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
RFileTest& RFileTest::Lock(TInt aPos,TInt aLen)
|
sl@0
|
121 |
//
|
sl@0
|
122 |
// Set a lock on the file. Expected not to fail.
|
sl@0
|
123 |
//
|
sl@0
|
124 |
{
|
sl@0
|
125 |
|
sl@0
|
126 |
test.Printf(_L("%S lock %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
127 |
TInt r=RFile::Lock(aPos,aLen);
|
sl@0
|
128 |
test(r==KErrNone);
|
sl@0
|
129 |
return(*this);
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
RFileTest& RFileTest::LockE(TInt aPos,TInt aLen)
|
sl@0
|
133 |
//
|
sl@0
|
134 |
// Set a lock on the file. Expected to fail.
|
sl@0
|
135 |
//
|
sl@0
|
136 |
{
|
sl@0
|
137 |
|
sl@0
|
138 |
test.Printf(_L("%S lockE %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
139 |
TInt r=RFile::Lock(aPos,aLen);
|
sl@0
|
140 |
test(r==KErrLocked);
|
sl@0
|
141 |
return(*this);
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
RFileTest& RFileTest::UnLock(TInt aPos,TInt aLen)
|
sl@0
|
145 |
//
|
sl@0
|
146 |
// Unlock the file. Expected not to fail.
|
sl@0
|
147 |
//
|
sl@0
|
148 |
{
|
sl@0
|
149 |
|
sl@0
|
150 |
test.Printf(_L("%S ulock %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
151 |
TInt r=RFile::UnLock(aPos,aLen);
|
sl@0
|
152 |
test(r==KErrNone);
|
sl@0
|
153 |
return(*this);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
RFileTest& RFileTest::UnLockE(TInt aPos,TInt aLen)
|
sl@0
|
157 |
//
|
sl@0
|
158 |
// Unlock the file. Expected to fail.
|
sl@0
|
159 |
//
|
sl@0
|
160 |
{
|
sl@0
|
161 |
|
sl@0
|
162 |
test.Printf(_L("%S ulockE %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
163 |
TInt r=RFile::UnLock(aPos,aLen);
|
sl@0
|
164 |
test(r==KErrNotFound);
|
sl@0
|
165 |
return(*this);
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
|
sl@0
|
169 |
RFileTest& RFileTest::LockEA(TInt aPos,TInt aLen)
|
sl@0
|
170 |
//
|
sl@0
|
171 |
// Set a lock on the file. Expected to fail with KErrArgument.
|
sl@0
|
172 |
//
|
sl@0
|
173 |
{
|
sl@0
|
174 |
|
sl@0
|
175 |
test.Printf(_L("%S lock %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
176 |
TInt r=RFile::Lock(aPos,aLen);
|
sl@0
|
177 |
test(r==KErrArgument);
|
sl@0
|
178 |
return(*this);
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
RFileTest& RFileTest::UnLockEA(TInt aPos,TInt aLen)
|
sl@0
|
182 |
//
|
sl@0
|
183 |
// Unlock the file. Expected to fail with KErrArgument.
|
sl@0
|
184 |
//
|
sl@0
|
185 |
{
|
sl@0
|
186 |
|
sl@0
|
187 |
test.Printf(_L("%S ulock %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
188 |
TInt r=RFile::UnLock(aPos,aLen);
|
sl@0
|
189 |
test(r==KErrArgument);
|
sl@0
|
190 |
return(*this);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
RFileTest& RFileTest::Write(TInt aPos,TInt aLen)
|
sl@0
|
194 |
//
|
sl@0
|
195 |
// Write to the file. Expected not to fail.
|
sl@0
|
196 |
//
|
sl@0
|
197 |
{
|
sl@0
|
198 |
|
sl@0
|
199 |
test.Printf(_L("%S write %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
200 |
TInt r=RFile::Write(aPos,Pattern,aLen);
|
sl@0
|
201 |
test(r==KErrNone);
|
sl@0
|
202 |
return(*this);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
RFileTest& RFileTest::WriteE(TInt aPos,TInt aLen)
|
sl@0
|
206 |
//
|
sl@0
|
207 |
// Write to the file. Expected to fail.
|
sl@0
|
208 |
//
|
sl@0
|
209 |
{
|
sl@0
|
210 |
|
sl@0
|
211 |
test.Printf(_L("%S writeE %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
212 |
TInt r=RFile::Write(aPos,Pattern,aLen);
|
sl@0
|
213 |
test(r==KErrLocked);
|
sl@0
|
214 |
return(*this);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
RFileTest& RFileTest::Read(TInt aPos,TInt aLen)
|
sl@0
|
218 |
//
|
sl@0
|
219 |
// Read from the file. Expected not to fail.
|
sl@0
|
220 |
//
|
sl@0
|
221 |
{
|
sl@0
|
222 |
|
sl@0
|
223 |
test.Printf(_L("%S read %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
224 |
TInt r=RFile::Read(aPos,Buffer,aLen);
|
sl@0
|
225 |
test(r==KErrNone);
|
sl@0
|
226 |
return(*this);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
RFileTest& RFileTest::ReadE(TInt aPos,TInt aLen)
|
sl@0
|
230 |
//
|
sl@0
|
231 |
// Read from the file. Expected to fail.
|
sl@0
|
232 |
//
|
sl@0
|
233 |
{
|
sl@0
|
234 |
|
sl@0
|
235 |
test.Printf(_L("%S readE %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
|
sl@0
|
236 |
TInt r=RFile::Read(aPos,Buffer,aLen);
|
sl@0
|
237 |
test(r==KErrLocked);
|
sl@0
|
238 |
return(*this);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
RFileTest& RFileTest::Size(TInt aSize)
|
sl@0
|
242 |
//
|
sl@0
|
243 |
// Set the size of the file. Expected not to fail.
|
sl@0
|
244 |
//
|
sl@0
|
245 |
{
|
sl@0
|
246 |
|
sl@0
|
247 |
test.Printf(_L("%S size %08x\n"),&iName,aSize);
|
sl@0
|
248 |
TInt r=RFile::SetSize(aSize);
|
sl@0
|
249 |
test(r==KErrNone);
|
sl@0
|
250 |
return(*this);
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
RFileTest& RFileTest::SizeE(TInt aSize)
|
sl@0
|
254 |
//
|
sl@0
|
255 |
// Set the size of the file. Expected to fail.
|
sl@0
|
256 |
//
|
sl@0
|
257 |
{
|
sl@0
|
258 |
|
sl@0
|
259 |
test.Printf(_L("%S sizeE %08x\n"),&iName,aSize);
|
sl@0
|
260 |
TInt r=RFile::SetSize(aSize);
|
sl@0
|
261 |
test(r==KErrLocked);
|
sl@0
|
262 |
return(*this);
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
LOCAL_C void setup()
|
sl@0
|
266 |
//
|
sl@0
|
267 |
// Create the test files.
|
sl@0
|
268 |
//
|
sl@0
|
269 |
{
|
sl@0
|
270 |
|
sl@0
|
271 |
test.Start(_L("Settting test environment"));
|
sl@0
|
272 |
//
|
sl@0
|
273 |
Test1.Replace(_L("\\F32-TST\\LOCK.TST"));
|
sl@0
|
274 |
Test2.Open(_L("\\F32-TST\\LOCK.TST"));
|
sl@0
|
275 |
//
|
sl@0
|
276 |
test.Next(_L("Creating test pattern"));
|
sl@0
|
277 |
Pattern.SetLength(Pattern.MaxLength());
|
sl@0
|
278 |
for (TInt i=0;i<Pattern.MaxLength();i++)
|
sl@0
|
279 |
Pattern[i]=(TText8)i;
|
sl@0
|
280 |
//
|
sl@0
|
281 |
test.End();
|
sl@0
|
282 |
}
|
sl@0
|
283 |
|
sl@0
|
284 |
LOCAL_C void testLock1()
|
sl@0
|
285 |
//
|
sl@0
|
286 |
// Test file sharing.
|
sl@0
|
287 |
//
|
sl@0
|
288 |
{
|
sl@0
|
289 |
|
sl@0
|
290 |
test.Start(_L("Test locking 1"));
|
sl@0
|
291 |
//
|
sl@0
|
292 |
test.Next(_L("Single file tests"));
|
sl@0
|
293 |
Test1.UnLockE(0).Lock(0).LockE(0).UnLock(0);
|
sl@0
|
294 |
Test1.Lock(0,0x100).Lock(0x100,0x100).Lock(0x200,0x100);
|
sl@0
|
295 |
Test1.UnLock(0x100,0x100).UnLock(0x200,0x100).UnLock(0,0x100);
|
sl@0
|
296 |
Test1.Lock(0,0x100).Lock(0x200,0x100).Lock(0x100,0x100);
|
sl@0
|
297 |
Test1.UnLock(0x200,0x100).UnLock(0x100,0x100).UnLock(0,0x100);
|
sl@0
|
298 |
Test1.Lock(0,0x100).Lock(0x200,0x100);
|
sl@0
|
299 |
Test1.LockE(0x100,0x101).LockE(0x180,0x100).LockE(0x80,0x100);
|
sl@0
|
300 |
Test1.Lock(0x400,0x100).LockE(0x180,0x400).LockE(0,0x400);
|
sl@0
|
301 |
Test1.UnLock(0x0,0x100).UnLock(0x200,0x100).UnLock(0x400,0x100);
|
sl@0
|
302 |
Test1.LockEA(0x40000000,0x40000002).LockEA(0x7FFFFFFC,0x10).LockEA(0x7FFFFFFF,0x100);
|
sl@0
|
303 |
Test1.UnLockEA(0x40000000,0x40000001).UnLockEA(0x7FFFFFFF,0x100).UnLockEA(0x7FFFFFFE,0x05);
|
sl@0
|
304 |
//
|
sl@0
|
305 |
test.Next(_L("Multi file tests"));
|
sl@0
|
306 |
Test1.Lock(0);
|
sl@0
|
307 |
Test2.LockE(0);
|
sl@0
|
308 |
Test1.UnLock(0);
|
sl@0
|
309 |
Test2.Lock(0);
|
sl@0
|
310 |
Test1.LockE(0);
|
sl@0
|
311 |
Test2.UnLock(0);
|
sl@0
|
312 |
//
|
sl@0
|
313 |
test.End();
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
GLDEF_C void CallTestsL()
|
sl@0
|
317 |
//
|
sl@0
|
318 |
// Do all tests
|
sl@0
|
319 |
//
|
sl@0
|
320 |
{
|
sl@0
|
321 |
|
sl@0
|
322 |
MakeTestDirectory();
|
sl@0
|
323 |
setup();
|
sl@0
|
324 |
testLock1();
|
sl@0
|
325 |
|
sl@0
|
326 |
Test1.Close();
|
sl@0
|
327 |
Test2.Close();
|
sl@0
|
328 |
}
|