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