smsprotocols/smsstack/smsprot/Test/TE_Smsprt/TE_smsprtbase.cpp
changeset 20 244d7c5f118e
parent 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
19:1f776524b15c 20:244d7c5f118e
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 /**
    16 /**
    17  @file
    17     @file
       
    18     @test
    18 */
    19 */
    19 #include <cfshared.h>
       
    20 #include <c32root.h>
       
    21 #include <sacls.h>
       
    22 #include <e32math.h>
       
    23 
    20 
    24 #include "TE_smsprtbase.h"
    21 #include "TE_smsprtbase.h"
    25 
       
    26 
       
    27 /**
       
    28 	Preamble for all CSmsPrtTestStep
       
    29 */
       
    30 TVerdict CSmsPrtTestStep::doTestStepPreambleL()
       
    31 	{
       
    32 	//base class preamble - marks the heap
       
    33 	CSMSTestSteps::doTestStepPreambleL();
       
    34 	
       
    35 	iScheduler = new(ELeave) CActiveScheduler;
       
    36 	CActiveScheduler::Install(iScheduler);
       
    37 	
       
    38 
       
    39     TRAPD(ret, ParseSettingsFromFileL());
       
    40 	if (ret != KErrNone)
       
    41 		{
       
    42 		INFO_PRINTF2(_L("ParseSettingsFromFileL [err=%d]"), ret);
       
    43 		}
       
    44 	
       
    45 	iSmsStackTestUtils = CSmsStackTestUtils::NewL(this,  iFs);
       
    46 	
       
    47 	return TestStepResult() ;
       
    48 	}
       
    49 
       
    50 /**
       
    51 	Cleanup SmsStackTestUtils, close the filer server session and delete the scheduler
       
    52 */
       
    53 TVerdict CSmsPrtTestStep::doTestStepPostambleL()
       
    54 	{
       
    55 	delete iSmsStackTestUtils;
       
    56 	iSmsStackTestUtils = NULL;
       
    57 	
       
    58 	delete iScheduler;
       
    59 	iScheduler = NULL;
       
    60 
       
    61 	//base class postamble - unmarks the heap
       
    62 	CSMSTestSteps::doTestStepPostambleL();
       
    63 	
       
    64 	//DoESockMemoryLeakTestL();
       
    65 
       
    66  	return CSMSTestSteps::doTestStepPostambleL() ;
       
    67 	} // CSmsPrtTestStep::doTestStepPostambleL
       
    68 
       
    69 
       
    70 void CSmsPrtTestStep::DoESockMemoryLeakTestL()
       
    71 	{
       
    72 	//
       
    73 	// Find the current number of leaked cells in ESock...
       
    74 	//
       
    75 	TInt  ret, startLeakCounter;
       
    76 	
       
    77 	ret = RProperty::Get(KUidCommsProcess, KUidCommsModuleLeakCounter, startLeakCounter);
       
    78 	if (ret == KErrNotFound)
       
    79 		{
       
    80 		// No variable to monitor, ESock is probably not in debug mode.
       
    81 		return;
       
    82 		}
       
    83 	else
       
    84 		{
       
    85 		TESTL(ret == KErrNone);
       
    86 		}
       
    87 
       
    88 	//
       
    89 	// Connect to Rootserver...
       
    90 	//
       
    91 	RRootServ  rootserver;
       
    92 
       
    93 	User::LeaveIfError(rootserver.Connect());
       
    94 	CleanupClosePushL(rootserver);
       
    95 
       
    96 	//
       
    97 	// Shutdown all the ESock CPMs gracefully...
       
    98 	//
       
    99 	TRSIter  iter;
       
   100 	TCFModuleName  modName;
       
   101 	TRSModuleInfo  modInfo;
       
   102 	TRequestStatus  statusArray[16];
       
   103 	TInt  statusCount = 0;
       
   104 
       
   105 	while (rootserver.EnumerateModules(iter, modName) == KErrNone)
       
   106 		{
       
   107 		if (rootserver.GetModuleInfo(modName, modInfo) == KErrNone  &&
       
   108 		    modInfo.iParams.iDll.MatchF(_L("*ESOCKSVR.DLL")) >= 0)
       
   109 			{
       
   110 			rootserver.UnloadCpm(statusArray[statusCount++], modInfo.iParams.iName,
       
   111 			                     EGraceful);
       
   112 			}
       
   113 		}
       
   114 
       
   115 	while (statusCount > 0)
       
   116 		{
       
   117 		statusCount--;
       
   118 		User::WaitForRequest(statusArray[statusCount]);
       
   119 		TEST(statusArray[statusCount] == KErrNone);
       
   120 		}
       
   121 
       
   122 	//
       
   123 	// Close Rootserver session...
       
   124 	//
       
   125 	CleanupStack::PopAndDestroy(1, &rootserver);
       
   126 	
       
   127 	//
       
   128 	// Get the latest number of leaked cells in ESock...
       
   129 	//
       
   130 	TInt  finalLeakCounter;
       
   131 
       
   132 	ret = RProperty::Get(KUidCommsProcess, KUidCommsModuleLeakCounter, finalLeakCounter);
       
   133 	TESTL(ret == KErrNone);
       
   134 
       
   135 	if (finalLeakCounter > startLeakCounter)
       
   136 		{
       
   137 		INFO_PRINTF1(_L("<font size=2 color=FF0000><B>A memory leak has been detected inside ESock - Check SMS Stack!</B></font>"));
       
   138 		TEST(finalLeakCounter == startLeakCounter);
       
   139 		}
       
   140 
       
   141 	//
       
   142 	// Restart C32...
       
   143 	//
       
   144 	_LIT(KDummyCMI, "");
       
   145 	WarmBootC32(KDummyCMI);
       
   146 	} // CSmsPrtTestStep::DoESockMemoryLeakTestL
       
   147 
       
   148 
    22 
   149 /**
    23 /**
   150  *	Pre-test step function for Encoding tests.
    24  *	Pre-test step function for Encoding tests.
   151  * 
    25  * 
   152  *  @return EPass or EFail verdict.
    26  *  @return EPass or EFail verdict.
   153  */
    27  */
   154 TVerdict CSmsPrtEncodingTestStep::doTestStepPreambleL()
    28 TVerdict CSmsPrtEncodingTestStep::doTestStepPreambleL()
   155 	{
    29 	{
   156 	CSmsPrtTestStep::doTestStepPreambleL();
    30     CSmsBaseTestStep::doTestStepPreambleL();
   157 	
    31 	
   158 	iTestAlphabet = CSmsPrtTestAlphabet::NewL();
    32 	iTestAlphabet = CSmsPrtTestAlphabet::NewL();
   159 	
    33 	
   160 	return TestStepResult() ;
    34 	return TestStepResult();
   161 	} // CSmsPrtEncodingTestStep::doTestStepPreambleL
    35 	}
   162 
       
   163 
    36 
   164 /**
    37 /**
   165  *	Post-test step function for Encoding tests.
    38  *	Post-test step function for Encoding tests.
   166  * 
    39  * 
   167  *  @return EPass or EFail verdict.
    40  *  @return EPass or EFail verdict.
   172 	iTestAlphabet = NULL;
    45 	iTestAlphabet = NULL;
   173 	
    46 	
   174     iCharSets.Reset();
    47     iCharSets.Reset();
   175     iAdditionalCharSets.Reset();
    48     iAdditionalCharSets.Reset();
   176 	
    49 	
   177  	return CSmsPrtTestStep::doTestStepPostambleL();
    50  	return CSmsBaseTestStep::doTestStepPostambleL();
   178  	} // CSmsPrtEncodingTestStep::doTestStepPostambleL
    51  	}
   179 
    52 
   180 /**
    53 /**
   181  *  Computes the expected number of PDUs and expected number of free characters
    54  *  Computes the expected number of PDUs and expected number of free characters
   182  *  (User Data Units) in the last PDU. This is computed from the number of
    55  *  (User Data Units) in the last PDU. This is computed from the number of
   183  *  octets in the message.
    56  *  octets in the message.
   472     // Work out the number of characters to test with...
   345     // Work out the number of characters to test with...
   473     //
   346     //
   474     TInt  charSetSize = 0;
   347     TInt  charSetSize = 0;
   475     TInt countTestCharSetNames = aTestCharSetNames.Count();
   348     TInt countTestCharSetNames = aTestCharSetNames.Count();
   476     
   349     
   477     for (TInt charSet = 0;  charSet < countTestCharSetNames;  ++charSet)
   350     for (TInt charSet = 0; charSet < countTestCharSetNames ; ++charSet)
   478         {
   351         {
   479         TInt  charactersInCharSet = iTestAlphabet->GetCharacterSetSizeL(aTestCharSetNames[charSet]);
   352         TInt  charactersInCharSet = iTestAlphabet->GetCharacterSetSizeL(aTestCharSetNames[charSet]);
   480         charSetSize += charactersInCharSet;
   353         charSetSize += charactersInCharSet;
   481         }
   354         }
   482 
   355 
   496                                               TInt aAdditionalTestCharacters,
   369                                               TInt aAdditionalTestCharacters,
   497                                               RArray<TPtrC>& aAdditionalTestCharSetNames,
   370                                               RArray<TPtrC>& aAdditionalTestCharSetNames,
   498                                               TSmsDataCodingScheme::TSmsAlphabet aAlphabet,
   371                                               TSmsDataCodingScheme::TSmsAlphabet aAlphabet,
   499                                               TSmsEncoding aEncodingToUse,
   372                                               TSmsEncoding aEncodingToUse,
   500                                               TSmsEncoding aEncodingExpected)
   373                                               TSmsEncoding aEncodingExpected)
   501     {          
   374     {
       
   375     
   502 	//
   376 	//
   503 	// Display the test name and details...
   377 	// Display the test name and details...
   504 	//
   378 	//
   505     TInt countTestCharSetNames = aTestCharSetNames.Count();
   379     TInt countTestCharSetNames = aTestCharSetNames.Count();
       
   380     
   506     for (TInt charSet = 0;  charSet < countTestCharSetNames;  ++charSet)
   381     for (TInt charSet = 0;  charSet < countTestCharSetNames;  ++charSet)
   507         {
   382         {
   508         TInt  charactersInCharSet = iTestAlphabet->GetCharacterSetSizeL(aTestCharSetNames[charSet]);
   383         TInt  charactersInCharSet = iTestAlphabet->GetCharacterSetSizeL(aTestCharSetNames[charSet]);
   509         INFO_PRINTF3(_L("  Using character set \"%S\" which contains %d characters..."),
   384         INFO_PRINTF3(_L("  Using character set \"%S\" which contains %d characters..."),
   510                      &aTestCharSetNames[charSet], charactersInCharSet);
   385                      &aTestCharSetNames[charSet], charactersInCharSet);
   511         }
   386         }
   512 
   387 
   513     INFO_PRINTF2(_L("Testing encode functions starting with %d characters."), aTestCharacters);
   388     INFO_PRINTF2(_L("Testing encode functions starting with %d characters."), aTestCharacters);
   514     TInt countAdditionalTestCharSetNames = aAdditionalTestCharSetNames.Count();
   389     TInt countAdditionalTestCharSetNames = aAdditionalTestCharSetNames.Count();
       
   390     
   515     for (TInt charSet = 0;  charSet < countAdditionalTestCharSetNames;  ++charSet)
   391     for (TInt charSet = 0;  charSet < countAdditionalTestCharSetNames;  ++charSet)
   516         {
   392         {
   517         TInt  charactersInCharSet = iTestAlphabet->GetCharacterSetSizeL(aAdditionalTestCharSetNames[charSet]);
   393         TInt  charactersInCharSet = iTestAlphabet->GetCharacterSetSizeL(aAdditionalTestCharSetNames[charSet]);
   518         INFO_PRINTF3(_L("  Using additional character set \"%S\" which contains %d characters..."),
   394         INFO_PRINTF3(_L("  Using additional character set \"%S\" which contains %d characters..."),
   519                      &aAdditionalTestCharSetNames[charSet], charactersInCharSet);
   395                      &aAdditionalTestCharSetNames[charSet], charactersInCharSet);
   589 			continue;
   465 			continue;
   590 			}
   466 			}
   591 
   467 
   592 		lastOctetCountTested = octetsCount;
   468 		lastOctetCountTested = octetsCount;
   593 		
   469 		
   594 		//
   470 		CSmsMessage*  smsMessage = CreateSmsMessageLC(originalPtr, aAlphabet);
   595 		// Create a CSmsMessage...
       
   596 		//
       
   597 		CSmsMessage*  smsMessage = CreateSmsMessageL(originalPtr, aAlphabet);
       
   598 		CleanupStack::PushL(smsMessage);
       
   599 
   471 
   600 		//
   472 		//
   601 		// Perform various character tests on the smsMessage
   473 		// Perform various character tests on the smsMessage
   602 		//
   474 		//
   603 		octetsCount = PerformCharacterTestsL(smsMessage, originalPtr, aAlphabet, aEncodingToUse, aEncodingExpected, octetsCount, extendedCharAdded);
   475 		octetsCount = PerformCharacterTestsL(smsMessage, originalPtr, aAlphabet, aEncodingToUse, aEncodingExpected, octetsCount, extendedCharAdded);
   661 			
   533 			
   662 			INFO_PRINTF2(_L("Sending final message of %d characters..."),
   534 			INFO_PRINTF2(_L("Sending final message of %d characters..."),
   663 					     originalPtr.Length());
   535 					     originalPtr.Length());
   664 
   536 
   665 			TRAPD(sendErr, SendSmsL(smsMessage, aSocket));
   537 			TRAPD(sendErr, SendSmsL(smsMessage, aSocket));
   666 			TESTCHECK(sendErr, KErrNone);
   538 		    TESTCHECK(sendErr, KErrNone, "Sending SMS");
   667 			}
   539 			}
   668 		
   540 		
   669 		CleanupStack::PopAndDestroy(smsMessage);
   541 		CleanupStack::PopAndDestroy(smsMessage);
   670 		}
   542 		}
   671 	
   543 	
   676 	if (TimedWaitForRecvL(aSocket, 60*1000000))
   548 	if (TimedWaitForRecvL(aSocket, 60*1000000))
   677 		{
   549 		{
   678 		CSmsMessage*  smsMessage = RecvSmsL(aSocket);
   550 		CSmsMessage*  smsMessage = RecvSmsL(aSocket);
   679 		CleanupStack::PushL(smsMessage);
   551 		CleanupStack::PushL(smsMessage);
   680 		TestSmsContentsL(smsMessage, expectedPtr);
   552 		TestSmsContentsL(smsMessage, expectedPtr);
   681 		TESTCHECK(smsMessage->Alternative7bitEncoding(), aEncodingExpected);
   553 		TESTCHECK(smsMessage->Alternative7bitEncoding(), aEncodingExpected, "Getting the Alternative7bitEncoding");
   682 		CleanupStack::PopAndDestroy(smsMessage);
   554 		CleanupStack::PopAndDestroy(smsMessage);
   683 		}
   555 		}
   684 	else
   556 	else
   685 		{
   557 		{
   686 		INFO_PRINTF1(_L("<font color=FF0000>Failed: No SMS message received.</font>"));
   558 		ERR_PRINTF1(_L("<font color=FF0000>Failed: No SMS message received.</font>"));
   687         SetTestStepResult(EFail);
   559         SetTestStepResult(EFail);
   688 		}
   560 		}
   689 
   561 
   690 	CleanupStack::PopAndDestroy(expectedBuf);
   562 	CleanupStack::PopAndDestroy(2, originalBuf); // originalBuf, expectedBuf
   691 	CleanupStack::PopAndDestroy(originalBuf);
   563 	}
   692 	} // CSmsPrtEncodingTestStep::DoEncodingTestL
       
   693 
   564 
   694 TInt CSmsPrtEncodingTestStep::PerformCharacterTestsL(
   565 TInt CSmsPrtEncodingTestStep::PerformCharacterTestsL(
   695         CSmsMessage* aSmsMessage, 
   566         CSmsMessage* aSmsMessage, 
   696         TDesC16& aOriginalPtr,
   567         TDesC16& aOriginalPtr,
   697         TSmsDataCodingScheme::TSmsAlphabet& aAlphabet,
   568         TSmsDataCodingScheme::TSmsAlphabet& aAlphabet,
   699         TSmsEncoding aEncodingExpected,
   570         TSmsEncoding aEncodingExpected,
   700         TInt aOctetsCount,
   571         TInt aOctetsCount,
   701         TBool aExtendedCharAdded
   572         TBool aExtendedCharAdded
   702         )
   573         )
   703     {
   574     {
   704     //
   575     TESTCHECK(aSmsMessage->SetAlternative7bitEncoding(aEncodingToUse), KErrNone, "Switch on Alternative 7Bit Encoding if required");
   705     // Switch on Alternative 7Bit Encoding if required...
       
   706     //
       
   707     TESTCHECK(aSmsMessage->SetAlternative7bitEncoding(aEncodingToUse), KErrNone);
       
   708 
   576 
   709     //
   577     //
   710     // Find the expected number of supported characters that would have
   578     // Find the expected number of supported characters that would have
   711     // appeared using the old API...
   579     // appeared using the old API...
   712     //
   580     //
   725     TInt  numberOfUnconvertibleCharacters, indexOfFirstUnconvertibleCharacter;
   593     TInt  numberOfUnconvertibleCharacters, indexOfFirstUnconvertibleCharacter;
   726     
   594     
   727     if (aAlphabet != TSmsDataCodingScheme::ESmsAlphabetUCS2)
   595     if (aAlphabet != TSmsDataCodingScheme::ESmsAlphabetUCS2)
   728         {
   596         {
   729         TESTCHECKCONDITION(aSmsMessage->IsSupportedL(aOriginalPtr, numberOfUnconvertibleCharacters,
   597         TESTCHECKCONDITION(aSmsMessage->IsSupportedL(aOriginalPtr, numberOfUnconvertibleCharacters,
   730                                                     indexOfFirstUnconvertibleCharacter) == msgSupported);
   598                                                     indexOfFirstUnconvertibleCharacter) == msgSupported,
   731         TESTCHECK(numberOfUnconvertibleCharacters, expectedUnconvertibleChars);
   599                                                     "Checking if a buffer can be encoded without loss of information");
   732         TESTCHECK(indexOfFirstUnconvertibleCharacter, expectedFirstUnconvertibleChar);
   600         TESTCHECK(numberOfUnconvertibleCharacters, expectedUnconvertibleChars, "Checking number of unconvertable charachters");
       
   601         TESTCHECK(indexOfFirstUnconvertibleCharacter, expectedFirstUnconvertibleChar, "Checking index of the first unconvertable charachter");
   733         }
   602         }
   734 
   603 
   735     //
   604     //
   736     // Get the expected number of supported characters, downgraded characters
   605     // Get the expected number of supported characters, downgraded characters
   737     // and alternative encodings that would have appeared using the new API...
   606     // and alternative encodings that would have appeared using the new API...
   755     if (aAlphabet != TSmsDataCodingScheme::ESmsAlphabetUCS2)
   624     if (aAlphabet != TSmsDataCodingScheme::ESmsAlphabetUCS2)
   756         {
   625         {
   757         TESTCHECKCONDITION(aSmsMessage->IsSupportedL(aOriginalPtr, numberOfUnconvertibleCharacters,
   626         TESTCHECKCONDITION(aSmsMessage->IsSupportedL(aOriginalPtr, numberOfUnconvertibleCharacters,
   758                                                     numberOfDowngradedCharacters,
   627                                                     numberOfDowngradedCharacters,
   759                                                     numberRequiringAlternativeEncoding,
   628                                                     numberRequiringAlternativeEncoding,
   760                                                     indexOfFirstUnconvertibleCharacter) == msgSupported);        
   629                                                     indexOfFirstUnconvertibleCharacter) == msgSupported,
   761         TESTCHECK(numberOfUnconvertibleCharacters, expectedUnconvertibleChars);
   630                                                     "Checking if a buffer can be encoded without loss of information");
   762         TESTCHECK(numberOfDowngradedCharacters, expectedDowngradedChars);
   631         TESTCHECK(numberOfUnconvertibleCharacters, expectedUnconvertibleChars, "Checking number of unconvertable charachters");
   763         TESTCHECK(numberRequiringAlternativeEncoding, expectedAlternativeEncodingChars);
   632         TESTCHECK(numberOfDowngradedCharacters, expectedDowngradedChars, "Checking number of Downgraded charachters");
   764         TESTCHECK(indexOfFirstUnconvertibleCharacter, expectedFirstUnconvertibleChar);
   633         TESTCHECK(numberRequiringAlternativeEncoding, expectedAlternativeEncodingChars, "Checking number requiring alternative encoding charachters");
       
   634         TESTCHECK(indexOfFirstUnconvertibleCharacter, expectedFirstUnconvertibleChar, "Checking index of the first unconvertable charachter");
   765         }
   635         }
   766 
   636 
   767     //
   637     //
   768     // Get the expected PDU count and free units...
   638     // Get the expected PDU count and free units...
   769     //
   639     //
   797         octetsCount++;
   667         octetsCount++;
   798         GetExpectedPDUCountAndUDUnitsFreeL(octetsCount, aAlphabet, aEncodingExpected,
   668         GetExpectedPDUCountAndUDUnitsFreeL(octetsCount, aAlphabet, aEncodingExpected,
   799                                            expectedPDUs, expectedFreeUDUnitsInLastPDU);
   669                                            expectedPDUs, expectedFreeUDUnitsInLastPDU);
   800         }
   670         }
   801 
   671 
   802     TESTCHECK(pdus, expectedPDUs);
   672     TESTCHECK(pdus, expectedPDUs, "Checking number of expected PDUs");
   803     TESTCHECK(numberOfUnconvertibleCharacters, expectedUnconvertibleChars);
   673     TESTCHECK(numberOfUnconvertibleCharacters, expectedUnconvertibleChars,  "Checking number of unconvertable charachters");
   804     TESTCHECK(numberOfDowngradedCharacters, expectedDowngradedChars);
   674     TESTCHECK(numberOfDowngradedCharacters, expectedDowngradedChars, "Checking number of Downgraded charachters");
   805     TESTCHECK(freeUDUnitsInLastPDU, expectedFreeUDUnitsInLastPDU);
   675     TESTCHECK(freeUDUnitsInLastPDU, expectedFreeUDUnitsInLastPDU, "Checking freeUDUnitsInLastPDU");
   806 
   676 
   807     //
   677     //
   808     // Check the old PDU count function...
   678     // Check the old PDU count function...
   809     //
   679     //
   810     pdus = aSmsMessage->NumMessagePDUsL();
   680     pdus = aSmsMessage->NumMessagePDUsL();
   811     TESTCHECK(pdus, expectedPDUs);
   681     TESTCHECK(pdus, expectedPDUs, "Checking number of expected PDUs");
   812     
   682     
   813     return octetsCount;
   683     return octetsCount;
   814     }
   684     }
   815