installationservices/swtransactionservices/test/source/tststestsuiteserver.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @test
       
    22  @internalComponent
       
    23 */
       
    24 #include "tststestsuitestepcommon.h"
       
    25 #include "tststestsuiteserver.h"
       
    26 #include "tststestsuitestep.h"
       
    27 #include "tintegrityservicesstep.h"
       
    28 
       
    29 using namespace Usif;
       
    30 
       
    31 LOCAL_C void MainL()
       
    32 	{
       
    33 	CActiveScheduler* sched=NULL;
       
    34 	sched=new(ELeave) CActiveScheduler;
       
    35 	CActiveScheduler::Install(sched);
       
    36 	CStsTestServer* server = NULL;
       
    37 	// Create the CTestServer derived server
       
    38 	TRAPD(err,server = CStsTestServer::NewL());
       
    39 	if(!err)
       
    40 		{
       
    41 		// Sync with the client and enter the active scheduler
       
    42 		RProcess::Rendezvous(KErrNone);
       
    43 		sched->Start();
       
    44 		}
       
    45 	delete server;
       
    46 	delete sched;
       
    47 	}
       
    48 
       
    49 
       
    50 TInt E32Main()
       
    51 /**
       
    52  @return - Standard Epoc error code on process exit
       
    53  Process entry point. Called by client using RProcess API
       
    54  */
       
    55 	{
       
    56 	__UHEAP_MARK;
       
    57 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
    58 	if(cleanup == NULL)
       
    59 		{
       
    60 		return KErrNoMemory;
       
    61 		}
       
    62 	TRAPD(err,MainL());
       
    63 	delete cleanup;
       
    64 	__UHEAP_MARKEND;
       
    65 	return err;
       
    66 	}
       
    67 
       
    68 _LIT(KServerName,"tststestserver");
       
    69 
       
    70 CStsTestServer* CStsTestServer::NewL()
       
    71 /**
       
    72  @return - Instance of the test server
       
    73  Called inside the MainL() function to create and start the
       
    74  CTestServer derived server.
       
    75  */
       
    76 	{
       
    77 	CStsTestServer * server = new (ELeave) CStsTestServer();
       
    78 	CleanupStack::PushL(server);
       
    79 	server-> ConstructL();
       
    80 	CleanupStack::Pop(server);
       
    81 	return server;
       
    82 	}
       
    83 
       
    84 void CStsTestServer::ConstructL()
       
    85 	{
       
    86 	CTestServer::ConstructL(KServerName);
       
    87 	User::LeaveIfError(iTestutil.Connect());
       
    88 	iTestutil.ShareAuto();
       
    89 	}
       
    90 
       
    91 CStsTestServer::~CStsTestServer()
       
    92 	{
       
    93 	for(TInt i=0; i<maxNumberOfSessions; ++i)
       
    94 		{
       
    95 		iSessions[i].Close(); //close the session in case it is open
       
    96 		}
       
    97 	iTestutil.Close();
       
    98 	}
       
    99 
       
   100 CTestStep* CStsTestServer::CreateTestStep(const TDesC& aStepName)
       
   101 /**
       
   102  @return - A CTestStep derived instance
       
   103  Implementation of CTestServer pure virtual
       
   104  */
       
   105 	{
       
   106 	CTestStep* testStep = NULL;
       
   107 
       
   108 	if(aStepName == KCreateTransactionStep)
       
   109 		testStep = new CCreateTransactionStep(*this);
       
   110 	else if(aStepName == KOpenTransactionStep)
       
   111 		testStep = new COpenTransactionStep(*this);
       
   112 	else if(aStepName == KCloseTransactionStep)
       
   113 		testStep = new CCloseTransactionStep(*this);
       
   114 	else if(aStepName == KRegisterNewFileStep)
       
   115 		testStep = new CRegisterNewFileStep(*this);
       
   116 	else if(aStepName == KCreateNewFileStep)
       
   117 		testStep = new CCreateNewFileStep(*this);
       
   118 	else if(aStepName == KRemoveStep)
       
   119 		testStep = new CRemoveStep(*this);
       
   120 	else if(aStepName == KRegisterTemporaryStep)
       
   121 		testStep = new CRegisterTemporaryStep(*this);
       
   122 	else if(aStepName == KCreateTemporaryStep)
       
   123 		testStep = new CCreateTemporaryStep(*this);
       
   124 	else if(aStepName == KOverwriteStep)
       
   125 		testStep = new COverwriteStep(*this);
       
   126 	else if(aStepName == KCommitStep)
       
   127 		testStep = new CCommitStep(*this);
       
   128 	else if(aStepName == KRollbackStep)
       
   129 		testStep = new CRollbackStep(*this);
       
   130 	else if(aStepName == KRollbackAllPendingStep)
       
   131 		testStep = new CRollbackAllPendingStep(*this);
       
   132 	else if(aStepName == KCheckFilesStep)
       
   133 		testStep = new CCheckFilesStep(*this);
       
   134 	else if(aStepName == KCheckFileModeChangeStep)
       
   135 		testStep = new CheckFileModeChangeStep(*this);
       
   136 	else if(aStepName == KFileOperationsStep)
       
   137 		testStep = new CFileOperationsStep(*this);
       
   138 	else if(aStepName == KFileModeTestStep)
       
   139 		testStep = new CFileModeTestStep(*this);	
       
   140 		
       
   141 	//legacy integrity services support
       
   142 	else if (aStepName == KInstall)
       
   143 		testStep = new CInstallStep(*this);
       
   144 	else if (aStepName == KRecover)
       
   145 		testStep = new CRecoverStep(*this);
       
   146 	else if (aStepName == KCleanup)
       
   147 		testStep = new CCleanupStep(*this);
       
   148 	else if (aStepName == KCheck)
       
   149 		testStep = new CCheckStep(*this);
       
   150 
       
   151 	//integrity services unit tests
       
   152 	else if (aStepName == KJournalFileUnitTest)
       
   153 		testStep = new CJournalFileUnitTest(*this);
       
   154 	else if (aStepName == KJournalFileUnitTestAdd)
       
   155 		testStep = new CJournalFileUnitTestAdd(*this);
       
   156 	else if (aStepName == KJournalFileUnitTestTemp)
       
   157 		testStep = new CJournalFileUnitTestTemp(*this);
       
   158 	else if (aStepName == KJournalFileUnitTestRemove)
       
   159 		testStep = new CJournalFileUnitTestRemove(*this);
       
   160 	else if (aStepName == KJournalFileUnitTestRead)
       
   161 		testStep = new CJournalFileUnitTestRead(*this);
       
   162 	else if (aStepName == KJournalFileUnitTestEvent)
       
   163 		testStep = new CJournalFileUnitTestEvent(*this);
       
   164 	else if (aStepName == KJournalUnitTest)
       
   165 		testStep = new CJournalUnitTest(*this);
       
   166 	else if (aStepName == KJournalUnitTestInstall)
       
   167 		testStep = new CJournalUnitTestInstall(*this);
       
   168 	else if (aStepName == KJournalUnitTestRollback)
       
   169 		testStep = new CJournalUnitTestRollback(*this);
       
   170 	else if (aStepName == KIntegrityservicesUnitTestInstall)
       
   171 		testStep = new CIntegrityServicesTestInstall(*this);
       
   172 	else if (aStepName == KIntegrityservicesUnitTestRollback)
       
   173 		testStep = new CIntegrityServicesTestRollback(*this);	
       
   174 	else if (aStepName == KCreateLongFileNameTestStep)
       
   175 		testStep = new CCreateLongFileNameTestStep(*this);	
       
   176 	return testStep;
       
   177 	}
       
   178 
       
   179 TStsTransactionId CStsTestServer::CreateTransactionL(TInt aPos)
       
   180 	{
       
   181 	RStsSession& s = GetSessionL(aPos); //leaves if aPos is out of boundaries
       
   182 	TStsTransactionId id(0);
       
   183 	//see remark below at OpenTransactionL()
       
   184 	id = s.CreateTransactionL();
       
   185 	s.ShareAuto();
       
   186 	return id;
       
   187 	}
       
   188 
       
   189 void CStsTestServer::OpenTransactionL(TInt aPos, TStsTransactionId aTransactionID)
       
   190 	{
       
   191 	RStsSession& s = GetSessionL(aPos); //leaves if aPos is out of boundaries
       
   192 	/*
       
   193 	 If OpenTransactionL() leaves for some reasons (eg: in one of the testcases invalid id is supplied
       
   194 	 so it is expected to leave with KErrNotFound) s.ShareAuto() is not invoked, that's s is not shared
       
   195 	 in the context of the process. As leaving causes the corresponding teststep's thread to be killed the
       
   196 	 connection between the client and the server is destroyed by the kernel leaving s's iHandle to point to and invalid object.
       
   197 	 As a result any subsequent API call on s causes panic therefore we need to clean up properly in case of leave. 
       
   198 	 */
       
   199 	TRAPD(err, s.OpenTransactionL(aTransactionID));
       
   200 	if(err != KErrNone)
       
   201 		{
       
   202 		CloseTransactionL(aPos);
       
   203 		User::Leave(err);
       
   204 		}
       
   205 	s.ShareAuto();
       
   206 	}
       
   207 
       
   208 void CStsTestServer::CloseTransactionL(TInt aPos)
       
   209 	{
       
   210 	GetSessionL(aPos).Close();
       
   211 	}
       
   212 
       
   213 void CStsTestServer::RegisterNewL(TInt aPos, const TDesC& aFileName)
       
   214 	{
       
   215 	GetSessionL(aPos).RegisterNewL(aFileName);
       
   216 	}
       
   217 
       
   218 void CStsTestServer::CreateNewL(TInt aPos, const TDesC& aFileName, RFile &aFile, TUint aFileMode)
       
   219 	{
       
   220 	GetSessionL(aPos).CreateNewL(aFileName, aFile, aFileMode);
       
   221 	}
       
   222 
       
   223 void CStsTestServer::RemoveL(TInt aPos, const TDesC& aFileName)
       
   224 	{
       
   225 	GetSessionL(aPos).RemoveL(aFileName);
       
   226 	}
       
   227 
       
   228 void CStsTestServer::RegisterTemporaryL(TInt aPos, const TDesC& aFileName)
       
   229 	{
       
   230 	GetSessionL(aPos).RegisterTemporaryL(aFileName);
       
   231 	}
       
   232 
       
   233 void CStsTestServer::CreateTemporaryL(TInt aPos, const TDesC& aFileName, RFile &aFile, TUint aFileMode)
       
   234 	{
       
   235 	GetSessionL(aPos).CreateTemporaryL(aFileName, aFile, aFileMode);
       
   236 	}
       
   237 
       
   238 void CStsTestServer::OverwriteL(TInt aPos, const TDesC& aFileName, RFile &aFile, TUint aFileMode)
       
   239 	{
       
   240 	GetSessionL(aPos).OverwriteL(aFileName, aFile, aFileMode);
       
   241 	}
       
   242 
       
   243 void CStsTestServer::CommitL(TInt aPos)
       
   244 	{
       
   245 	GetSessionL(aPos).CommitL();
       
   246 	CloseTransactionL(aPos);
       
   247 	}
       
   248 
       
   249 void CStsTestServer::RollBackL(TInt aPos)
       
   250 	{
       
   251 	GetSessionL(aPos).RollBackL();
       
   252 	CloseTransactionL(aPos);
       
   253 	}
       
   254 
       
   255 RStsSession& CStsTestServer::GetSessionL(TInt aPos)
       
   256 	{
       
   257 	if(aPos <0 || aPos>=maxNumberOfSessions)
       
   258 		{
       
   259 		ERR_PRINTF2(_L("Position %d is out of boundaries!"), aPos);
       
   260 		User::Leave(KErrArgument);
       
   261 		}
       
   262 	return iSessions[aPos];
       
   263 	}
       
   264 
       
   265 TStsTransactionId CStsTestServer::GetTransactionIDL(TInt aPos)
       
   266 	{
       
   267 	return GetSessionL(aPos).TransactionIdL();
       
   268 	}
       
   269