pimprotocols/phonebooksync/Test/TE_Sync/TE_SyncServer.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 // Phonebook Sync Single Phonebook Unit Test server test code.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include "TE_SyncServer.h"
       
    24 #include "TE_SyncBase.h"
       
    25 #include "TE_Sync.h"
       
    26 
       
    27 _LIT(KServerName,"TE_Sync");
       
    28 
       
    29 
       
    30 CSyncTestServer::~CSyncTestServer()
       
    31 	{
       
    32 	//
       
    33 	// Shutdown the server if possible (only works in debug mode).
       
    34 	//
       
    35 	RPhoneBookSession  phoneBookSession;
       
    36 	TInt  ret;
       
    37 	
       
    38 	ret = phoneBookSession.Connect();
       
    39 	if (ret == KErrNone)
       
    40 		{
       
    41 		phoneBookSession.ShutdownServer(EFalse);
       
    42 		phoneBookSession.Close();
       
    43 		}
       
    44 	} // CSyncTestServer::~CSyncTestServer
       
    45 
       
    46 
       
    47 /**
       
    48  *  Called inside the MainL() function to create and start the CTestServer
       
    49  *  derived server.
       
    50  *
       
    51  *  @return Instance of the test server
       
    52  */
       
    53 CSyncTestServer* CSyncTestServer::NewL()
       
    54 	{
       
    55 	CSyncTestServer*  server = new(ELeave) CSyncTestServer();
       
    56 	CleanupStack::PushL(server);
       
    57 	server->StartL(KServerName);
       
    58 	CleanupStack::Pop(server);
       
    59 	return server;
       
    60 	} // CSyncTestServer::NewL
       
    61 
       
    62 
       
    63 /**
       
    64  *  Uses the new Rendezvous() call to sync with the client.
       
    65  */
       
    66 LOCAL_C void MainL()
       
    67 	{
       
    68 	//
       
    69 	// Start an active scheduler...
       
    70 	//
       
    71 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
       
    72 	CleanupStack::PushL(scheduler);
       
    73 	CActiveScheduler::Install(scheduler);
       
    74 
       
    75 	//
       
    76 	// Ensure the SIMTSY config number is reset prior to starting...
       
    77 	//
       
    78 	TInt  result;
       
    79 	
       
    80 	result = RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, 0);
       
    81 	if (result != KErrNone  &&  result != KErrNotFound)
       
    82 		{
       
    83 		User::Leave(result);
       
    84 		}
       
    85 
       
    86 	//
       
    87 	// Create the CTestServer derived server...
       
    88 	//
       
    89 	CSyncTestServer* server = NULL;
       
    90 
       
    91 	TRAPD(err, server = CSyncTestServer::NewL());
       
    92 	if (err == KErrNone)
       
    93 		{
       
    94 		//
       
    95 		// Sync with the client and enter the active scheduler
       
    96 		//
       
    97 		RProcess::Rendezvous(KErrNone);
       
    98 		scheduler->Start();
       
    99 		}
       
   100 
       
   101 	//
       
   102 	// Clean up...
       
   103 	//
       
   104 	CleanupStack::Pop(scheduler);
       
   105 	delete server;
       
   106 	delete scheduler;
       
   107 	} // MainL
       
   108 
       
   109 /**
       
   110  *  @return Standard Epoc error code on exit.
       
   111  */
       
   112 GLDEF_C TInt E32Main()
       
   113 	{
       
   114 	CTrapCleanup*  cleanup = CTrapCleanup::New();
       
   115 
       
   116 	if (cleanup == NULL)
       
   117 		{
       
   118 		return KErrNoMemory;
       
   119 		}
       
   120 
       
   121 	TRAPD(err, MainL());
       
   122 
       
   123 	delete cleanup;
       
   124 
       
   125 	return err;
       
   126 	} // E32Main
       
   127 
       
   128 
       
   129 /**
       
   130  *  Implementation of CTestServer pure virtual.
       
   131  *
       
   132  *  @return A CTestStep derived instance.
       
   133  */
       
   134 CTestStep* CSyncTestServer::CreateTestStep(const TDesC& aStepName)
       
   135 	{
       
   136     //
       
   137 	// Create the required test step...
       
   138 	//
       
   139 	CTestStep*  testStep = NULL;
       
   140 
       
   141 	if (aStepName == _L("TestOpen"))
       
   142 		{
       
   143 		testStep = new CTestOpen();
       
   144 		}
       
   145 
       
   146 	if (aStepName == _L("TestDoSynchronisation"))
       
   147 		{
       
   148 		testStep = new CTestDoSynchronisation();
       
   149 		}
       
   150 
       
   151 	if (aStepName == _L("TestWriteContactToICCTest"))
       
   152 		{
       
   153 		testStep = new CTestWriteContactToICCTest();
       
   154 		}
       
   155 
       
   156 	if (aStepName == _L("TestWriteContactToICCOverwriteTest"))
       
   157 		{
       
   158 		testStep = new CTestWriteContactToICCOverwriteTest();
       
   159 		}
       
   160 
       
   161 	if (aStepName == _L("TestWriteContactToICCNoSlotTest"))
       
   162 		{
       
   163 		testStep = new CTestWriteContactToICCNoSlotTest();
       
   164 		}
       
   165 
       
   166 	if (aStepName == _L("TestWriteContactToICCInvalidSlotTest"))
       
   167 		{
       
   168 		testStep = new CTestWriteContactToICCInvalidSlotTest();
       
   169 		}
       
   170 
       
   171 	if (aStepName == _L("TestWriteContactToICCBlankNumTest"))
       
   172 		{
       
   173 		testStep = new CTestWriteContactToICCBlankNumTest();
       
   174 		}
       
   175 
       
   176 	if (aStepName == _L("TestWriteContactToICCBlankNameTest"))
       
   177 		{
       
   178 		testStep = new CTestWriteContactToICCBlankNameTest();
       
   179 		}
       
   180 
       
   181 	if (aStepName == _L("TestWriteContactToICCExceedMaxNumTest"))
       
   182 		{
       
   183 		testStep = new CTestWriteContactToICCExceedMaxNumTest();
       
   184 		}
       
   185 
       
   186 	if (aStepName == _L("TestWriteContactToICCExceedMaxNameTest"))
       
   187 		{
       
   188 		testStep = new CTestWriteContactToICCExceedMaxNameTest();
       
   189 		}
       
   190 
       
   191 	if (aStepName == _L("TestWriteContactToICCMaxNumTest"))
       
   192 		{
       
   193 		testStep = new CTestWriteContactToICCMaxNumTest();
       
   194 		}
       
   195 
       
   196 	if (aStepName == _L("TestWriteContactToICCMaxNameTest"))
       
   197 		{
       
   198 		testStep = new CTestWriteContactToICCMaxNameTest();
       
   199 		}
       
   200 
       
   201 	if (aStepName == _L("TestWriteContactToICCNumLettersTest"))
       
   202 		{
       
   203 		testStep = new CTestWriteContactToICCNumLettersTest();
       
   204 		}
       
   205 
       
   206 	if (aStepName == _L("TestWriteContactToICCObsecureTest"))
       
   207 		{
       
   208 		testStep = new CTestWriteContactToICCObsecureTest();
       
   209 		}
       
   210 
       
   211 	if (aStepName == _L("TestValidateContact"))
       
   212 		{
       
   213 		testStep = new CTestValidateContact();
       
   214 		}
       
   215 
       
   216 	if (aStepName == _L("TestValidateContactAccessLockedTest"))
       
   217 		{
       
   218 		testStep = new CTestValidateContactAccessLockedTest();
       
   219 		}
       
   220 
       
   221 	if (aStepName == _L("TestValidateContactInvalidUIDTest"))
       
   222 		{
       
   223 		testStep = new CTestValidateContactInvalidUIDTest();
       
   224 		}
       
   225 
       
   226 	if (aStepName == _L("TestUpdateLookUpTableFailure"))
       
   227 		{
       
   228 		testStep = new CTestUpdateLookUpTableFailure();
       
   229 		}
       
   230 
       
   231 	if (aStepName == _L("TestUpdateLookUpTableSuccess"))
       
   232 		{
       
   233 		testStep = new CTestUpdateLookUpTableSuccess();
       
   234 		}
       
   235 
       
   236 	if (aStepName == _L("TestGetSyncMode"))
       
   237 		{
       
   238 		testStep = new CTestGetSyncMode();
       
   239 		}
       
   240 
       
   241 	if (aStepName == _L("TestSetSyncMode"))
       
   242 		{
       
   243 		testStep = new CTestSetSyncMode();
       
   244 		}
       
   245 
       
   246 	if (aStepName == _L("TestDeleteContactFromICC"))
       
   247 		{
       
   248 		testStep = new CTestDeleteContactFromICC();
       
   249 		}
       
   250 
       
   251 	if (aStepName == _L("TestDeleteContactInvalidIdFromICC"))
       
   252 		{
       
   253 		testStep = new CTestDeleteContactInvalidIdFromICC();
       
   254 		}
       
   255 
       
   256 	if (aStepName == _L("TestGetContactFormat"))
       
   257 		{
       
   258 		testStep = new CTestGetContactFormat();
       
   259 		}
       
   260 
       
   261 	if (aStepName == _L("TestGetPhoneBookCacheState"))
       
   262 		{
       
   263 		testStep = new CTestGetPhoneBookCacheState();
       
   264 		}
       
   265 
       
   266 	if (aStepName == _L("TestVersionTest"))
       
   267 		{
       
   268 		testStep = new CTestVersionTest();
       
   269 		}
       
   270 
       
   271 	if (aStepName == _L("TestGetLastSyncError"))
       
   272 		{
       
   273 		testStep = new CTestGetLastSyncError();
       
   274 		}
       
   275 
       
   276 	if (aStepName == _L("TestNotifyCacheStateChange"))
       
   277 		{
       
   278 		testStep = new CTestNotifyCacheStateChange();
       
   279 		}
       
   280 
       
   281 	if (aStepName == _L("TestGetPhoneBookId"))
       
   282 		{
       
   283 		testStep = new CTestGetPhoneBookId();
       
   284 		}
       
   285 
       
   286 	if (aStepName == _L("TestReset"))
       
   287 		{
       
   288 		testStep = new CTestReset();
       
   289 		}
       
   290 
       
   291 	if (aStepName == _L("TestSlotHandlingTest"))
       
   292 		{
       
   293 		testStep = new CTestSlotHandlingTest();
       
   294 		}
       
   295 
       
   296 	if (aStepName == _L("TestWriteToSlotTest"))
       
   297 		{
       
   298 		testStep = new CTestWriteToSlotTest();
       
   299 		}
       
   300 
       
   301 	if (aStepName == _L("TestCancelWriteRequest"))
       
   302 		{
       
   303 		testStep = new CTestCancelWriteRequest();
       
   304 		}
       
   305 
       
   306 	if (aStepName == _L("TestCancelDeleteRequest"))
       
   307 		{
       
   308 		testStep = new CTestCancelDeleteRequest();
       
   309 		}
       
   310 
       
   311 	if (aStepName == _L("TestCancelDoSyncRequest"))
       
   312 		{
       
   313 		testStep = new CTestCancelDoSyncRequest();
       
   314 		}
       
   315 
       
   316 	if (aStepName == _L("TestConnectionTest"))
       
   317 		{
       
   318 		testStep = new CTestConnectionTest();
       
   319 		}
       
   320 
       
   321 	if (aStepName == _L("TestFailedPhoneStartup"))
       
   322 		{
       
   323 		testStep = new CTestFailedPhoneStartup();
       
   324 		}
       
   325 
       
   326 	return testStep;
       
   327 	} // CSyncTestServer::CreateTestStep