1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/fileshare/handshare.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,730 @@
1.4 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\loader\handshare.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32svr.h>
1.22 +#include <e32test.h>
1.23 +#include "handshare.h"
1.24 +
1.25 +#ifdef __VC32__
1.26 +#pragma warning(disable:4706)
1.27 +#endif
1.28 +
1.29 +
1.30 +
1.31 +GLDEF_D RTest test(_L("HANDSHARE_SVR"));
1.32 +
1.33 +#define PANIC() FHSvrPanic(__LINE__)
1.34 +#define FHS_ASSERT(c) ((void)((c)||(PANIC(),0)))
1.35 +
1.36 +const TTimeIntervalMicroSeconds32 KHalfSecond(500000);
1.37 +
1.38 +const TInt KHeapSize=0x2000;
1.39 +
1.40 +void FHSvrPanic(TInt aLine)
1.41 + {
1.42 + User::Panic(_L("FHServer"),aLine);
1.43 + }
1.44 +
1.45 +LOCAL_D TInt gTestDrive;
1.46 +
1.47 +/******************************************************************************
1.48 + * Class Definitions
1.49 + ******************************************************************************/
1.50 +
1.51 +
1.52 +class CFHServer : public CServer2
1.53 + {
1.54 +public:
1.55 + static CFHServer* NewL();
1.56 + void ConstructL();
1.57 + virtual ~CFHServer();
1.58 + virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
1.59 + virtual TInt RunError(TInt aError);
1.60 +private:
1.61 + CFHServer();
1.62 + };
1.63 +
1.64 +class CFHSession : public CSession2
1.65 + {
1.66 +public:
1.67 + virtual ~CFHSession();
1.68 + virtual void CreateL();
1.69 + virtual void ServiceL(const RMessage2& aMessage);
1.70 +public:
1.71 +
1.72 + void GetFileHandle(const RMessage2& aMsg);
1.73 + void GetFileHandle2(const RMessage2& aMsg);
1.74 + void PassFileHandle(const RMessage2& aMsg);
1.75 + void PassFileHandleProcess(const RMessage2& aMsg);
1.76 + void PassInvalidFileHandle(const RMessage2& aMsg);
1.77 + };
1.78 +
1.79 +// a second server so we can test passing file handles from
1.80 +// client to server to server2
1.81 +class CFHServer2 : public CServer2
1.82 + {
1.83 +public:
1.84 + static CFHServer2* NewL();
1.85 + void ConstructL();
1.86 + virtual ~CFHServer2();
1.87 + virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
1.88 + virtual TInt RunError(TInt aError);
1.89 +private:
1.90 + CFHServer2();
1.91 +public:
1.92 + };
1.93 +
1.94 +
1.95 +class CFHSession2 : public CSession2
1.96 + {
1.97 +public:
1.98 + virtual ~CFHSession2();
1.99 + virtual void CreateL();
1.100 + virtual void ServiceL(const RMessage2& aMessage);
1.101 +public:
1.102 + void PassFileHandle(const RMessage2& aMsg);
1.103 + void GetFileHandle(const RMessage2& aMsg);
1.104 + };
1.105 +
1.106 +
1.107 +/******************************************************************************
1.108 + * Class CFHSession/CFHServer
1.109 + ******************************************************************************/
1.110 +void ExceptionHandler(TExcType)
1.111 + {
1.112 + User::Leave(KErrGeneral);
1.113 + }
1.114 +
1.115 +
1.116 +
1.117 +CFHSession::~CFHSession()
1.118 + {
1.119 + }
1.120 +
1.121 +void CFHSession::CreateL()
1.122 + {
1.123 +
1.124 + }
1.125 +
1.126 +void CFHSession::ServiceL(const RMessage2& aMessage)
1.127 + {
1.128 + __UHEAP_MARK;
1.129 + TInt mid=aMessage.Function();
1.130 + switch(mid)
1.131 + {
1.132 + case RFileHandleSharer::EMsgGetFileHandle:
1.133 + GetFileHandle(aMessage);
1.134 + break;
1.135 +
1.136 + case RFileHandleSharer::EMsgGetFileHandle2:
1.137 + GetFileHandle2(aMessage);
1.138 + break;
1.139 +
1.140 + case RFileHandleSharer::EMsgPassFileHandle:
1.141 + PassFileHandle(aMessage);
1.142 + break;
1.143 +
1.144 + case RFileHandleSharer::EMsgPassFileHandleProcess:
1.145 + PassFileHandleProcess(aMessage);
1.146 + break;
1.147 +
1.148 + case RFileHandleSharer::EMsgPassInvalidFileHandle:
1.149 + PassInvalidFileHandle(aMessage);
1.150 + break;
1.151 +
1.152 + case RFileHandleSharer::EMsgExit:
1.153 + {
1.154 + // stop server2
1.155 + RFileHandleSharer2 handsvr2;
1.156 + TInt r=handsvr2.Connect();
1.157 + test(r==KErrNone);
1.158 + r = handsvr2.Exit();
1.159 + test(r==KErrNone || r == KErrServerTerminated);
1.160 + handsvr2.Close();
1.161 +
1.162 + aMessage.Complete(KErrNone);
1.163 +
1.164 + CActiveScheduler::Stop();
1.165 + }
1.166 + break;
1.167 +
1.168 + case RFileHandleSharer::EMsgSync:
1.169 + aMessage.Complete(KErrNone);
1.170 + break;
1.171 +
1.172 + case RFileHandleSharer::EMsgDrive:
1.173 + gTestDrive=aMessage.Int0();
1.174 + aMessage.Complete(KErrNone);
1.175 + break;
1.176 + default:
1.177 + break;
1.178 + }
1.179 + __UHEAP_MARKEND;
1.180 + }
1.181 +
1.182 +
1.183 +//
1.184 +// Returns session and relevant file handle to Client in read mode
1.185 +// This is to allow the client to test the deprcated function RFile::Adopt()
1.186 +void CFHSession::GetFileHandle(const RMessage2& aMsg)
1.187 + {
1.188 + test.Printf(_L("Get file handle"));
1.189 +
1.190 + // get the requested file mode
1.191 + TInt fileMode = aMsg.Int1();
1.192 +
1.193 + RFs fs;
1.194 + TInt r=fs.Connect();
1.195 + r=fs.CreatePrivatePath(gTestDrive);
1.196 + test(r==KErrNone);
1.197 + r=fs.SetSessionToPrivate(gTestDrive);
1.198 + test(r==KErrNone);
1.199 + r=fs.ShareProtected();
1.200 + test(r==KErrNone);
1.201 + RFile file1;
1.202 + r=file1.Create(fs,KSvrFileName,EFileWrite);
1.203 + test(r==KErrNone || r==KErrAlreadyExists);
1.204 + if (r==KErrAlreadyExists)
1.205 + {
1.206 + r=file1.Open(fs,KSvrFileName, EFileWrite);
1.207 + test(r==KErrNone);
1.208 + }
1.209 + r=file1.Write(KTestData1());
1.210 + test(r==KErrNone);
1.211 + file1.Close();
1.212 +
1.213 + r=file1.Open(fs,KSvrFileName, fileMode);
1.214 + test(r==KErrNone);
1.215 +
1.216 + TInt fssh=file1.SubSessionHandle();
1.217 + r=aMsg.Write(0, TPckgC<TInt>(fssh));
1.218 + test(r==KErrNone);
1.219 + aMsg.Complete(fs);
1.220 + fs.Close();
1.221 + }
1.222 +
1.223 +//
1.224 +// Returns a file handle from server2
1.225 +//
1.226 +void CFHSession::GetFileHandle2(const RMessage2& aMsg)
1.227 + {
1.228 + test.Next(_L("RFile::AdoptFromServer()"));
1.229 +
1.230 + // pass the request on to FHServer2 - this will create a file
1.231 + // which we can then adopt before returning it to the client
1.232 +
1.233 + // get the requested file mode
1.234 + TInt fileMode = aMsg.Int1();
1.235 +
1.236 + RFileHandleSharer2 handsvr2;
1.237 + TInt r = handsvr2.Connect();
1.238 + test(r==KErrNone);
1.239 +
1.240 + TInt ssh;
1.241 + TInt fsh = handsvr2.GetFileHandle(ssh, TFileMode(fileMode));
1.242 + test(fsh >= 0);
1.243 +
1.244 + // adopt the file from FHServer2
1.245 + RFile file;
1.246 + r=file.AdoptFromServer(fsh, ssh);
1.247 + test(r==KErrNone);
1.248 +
1.249 + test.Next(_L("RFile::TransferToClient()"));
1.250 +
1.251 + // transfer the file to the client
1.252 + r = file.TransferToClient(aMsg, 0);
1.253 + test(r==KErrNone);
1.254 +
1.255 + // test we can still use the file
1.256 + TInt pos = 0;
1.257 + r = file.Seek(ESeekStart, pos);
1.258 + test(r==KErrNone);
1.259 + TBuf8<100> rbuf;
1.260 + r=file.Read(0,rbuf);
1.261 + test(r==KErrNone);
1.262 + r=rbuf.CompareF(KTestData1());
1.263 + test(r==KErrNone);
1.264 +
1.265 + handsvr2.Close();
1.266 +
1.267 + file.Close();
1.268 +
1.269 + RDebug::Print(_L("completed"));
1.270 + }
1.271 +
1.272 +void CFHSession::PassFileHandle(const RMessage2& aMsg)
1.273 +//
1.274 +// Adopts file from test program and tests what it can and can't do
1.275 +// Uses new AdoptFromClient() API
1.276 +//
1.277 + {
1.278 + test.Next(_L("RFile::AdoptFromClient()"));
1.279 +
1.280 + // connect to FHServer2
1.281 + RFileHandleSharer2 handsvr2;
1.282 + TInt r = handsvr2.Connect();
1.283 + test(r==KErrNone);
1.284 +
1.285 + RFile file;
1.286 +
1.287 + // Message slot 0 is a RFs handle
1.288 + // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle())
1.289 + r = file.AdoptFromClient(aMsg, 0, 1);
1.290 + test(r==KErrNone);
1.291 +
1.292 +
1.293 +
1.294 + TBuf8<100> rbuf;
1.295 + r=file.Read(0,rbuf);
1.296 + test(r==KErrNone);
1.297 + r=rbuf.CompareF(KTestData());
1.298 + test(r==KErrNone);
1.299 + r=file.Write(KTestData1());
1.300 + test(r==KErrAccessDenied);
1.301 + r=file.ChangeMode(EFileWrite);
1.302 + test(r==KErrArgument);
1.303 + r=file.Rename(_L("\\newname.txt"));
1.304 + test(r==KErrPermissionDenied || r==KErrAccessDenied);
1.305 +// should try a delete
1.306 +
1.307 + // pass the file handle to FHServer2
1.308 + test.Next(_L("RFile::TransferToServer()"));
1.309 +
1.310 + TIpcArgs ipcArgs;
1.311 + file.TransferToServer(ipcArgs, 0, 1);
1.312 + r = handsvr2.PassFileHandle(ipcArgs);
1.313 + test(r==KErrNone);
1.314 +
1.315 + TInt pos = 0;
1.316 + r = file.Seek(ESeekStart, pos);
1.317 + test(r==KErrNone);
1.318 + r=file.Read(0,rbuf);
1.319 + test(r==KErrNone);
1.320 + r=rbuf.CompareF(KTestData());
1.321 + test(r==KErrNone);
1.322 +
1.323 + file.Close();
1.324 +
1.325 + handsvr2.Close();
1.326 +
1.327 + aMsg.Complete(KErrNone);
1.328 + }
1.329 +
1.330 +//
1.331 +// Adopts file from test program and tests what it can and can't do
1.332 +// Uses new AdoptFromCreator() API
1.333 +//
1.334 +void CFHSession::PassFileHandleProcess(const RMessage2& aMsg)
1.335 + {
1.336 + test.Next(_L("RFile::AdoptFromCreator()"));
1.337 +
1.338 + RFile file;
1.339 + TInt r = file.AdoptFromCreator(1, 2);
1.340 + test(r == KErrNone);
1.341 +
1.342 + TBuf8<100> rbuf;
1.343 + r=file.Read(0,rbuf);
1.344 + test(r==KErrNone);
1.345 + r=rbuf.CompareF(KTestData());
1.346 + test(r==KErrNone);
1.347 +
1.348 + test.Next(_L("RFile::Rename()"));
1.349 +
1.350 + // define a filename in our private path
1.351 + RFs fs;
1.352 + r=fs.Connect();
1.353 + test(r==KErrNone);
1.354 +
1.355 + TFileName sessionp;
1.356 + fs.SessionPath(sessionp);
1.357 + r = fs.MkDirAll(sessionp);
1.358 + test(r==KErrNone || r==KErrAlreadyExists);
1.359 +
1.360 + r=fs.ShareProtected();
1.361 + test(r==KErrNone);
1.362 +
1.363 + r=fs.CreatePrivatePath(gTestDrive);
1.364 + test(r==KErrNone);
1.365 + r=fs.SetSessionToPrivate(gTestDrive);
1.366 + test(r==KErrNone);
1.367 +
1.368 + TPath newPath;
1.369 + fs.PrivatePath(newPath);
1.370 + TFileName newFileName;
1.371 + newFileName = newPath;
1.372 + newFileName.Append(_L("newname.txt"));
1.373 +
1.374 + // delete the file before we try to rename anything to it
1.375 + r = fs.Delete(newFileName);
1.376 + test(r == KErrNone || r == KErrNotFound);
1.377 +
1.378 + r=file.Rename(newFileName);
1.379 + test(r==KErrNone);
1.380 +
1.381 + file.Close();
1.382 +
1.383 + // Next verify that we can delete the file (which should now
1.384 + // have been moved to our private directory)
1.385 + test.Next(_L("RFs::Delete()"));
1.386 + r = fs.Delete(newFileName);
1.387 + test(r == KErrNone);
1.388 +
1.389 + fs.Close();
1.390 +
1.391 +
1.392 + aMsg.Complete(KErrNone);
1.393 + }
1.394 +
1.395 +void CFHSession::PassInvalidFileHandle(const RMessage2& aMsg)
1.396 +//
1.397 +// Attempts to adopt an invalid file handle from test program
1.398 +// and tests that KErrBadHandle is returned by AdoptFromClient()
1.399 +//
1.400 + {
1.401 + test.Next(_L("PassInvalidFileHandle - RFile::AdoptFromClient()"));
1.402 +
1.403 + RFile file;
1.404 +
1.405 + // Message slot 0 is a RFs handle
1.406 + // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle())
1.407 + TInt r = file.AdoptFromClient(aMsg, 0, 1);
1.408 + test(r==KErrBadHandle);
1.409 +
1.410 +
1.411 + aMsg.Complete(r);
1.412 + }
1.413 +
1.414 +CFHServer* CFHServer::NewL()
1.415 + {
1.416 + CFHServer* server = new (ELeave) CFHServer;
1.417 + CleanupStack::PushL(server);
1.418 + server->ConstructL();
1.419 + CleanupStack::Pop(server);
1.420 + return server;
1.421 + }
1.422 +
1.423 +void CFHServer::ConstructL()
1.424 + {
1.425 + }
1.426 +
1.427 +CFHServer::CFHServer()
1.428 + : CServer2(0,ESharableSessions)
1.429 + {
1.430 + }
1.431 +
1.432 +CFHServer::~CFHServer()
1.433 + {
1.434 + }
1.435 +
1.436 +CSession2* CFHServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const
1.437 +//
1.438 +// Create New Session
1.439 +//
1.440 + {
1.441 + (void)aVersion;
1.442 + CFHSession* s = new (ELeave) CFHSession;
1.443 + return s;
1.444 + }
1.445 +
1.446 +_LIT(KErr,"FHSERVER_ERR");
1.447 +CFHServer2* CFHServer2::NewL()
1.448 + {
1.449 + CFHServer2* server = new (ELeave) CFHServer2;
1.450 + CleanupStack::PushL(server);
1.451 + server->ConstructL();
1.452 + CleanupStack::Pop(server);
1.453 + return server;
1.454 + }
1.455 +
1.456 +void CFHServer2::ConstructL()
1.457 + {
1.458 + }
1.459 +
1.460 +TInt CFHServer::RunError(TInt aError)
1.461 + {
1.462 + User::Panic(KErr,aError);
1.463 + return 0;
1.464 + }
1.465 +
1.466 +// File handle server #2
1.467 +CFHServer2::CFHServer2()
1.468 + : CServer2(0,ESharableSessions)
1.469 + {
1.470 + }
1.471 +
1.472 +CFHServer2::~CFHServer2()
1.473 + {
1.474 + }
1.475 +
1.476 +CSession2* CFHServer2::NewSessionL(const TVersion& aVersion, const RMessage2&) const
1.477 +//
1.478 +// Create New Session
1.479 +//
1.480 + {
1.481 + (void)aVersion;
1.482 + CFHSession2* s = new (ELeave) CFHSession2;
1.483 + return s;
1.484 + }
1.485 +
1.486 +_LIT(KErr2,"FHSERVER2_ERR");
1.487 +TInt CFHServer2::RunError(TInt aError)
1.488 + {
1.489 + User::Panic(KErr2,aError);
1.490 + return 0;
1.491 + }
1.492 +
1.493 +CFHSession2::~CFHSession2()
1.494 + {
1.495 + }
1.496 +
1.497 +void CFHSession2::CreateL()
1.498 + {
1.499 +
1.500 + }
1.501 +
1.502 +void CFHSession2::ServiceL(const RMessage2& aMessage)
1.503 + {
1.504 + __UHEAP_MARK;
1.505 + TInt mid=aMessage.Function();
1.506 + switch(mid)
1.507 + {
1.508 + case RFileHandleSharer::EMsgPassFileHandle:
1.509 + PassFileHandle(aMessage);
1.510 + break;
1.511 +
1.512 + case RFileHandleSharer::EMsgGetFileHandle:
1.513 + GetFileHandle(aMessage);
1.514 + break;
1.515 +
1.516 + case RFileHandleSharer::EMsgExit:
1.517 + aMessage.Complete(KErrNone);
1.518 + CActiveScheduler::Stop();
1.519 + break;
1.520 +
1.521 + default:
1.522 + break;
1.523 + }
1.524 + __UHEAP_MARKEND;
1.525 + }
1.526 +
1.527 +
1.528 +//
1.529 +// Adopts file from server 1
1.530 +//
1.531 +void CFHSession2::PassFileHandle(const RMessage2& aMsg)
1.532 + {
1.533 + RFile file;
1.534 +
1.535 + // Message slot 0 is a RFs handle
1.536 + // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle())
1.537 + TInt r = file.AdoptFromClient(aMsg, 0, 1);
1.538 + if (r != KErrNone)
1.539 + {
1.540 + aMsg.Complete(r);
1.541 + return;
1.542 + }
1.543 +
1.544 +
1.545 + TBuf8<100> rbuf;
1.546 +
1.547 + if (r == KErrNone)
1.548 + r=file.Read(0,rbuf);
1.549 +
1.550 + if (r == KErrNone)
1.551 + r = rbuf.CompareF(KTestData());
1.552 +
1.553 + if (r == KErrNone)
1.554 + {
1.555 + r = file.Write(KTestData1());
1.556 + if (r == KErrAccessDenied)
1.557 + r = KErrNone;
1.558 + }
1.559 +
1.560 + if (r == KErrNone)
1.561 + {
1.562 + r = file.ChangeMode(EFileWrite);
1.563 + if (r == KErrArgument)
1.564 + r = KErrNone;
1.565 + }
1.566 +
1.567 + if (r == KErrNone)
1.568 + {
1.569 + r = file.Rename(_L("\\newname.txt"));
1.570 + if (r == KErrPermissionDenied || r == KErrAccessDenied)
1.571 + r = KErrNone;
1.572 + }
1.573 +
1.574 + file.Close();
1.575 +
1.576 + aMsg.Complete(r);
1.577 + }
1.578 +
1.579 +
1.580 +void CFHSession2::GetFileHandle(const RMessage2& aMsg)
1.581 +//
1.582 +// Returns a file handle in write mode
1.583 +//
1.584 + {
1.585 + RFs fs;
1.586 + TInt r = fs.Connect();
1.587 +
1.588 + if (r == KErrNone)
1.589 + r = fs.CreatePrivatePath(gTestDrive);
1.590 +
1.591 + if (r == KErrNone)
1.592 + r = fs.SetSessionToPrivate(gTestDrive);
1.593 +
1.594 + if (r == KErrNone)
1.595 + r = fs.ShareProtected();
1.596 +
1.597 + // make sure file exists & has valid data in it
1.598 + RFile file1;
1.599 + if (r == KErrNone)
1.600 + r = file1.Replace(fs,KSvrFileName,EFileWrite);
1.601 +
1.602 + if (r == KErrNone)
1.603 + r = file1.Write(KTestData1());
1.604 +
1.605 + file1.Close();
1.606 +
1.607 +
1.608 + // re-open the file with the mode the client has requested & pass it to the client
1.609 + TFileMode fileMode = TFileMode(aMsg.Int1());
1.610 + if (r == KErrNone)
1.611 + r = file1.Open(fs,KSvrFileName, fileMode);
1.612 + if (r == KErrNone)
1.613 + r = file1.TransferToClient(aMsg, 0);
1.614 + file1.Close();
1.615 +
1.616 + fs.Close();
1.617 +
1.618 + if (r != KErrNone)
1.619 + aMsg.Complete(r);
1.620 + }
1.621 +
1.622 +LOCAL_C TInt FHServer2(TAny * /*anArg*/)
1.623 + {
1.624 + RTest test(_L("FHServer2"));
1.625 +
1.626 + // Remember the number of open handles. Just for a sanity check ....
1.627 + TInt start_thc, start_phc;
1.628 + RThread().HandleCount(start_phc, start_thc);
1.629 +
1.630 +
1.631 + CTrapCleanup* cleanup;
1.632 + cleanup=CTrapCleanup::New();
1.633 +
1.634 + CActiveScheduler* sched=new CActiveScheduler;
1.635 + FHS_ASSERT(sched);
1.636 + CActiveScheduler::Install(sched);
1.637 +
1.638 + CFHServer2* svr2 = NULL;
1.639 + TRAP_IGNORE(svr2 = CFHServer2::NewL());
1.640 + FHS_ASSERT(svr2);
1.641 + FHS_ASSERT(svr2->Start(_L("FHServer2"))==KErrNone);
1.642 +
1.643 + CActiveScheduler::Start();
1.644 +
1.645 + delete svr2;
1.646 + delete sched;
1.647 +
1.648 + delete cleanup;
1.649 +
1.650 + // Sanity check for open handles
1.651 + TInt end_thc, end_phc;
1.652 + RThread().HandleCount(end_phc, end_thc);
1.653 + test(start_thc == end_thc);
1.654 + test(start_phc == end_phc);
1.655 + // and also for pending requests ...
1.656 + test(RThread().RequestCount() == 0);
1.657 +
1.658 +
1.659 + return KErrNone;
1.660 + }
1.661 +
1.662 +
1.663 +
1.664 +GLDEF_C TInt E32Main()
1.665 +//
1.666 +// Test Server for file handle sharing
1.667 +//
1.668 + {
1.669 + test.Title();
1.670 + test.Start(_L("Starting FHServer..."));
1.671 +
1.672 + // Remember the number of open handles. Just for a sanity check ....
1.673 + TInt start_thc, start_phc;
1.674 + RThread().HandleCount(start_phc, start_thc);
1.675 +
1.676 + CTrapCleanup* cleanup=CTrapCleanup::New();
1.677 +
1.678 + FHS_ASSERT(cleanup);
1.679 + CActiveScheduler* sched=new CActiveScheduler;
1.680 + FHS_ASSERT(sched);
1.681 + CActiveScheduler::Install(sched);
1.682 +
1.683 + // start server1
1.684 + CFHServer* svr = NULL;
1.685 + TRAP_IGNORE(svr = CFHServer::NewL());
1.686 + FHS_ASSERT(svr);
1.687 + FHS_ASSERT(svr->Start(_L("FHServer"))==KErrNone);
1.688 +
1.689 + test.Title();
1.690 + test.Start(_L("Starting tests..."));
1.691 +
1.692 + // start server2 in a seperate thread
1.693 + RThread server2Thread;
1.694 + TInt r = server2Thread.Create(_L("FHServer2"), FHServer2, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.695 + test(r==KErrNone);
1.696 + TRequestStatus statq;
1.697 + server2Thread.Logon(statq);
1.698 + server2Thread.Resume();
1.699 +
1.700 + CActiveScheduler::Start();
1.701 +
1.702 +
1.703 + // wait for server2's thread to end gracefully
1.704 + User::WaitForRequest(statq);
1.705 +
1.706 +
1.707 + server2Thread.Close();
1.708 +
1.709 + RFs cleanupfs;
1.710 + r = cleanupfs.Connect();
1.711 + test(r==KErrNone);
1.712 + r=cleanupfs.SetSessionToPrivate(gTestDrive);
1.713 + test(r==KErrNone);
1.714 + r=cleanupfs.Delete(KSvrFileName);
1.715 + test(r==KErrNone || r==KErrNotFound);
1.716 + cleanupfs.Close();
1.717 +
1.718 +
1.719 + test.End();
1.720 +
1.721 + delete svr;
1.722 + delete sched;
1.723 + delete cleanup;
1.724 +
1.725 + // Sanity check for open handles and pending requests
1.726 + TInt end_thc, end_phc;
1.727 + RThread().HandleCount(end_phc, end_thc);
1.728 + test(start_thc == end_thc);
1.729 + test(start_phc == end_phc);
1.730 + test(RThread().RequestCount() == 0);
1.731 +
1.732 + return 0;
1.733 + }