Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_lock.cpp
23 class RFileTest : public RFile
26 RFileTest(const TDesC& aName);
27 RFileTest& Replace(const TDesC& aName);
28 RFileTest& Open(const TDesC& aName);
29 RFileTest& Lock(TInt aPos,TInt aLen=1);
30 RFileTest& LockE(TInt aPos,TInt aLen=1);
31 RFileTest& UnLock(TInt aPos,TInt aLen=1);
32 RFileTest& UnLockE(TInt aPos,TInt aLen=1);
33 RFileTest& LockEA(TInt aPos,TInt aLen=1);
34 RFileTest& UnLockEA(TInt aPos,TInt aLen=1);
35 RFileTest& Write(TInt aPos,TInt aLen=1);
36 RFileTest& WriteE(TInt aPos,TInt aLen=1);
37 RFileTest& Read(TInt aPos,TInt aLen=1);
38 RFileTest& ReadE(TInt aPos,TInt aLen=1);
39 RFileTest& Size(TInt aSize);
40 RFileTest& SizeE(TInt aSize);
45 GLDEF_D RTest test(_L("T_LOCK"));
46 LOCAL_D RFileTest Test1(_L("File 1"));
47 LOCAL_D RFileTest Test2(_L("File 2"));
48 LOCAL_D TBuf8<0x100> Pattern;
49 LOCAL_D TBuf8<0x100> Buffer;
51 LOCAL_C void DoFormat()
60 TInt r=format.Open(TheFs,_L("Y:\\"),EHighDensity,count);
62 TInt r=format.Open(TheFs,_L("C:\\"),EHighDensity,count);
73 LOCAL_C void MakeTestDirectory()
75 // Format the ramdisk if it is corrupt
79 TPtrC testDir=_L("\\F32-TST\\");
80 TInt r=TheFs.MkDir(testDir);
81 if (r==KErrNone || r==KErrAlreadyExists)
83 test.Next(_L("Formatting disk"));
85 r=TheFs.MkDir(testDir);
89 RFileTest::RFileTest(const TDesC& aName)
96 RFileTest& RFileTest::Replace(const TDesC& aName)
102 test.Printf(_L("%S replace %S\n"),&iName,&aName);
103 TInt r=RFile::Replace(TheFs,aName,EFileStream|EFileWrite|EFileShareAny);
108 RFileTest& RFileTest::Open(const TDesC& aName)
114 test.Printf(_L("%S open %S\n"),&iName,&aName);
115 TInt r=RFile::Open(TheFs,aName,EFileStream|EFileWrite|EFileShareAny);
120 RFileTest& RFileTest::Lock(TInt aPos,TInt aLen)
122 // Set a lock on the file. Expected not to fail.
126 test.Printf(_L("%S lock %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
127 TInt r=RFile::Lock(aPos,aLen);
132 RFileTest& RFileTest::LockE(TInt aPos,TInt aLen)
134 // Set a lock on the file. Expected to fail.
138 test.Printf(_L("%S lockE %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
139 TInt r=RFile::Lock(aPos,aLen);
144 RFileTest& RFileTest::UnLock(TInt aPos,TInt aLen)
146 // Unlock the file. Expected not to fail.
150 test.Printf(_L("%S ulock %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
151 TInt r=RFile::UnLock(aPos,aLen);
156 RFileTest& RFileTest::UnLockE(TInt aPos,TInt aLen)
158 // Unlock the file. Expected to fail.
162 test.Printf(_L("%S ulockE %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
163 TInt r=RFile::UnLock(aPos,aLen);
164 test(r==KErrNotFound);
169 RFileTest& RFileTest::LockEA(TInt aPos,TInt aLen)
171 // Set a lock on the file. Expected to fail with KErrArgument.
175 test.Printf(_L("%S lock %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
176 TInt r=RFile::Lock(aPos,aLen);
177 test(r==KErrArgument);
181 RFileTest& RFileTest::UnLockEA(TInt aPos,TInt aLen)
183 // Unlock the file. Expected to fail with KErrArgument.
187 test.Printf(_L("%S ulock %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
188 TInt r=RFile::UnLock(aPos,aLen);
189 test(r==KErrArgument);
193 RFileTest& RFileTest::Write(TInt aPos,TInt aLen)
195 // Write to the file. Expected not to fail.
199 test.Printf(_L("%S write %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
200 TInt r=RFile::Write(aPos,Pattern,aLen);
205 RFileTest& RFileTest::WriteE(TInt aPos,TInt aLen)
207 // Write to the file. Expected to fail.
211 test.Printf(_L("%S writeE %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
212 TInt r=RFile::Write(aPos,Pattern,aLen);
217 RFileTest& RFileTest::Read(TInt aPos,TInt aLen)
219 // Read from the file. Expected not to fail.
223 test.Printf(_L("%S read %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
224 TInt r=RFile::Read(aPos,Buffer,aLen);
229 RFileTest& RFileTest::ReadE(TInt aPos,TInt aLen)
231 // Read from the file. Expected to fail.
235 test.Printf(_L("%S readE %08x-%08x\n"),&iName,aPos,aPos+aLen-1);
236 TInt r=RFile::Read(aPos,Buffer,aLen);
241 RFileTest& RFileTest::Size(TInt aSize)
243 // Set the size of the file. Expected not to fail.
247 test.Printf(_L("%S size %08x\n"),&iName,aSize);
248 TInt r=RFile::SetSize(aSize);
253 RFileTest& RFileTest::SizeE(TInt aSize)
255 // Set the size of the file. Expected to fail.
259 test.Printf(_L("%S sizeE %08x\n"),&iName,aSize);
260 TInt r=RFile::SetSize(aSize);
267 // Create the test files.
271 test.Start(_L("Settting test environment"));
273 Test1.Replace(_L("\\F32-TST\\LOCK.TST"));
274 Test2.Open(_L("\\F32-TST\\LOCK.TST"));
276 test.Next(_L("Creating test pattern"));
277 Pattern.SetLength(Pattern.MaxLength());
278 for (TInt i=0;i<Pattern.MaxLength();i++)
279 Pattern[i]=(TText8)i;
284 LOCAL_C void testLock1()
286 // Test file sharing.
290 test.Start(_L("Test locking 1"));
292 test.Next(_L("Single file tests"));
293 Test1.UnLockE(0).Lock(0).LockE(0).UnLock(0);
294 Test1.Lock(0,0x100).Lock(0x100,0x100).Lock(0x200,0x100);
295 Test1.UnLock(0x100,0x100).UnLock(0x200,0x100).UnLock(0,0x100);
296 Test1.Lock(0,0x100).Lock(0x200,0x100).Lock(0x100,0x100);
297 Test1.UnLock(0x200,0x100).UnLock(0x100,0x100).UnLock(0,0x100);
298 Test1.Lock(0,0x100).Lock(0x200,0x100);
299 Test1.LockE(0x100,0x101).LockE(0x180,0x100).LockE(0x80,0x100);
300 Test1.Lock(0x400,0x100).LockE(0x180,0x400).LockE(0,0x400);
301 Test1.UnLock(0x0,0x100).UnLock(0x200,0x100).UnLock(0x400,0x100);
302 Test1.LockEA(0x40000000,0x40000002).LockEA(0x7FFFFFFC,0x10).LockEA(0x7FFFFFFF,0x100);
303 Test1.UnLockEA(0x40000000,0x40000001).UnLockEA(0x7FFFFFFF,0x100).UnLockEA(0x7FFFFFFE,0x05);
305 test.Next(_L("Multi file tests"));
316 GLDEF_C void CallTestsL()