pimappservices/calendar/tsrc/unit/src/TestCalInterimApiDCSuiteServer.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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 //
       
    15  
       
    16 #include "TestCalInterimApiDCSuiteServer.h"
       
    17 
       
    18 #include "TestCalInterimApiDefines.h"
       
    19 #include "TestCalInterimApiDCStep.h"
       
    20 #include "TestCalInterimApiDCCreateEntries.h"
       
    21 
       
    22 _LIT(KServerName,"calinterimapiunittestserver");
       
    23 	
       
    24 CTestCalInterimApiDCSuite* CTestCalInterimApiDCSuite::NewL()
       
    25 /**
       
    26  * @return - Instance of the test server
       
    27  * Same code for Secure and non-secure variants
       
    28  * Called inside the MainL() function to create and start the
       
    29  * CTestServer derived server.
       
    30  */
       
    31 	{
       
    32 	CTestCalInterimApiDCSuite * server = new (ELeave) CTestCalInterimApiDCSuite();
       
    33 	CleanupStack::PushL(server);
       
    34 
       
    35 	// CServer base class call which can be either StartL or ConstructL,
       
    36 	// the later will permit Server Logging.
       
    37 	server->StartL(KServerName);
       
    38 	//server->ConstructL(KServerName);
       
    39 
       
    40 	CleanupStack::Pop(server);
       
    41 	return server;
       
    42 	}
       
    43 
       
    44 // Secure variants much simpler
       
    45 // For EKA2, just an E32Main and a MainL()
       
    46 LOCAL_C void MainL()
       
    47 /**
       
    48  * Secure variant
       
    49  * Much simpler, uses the new Rendezvous() call to sync with the client
       
    50  */
       
    51 	{
       
    52 	// Leave the hooks in for platform security
       
    53 #if (defined __DATA_CAGING__)
       
    54 	RProcess().DataCaging(RProcess::EDataCagingOn);
       
    55 	RProcess().DataCaging(RProcess::ESecureApiOn);
       
    56 #endif
       
    57 	CActiveScheduler* sched=NULL;
       
    58 	sched=new(ELeave) CActiveScheduler;
       
    59 	CActiveScheduler::Install(sched);
       
    60 	CTestCalInterimApiDCSuite* server = NULL;
       
    61 	// Create the CTestServer derived server
       
    62 	TRAPD(err,server = CTestCalInterimApiDCSuite::NewL());
       
    63 	if(!err)
       
    64 		{
       
    65 		// Sync with the client and enter the active scheduler
       
    66 		RProcess::Rendezvous(KErrNone);
       
    67 	#ifdef __WINS__ 
       
    68 		// Start the Alarm Server
       
    69 		TBuf<MAX_TEXT_MESSAGE> buffer;
       
    70 		buffer.Append('p');
       
    71 		buffer.Append('p');
       
    72 		buffer.Append(EKeyEscape);
       
    73 		RProcess alarmServer;
       
    74 		alarmServer.Create(KConsoleAlarmAlertServerImg, buffer, serverUid);	
       
    75 		TRequestStatus stat;
       
    76 		alarmServer.Rendezvous(stat);
       
    77 		if (stat != KRequestPending)
       
    78 			{
       
    79 			alarmServer.Kill(0);
       
    80 			}
       
    81 			else
       
    82 			{
       
    83 			alarmServer.Resume();
       
    84 			}
       
    85 		
       
    86 		User::WaitForRequest(stat);
       
    87 		TInt result = stat.Int();
       
    88 		if(result != KErrNone && result != KErrAlreadyExists)
       
    89 			{
       
    90 			User::LeaveIfError(result);	
       
    91 			}
       
    92 	#endif //WINS
       
    93 		sched->Start();
       
    94 		}
       
    95 
       
    96 	delete server;
       
    97 	delete sched;
       
    98 	}
       
    99 
       
   100 GLDEF_C TInt E32Main()
       
   101 /**
       
   102  * @return - Standard Epoc error code on process exit
       
   103  * Secure variant only
       
   104  * Process entry point. Called by client using RProcess API
       
   105  */
       
   106 	{
       
   107 	__UHEAP_MARK;
       
   108 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   109 	if(cleanup == NULL)
       
   110 		{
       
   111 		return KErrNoMemory;
       
   112 		}
       
   113 	TRAP_IGNORE(MainL());
       
   114 	delete cleanup;
       
   115 	__UHEAP_MARKEND;
       
   116 	return KErrNone;
       
   117     }
       
   118 
       
   119 CTestStep* CTestCalInterimApiDCSuite::CreateTestStep(const TDesC& aStepName)
       
   120 /**
       
   121  * @return - A CTestStep derived instance
       
   122  * Secure and non-secure variants
       
   123  * Implementation of CTestServer pure virtual
       
   124  */
       
   125 	{
       
   126 	CTestStep* testStep = NULL;
       
   127 	// They are created "just in time" when the worker thread is created
       
   128 	// More test steps can be added below 
       
   129 	if(aStepName == KTestCalInterimApiDCCreateEntries)
       
   130 		{
       
   131 		testStep = new CTestCalInterimApiDCCreateEntries();
       
   132 		}
       
   133 	else if(aStepName == KTestCalInterimApiDCTest)
       
   134 		{
       
   135 		testStep = new CTestCalInterimApiDCTest();
       
   136 		}
       
   137 	return testStep;
       
   138 	}