First public contribution.
1 // Copyright (c) 1996-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 // File Name: f32test/fileshare/t_handshare64bit.cpp
15 // 64 bit FileHandle Server. Used by t_file64bit for testing
16 // RFile64::AdoptFromServer() and RFile64::TransferToServer()
24 #include "handshare64bit.h"
27 #pragma warning(disable:4706)
32 GLDEF_D RTest test(_L("HANDSHARE_SVR"));
33 const TInt64 KGB = 1<<30;
34 const TInt64 K4GB = 4 * KGB;
37 #define PANIC() FHSvrPanic(__LINE__)
38 #define FHS_ASSERT(c) ((void)((c)||(PANIC(),0)))
40 const TTimeIntervalMicroSeconds32 KHalfSecond(500000);
43 void FHSvrPanic(TInt aLine)
45 User::Panic(_L("FHServer"),aLine);
48 LOCAL_D TInt gTestDrive;
50 /******************************************************************************
52 ******************************************************************************/
55 class CFHServer64Bit : public CServer2
58 static CFHServer64Bit* NewL();
60 virtual ~CFHServer64Bit();
61 virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
62 virtual TInt RunError(TInt aError);
67 class CFHSession64Bit : public CSession2
70 virtual ~CFHSession64Bit();
71 virtual void CreateL();
72 virtual void ServiceL(const RMessage2& aMessage);
75 void GetFileHandleLargeFile2(const RMessage2& aMsg);
76 void PassFileHandleLargeFile(const RMessage2& aMsg);
77 void PassFileHandleProcessLargeFile(const RMessage2& aMsg);
80 /******************************************************************************
81 * Class CFHSession/CFHServer
82 ******************************************************************************/
83 void ExceptionHandler(TExcType)
85 User::Leave(KErrGeneral);
90 CFHSession64Bit::~CFHSession64Bit()
94 void CFHSession64Bit::CreateL()
99 void CFHSession64Bit::ServiceL(const RMessage2& aMessage)
102 TInt mid=aMessage.Function();
105 case RFileHandleSharer64Bit::EMsgGetFileHandleLargeFile:
106 GetFileHandleLargeFile2(aMessage);
109 case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileClient:
110 PassFileHandleLargeFile(aMessage);
113 case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileCreator:
114 PassFileHandleProcessLargeFile(aMessage);
117 case RFileHandleSharer64Bit::EMsgExit:
119 aMessage.Complete(KErrNone);
121 CActiveScheduler::Stop();
125 case RFileHandleSharer64Bit::EMsgSync:
126 aMessage.Complete(KErrNone);
129 case RFileHandleSharer64Bit::EMsgDrive:
130 gTestDrive=aMessage.Int0();
131 aMessage.Complete(KErrNone);
140 // Returns a file handle from server
142 void CFHSession64Bit::GetFileHandleLargeFile2(const RMessage2& aMsg)
144 test.Next(_L("RFile64::AdoptFromServer()"));
145 // get the requested file mode
146 TFileMode fileMode = TFileMode(aMsg.Int1());
149 TInt r = fs.Connect();
152 r = fs.CreatePrivatePath(gTestDrive);
155 r = fs.SetSessionToPrivate(gTestDrive);
158 r = fs.ShareProtected();
160 // make sure file exists & has valid data in it
163 r = file1.Replace(fs,KServerFileName,EFileWrite);
164 r=file1.SetSize(K4GB-1);
166 r = file1.Write(K4GB-10,KTestData4());
171 // re-open the file with the mode the client has requested & pass it to the client
174 r = file1.Open(fs,KServerFileName, fileMode);
177 test.Next(_L("RFile::TransferToClient()"));
179 // transfer the file to the client
180 r = file1.TransferToClient(aMsg, 0);
183 // test we can still use the file
185 r = file1.Seek(ESeekStart, pos);
188 r=file1.Read(K4GB-10,rbuf);
190 r=rbuf.CompareF(KTestData4());
195 RDebug::Print(_L("completed"));
199 void CFHSession64Bit::PassFileHandleLargeFile(const RMessage2& aMsg)
201 // Adopts file from test program and tests what it can and can't do
202 // Uses RFile64::AdoptFromClient() API
205 test.Next(_L("RFile64::AdoptFromClient()"));
209 // Message slot 0 is a RFs handle
210 // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle())
211 TInt r = file.AdoptFromClient(aMsg, 0, 1);
215 r=file.Read(K4GB-10,rbuf);
217 r=rbuf.CompareF(KTestData3());
219 r=file.Write(KTestData1());
220 test(r==KErrAccessDenied);
221 r=file.ChangeMode(EFileWrite);
222 test(r==KErrArgument);
223 r=file.Rename(_L("\\newname.txt"));
224 test(r==KErrPermissionDenied || r==KErrAccessDenied);
227 aMsg.Complete(KErrNone);
231 // Adopts file from test program and tests what it can and can't do
232 // Uses RFile64::AdoptFromCreator() API
234 void CFHSession64Bit::PassFileHandleProcessLargeFile(const RMessage2& aMsg)
236 test.Next(_L("RFile64::AdoptFromCreator()"));
239 TInt r = file.AdoptFromCreator(1, 2);
243 r=file.Read(K4GB-10,rbuf,3);
245 r=rbuf.CompareF(KTestData2());
248 test.Next(_L("RFile::Rename()"));
250 // define a filename in our private path
256 fs.SessionPath(sessionp);
257 r = fs.MkDirAll(sessionp);
258 test(r==KErrNone || r==KErrAlreadyExists);
260 r=fs.ShareProtected();
263 r=fs.CreatePrivatePath(gTestDrive);
265 r=fs.SetSessionToPrivate(gTestDrive);
269 fs.PrivatePath(newPath);
270 TFileName newFileName;
271 newFileName = newPath;
272 newFileName.Append(_L("newname.txt"));
274 // delete the file before we try to rename anything to it
275 r = fs.Delete(newFileName);
276 test(r == KErrNone || r == KErrNotFound);
279 r = file.FullName(fileName);
280 test (r == KErrNone);
282 r=file.Rename(newFileName);
287 // Next verify that we can delete the file (which should now
288 // have been moved to our private directory)
289 test.Next(_L("RFs::Delete()"));
290 r = fs.Delete(newFileName);
296 aMsg.Complete(KErrNone);
302 CFHServer64Bit* CFHServer64Bit::NewL()
304 CFHServer64Bit* server = new (ELeave) CFHServer64Bit;
305 CleanupStack::PushL(server);
306 server->ConstructL();
307 CleanupStack::Pop(server);
311 void CFHServer64Bit::ConstructL()
315 CFHServer64Bit::CFHServer64Bit()
316 : CServer2(0,ESharableSessions)
320 CFHServer64Bit::~CFHServer64Bit()
324 CSession2* CFHServer64Bit::NewSessionL(const TVersion& aVersion, const RMessage2&) const
326 // Create New Session
330 CFHSession64Bit* s = new (ELeave) CFHSession64Bit;
334 _LIT(KErr,"FHSERVER64BIT_ERR");
337 TInt CFHServer64Bit::RunError(TInt aError)
339 User::Panic(KErr,aError);
348 // Test Server for file handle sharing
352 test.Start(_L("Starting FHServer64bit..."));
354 // Remember the number of open handles. Just for a sanity check ....
355 TInt start_thc, start_phc;
356 RThread().HandleCount(start_phc, start_thc);
358 CTrapCleanup* cleanup=CTrapCleanup::New();
361 CActiveScheduler* sched=new CActiveScheduler;
363 CActiveScheduler::Install(sched);
366 CFHServer64Bit* svr = NULL;
367 TRAP_IGNORE(svr = CFHServer64Bit::NewL());
369 FHS_ASSERT(svr->Start(_L("FHServer64bit"))== KErrNone||KErrAlreadyExists);
372 test.Start(_L("Starting tests..."));
375 CActiveScheduler::Start();
378 TInt r = cleanupfs.Connect();
380 r=cleanupfs.SetSessionToPrivate(gTestDrive);
382 r=cleanupfs.Delete(KSvrFileName);
383 test(r==KErrNone || r==KErrNotFound);
393 // Sanity check for open handles and pending requests
394 TInt end_thc, end_phc;
395 RThread().HandleCount(end_phc, end_thc);
396 test(start_thc == end_thc);
397 test(start_phc == end_phc);
398 test(RThread().RequestCount() == 0);