messagingfw/wappushfw/examples/PushAppHandlerEx/test/t_ScriptTest.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2000-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 "pushtests.h"
       
    17 #include "dummywapstack.h"
       
    18 #include "WapPushMsgGen.h"
       
    19 #include "WPushUtils.h"
       
    20 #include "testscripts.h"
       
    21 
       
    22 // Location of INI file that defines the test cases to be run
       
    23 _LIT(KAcceptanceTestCompName, "acceptance");
       
    24 _LIT(KAcceptanceTestScriptName, "pushtestcases.ini");
       
    25 
       
    26 
       
    27 // Labels for section names and resources in the INI file
       
    28 _LIT(KSectionMMSheader, "MMSheader");
       
    29 _LIT(KSectionMMSbody, "MMSbody");
       
    30 
       
    31 CWapScriptTest::~CWapScriptTest()
       
    32 	{
       
    33 	delete iIniFile;
       
    34 	}
       
    35 
       
    36 const TDesC& CWapScriptTest::TestName()
       
    37 	{
       
    38 	_LIT(KTextNotifMessageTest,"Script Test");
       
    39 	return KTextNotifMessageTest;
       
    40 	}
       
    41 
       
    42 /** specify the number of test messages to use */
       
    43 void CWapScriptTest::NumberTestCasesToRunL()
       
    44 	{
       
    45 	_LIT(KErrScriptObject, "CScriptFile Object not created succesfully");
       
    46 	TRAPD(err, iIniFile = CScriptFile::NewL(KAcceptanceTestCompName));
       
    47 	if (err != KErrNone)
       
    48 		WPLPrintf(KErrScriptObject);
       
    49 
       
    50 	// Read from the script
       
    51 	_LIT(KFileNotFound, "Script File Not Found");
       
    52 	TInt error = iIniFile->ReadScriptL(KAcceptanceTestScriptName);
       
    53 
       
    54 	if (error != KErrNone)
       
    55 		WPLPrintf(KFileNotFound);
       
    56 
       
    57  	// Get the number of TestCases from section[0]
       
    58 	_LIT(KNumOfTestCasesItem, "numOfTestCases");
       
    59 	TInt testCases = iIniFile->Section(0).ItemValue(KNumOfTestCasesItem,0);
       
    60 	iNumberOfTestCases = testCases;
       
    61 	}
       
    62 
       
    63 void CWapScriptTest::PrepareTestMessageL(TInt aTestCase) // aTestCase = 0,1,2 etc
       
    64 {
       
    65 	iHeadersBuf.Zero();
       
    66 	iBodyBuf.Zero();
       
    67 
       
    68 	// Position in the sections array for the testcase: aTestCase
       
    69 	TInt aTestCaseSecPos = aTestCase + 1; // add 1 to get the index position of the test case section to be tested
       
    70 
       
    71 	// MMSHEADER: Get the header name for the TestCase at position aTestCaseSecPos
       
    72 	TPtrC hdrName = iIniFile->Section(aTestCaseSecPos).Item(0).Value();
       
    73 
       
    74 	// Get the header section with the above named header 'hdrName'
       
    75  	CScriptSection* headerSection = iIniFile->Section(hdrName);
       
    76 
       
    77 	_LIT(KHdrSectionNotFound, "The MMS Header is not found in the script file");
       
    78 	if (!headerSection)
       
    79 		{
       
    80 		WPLPrintf(KHdrSectionNotFound);
       
    81 		}
       
    82 		// MMSBODY: Get the body name for the TestCase at position aTestCaseSecPos
       
    83 	TPtrC bodyName = iIniFile->Section(aTestCaseSecPos).Item(1).Value();
       
    84 
       
    85 	// Get the body section with the above named header 'body'
       
    86 	_LIT(KBodySectionNotFound, "The MMS Body is not found in the script file");
       
    87 	CScriptSection* bodySection = iIniFile->Section(bodyName);
       
    88 	if (!bodySection)
       
    89 		{
       
    90 		WPLPrintf(KBodySectionNotFound);
       
    91 		}
       
    92 
       
    93 	// Append the header to iHeadersBuf
       
    94 	_LIT(KHdrCodeLex, "To Initialize TLex Object");
       
    95 	TLex HdrCodeLex(KHdrCodeLex);
       
    96 	TInt itemCount;
       
    97 	itemCount = headerSection->Items().Count();
       
    98 	TInt i;
       
    99 	for (i = 0; i<itemCount; ++i)
       
   100 		{
       
   101 		TPtrC name = headerSection->Item(i).Value();
       
   102 		// Check if the contents is a string then don't convert to integer
       
   103 		if(name[0] >= '0' && name[0] <='9')
       
   104 			{
       
   105 			HdrCodeLex.Assign(name);
       
   106 			TUint nameInt;
       
   107 			HdrCodeLex.Val(nameInt);
       
   108 			iHeadersBuf.Append(nameInt);
       
   109 			}
       
   110 		else
       
   111 			iHeadersBuf.Append(name);
       
   112 		}
       
   113 
       
   114 	// Append the body to iBodyBuf
       
   115 	itemCount = bodySection->Items().Count();
       
   116 	for (TInt ii = 0; ii<itemCount; ++ii)
       
   117 		{
       
   118 		TPtrC name = bodySection->Item(ii).Value();
       
   119 		// Check if the contents is a string then don't convert to integer
       
   120 		if(name[0] >= '0' && name[0] <='9')
       
   121 			{
       
   122 			HdrCodeLex.Assign(name);
       
   123 			TUint nameInt;
       
   124 			HdrCodeLex.Val(nameInt);
       
   125 			iBodyBuf.Append(nameInt);
       
   126 			}
       
   127 		else
       
   128 			iBodyBuf.Append(name);
       
   129 		}
       
   130 
       
   131 	}
       
   132 
       
   133 TBool CWapScriptTest::ConfirmMessagesSavedL()
       
   134 	{
       
   135 	return ETrue;
       
   136 	}