sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // File Name: f32test/fileshare/t_handshare64bit.cpp sl@0: // 64 bit FileHandle Server. Used by t_file64bit for testing sl@0: // RFile64::AdoptFromServer() and RFile64::TransferToServer() sl@0: // functionality. sl@0: // sl@0: // sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "handshare64bit.h" sl@0: sl@0: #ifdef __VC32__ sl@0: #pragma warning(disable:4706) sl@0: #endif sl@0: sl@0: sl@0: sl@0: GLDEF_D RTest test(_L("HANDSHARE_SVR")); sl@0: const TInt64 KGB = 1<<30; sl@0: const TInt64 K4GB = 4 * KGB; sl@0: sl@0: sl@0: #define PANIC() FHSvrPanic(__LINE__) sl@0: #define FHS_ASSERT(c) ((void)((c)||(PANIC(),0))) sl@0: sl@0: const TTimeIntervalMicroSeconds32 KHalfSecond(500000); sl@0: sl@0: sl@0: void FHSvrPanic(TInt aLine) sl@0: { sl@0: User::Panic(_L("FHServer"),aLine); sl@0: } sl@0: sl@0: LOCAL_D TInt gTestDrive; sl@0: sl@0: /****************************************************************************** sl@0: * Class Definitions sl@0: ******************************************************************************/ sl@0: sl@0: sl@0: class CFHServer64Bit : public CServer2 sl@0: { sl@0: public: sl@0: static CFHServer64Bit* NewL(); sl@0: void ConstructL(); sl@0: virtual ~CFHServer64Bit(); sl@0: virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const; sl@0: virtual TInt RunError(TInt aError); sl@0: private: sl@0: CFHServer64Bit(); sl@0: }; sl@0: sl@0: class CFHSession64Bit : public CSession2 sl@0: { sl@0: public: sl@0: virtual ~CFHSession64Bit(); sl@0: virtual void CreateL(); sl@0: virtual void ServiceL(const RMessage2& aMessage); sl@0: public: sl@0: sl@0: void GetFileHandleLargeFile2(const RMessage2& aMsg); sl@0: void PassFileHandleLargeFile(const RMessage2& aMsg); sl@0: void PassFileHandleProcessLargeFile(const RMessage2& aMsg); sl@0: }; sl@0: sl@0: /****************************************************************************** sl@0: * Class CFHSession/CFHServer sl@0: ******************************************************************************/ sl@0: void ExceptionHandler(TExcType) sl@0: { sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: sl@0: sl@0: CFHSession64Bit::~CFHSession64Bit() sl@0: { sl@0: } sl@0: sl@0: void CFHSession64Bit::CreateL() sl@0: { sl@0: sl@0: } sl@0: sl@0: void CFHSession64Bit::ServiceL(const RMessage2& aMessage) sl@0: { sl@0: __UHEAP_MARK; sl@0: TInt mid=aMessage.Function(); sl@0: switch(mid) sl@0: { sl@0: case RFileHandleSharer64Bit::EMsgGetFileHandleLargeFile: sl@0: GetFileHandleLargeFile2(aMessage); sl@0: break; sl@0: sl@0: case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileClient: sl@0: PassFileHandleLargeFile(aMessage); sl@0: break; sl@0: sl@0: case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileCreator: sl@0: PassFileHandleProcessLargeFile(aMessage); sl@0: break; sl@0: sl@0: case RFileHandleSharer64Bit::EMsgExit: sl@0: { sl@0: aMessage.Complete(KErrNone); sl@0: sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: break; sl@0: sl@0: case RFileHandleSharer64Bit::EMsgSync: sl@0: aMessage.Complete(KErrNone); sl@0: break; sl@0: sl@0: case RFileHandleSharer64Bit::EMsgDrive: sl@0: gTestDrive=aMessage.Int0(); sl@0: aMessage.Complete(KErrNone); sl@0: break; sl@0: default: sl@0: break; sl@0: } sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: // sl@0: // Returns a file handle from server sl@0: // sl@0: void CFHSession64Bit::GetFileHandleLargeFile2(const RMessage2& aMsg) sl@0: { sl@0: test.Next(_L("RFile64::AdoptFromServer()")); sl@0: // get the requested file mode sl@0: TFileMode fileMode = TFileMode(aMsg.Int1()); sl@0: sl@0: RFs fs; sl@0: TInt r = fs.Connect(); sl@0: sl@0: if (r == KErrNone) sl@0: r = fs.CreatePrivatePath(gTestDrive); sl@0: sl@0: if (r == KErrNone) sl@0: r = fs.SetSessionToPrivate(gTestDrive); sl@0: sl@0: if (r == KErrNone) sl@0: r = fs.ShareProtected(); sl@0: sl@0: // make sure file exists & has valid data in it sl@0: RFile64 file1; sl@0: if (r == KErrNone) sl@0: r = file1.Replace(fs,KServerFileName,EFileWrite); sl@0: r=file1.SetSize(K4GB-1); sl@0: test(r==KErrNone); sl@0: r = file1.Write(K4GB-10,KTestData4()); sl@0: sl@0: file1.Close(); sl@0: sl@0: sl@0: // re-open the file with the mode the client has requested & pass it to the client sl@0: sl@0: if (r == KErrNone) sl@0: r = file1.Open(fs,KServerFileName, fileMode); sl@0: if (r == KErrNone) sl@0: sl@0: test.Next(_L("RFile::TransferToClient()")); sl@0: sl@0: // transfer the file to the client sl@0: r = file1.TransferToClient(aMsg, 0); sl@0: test(r==KErrNone); sl@0: sl@0: // test we can still use the file sl@0: TInt64 pos = 0; sl@0: r = file1.Seek(ESeekStart, pos); sl@0: test(r == KErrNone); sl@0: TBuf8<9> rbuf; sl@0: r=file1.Read(K4GB-10,rbuf); sl@0: test(r == KErrNone); sl@0: r=rbuf.CompareF(KTestData4()); sl@0: test(r == KErrNone); sl@0: sl@0: file1.Close(); sl@0: fs.Close(); sl@0: RDebug::Print(_L("completed")); sl@0: } sl@0: sl@0: sl@0: void CFHSession64Bit::PassFileHandleLargeFile(const RMessage2& aMsg) sl@0: // sl@0: // Adopts file from test program and tests what it can and can't do sl@0: // Uses RFile64::AdoptFromClient() API sl@0: // sl@0: { sl@0: test.Next(_L("RFile64::AdoptFromClient()")); sl@0: sl@0: RFile64 file; sl@0: sl@0: // Message slot 0 is a RFs handle sl@0: // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle()) sl@0: TInt r = file.AdoptFromClient(aMsg, 0, 1); sl@0: test(r==KErrNone); sl@0: sl@0: TBuf8<9> rbuf; sl@0: r=file.Read(K4GB-10,rbuf); sl@0: test(r==KErrNone); sl@0: r=rbuf.CompareF(KTestData3()); sl@0: test(r==KErrNone); sl@0: r=file.Write(KTestData1()); sl@0: test(r==KErrAccessDenied); sl@0: r=file.ChangeMode(EFileWrite); sl@0: test(r==KErrArgument); sl@0: r=file.Rename(_L("\\newname.txt")); sl@0: test(r==KErrPermissionDenied || r==KErrAccessDenied); sl@0: file.Close(); sl@0: sl@0: aMsg.Complete(KErrNone); sl@0: } sl@0: sl@0: // sl@0: // Adopts file from test program and tests what it can and can't do sl@0: // Uses RFile64::AdoptFromCreator() API sl@0: // sl@0: void CFHSession64Bit::PassFileHandleProcessLargeFile(const RMessage2& aMsg) sl@0: { sl@0: test.Next(_L("RFile64::AdoptFromCreator()")); sl@0: sl@0: RFile64 file; sl@0: TInt r = file.AdoptFromCreator(1, 2); sl@0: test(r == KErrNone); sl@0: sl@0: TBuf8<3> rbuf; sl@0: r=file.Read(K4GB-10,rbuf,3); sl@0: test(r==KErrNone); sl@0: r=rbuf.CompareF(KTestData2()); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("RFile::Rename()")); sl@0: sl@0: // define a filename in our private path sl@0: RFs fs; sl@0: r=fs.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: TFileName sessionp; sl@0: fs.SessionPath(sessionp); sl@0: r = fs.MkDirAll(sessionp); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: r=fs.ShareProtected(); sl@0: test(r==KErrNone); sl@0: sl@0: r=fs.CreatePrivatePath(gTestDrive); sl@0: test(r==KErrNone); sl@0: r=fs.SetSessionToPrivate(gTestDrive); sl@0: test(r==KErrNone); sl@0: sl@0: TPath newPath; sl@0: fs.PrivatePath(newPath); sl@0: TFileName newFileName; sl@0: newFileName = newPath; sl@0: newFileName.Append(_L("newname.txt")); sl@0: sl@0: // delete the file before we try to rename anything to it sl@0: r = fs.Delete(newFileName); sl@0: test(r == KErrNone || r == KErrNotFound); sl@0: sl@0: TFileName fileName; sl@0: r = file.FullName(fileName); sl@0: test (r == KErrNone); sl@0: sl@0: r=file.Rename(newFileName); sl@0: test(r==KErrNone); sl@0: sl@0: file.Close(); sl@0: sl@0: // Next verify that we can delete the file (which should now sl@0: // have been moved to our private directory) sl@0: test.Next(_L("RFs::Delete()")); sl@0: r = fs.Delete(newFileName); sl@0: test(r == KErrNone); sl@0: sl@0: fs.Close(); sl@0: sl@0: sl@0: aMsg.Complete(KErrNone); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: CFHServer64Bit* CFHServer64Bit::NewL() sl@0: { sl@0: CFHServer64Bit* server = new (ELeave) CFHServer64Bit; sl@0: CleanupStack::PushL(server); sl@0: server->ConstructL(); sl@0: CleanupStack::Pop(server); sl@0: return server; sl@0: } sl@0: sl@0: void CFHServer64Bit::ConstructL() sl@0: { sl@0: } sl@0: sl@0: CFHServer64Bit::CFHServer64Bit() sl@0: : CServer2(0,ESharableSessions) sl@0: { sl@0: } sl@0: sl@0: CFHServer64Bit::~CFHServer64Bit() sl@0: { sl@0: } sl@0: sl@0: CSession2* CFHServer64Bit::NewSessionL(const TVersion& aVersion, const RMessage2&) const sl@0: // sl@0: // Create New Session sl@0: // sl@0: { sl@0: (void)aVersion; sl@0: CFHSession64Bit* s = new (ELeave) CFHSession64Bit; sl@0: return s; sl@0: } sl@0: sl@0: _LIT(KErr,"FHSERVER64BIT_ERR"); sl@0: sl@0: sl@0: TInt CFHServer64Bit::RunError(TInt aError) sl@0: { sl@0: User::Panic(KErr,aError); sl@0: return 0; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: TInt E32Main() sl@0: // sl@0: // Test Server for file handle sharing sl@0: // sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Starting FHServer64bit...")); sl@0: sl@0: // Remember the number of open handles. Just for a sanity check .... sl@0: TInt start_thc, start_phc; sl@0: RThread().HandleCount(start_phc, start_thc); sl@0: sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: sl@0: FHS_ASSERT(cleanup); sl@0: CActiveScheduler* sched=new CActiveScheduler; sl@0: FHS_ASSERT(sched); sl@0: CActiveScheduler::Install(sched); sl@0: sl@0: // start server1 sl@0: CFHServer64Bit* svr = NULL; sl@0: TRAP_IGNORE(svr = CFHServer64Bit::NewL()); sl@0: FHS_ASSERT(svr); sl@0: FHS_ASSERT(svr->Start(_L("FHServer64bit"))== KErrNone||KErrAlreadyExists); sl@0: sl@0: test.Title(); sl@0: test.Start(_L("Starting tests...")); sl@0: sl@0: sl@0: CActiveScheduler::Start(); sl@0: sl@0: RFs cleanupfs; sl@0: TInt r = cleanupfs.Connect(); sl@0: test(r==KErrNone); sl@0: r=cleanupfs.SetSessionToPrivate(gTestDrive); sl@0: test(r==KErrNone); sl@0: r=cleanupfs.Delete(KSvrFileName); sl@0: test(r==KErrNone || r==KErrNotFound); sl@0: cleanupfs.Close(); sl@0: sl@0: sl@0: test.End(); sl@0: sl@0: delete svr; sl@0: delete sched; sl@0: delete cleanup; sl@0: sl@0: // Sanity check for open handles and pending requests sl@0: TInt end_thc, end_phc; sl@0: RThread().HandleCount(end_phc, end_thc); sl@0: test(start_thc == end_thc); sl@0: test(start_phc == end_phc); sl@0: test(RThread().RequestCount() == 0); sl@0: sl@0: return 0; sl@0: }