messagingfw/msgtest/integration/sms/src/T_SmsSc.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 "T_SmsSc.h"
       
    17 #include <smscmds.h>
       
    18 #include <smutsimparam.h>
       
    19 #include <smsclnt.h>
       
    20 
       
    21 #include <mmlist.h>
       
    22 
       
    23 //#ifndef NO_SIM_PARAMS_TEST
       
    24 //#include <etelagsm.h>
       
    25 //#endif
       
    26 
       
    27 CSmsScTest::~CSmsScTest()
       
    28 	{
       
    29 	}
       
    30 
       
    31 #ifndef NO_SIM_PARAMS_TEST
       
    32 void CSmsScTest::TestReadSimParamsL()
       
    33 	{
       
    34 	iSmsTest.Test().Next(_L("Read Service Centres from Sim Params"));
       
    35 	iState = EStateReadingSimParams;
       
    36 	delete iOperation;
       
    37 	iOperation = Client().ReadSimParamsL(iStatus);
       
    38 	SetActive();
       
    39 	CActiveScheduler::Start();
       
    40 	}
       
    41 #endif
       
    42 
       
    43 CSmsScTest* CSmsScTest::NewLC(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
    44 	{
       
    45 	CSmsScTest* self = new (ELeave) CSmsScTest(aSmsTest, aScriptFile, aNextTest);
       
    46 	CleanupStack::PushL(self);
       
    47 
       
    48 	self->ConstructL();
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 
       
    53 
       
    54 CSmsScTest::CSmsScTest(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
    55 : CSmsTestBase(aSmsTest, aScriptFile, aNextTest), iState(EStateWaiting)
       
    56 	{
       
    57 	}
       
    58 
       
    59 void CSmsScTest::RunAutoL()
       
    60 	{
       
    61 #ifndef NO_SIM_PARAMS_TEST
       
    62 	iSmsTest.TestStart(++iNextTest, _L("Read Service Centres from Sim Params"));
       
    63 	TestReadSimParamsL();
       
    64 	User::LeaveIfError(iStatus.Int());
       
    65 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
    66 #endif
       
    67 	}
       
    68 
       
    69 void CSmsScTest::ConstructL()
       
    70 	{
       
    71 	SetTestNameL(KSmsScTestName);
       
    72 	iSmsTest.InstantiateClientMtmsL();
       
    73 
       
    74 	iSmsTest.SetLogToFile();
       
    75 
       
    76 	iSelection = new (ELeave) CMsvEntrySelection();
       
    77 	iTimer = CTestTimer::NewL();
       
    78 	CActiveScheduler::Add(this);
       
    79 	}
       
    80 
       
    81 void CSmsScTest::ShowMenuL()
       
    82 	{
       
    83 	iSmsTest.ResetMenu();
       
    84 
       
    85 	iSmsTest.AppendToMenuL(_L("Read Sim Params"));
       
    86 	iSmsTest.AppendToMenuL(_L("Run Auto"));
       
    87 
       
    88 	TInt result = iSmsTest.DisplayMenu(_L("SMS Service Centre Test"));
       
    89 
       
    90 	if (result <= 0)
       
    91 		return;
       
    92 
       
    93 	switch (result)
       
    94 		{
       
    95 #ifndef NO_SIM_PARAMS_TEST
       
    96 		case 1:
       
    97 			TestReadSimParamsL();
       
    98 			break;
       
    99 		case 2:
       
   100 #else
       
   101 		case 1:
       
   102 #endif
       
   103 			iSmsTest.SetRunAuto(ETrue);
       
   104 			RunAutoL();
       
   105 			break;
       
   106 		default:
       
   107 			User::Leave(KErrArgument);
       
   108 			break;
       
   109 		}
       
   110 
       
   111 	ShowMenuL();
       
   112 	}
       
   113 
       
   114 void CSmsScTest::RunL()
       
   115 	{
       
   116 	CActiveScheduler::Stop();
       
   117 
       
   118 	switch (iState)
       
   119 		{
       
   120 #ifndef NO_SIM_PARAMS_TEST
       
   121 		case EStateReadingSimParams:
       
   122 			{
       
   123 			DoRunReadSimParamsL();
       
   124 			break;
       
   125 			}
       
   126 #endif
       
   127 		default:
       
   128 			{
       
   129 			break;
       
   130 			}
       
   131 		}
       
   132 	}
       
   133 
       
   134 #ifndef NO_SIM_PARAMS_TEST
       
   135 void CSmsScTest::DoRunReadSimParamsL()
       
   136 	{
       
   137 	if (iStatus == KErrNone)
       
   138 		{
       
   139 		TIntBuf progressBuf;
       
   140 		progressBuf.Copy(iOperation->ProgressL());
       
   141 		iStatus = progressBuf();
       
   142 		}
       
   143 
       
   144 	iSmsTest.Printf(_L("ReadSimParams completed with error %d\n"), iStatus);
       
   145 	iSmsTest(iStatus == KErrNone || iStatus == KErrNotFound || iStatus == KErrNotSupported);
       
   146 
       
   147 	if (iStatus != KErrNone)
       
   148 		iSmsTest.Printf(_L("Error %d expected\n"), iStatus);
       
   149 
       
   150 	if (iStatus == KErrNone)
       
   151 		{
       
   152 		CSmsSimParamOperation* op = (CSmsSimParamOperation*) iOperation;
       
   153 
       
   154 		TInt count = 0;
       
   155 
       
   156 		count = op->SmspList().Enumerate();
       
   157 
       
   158 		iSmsTest.Printf(_L("ReadSimParams found:\n\t%d SMS params on SIM\n"), count);
       
   159 		iSmsTest(count);
       
   160 
       
   161 		CMobilePhoneSmspList* sc = op->ServiceCentersLC();
       
   162 
       
   163 		count = sc->Enumerate();
       
   164 
       
   165 		iSmsTest.Printf(_L("\t%d Service Centre(s)\n"), count);
       
   166 
       
   167 		while (count--)
       
   168 			{
       
   169 			RMobileSmsMessaging::TMobileSmspEntryV1 smspEntry;
       
   170 			smspEntry = sc->GetEntryL(count);
       
   171 			iSmsTest.Printf(_L("\t\tService Centre \"%S\", Name \"%S\"\n"), &smspEntry.iServiceCentre.iTelNumber, &smspEntry.iText);
       
   172 			}
       
   173 
       
   174 		CleanupStack::PopAndDestroy(); //sc
       
   175 		}
       
   176 
       
   177 	iStatus = KErrNone;
       
   178 
       
   179 	delete iOperation;
       
   180 	iOperation = NULL;
       
   181 
       
   182 	if (!iSmsTest.RunAuto())
       
   183 		{
       
   184 		iSmsTest.Printf(_L("\nPress any key to continue...\n"));
       
   185 		iSmsTest.Test().Getch();
       
   186 		}
       
   187 	}
       
   188 #endif
       
   189 
       
   190 void CSmsScTest::DoCancel()
       
   191 	{
       
   192 	if (iOperation)
       
   193 		{
       
   194 		iOperation->Cancel();
       
   195 		iSmsTest.Printf(_L("Operation Cancelled!\n"));
       
   196 		}
       
   197 	delete iOperation;
       
   198 	iOperation = NULL;
       
   199 	}