messagingfw/msgtest/integration/biomsg/src/parsertest.cpp
changeset 0 8e480a14352b
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 "parsertest.h"
       
    17 #include <biocmtm.h>
       
    18 #include <bioscmds.h>
       
    19 #include <bitsids.h>
       
    20 
       
    21 #include <bsp.h>
       
    22 #include "iacp.h"
       
    23 
       
    24 #include "iaptest.h"
       
    25 //#include "wapptest.h"
       
    26 
       
    27 const TUid KUidMsgTypeSmartMessage  = {0x10001262};
       
    28 
       
    29 TestUiTimer* TestUiTimer::NewLC(CSmsTestUtils& aTestUtils)
       
    30 	{
       
    31 	TestUiTimer* self = new(ELeave) TestUiTimer(aTestUtils);
       
    32 	CleanupStack::PushL(self);
       
    33 	self->ConstructL();
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 TestUiTimer::TestUiTimer(CSmsTestUtils& aTestUtils)
       
    38 	: CTimer(5), iSmsTest(aTestUtils)
       
    39 	{
       
    40 	period = KPeriod;
       
    41 	}
       
    42 
       
    43 TestUiTimer::~TestUiTimer()
       
    44 	{
       
    45 	delete iOperation;
       
    46 	}
       
    47 
       
    48 void TestUiTimer::ConstructL()
       
    49 	{
       
    50 	CTimer::ConstructL();
       
    51 	CActiveScheduler::Add(this);
       
    52 	}
       
    53 
       
    54 void TestUiTimer::IssueRequest()
       
    55 	{
       
    56 	After(period);
       
    57 	}
       
    58 
       
    59 void TestUiTimer::SetOperation(CMsvOperation *aOperation)
       
    60 	{
       
    61 	if(iOperation)
       
    62 		{
       
    63 		delete iOperation;
       
    64 		iOperation=NULL;
       
    65 		}
       
    66 	iOperation = aOperation;
       
    67 	}
       
    68 
       
    69 void TestUiTimer::DoCancel()
       
    70 	{
       
    71 	CTimer::DoCancel();
       
    72 	}
       
    73 
       
    74 void TestUiTimer::RunL()
       
    75 	{
       
    76 	// display the current progress
       
    77 	if(iOperation!=NULL)
       
    78 		{
       
    79 		TBioProgress temp;	
       
    80 		TPckgC<TBioProgress> paramPack(temp);
       
    81 
       
    82 		const TDesC8& progBuf = iOperation->ProgressL();	
       
    83 		paramPack.Set(progBuf);
       
    84 //		TBioProgress progress=paramPack();	
       
    85 
       
    86 //		iSmsTest.Printf(TRefByValue<const TDesC>_L("   Operation: %d"),progress.iBioState);
       
    87 //		iSmsTest.Printf(TRefByValue<const TDesC>_L("   Progress:  Error: %d\n"),
       
    88 //					progress.iErrorCode);
       
    89 		}
       
    90 	IssueRequest();
       
    91 	};
       
    92 
       
    93 CParserTest::~CParserTest()
       
    94 	{
       
    95 	delete iBioClientMtm;
       
    96 
       
    97 	iBioMessages = NULL;
       
    98 	delete iBioMessages;
       
    99 
       
   100 	delete iSelection;
       
   101 	delete iTimer;
       
   102 
       
   103 	delete iIapTester;
       
   104 //	delete iWapTester;
       
   105 
       
   106 	delete iClientMtmRegistry;
       
   107 	}
       
   108 
       
   109 
       
   110 CParserTest* CParserTest::NewL(CSmsTestUtils& aTestUtils)
       
   111 	{
       
   112 	CParserTest* self = new (ELeave) CParserTest(aTestUtils);
       
   113 	CleanupStack::PushL(self);
       
   114 
       
   115 	self->ConstructL();
       
   116 
       
   117 	CleanupStack::Pop();
       
   118 	return self;
       
   119 	}
       
   120 
       
   121 
       
   122 
       
   123 CParserTest::CParserTest(CSmsTestUtils& aTestUtils)
       
   124 : iCurrentMessageNum(-1),iSmsTest(aTestUtils)
       
   125 	{
       
   126 	}
       
   127 
       
   128 void CParserTest::StartL(CMsvEntrySelection* aReceived)
       
   129 	{
       
   130 	iCurrentTest = 0;
       
   131 	iAllTestsSuccessful = ETrue;
       
   132 	
       
   133 	iSmsTest.TestStart(++iCurrentTest, _L("GetBioMessages"));
       
   134 
       
   135 	iBioMessages = aReceived;
       
   136 
       
   137 	TInt numMessages = iBioMessages->Count();
       
   138 	// 
       
   139 	iCurrentTest++;
       
   140 
       
   141 	for(TInt i =0; i < numMessages; i++)
       
   142 		{
       
   143 		iSelection->Reset();
       
   144 		iSelection->AppendL((*iBioMessages)[i]);
       
   145 		MsvEntry().SetEntryL((*iBioMessages)[i]);
       
   146 		iSmsTest.Printf(_L("\nMessage type %d\n"),MsvEntry().Entry().Id());
       
   147 		iSmsTest.TestStart(iCurrentTest,_L("Parse and process"));
       
   148 		TRAPD(error,CreateParserL());
       
   149 
       
   150 		ProcessError(error);
       
   151 		if(error == KErrNone)
       
   152 			{
       
   153 			iSmsTest.TestFinish(iCurrentTest);
       
   154 			iCurrentTest++;
       
   155 			iSmsTest.TestStart(iCurrentTest,_L("Reparse"));
       
   156 			TRAP(error,ReParseL());
       
   157 			ProcessError(error);
       
   158 			iSmsTest.TestFinish(iCurrentTest,error);
       
   159 			if(error == KErrNone)
       
   160 				{
       
   161 				iCurrentTest++;
       
   162 				iSmsTest.TestStart(iCurrentTest,_L("Reprocess"));
       
   163 				TRAP(error,ReProcessL());
       
   164 				ProcessError(error);
       
   165 				if(error==KErrNone)
       
   166 					{
       
   167 					iSmsTest.TestFinish(iCurrentTest);
       
   168 					TRAP(error,CheckMessageTypeL());
       
   169 					}
       
   170 				else
       
   171 					{
       
   172 					iSmsTest.TestFinish(iCurrentTest,error);
       
   173 					iAllTestsSuccessful = EFalse;
       
   174 					}
       
   175 				}
       
   176 			}
       
   177 		else
       
   178 			{
       
   179 			iSmsTest.TestFinish(iCurrentTest,error);
       
   180 			iAllTestsSuccessful = EFalse;
       
   181 			}
       
   182 		}
       
   183 	iSmsTest.TestFinish(iCurrentTest, KErrNone);
       
   184 	}
       
   185 
       
   186 void CParserTest::ConstructL()
       
   187 	{
       
   188 	iSelection = new(ELeave)CMsvEntrySelection();
       
   189 	// create our mtm
       
   190 	iClientMtmRegistry = CClientMtmRegistry::NewL(Session());
       
   191 	iBioClientMtm = (CBIOClientMtm*) iClientMtmRegistry->NewMtmL(KUidMsgTypeSmartMessage);
       
   192 
       
   193 	iTimer = TestUiTimer::NewLC(iSmsTest);
       
   194 	CleanupStack::Pop();	// iTimer
       
   195 	}
       
   196 
       
   197 void CParserTest::CreateParserL()
       
   198 	{
       
   199 	TBuf8<1> aParameter;
       
   200 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   201 	wait->iStatus = KRequestPending;
       
   202 
       
   203 	CMsvOperation* operation = iBioClientMtm->InvokeAsyncFunctionL( KBiosMtmParseThenProcess, *iSelection, aParameter, wait->iStatus);
       
   204 	
       
   205 	iTimer->SetOperation(operation);
       
   206 	iTimer->IssueRequest();
       
   207 	
       
   208 	wait->Start();
       
   209 	CActiveScheduler::Start();
       
   210 
       
   211 	TInt error = operation->iStatus.Int();
       
   212 	iTimer->Cancel();
       
   213 	CleanupStack::PopAndDestroy();	// wait
       
   214 	if(error !=KErrNone)
       
   215 		User::Leave(error);
       
   216 	}
       
   217 
       
   218 void CParserTest::ReParseL()
       
   219 	{
       
   220 	TBuf8<1> parameter;
       
   221 
       
   222 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   223 	wait->iStatus = KRequestPending;
       
   224 
       
   225 	CMsvOperation* operation = iBioClientMtm->InvokeAsyncFunctionL( KBiosMtmParse, *iSelection, parameter, wait->iStatus);
       
   226 
       
   227 	iTimer->SetOperation(operation);
       
   228 	iTimer->IssueRequest();
       
   229 
       
   230 	wait->Start();
       
   231 	CActiveScheduler::Start();
       
   232 	iTimer->Cancel();
       
   233 	TInt error = operation->iStatus.Int();
       
   234 	
       
   235 	CleanupStack::PopAndDestroy();	// wait
       
   236 	if(error !=KErrNone)
       
   237 		User::Leave(error);
       
   238 	}
       
   239 
       
   240 void CParserTest::ReProcessL()
       
   241 	{
       
   242 	TBuf8<1> aParameter;
       
   243 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   244 	wait->iStatus = KRequestPending;
       
   245 
       
   246 	CMsvOperation* operation = iBioClientMtm->InvokeAsyncFunctionL( KBiosMtmProcess, *iSelection, aParameter, wait->iStatus);
       
   247 	
       
   248 	iTimer->SetOperation(operation);
       
   249 	iTimer->IssueRequest();
       
   250 	
       
   251 	wait->Start();
       
   252 	CActiveScheduler::Start();
       
   253 
       
   254 	TInt error = operation->iStatus.Int();
       
   255 	iTimer->Cancel();
       
   256 	
       
   257 	CleanupStack::PopAndDestroy();	// wait
       
   258 	if(error !=KErrNone)
       
   259 		User::Leave(error);
       
   260 	}
       
   261 
       
   262 void CParserTest::ProcessError(TInt& aError)
       
   263 	{
       
   264 	if(aError==KErrNotSupported)
       
   265 		{
       
   266 		aError = KErrNone;
       
   267 		iSmsTest.WriteComment(_L("Unsupported operation"));
       
   268 		}
       
   269 	else if((aError <= -500 && aError >= -521) || (aError <= -600 && aError >= -614))
       
   270 		{
       
   271 		aError = KErrNone;
       
   272 		iSmsTest.WriteComment(_L("Corrupt or missing Bio-data"));
       
   273 		}
       
   274 	}
       
   275 
       
   276 void CParserTest::CheckMessageTypeL()
       
   277 	{
       
   278 	// get type
       
   279 	MsvEntry().SetEntryL((*iSelection)[0]);
       
   280 	TMsvEntry entry = MsvEntry().Entry();
       
   281 	if(entry.iBioType == KUidBIOInternetAccessPointMsg)
       
   282 		{
       
   283 		CIacSettingsParser::TSmsType type = CIacSettingsParser::TSmsType(entry.MtmData1());
       
   284 		if(type == CIacSettingsParser::EBasicMailIAP)
       
   285 			{
       
   286 			TestInternetAccessL();
       
   287 			}
       
   288 		}
       
   289 	else if(entry.iBioType == KUidBIOWAPAccessPointMsg)
       
   290 		{
       
   291 //		TestWapAccessL();
       
   292 		}
       
   293 
       
   294 
       
   295 	}
       
   296 
       
   297 void CParserTest::TestInternetAccessL()
       
   298 	{
       
   299 	CInternetAccessTester* iapTester = CInternetAccessTester::NewL(iSmsTest);
       
   300 	CleanupStack::PushL(iapTester);
       
   301 	iapTester->StartL(MsvEntry().Entry().Id());	
       
   302 
       
   303 	CleanupStack::PopAndDestroy();	// iapTester
       
   304 	}
       
   305 
       
   306 void CParserTest::TestWapAccessL()
       
   307 	{
       
   308 //	CWapAccessTester* wapTester = CWapAccessTester::NewL(iSmsTest);
       
   309 //	CleanupStack::PushL(wapTester);
       
   310 //	wapTester->StartL(MsvEntry().Entry().Id());
       
   311 //	CleanupStack::PopAndDestroy();	// wapTester
       
   312 	}