messagingfw/msgtest/testutils/sms/src/SmsTestBase.cpp
changeset 22 bde600d88860
parent 0 8e480a14352b
child 58 6c34d0baa0b1
equal deleted inserted replaced
21:08008ce8a6df 22:bde600d88860
       
     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 "smstestbase.h"
       
    17 #include <logcli.h>
       
    18 #include <smscmds.h>
       
    19 #include <txtrich.h> 
       
    20 #include <smsclnt.h>
       
    21 
       
    22 EXPORT_C CSmsTestBase::~CSmsTestBase()
       
    23 	{
       
    24 	if (iOperation)
       
    25 		{
       
    26 		iOperation->Cancel();
       
    27 		delete iOperation;
       
    28 		iOperation = NULL;
       
    29 		}
       
    30 
       
    31 	delete iSelection;
       
    32 	iSelection = NULL;
       
    33 
       
    34 	if (iTimer)
       
    35 		{
       
    36 		iTimer->Cancel();
       
    37 		delete iTimer;
       
    38 		iTimer = NULL;
       
    39 		}
       
    40 
       
    41 	delete iTestName;
       
    42 	iTestName = NULL;
       
    43 	}
       
    44 
       
    45 EXPORT_C CSmsTestBase::CSmsTestBase(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest, TInt aPriority)
       
    46 : CActive(aPriority), iComplete(EFalse), iError(KErrNone), iScriptFile(aScriptFile), iSmsTest(aSmsTest), iNextTest(aNextTest)
       
    47 	{
       
    48 	}
       
    49 
       
    50 EXPORT_C void CSmsTestBase::DisplayLogL()
       
    51 	{
       
    52 	CLogFilter* filter = CLogFilter::NewL();
       
    53 	CleanupStack::PushL(filter);
       
    54 
       
    55 	iSmsTest.DisplayLogL(*filter, ETrue);
       
    56 
       
    57 	CleanupStack::PopAndDestroy(); //filter
       
    58 
       
    59 	if (!iSmsTest.RunAuto())
       
    60 		{
       
    61 		iSmsTest.Test().Printf(_L("\nPress any key to continue...\n"));
       
    62 		iSmsTest.Test().Getch();
       
    63 		}
       
    64 	}
       
    65 
       
    66 EXPORT_C void CSmsTestBase::ClearLogL()
       
    67 	{
       
    68 	CLogFilter* filter = CLogFilter::NewL();
       
    69 	CleanupStack::PushL(filter);
       
    70 
       
    71 	iSmsTest.ClearLogL(*filter);
       
    72 
       
    73 	CleanupStack::PopAndDestroy(); //filter
       
    74 
       
    75 	if (!iSmsTest.RunAuto())
       
    76 		{
       
    77 		iSmsTest.Test().Printf(_L("\nPress any key to continue...\n"));
       
    78 		iSmsTest.Test().Getch();
       
    79 		}
       
    80 	}
       
    81 
       
    82 EXPORT_C TInt CSmsTestBase::RunError(TInt aError)
       
    83 	{
       
    84 	if (iStatus == KErrNone)
       
    85 		iStatus = aError;
       
    86 
       
    87 	return KErrNone;
       
    88 	}
       
    89 
       
    90 EXPORT_C void CSmsTestBase::DoTestForwardMsgL(TMsvId aId)
       
    91 // Test forwarding this message (ie Create a forwarded SMS, 
       
    92 // place it in the drafts folder & then send it).
       
    93 	{
       
    94 	// Load the SMS Client MTM if not already done so
       
    95 	if (! iSmsTest.iSmsClientMtm)
       
    96 		iSmsTest.InstantiateClientMtmsL();
       
    97 
       
    98 	// Get the SMS Client MTM to use & load this message
       
    99 	Client().SwitchCurrentEntryL(aId);
       
   100 	Client().LoadMessageL();
       
   101 
       
   102 	// Forward the message & store it in the Drafts folder
       
   103 	TMsvPartList part=0;
       
   104 	TRequestStatus status(0);
       
   105 	CMsvOperation* op = Client().ForwardL(KMsvDraftEntryId, part, status);
       
   106 	CleanupStack::PushL(op);
       
   107 
       
   108 	TMsvId temp;	
       
   109 	TPckgC<TMsvId> paramPack(temp);
       
   110 	const TDesC8& progBuf2 = op->ProgressL();	
       
   111 	paramPack.Set(progBuf2);
       
   112 	TMsvId progress=paramPack();
       
   113 	
       
   114 	CleanupStack::PopAndDestroy(); //op
       
   115 	op = NULL;
       
   116 
       
   117 	Client().SwitchCurrentEntryL(progress);
       
   118 	Client().LoadMessageL();
       
   119 
       
   120 	// Add additional text & an Addressee to the Forwarded Message
       
   121 	Client().Body().InsertL(0,_L("This is a forwarded Msg. "));
       
   122 	Client().AddAddresseeL(KScriptItemRecipientsDef);
       
   123 
       
   124 	// Change the description of the new message
       
   125 	CMsvEntry& cEntry = Client().Entry();
       
   126 	TMsvEntry tEntry = cEntry.Entry();
       
   127 	tEntry.iDescription.Set(_L("Forwarded Msg"));
       
   128 	cEntry.ChangeL(tEntry);
       
   129 
       
   130 	// Get the ID of the new Forwarded Message
       
   131 	TMsvId newEntryId = cEntry.EntryId();
       
   132 
       
   133 	// Save the new message
       
   134 	Client().SaveMessageL();
       
   135 
       
   136 	// Now send the Forwarded Message that we have just created
       
   137 	DoTestSendMesssageL(newEntryId);
       
   138 	}
       
   139 
       
   140 
       
   141 EXPORT_C void CSmsTestBase::DoTestSendMesssageL(TMsvId aMsgId)
       
   142 // Test Sending this message  
       
   143 	{
       
   144 	iSmsTest.Test().Next(_L("Sending"));
       
   145 	iSmsTest.Printf(_L("Sending %d messages...\n"), 1);
       
   146 	iSmsTest.DisplayMessageL(aMsgId);
       
   147 
       
   148 	// Get the Parent Id of the message we want to send & 
       
   149 	// then set the entry to this parent
       
   150 	iSmsTest.SetEntryL(aMsgId);
       
   151 	TMsvEntry entryToSend = iSmsTest.Entry();
       
   152 	TMsvId parentId = entryToSend.Parent();
       
   153 	iSmsTest.SetEntryL(parentId);
       
   154 
       
   155 	delete iOperation;
       
   156 	iOperation = NULL;
       
   157 
       
   158 	// Send the message, by copying it to the SMS Service.
       
   159 	iOperation = MsvEntry().CopyL(aMsgId, iSmsTest.iSmsServiceId, iStatus);
       
   160 
       
   161 	SetActive();
       
   162 	}
       
   163 
       
   164 EXPORT_C void CSmsTestBase::DoTestSendingL(const TDesC& aScript, TBool aMove)
       
   165 //
       
   166 //
       
   167 //
       
   168 	{
       
   169 	iSmsTest.Test().Next(_L("Sending"));
       
   170 
       
   171 	TTime now;
       
   172 	now.HomeTime();
       
   173 	now += (TTimeIntervalSeconds) 5;
       
   174 
       
   175 	iSmsTest.DeleteSmsMessagesL(KMsvGlobalOutBoxIndexEntryId);
       
   176 	iSelection->Reset();
       
   177 
       
   178 	// Create the test messages specified in the script file and place in the Outbox.
       
   179 	iSmsTest.Printf(_L("Creating msgs in outbox from script %S\n"), &aScript);
       
   180 	TBool read = EFalse;
       
   181 	TRAPD(err, read = iSmsTest.ReadScriptL(aScript, KMsvGlobalOutBoxIndexEntryId, *iSelection, now));
       
   182 
       
   183 	iSmsTest.Test()(!err && read);
       
   184 
       
   185 	iSmsTest.Printf(_L("Sending %d messages...\n"), iSelection->Count());
       
   186 	iSmsTest.DisplayMessagesL(*iSelection);
       
   187 	iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   188 
       
   189 	delete iOperation;
       
   190 
       
   191 	// Send the message, by copying it to the SMS Service.
       
   192 	if (aMove)
       
   193 		{
       
   194 		iOperation = MsvEntry().MoveL(*iSelection, iSmsTest.iSmsServiceId, iStatus);
       
   195 		}
       
   196 	else
       
   197 		{
       
   198 		iOperation = MsvEntry().CopyL(*iSelection, iSmsTest.iSmsServiceId, iStatus);
       
   199 		}
       
   200 
       
   201 	SetActive();
       
   202 	}
       
   203 
       
   204 EXPORT_C void CSmsTestBase::DoTestSchedulingL(const TDesC& aScript, TBool aMove, TTimeIntervalSeconds aFromNow)
       
   205 	{
       
   206 	iSmsTest.Test().Next(_L("Scheduling"));
       
   207 	iSmsTest.DeleteSmsMessagesL(KMsvGlobalOutBoxIndexEntryId);
       
   208 	iSelection->Reset();
       
   209 
       
   210 	TTime now;
       
   211 	now.HomeTime();
       
   212 	now += aFromNow;
       
   213 
       
   214 	iSmsTest.Printf(_L("Creating msgs in outbox from script %S\n"), &aScript);
       
   215 	TBool read = EFalse;
       
   216 	TRAPD(err, read = iSmsTest.ReadScriptL(aScript, KMsvGlobalOutBoxIndexEntryId, *iSelection, now));
       
   217 
       
   218 	iSmsTest.Test()(!err && read);
       
   219 
       
   220 	iSmsTest.Printf(_L("Scheduled %d messages...\n"), iSelection->Count());
       
   221 	iSmsTest.DisplayMessagesL(*iSelection);
       
   222 	MsvEntry().SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   223 
       
   224 	delete iOperation;
       
   225 
       
   226 	TInt cmd = aMove ? ESmsMtmCommandScheduleMove : ESmsMtmCommandScheduleCopy;
       
   227 
       
   228 	iOperation = Session().TransferCommandL(*iSelection, cmd, TPtrC8(), iStatus);
       
   229 	SetActive();
       
   230 	}
       
   231 
       
   232 EXPORT_C void CSmsTestBase::StartL()
       
   233 	{
       
   234 	TRAP(iError, iSmsTest.RunAuto() ? RunAutoL() : ShowMenuL());
       
   235 
       
   236 	if (iError)
       
   237 		{
       
   238 		if (iNextTest)
       
   239 			{
       
   240 			iSmsTest.TestFinish(iNextTest, iError);
       
   241 			}
       
   242 
       
   243 		iSmsTest.TestHarnessFailed(iError);
       
   244 		}
       
   245 	else
       
   246 		{
       
   247 		iSmsTest.TestHarnessCompleted();
       
   248 		iComplete = ETrue;
       
   249 		}
       
   250 	}