genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestTelUriValidationStep.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2007-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 // Contains implementation of CTestTelUriValidationStep class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology 
       
    21 */
       
    22 
       
    23 // User Include
       
    24 #include "TestTelUriValidationStep.h"
       
    25 // System Include
       
    26 #include <uri8.h>
       
    27 #include <uriutils.h>
       
    28 
       
    29 /**
       
    30   Constructor: Sets the test step name.
       
    31   @internalTechnology
       
    32   @test
       
    33 */
       
    34 CTestTelUriValidationStep::CTestTelUriValidationStep()
       
    35 	{
       
    36 	//Call base class method to set human readable name for test step
       
    37 	SetTestStepName(KTestTelUriValidationStep);
       
    38 	}
       
    39 
       
    40 /**
       
    41   Destructor
       
    42   @internalTechnology
       
    43   @test
       
    44 */
       
    45 CTestTelUriValidationStep::~CTestTelUriValidationStep()
       
    46 	{
       
    47 
       
    48 	}
       
    49 
       
    50 /**
       
    51   Does the main functionality of a test step.
       
    52   Here, reads values from INI file 
       
    53   and calls TestTelUriValidate() which does validation of a tel uri.
       
    54   @internalTechnology 
       
    55   @param		None
       
    56   @return		EPass or EFail indicating the success or failure of the test step
       
    57 */
       
    58 TVerdict CTestTelUriValidationStep::doTestStepL()
       
    59 	{
       
    60 	__UHEAP_MARK;
       
    61 	INFO_PRINTF1(_L("\n"));
       
    62 	// Get necessary information from INI file
       
    63 	TPtrC telUri;
       
    64 	TInt expRetCode;
       
    65 
       
    66 	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, telUri) ||
       
    67 	   !GetIntFromConfig(ConfigSection(), KIniExpectedRetCode, expRetCode) )
       
    68 		{
       
    69 		ERR_PRINTF3(_L("Problem in reading values from ini.			\
       
    70 						\nExpected fields are: \n%S\n%S\n" ),&KIniUri, &KIniExpectedRetCode );
       
    71 		SetTestStepResult(EFail);
       
    72 		}
       
    73 	else
       
    74 		{
       
    75 		// No problem in reading values from INI file. Proceed.
       
    76 		// Calling TestTelUriValidate which does validation of tel uri and comparing results.
       
    77 	    TRAPD(err, TestTelUriValidateAndCompareL(telUri,expRetCode));
       
    78 	    if(err != KErrNone)
       
    79 		    {
       
    80 	        ERR_PRINTF1(_L("Test step failed: Leave occured in TestTelUriValidateAndCompareL \n"));
       
    81 	        SetTestStepResult(EFail);	
       
    82 		    }
       
    83 		}
       
    84 	__UHEAP_MARKEND;
       
    85 	INFO_PRINTF1(_L("\nTest of TelUri Validation is Executed"));
       
    86 	return TestStepResult();
       
    87 	}
       
    88 
       
    89 /**
       
    90   Performs tel uri validation and compares actual & expected result.
       
    91   @param		aTelUri A reference to tel-uri to be validated.
       
    92   @param		aExpRetCode An expected retrn code to be compared.
       
    93 */	
       
    94 void CTestTelUriValidationStep::TestTelUriValidateAndCompareL(const TDesC16& aTelUri, const TInt aExpRetCode)
       
    95 	{
       
    96     CUri8* cUri8 = UriUtils::CreateUriL(aTelUri);
       
    97     const TUriC8& telUri(cUri8->Uri());
       
    98 	// Validating tel uri
       
    99 	TInt errCode = telUri.Validate();
       
   100     if(errCode != aExpRetCode)
       
   101 		{
       
   102 	  	ERR_PRINTF2(_L("Tel URI validation failed %D\n"), errCode);
       
   103 	    SetTestStepResult(EFail);	
       
   104 		}
       
   105 	delete cUri8;
       
   106 	}
       
   107 
       
   108 /**
       
   109   Constructor: Sets the test step name.
       
   110   @internalTechnology
       
   111   @test
       
   112 */
       
   113 CTestTelUriValidationOomStep::CTestTelUriValidationOomStep()
       
   114 	{
       
   115 	//Call base class method to set human readable name for test step
       
   116 	SetTestStepName(KTestOomTelUriValidationStep);
       
   117 	}
       
   118 
       
   119 /**
       
   120   Destructor
       
   121   @internalTechnology
       
   122   @test
       
   123 */
       
   124 CTestTelUriValidationOomStep::~CTestTelUriValidationOomStep()
       
   125 	{
       
   126 
       
   127 	}
       
   128 
       
   129 /**
       
   130   Does the main functionality of a test step and performs OOM test.
       
   131   Here, reads values from INI file 
       
   132   and calls TestTelUriValidate() which does validation of a tel uri.
       
   133   @internalTechnology 
       
   134   @param		None
       
   135   @return		EPass or EFail indicating the success or failure of the test step
       
   136 */
       
   137 TVerdict CTestTelUriValidationOomStep::doTestStepL()
       
   138 	{
       
   139 	__UHEAP_MARK;
       
   140 	TPtrC telUri;
       
   141 	if(!GetStringFromConfig(ConfigSection(), 	KIniUri, telUri) )
       
   142 		{
       
   143 		ERR_PRINTF2(_L("Problem in reading values from ini.    \
       
   144 						\nExpected fields are: \n%S\n" ), &KIniUri);
       
   145 		SetTestStepResult(EFail);
       
   146 		}
       
   147 	else
       
   148 		{
       
   149 		CUri8* cUri8 = UriUtils::CreateUriL(telUri);
       
   150     	const TUriC8& telUri(cUri8->Uri());
       
   151 		INFO_PRINTF1(_L("Calling telUri.Validate() which does tel-Uri Validation.")); 	
       
   152 		TInt ret = KErrNoMemory;
       
   153 		TInt failAt = 0;
       
   154 		while(ret != KErrNone)
       
   155 			{
       
   156 			failAt++;
       
   157 			INFO_PRINTF2(_L("OOM test step: %d\n"),failAt);
       
   158 
       
   159 			__UHEAP_SETFAIL( RHeap::EDeterministic, failAt );
       
   160 			__UHEAP_MARK;
       
   161 			TRAP( ret, telUri.Validate());
       
   162 			__UHEAP_MARKEND;
       
   163 			__UHEAP_RESET;
       
   164 			if((ret == KErrNoMemory) || (ret == KErrNone))
       
   165 				{
       
   166 				INFO_PRINTF2(_L("Error/RetCode : %D\n"),ret);
       
   167 				}
       
   168 			}
       
   169 		delete cUri8;
       
   170 		}
       
   171 	__UHEAP_MARKEND;
       
   172 	INFO_PRINTF1(_L("\n OOM Test of TelUri Validation is Executed"));
       
   173 	return TestStepResult();
       
   174 	}
       
   175 
       
   176