messagingfw/msgtest/integration/sms/src/T_SmsEnum.cpp
changeset 0 8e480a14352b
child 58 6c34d0baa0b1
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 <e32test.h>
       
    17 #include <e32uid.h>
       
    18 #include <e32std.h>
       
    19 #include <smuthdr.h>
       
    20 #include <smscmds.h>
       
    21 #include "T_SmsEnum.h"
       
    22 #include <txtrich.h>
       
    23 
       
    24 void CSmsEnumTest::TestCopyFromSimL()
       
    25 	{
       
    26 	iSmsTest.Test().Next(_L("Copy From SIM"));
       
    27 	iState = EStateCopyFromSim;
       
    28 
       
    29 	MsvEntry().SetEntryL(iSmsTest.iProgress.iEnumerateFolder);
       
    30 
       
    31 	delete iSelection;
       
    32 	iSelection = MsvEntry().ChildrenL();
       
    33 	iSelection->InsertL(0,iSmsTest.iSmsServiceId);
       
    34 
       
    35 	TPckgBuf<TMsvId> pkg(KMsvGlobalInBoxIndexEntryId);
       
    36 
       
    37 	delete iOperation;
       
    38 	iOperation = Session().TransferCommandL(*iSelection, ESmsMtmCommandCopyFromPhoneStore, pkg, iStatus);
       
    39 	SetActive();
       
    40 	CActiveScheduler::Start();
       
    41 	}
       
    42 
       
    43 void CSmsEnumTest::TestMoveFromSimL()
       
    44 	{
       
    45 	iSmsTest.Test().Next(_L("Move From SIM"));
       
    46 	iState = EStateMoveFromSim;
       
    47 
       
    48 	MsvEntry().SetEntryL(iSmsTest.iProgress.iEnumerateFolder);
       
    49 
       
    50 	delete iSelection;
       
    51 	iSelection = MsvEntry().ChildrenL();
       
    52 	iSelection->InsertL(0,iSmsTest.iSmsServiceId);
       
    53 
       
    54 	TPckgBuf<TMsvId> pkg(KMsvGlobalInBoxIndexEntryId);
       
    55 
       
    56 	delete iOperation;
       
    57 	iOperation = Session().TransferCommandL(*iSelection, ESmsMtmCommandMoveFromPhoneStore, pkg, iStatus);
       
    58 	SetActive();
       
    59 	CActiveScheduler::Start();
       
    60 	}
       
    61 
       
    62 void CSmsEnumTest::TestDeleteFromSimL()
       
    63 	{
       
    64 	iSmsTest.Test().Next(_L("Delete From SIM"));
       
    65 	iState = EStateDeleteFromSim;
       
    66 
       
    67 	MsvEntry().SetEntryL(iSmsTest.iProgress.iEnumerateFolder);
       
    68 
       
    69 	delete iSelection;
       
    70 	iSelection = MsvEntry().ChildrenL();
       
    71 	iSelection->InsertL(0,iSmsTest.iSmsServiceId);
       
    72 
       
    73 	delete iOperation;
       
    74 	iOperation = Session().TransferCommandL(*iSelection, ESmsMtmCommandDeleteFromPhoneStore, TPtrC8(), iStatus);
       
    75 	SetActive();
       
    76 	CActiveScheduler::Start();
       
    77 	}
       
    78 
       
    79 void CSmsEnumTest::TestCopyToSimL()
       
    80 	{
       
    81 	iSmsTest.Test().Next(_L("Copy to SIM"));
       
    82 	iState = EStateCopyToSim;
       
    83 
       
    84 	iSelection->Reset();
       
    85 
       
    86 	TTime now;
       
    87 	now.HomeTime();
       
    88 	iSelection->Reset();
       
    89 	iSmsTest.ReadScriptL(iScriptFile, KMsvGlobalOutBoxIndexEntryId, *iSelection, now);
       
    90 	iSelection->InsertL(0,iSmsTest.iSmsServiceId);
       
    91 
       
    92 	iSmsTest(iSelection->Count());
       
    93 
       
    94 	delete iOperation;
       
    95 	iOperation = Session().TransferCommandL(*iSelection, ESmsMtmCommandCopyToPhoneStore, TPtrC8(), iStatus);
       
    96 	SetActive();
       
    97 	CActiveScheduler::Start();
       
    98 	}
       
    99 
       
   100 void CSmsEnumTest::TestEnumerateL()
       
   101 	{
       
   102 	iSmsTest.Test().Next(_L("Enumerate SIM"));
       
   103 	iState = EStateEnumerating;
       
   104 
       
   105 	iSelection->Reset();
       
   106 	iSelection->AppendL(iSmsTest.iSmsServiceId);
       
   107 
       
   108 	delete iOperation;
       
   109 	iOperation = Session().TransferCommandL(*iSelection, ESmsMtmCommandEnumeratePhoneStores, TPtrC8(), iStatus);
       
   110 	SetActive();
       
   111 	CActiveScheduler::Start();
       
   112 	}
       
   113 
       
   114 CSmsEnumTest::CSmsEnumTest(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
   115 : CSmsTestBase(aSmsTest, aScriptFile, aNextTest), iState(EStateWaiting)
       
   116 	{
       
   117 	}
       
   118 
       
   119 void CSmsEnumTest::RunAutoL()
       
   120 	{
       
   121 	iSmsTest.TestStart(++iNextTest, _L("Copy to SIM"));
       
   122 	TestCopyToSimL();
       
   123 	User::LeaveIfError(iStatus.Int());
       
   124 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   125 
       
   126 	iSmsTest.TestStart(++iNextTest, _L("Enumerate"));
       
   127 	TestEnumerateL();
       
   128 	User::LeaveIfError(iStatus.Int());
       
   129 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   130 
       
   131 	if (iSelection->Count())
       
   132 		{
       
   133 		iSmsTest.TestStart(++iNextTest, _L("Delete Remote Entries"));
       
   134 		TestDeleteRemoteEntryL();
       
   135 		User::LeaveIfError(iStatus.Int());
       
   136 		iSmsTest.TestFinish(iNextTest, KErrNone);
       
   137 		}
       
   138 
       
   139 	iSmsTest.TestStart(++iNextTest, _L("Enumerate"));
       
   140 	TestEnumerateL();
       
   141 	User::LeaveIfError(iStatus.Int());
       
   142 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   143 
       
   144 	if (iSelection->Count())
       
   145 		{
       
   146 		iSmsTest.TestStart(++iNextTest, _L("Move from SIM"));
       
   147 		TestCopyFromSimL();
       
   148 		User::LeaveIfError(iStatus.Int());
       
   149 		iSmsTest.TestFinish(iNextTest, KErrNone);
       
   150 		}
       
   151 
       
   152 	iSmsTest.TestStart(++iNextTest, _L("Enumerate"));
       
   153 	TestEnumerateL();
       
   154 	User::LeaveIfError(iStatus.Int());
       
   155 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   156 
       
   157 	if (iSelection->Count())
       
   158 		{
       
   159 		iSmsTest.TestStart(++iNextTest, _L("Move from SIM"));
       
   160 		TestMoveFromSimL();
       
   161 		User::LeaveIfError(iStatus.Int());
       
   162 		iSmsTest.TestFinish(iNextTest, KErrNone);
       
   163 		}
       
   164 	}
       
   165 
       
   166 void CSmsEnumTest::ConstructL()
       
   167 	{
       
   168 	SetTestNameL(KSmsEnumTestName);
       
   169 	iSmsTest.SetLogToFile();
       
   170 
       
   171 	iSelection = new (ELeave) CMsvEntrySelection();
       
   172 	iTimer = CTestTimer::NewL();
       
   173 	CActiveScheduler::Add(this);
       
   174 	}
       
   175 
       
   176 void CSmsEnumTest::ShowMenuL()
       
   177 	{
       
   178 	iSmsTest.ResetMenu();
       
   179 
       
   180 	iSmsTest.AppendToMenuL(_L("Enumerate SIM"));
       
   181 	iSmsTest.AppendToMenuL(_L("Copy To SIM"));
       
   182 	iSmsTest.AppendToMenuL(_L("Display Log"));
       
   183 	iSmsTest.AppendToMenuL(_L("Clear Log"));
       
   184 
       
   185 	TInt result = iSmsTest.DisplayMenu(_L("SMS Enumerate Sim Test"));
       
   186 
       
   187 	if (result <= 0)
       
   188 		return;
       
   189 
       
   190 	switch (result)
       
   191 		{
       
   192 		case 1:
       
   193 			TestEnumerateL();
       
   194 			break;
       
   195 		case 2:
       
   196 			TestCopyToSimL();
       
   197 			break;
       
   198 		case 3:
       
   199 			DisplayLogL();
       
   200 			break;
       
   201 		case 4:
       
   202 			ClearLogL();
       
   203 			break;
       
   204 		default:
       
   205 			User::Leave(KErrArgument);
       
   206 			break;
       
   207 		}
       
   208 
       
   209 	ShowMenuL();
       
   210 	}
       
   211 
       
   212 CSmsEnumTest::~CSmsEnumTest()
       
   213 	{
       
   214 	}
       
   215 
       
   216 CSmsEnumTest* CSmsEnumTest::NewLC(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
   217 	{
       
   218 	CSmsEnumTest* self = new (ELeave) CSmsEnumTest(aSmsTest, aScriptFile, aNextTest);
       
   219 	CleanupStack::PushL(self);
       
   220 
       
   221 	self->ConstructL();
       
   222 	return self;
       
   223 	}
       
   224 
       
   225 void CSmsEnumTest::RunL()
       
   226 	{
       
   227 	CActiveScheduler::Stop();
       
   228 
       
   229 	iSmsTest(iStatus.Int() == KErrNone);
       
   230 
       
   231 	iSmsTest.SetProgressL(*iOperation);
       
   232 
       
   233 	switch (iState)
       
   234 		{
       
   235 		case EStateEnumerating:
       
   236 			{
       
   237 			DoRunEnumerateL();
       
   238 			break;
       
   239 			}
       
   240 		case EStateCopyFromSim:
       
   241 		case EStateMoveFromSim:
       
   242 		case EStateDeleteFromSim:
       
   243 			{
       
   244 			DoRunCopyMoveDeleteFromSimL();
       
   245 			break;
       
   246 			}
       
   247 		case EStateCopyToSim:
       
   248 			{
       
   249 			DoRunCopyToSimL();
       
   250 			break;
       
   251 			}
       
   252 		default:
       
   253 			{
       
   254 			break;
       
   255 			}
       
   256 		}
       
   257 
       
   258 	delete iOperation;
       
   259 	iOperation = NULL;
       
   260 	}
       
   261 
       
   262 void CSmsEnumTest::DoRunCopyToSimL()
       
   263 	{
       
   264 	TInt err = iStatus.Int();
       
   265 
       
   266 	if (err == KErrNone)
       
   267 		{
       
   268 		err = iSmsTest.iProgress.iError;
       
   269 		}
       
   270 
       
   271 	iSmsTest.Printf(_L("Copy To SIM completed with error %d\n"), err);
       
   272 
       
   273 	iState = EStateWaiting;
       
   274 
       
   275 	if (!iSmsTest.RunAuto())
       
   276 		{
       
   277 		iSmsTest.Printf(_L("\nPress any key to continue...\n"));
       
   278 		iSmsTest.Test().Getch();
       
   279 		}
       
   280 	}
       
   281 
       
   282 void CSmsEnumTest::DoRunCopyMoveDeleteFromSimL()
       
   283 	{
       
   284 	TInt err = iStatus.Int();
       
   285 
       
   286 	if (err == KErrNone)
       
   287 		{
       
   288 		err = iSmsTest.iProgress.iError;
       
   289 		}
       
   290 
       
   291 	switch (iState)
       
   292 		{
       
   293 		case EStateCopyFromSim:
       
   294 			iSmsTest.Printf(_L("Copy From SIM completed with error %d\n"), err);
       
   295 			break;
       
   296 		case EStateMoveFromSim:
       
   297 			iSmsTest.Printf(_L("Move From SIM completed with error %d\n"), err);
       
   298 			break;
       
   299 		case EStateDeleteFromSim:
       
   300 			iSmsTest.Printf(_L("Delete From SIM completed with error %d\n"), err);
       
   301 			break;
       
   302 		default:
       
   303 			break;
       
   304 		}
       
   305 
       
   306 	iState = EStateWaiting;
       
   307 
       
   308 	if (!iSmsTest.RunAuto())
       
   309 		{
       
   310 		iSmsTest.Printf(_L("\nPress any key to continue...\n"));
       
   311 		iSmsTest.Test().Getch();
       
   312 		}
       
   313 	}
       
   314 
       
   315 void CSmsEnumTest::DoRunEnumerateL()
       
   316 	{
       
   317 	TInt err = iStatus.Int();
       
   318 
       
   319 	if (err == KErrNone)
       
   320 		{
       
   321 		err = iSmsTest.iProgress.iError;
       
   322 		iStatus = err;
       
   323 
       
   324 		if (err == KErrNone)
       
   325 			{
       
   326 			MsvEntry().SetEntryL(iSmsTest.iProgress.iEnumerateFolder);
       
   327 			delete iSelection;
       
   328 			iSelection = MsvEntry().ChildrenL();
       
   329 
       
   330 			iSmsTest.Printf(_L("%d message(s) on SIM. %d message(s) now contained in folder %d.\n"), iSmsTest.iProgress.iMsgCount, iSelection->Count(), iSmsTest.iProgress.iEnumerateFolder);
       
   331 			iSmsTest.DisplayMessagesL(*iSelection);
       
   332 			}
       
   333 		}
       
   334 
       
   335 	iSmsTest.Printf(_L("Enumerate SIM completed with %d\n"), err);
       
   336 	iState = EStateWaiting;
       
   337 
       
   338 	delete iOperation;
       
   339 	iOperation = NULL;
       
   340 
       
   341 	if (!iSmsTest.RunAuto())
       
   342 		{
       
   343 		iSmsTest.Printf(_L("\nPress any key to continue...\n"));
       
   344 		iSmsTest.Test().Getch();
       
   345 
       
   346 		if  (iSmsTest.iProgress.iMsgCount)
       
   347 			ShowMenuAfterEnumerateL();
       
   348 		}
       
   349 	}
       
   350 
       
   351 void CSmsEnumTest::ShowMenuAfterEnumerateL()
       
   352 	{
       
   353 	iSmsTest.ResetMenu();
       
   354 
       
   355 	iSmsTest.AppendToMenuL(_L("Copy From Sim To Inbox"));
       
   356 	iSmsTest.AppendToMenuL(_L("Move From Sim To Inbox"));
       
   357 	iSmsTest.AppendToMenuL(_L("Delete From Sim"));
       
   358 
       
   359 	TInt result = iSmsTest.DisplayMenu(_L("What to do with enumerated messages?"));
       
   360 
       
   361 	if (result <= 0)
       
   362 		return;
       
   363 
       
   364 	switch (result)
       
   365 		{
       
   366 		case 1:
       
   367 			TestCopyFromSimL();
       
   368 			break;
       
   369 		case 2:
       
   370 			TestMoveFromSimL();
       
   371 			break;
       
   372 		case 3:
       
   373 			TestDeleteFromSimL();
       
   374 			break;
       
   375 		default:
       
   376 			User::Leave(KErrArgument);
       
   377 			break;
       
   378 		}
       
   379 	}
       
   380 
       
   381 void CSmsEnumTest::DoCancel()
       
   382 	{
       
   383 	if (iOperation)
       
   384 		{
       
   385 		iOperation->Cancel();
       
   386 		iSmsTest.Printf(_L("Operation Cancelled!\n"));
       
   387 		}
       
   388 	else
       
   389 		{
       
   390 		iSmsTest.Printf(_L("No operation to cancel!\n"));
       
   391 		}
       
   392 
       
   393 	delete iOperation;
       
   394 	iOperation = NULL;
       
   395 	}
       
   396 
       
   397 void CSmsEnumTest::TestDeleteRemoteEntryL()
       
   398 	{
       
   399 	iSmsTest.Test().Next(_L("Test Delete Remote Entry\n"));
       
   400 
       
   401 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   402 	wait->Start();
       
   403 
       
   404 	iSmsTest.SetEntryL(iSmsTest.iProgress.iEnumerateFolder);
       
   405 	iSmsTest.SetEntryL(iSmsTest.Entry().Parent());
       
   406 
       
   407 	CMsvOperation* op = iSmsTest.iMsvEntry->DeleteL(iSmsTest.iProgress.iEnumerateFolder, wait->iStatus);
       
   408 	CleanupStack::PushL(op);
       
   409 
       
   410 	CActiveScheduler::Start();
       
   411 
       
   412 	iSmsTest.Printf(_L("Remote DeleteL() completed with %d\n"), wait->iStatus.Int());
       
   413 
       
   414 	User::LeaveIfError(wait->iStatus.Int());
       
   415 
       
   416 	iSmsTest.SetProgressL(*op);
       
   417 
       
   418 	iSmsTest.Printf(_L("Operation completed with %d, msg count %d\n"), iSmsTest.iProgress.iError, iSmsTest.iProgress.iMsgCount);
       
   419 	User::LeaveIfError(iSmsTest.iProgress.iError);
       
   420 
       
   421 	CleanupStack::PopAndDestroy(2); //wait, op
       
   422 	}