applayerpluginsandutils/bookmarksupport/test/Integration/TestBookmarksSuite/TestBookmarksServer.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2005-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 "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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Contains implementation of CTestBookmarksServer class
       
    15 // System Include
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology 
       
    22 */
       
    23 
       
    24 // User Includes
       
    25 // Test Server
       
    26 #include "TestBookmarksServer.h"
       
    27 
       
    28 // Test steps
       
    29 #include "TestBookmarksBaseStep.h"
       
    30 #include "TestCreateBookmarkItemsStep.h"
       
    31 #include "TestOpenItemStep.h"
       
    32 #include "TestSetPropertyStep.h"
       
    33 #include "TestGetPropertyStep.h"
       
    34 #include "TestDeleteFolderStep.h"
       
    35 #include "TestDeleteItemsInFolderStep.h"
       
    36 #include "TestCustomPropertyStep.h"
       
    37 #include "TestVersionStep.h"
       
    38 #include "TestUpdateVisitedStep.h"
       
    39 
       
    40 
       
    41 #if (!defined EKA2)
       
    42 // The system-wide unique name for the test-server
       
    43 _LIT(KServerName, "TestBookmarksServer");
       
    44 #endif
       
    45 
       
    46 /**
       
    47 Static factory constructor. Creates and returns instance of the test server
       
    48 @internalTechnology
       
    49 @test
       
    50 @return		A pointer to the newly created CTestBookmarksServer object
       
    51 */
       
    52 CTestBookmarksServer*  CTestBookmarksServer::NewL()
       
    53 	{
       
    54 	// Construct the server
       
    55 	CTestBookmarksServer* server = new(ELeave) CTestBookmarksServer();
       
    56 	CleanupStack::PushL(server);
       
    57 
       
    58 	// CServer base class call
       
    59 	// Name the server using the system-wide unique string
       
    60 	// Clients use this to create server sessions.
       
    61 	server->StartL(server->ServerName());
       
    62 
       
    63 	CleanupStack::Pop(server);
       
    64 	return server;
       
    65 	}
       
    66 
       
    67 /**
       
    68 Destructor. Closes the arrays.
       
    69 @internalTechnology
       
    70 @test
       
    71 */
       
    72 CTestBookmarksServer::~CTestBookmarksServer()
       
    73 	{
       
    74 	iIds.Reset();
       
    75 	iIds.Close();
       
    76 	iTitles.ResetAndDestroy();
       
    77 	iTitles.Close();
       
    78 	}
       
    79 
       
    80 #if (!defined EKA2)
       
    81 /**
       
    82 Creates the Active Scheduler, then creates the test-server, synchronises the
       
    83 thread with the client and then enters the active scheduler.
       
    84 
       
    85 This is EKA1 version of MainL(). Uses sempahore to sync with client
       
    86 as Rendezvous calls are not available
       
    87 */
       
    88 LOCAL_C void MainL()
       
    89 	{
       
    90 	// Create and install the active scheduler.
       
    91 	CActiveScheduler* sched = NULL;
       
    92 	sched = new(ELeave) CActiveScheduler;
       
    93 	CleanupStack::PushL(sched);
       
    94 	CActiveScheduler::Install(sched);
       
    95 
       
    96 	// Create the server inside trap harness
       
    97 	CTestBookmarksServer *server = NULL;
       
    98 	TRAPD(err, server = CTestBookmarksServer::NewL());
       
    99 	if (!err)
       
   100 		{
       
   101 		CleanupStack::PushL(server);
       
   102 		RSemaphore sem;
       
   103 
       
   104 		// The client API of TestExecute will already have created the
       
   105 		// semaphore and will be waiting on it.
       
   106 		User::LeaveIfError(sem.OpenGlobal(KServerName));
       
   107 
       
   108 		CleanupStack::Pop(server);
       
   109 
       
   110 		// Signal the client
       
   111 		sem.Signal();
       
   112 		sem.Close();
       
   113 
       
   114 		// Enter the active scheduler
       
   115 		sched->Start();
       
   116 		}
       
   117 	CleanupStack::Pop(sched);
       
   118 	delete server;
       
   119 	delete sched;
       
   120 	}
       
   121 #else
       
   122 /**
       
   123 EKA2 version of MainL()
       
   124 Uses the new Rendezvous call isntead of the older semaphore.
       
   125 */
       
   126 LOCAL_C void MainL()
       
   127 	{
       
   128 	// For platform security
       
   129 #if (defined __DATA_CAGING__)
       
   130 	RProcess().DataCaging(RProcess::EDataCagingOn);
       
   131 	RProcess().SecureApi(RProcess::ESecureApiOn);
       
   132 #endif
       
   133 	CActiveScheduler* sched = NULL;
       
   134 	sched = new(ELeave) CActiveScheduler;
       
   135 	CActiveScheduler::Install(sched);
       
   136 	CTestBookmarksServer* server = NULL;
       
   137 
       
   138 	// Create the test-server
       
   139 	TRAPD(err, server = CTestBookmarksServer::NewL());
       
   140 
       
   141 	if(!err)
       
   142 		{
       
   143 		// Sync with the client and enter the active scheduler
       
   144 		RProcess::Rendezvous(KErrNone);
       
   145 		sched->Start();
       
   146 		}
       
   147 	delete server;
       
   148 	delete sched;
       
   149 	}
       
   150 #endif		// #if (!defined EKA2)
       
   151 
       
   152 
       
   153 #if (defined __WINS__ && !defined EKA2)
       
   154 /**
       
   155 DLL entry-point for EKA1 emulator builds.
       
   156 */
       
   157 GLDEF_C TInt E32Dll(enum TDllReason /*aDllReason*/)
       
   158 	{
       
   159 	return KErrNone;
       
   160 	}
       
   161 #else
       
   162 /**
       
   163 Exe entry point code, for EKA1 hardware and EKA2 builds.
       
   164 */
       
   165 GLDEF_C TInt E32Main()
       
   166 	{
       
   167 	__UHEAP_MARK;
       
   168 	CTrapCleanup *cleanup = CTrapCleanup::New();
       
   169 	if (cleanup == NULL)
       
   170 		{
       
   171 		return KErrNoMemory;
       
   172 		}
       
   173 	TInt err = KErrNone;
       
   174 	TRAP(err, MainL());
       
   175 	delete cleanup;
       
   176 	__UHEAP_MARKEND;
       
   177 	return KErrNone;
       
   178 	}
       
   179 #endif		// #if (defined __WINS__ && !defined EKA2)
       
   180 
       
   181 #if (defined __WINS__ && !defined EKA2)
       
   182 /**
       
   183 For EKA1 emulator builds. This function is called when the thread is first
       
   184 resumed. Has the standard thread entry siganture.
       
   185 @internalTechnology
       
   186 @test
       
   187 @return		KErrNone if everything is fine or system-wide error if any
       
   188 */
       
   189 TInt ThreadFunc (TAny* /*aParam*/)
       
   190 	{
       
   191 	__UHEAP_MARK;
       
   192 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   193 	if (cleanup == NULL)
       
   194 		{
       
   195 		return KErrNoMemory;
       
   196 		}
       
   197 	TRAPD(err, MainL());
       
   198 	delete cleanup;
       
   199 	__UHEAP_MARKEND;
       
   200 	return KErrNone;
       
   201 	}
       
   202 
       
   203 /**
       
   204 For EKA1 emulator builds. Creates and starts a thread for the server to run.
       
   205 @internalTechnology
       
   206 @test
       
   207 @param		None
       
   208 @return		Integer value indicating the error code.
       
   209 */
       
   210 EXPORT_C TInt NewServer()
       
   211 	{
       
   212 	_LIT(KThread, "Thread");
       
   213 	RThread thread;
       
   214 
       
   215 	// Name the thread as "<Server-Name>Thread" making it hopefully unique
       
   216 	TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
       
   217 	threadName.Append(KThread);
       
   218 
       
   219 	const TInt KMaxHeapSize = 0x1000000;
       
   220 
       
   221 	// Create the thread
       
   222 	TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
       
   223 							 KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess
       
   224 							);
       
   225 	if (err != KErrNone)
       
   226 		{
       
   227 		return err;
       
   228 		}
       
   229 
       
   230 	// Start the thread -> effectively calls ThreadFunc
       
   231 	thread.Resume();
       
   232 
       
   233 	thread.Close();
       
   234 	return KErrNone;
       
   235 	}
       
   236 #endif 		// #if (defined __WINS__ && !defined EKA2)
       
   237 
       
   238 
       
   239 /**
       
   240 Base class pure virtual
       
   241 @internalTechnology
       
   242 @test
       
   243 @return 	Instance of the test step
       
   244 @param		Descriptor containing the test-step name
       
   245 */
       
   246 CTestStep* CTestBookmarksServer::CreateTestStep(const TDesC& aStepName)
       
   247 	{
       
   248 	CTestStep *testStep = NULL;
       
   249 
       
   250 	if (aStepName == KTestBookmarksBaseStep)
       
   251 		{
       
   252 		testStep = new (ELeave) CTestBookmarksBaseStep(*this);
       
   253 		}
       
   254 	if (aStepName == KTestCreateBookmarkItemsStep)
       
   255 		{
       
   256 		testStep = new (ELeave) CTestCreateBookmarkItemsStep(*this);
       
   257 		}
       
   258 	else if (aStepName == KTestOpenItemStep)
       
   259 		{
       
   260 		testStep = new (ELeave) CTestOpenItemStep(*this);
       
   261 		}
       
   262 	else if (aStepName == KTestSetPropertyStep)
       
   263 		{
       
   264 		testStep = new (ELeave) CTestSetPropertyStep(*this);
       
   265 		}
       
   266 	else if (aStepName == KTestGetPropertyStep)
       
   267 		{
       
   268 		testStep = new (ELeave) CTestGetPropertyStep(*this);
       
   269 		}
       
   270 	else if (aStepName == KTestDeleteFolderStep)
       
   271 		{
       
   272 		testStep = new (ELeave) CTestDeleteFolderStep(*this);
       
   273 		}
       
   274 	else if (aStepName == KTestDeleteItemsInFolderStep)
       
   275 		{
       
   276 		testStep = new (ELeave) CTestDeleteItemsInFolderStep(*this);
       
   277 		}
       
   278 	else if (aStepName == KTestCustomPropertyStep)
       
   279 		{
       
   280 		testStep = new (ELeave) CTestCustomPropertyStep(*this);
       
   281 		}
       
   282 	else if (aStepName == KTestVersionStep)
       
   283 		{
       
   284 		testStep = new (ELeave) CTestVersionStep(*this);
       
   285 		}
       
   286 	else if (aStepName == KTestUpdateVisitedStep)
       
   287 		{
       
   288 		testStep = new (ELeave) CTestUpdateVisitedStep(*this);
       
   289 		}
       
   290 	return testStep;
       
   291 	}
       
   292 /**
       
   293 Converts a string to TBool
       
   294 @internalTechnology
       
   295 @test
       
   296 @return		The boolean equivalent
       
   297 @param		Descriptor containing the string to be converted
       
   298 */
       
   299 TBool CTestBookmarksServer::GetBool(const TPtrC& aString)
       
   300 	{
       
   301 	_LIT(KTrue, "true");
       
   302 	return (aString.Compare(KTrue) == KErrNone) ? ETrue : EFalse;
       
   303 	}
       
   304 
       
   305 /**
       
   306 Converts a string to TUint32
       
   307 @internalTechnology
       
   308 @test
       
   309 @return		The TUint32 equivalent
       
   310 @param		Descriptor containing the value to be converted
       
   311 */
       
   312 TUint32	CTestBookmarksServer::GetTUint32(const TPtrC& aValue)
       
   313 	{
       
   314 	TUint32 tUint32;
       
   315 	TLex lex(aValue);
       
   316 	lex.Val(tUint32, EHex);
       
   317 	return tUint32;
       
   318 	}
       
   319 
       
   320 /**
       
   321 Converts a string to TInt
       
   322 @internalTechnology
       
   323 @test
       
   324 @return		The TInt equivalent
       
   325 @param		Descriptor containing the value to be converted
       
   326 */
       
   327 TInt CTestBookmarksServer::GetTInt(const TPtrC& aValue)
       
   328 	{
       
   329 	TInt tInt;
       
   330 	TLex lex(aValue);
       
   331 	lex.Val(tInt);
       
   332 	return tInt;
       
   333 	}
       
   334 
       
   335 /**
       
   336 Converts a string to TReal
       
   337 @internalTechnology
       
   338 @test
       
   339 @return		The TReal equivalent
       
   340 @param		Descriptor containing the value to be converted
       
   341 */
       
   342 TReal CTestBookmarksServer::GetTReal(const TPtrC& aValue)
       
   343 	{
       
   344 	TReal tReal;
       
   345 	TLex lex(aValue);
       
   346 	lex.Val(tReal);
       
   347 	return tReal;
       
   348 	}
       
   349 
       
   350 /**
       
   351 Returns server name based on the EKA version
       
   352 @internalTechnology
       
   353 @test
       
   354 @return		Descriptor containing the servername
       
   355 */
       
   356 const TPtrC CTestBookmarksServer::ServerName()
       
   357 	{
       
   358 #if (!defined EKA2)
       
   359 	return KServerName();
       
   360 #else
       
   361 	// The exe name can be either TestBookmarksServer or
       
   362 	// TestBookmarksServer_Cap based on whether the normal
       
   363 	// or the security tests are being run. So decide the server
       
   364 	// name during runtime
       
   365 	TParsePtrC serverName(RProcess().FileName());
       
   366 	return serverName.Name();
       
   367 #endif
       
   368 	}