os/ossrv/genericservices/httputils/Test/te_authentication/src/authentication_TEF0Step.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 // Example CTestStep derived implementation
    15 // 
    16 //
    17 
    18 /**
    19  @file Authentication_TEF0Step.cpp
    20 */
    21 #include "authentication_TEF0Step.h"
    22 #include "Te_authentication_TEFSuiteDefs.h"
    23 
    24 #include <cauthentication.h>
    25 
    26 CAuthentication_TEF0Step::~CAuthentication_TEF0Step()
    27 /**
    28  * Destructor
    29  */
    30 	{
    31 	}
    32 
    33 CAuthentication_TEF0Step::CAuthentication_TEF0Step()
    34 /**
    35  * Constructor
    36  */
    37 	{
    38 	// **MUST** call SetTestStepName in the constructor as the controlling
    39 	// framework uses the test step name immediately following construction to set
    40 	// up the step's unique logging ID.
    41 	SetTestStepName(KAuthentication_TEF0Step);
    42 	}
    43 
    44 TVerdict CAuthentication_TEF0Step::doTestStepPreambleL()
    45 /**
    46  * @return - TVerdict code
    47  * Override of base class virtual
    48  */
    49 	{
    50 	SetTestStepResult(EPass);
    51 	return TestStepResult();
    52 	}
    53 
    54 
    55 TVerdict CAuthentication_TEF0Step::doTestStepL()
    56 /**
    57  * @return - TVerdict code
    58  * Override of base class pure virtual
    59  * Our implementation only gets called if the base class doTestStepPreambleL() did
    60  * not leave. That being the case, the current test result value will be EPass.
    61  */
    62 	{
    63 	__UHEAP_MARK;		
    64 
    65 	CAuthentication* auth;
    66 	CUri8* uri;
    67 	TPtrC8 name;
    68 	TPtrC8 pwd;
    69 	
    70 	// create auth obj from name and pwd
    71 	auth = CAuthentication::NewL(KUser1, KPwd1);
    72 	CleanupStack::PushL(auth);
    73 
    74 	
    75 	// *********** test default parameters *********** //	              
    76 
    77 	// get name and compare to expected
    78 	name.Set(auth->Name());
    79 	if(name.Compare(KUser1) != 0)
    80 		{
    81 		INFO_PRINTF1(KNameNotRetreivedProperly); 
    82 		SetTestStepResult(EFail);		
    83 		}
    84 	
    85 	// get pwd and compare to expected
    86 	pwd.Set(auth->Password());
    87 	if(pwd.Compare(KPwd1) != 0)
    88 		{
    89 		INFO_PRINTF1(KPasswordNotRetreivedProperly); 
    90 		SetTestStepResult(EFail);		
    91 		}
    92 		
    93 	// compare default method to expected
    94 	if(auth->Method() != CAuthentication::EDigest)
    95 		{
    96 		INFO_PRINTF1(KMethodNotRetreivedProperly); 
    97 		SetTestStepResult(EFail);		
    98 		}
    99 	
   100 	// *********** test changing parameters *********** //
   101 	
   102 	// change and check new name
   103 	auth->SetNameL(KUser2);
   104 	name.Set(auth->Name());
   105 	if(name.Compare(KUser2) != 0)
   106 		{
   107 		INFO_PRINTF1(KNameNotRetreivedProperly); 
   108 		SetTestStepResult(EFail);		
   109 		}
   110 	
   111 	// change and check new pwd
   112 	auth->SetPasswordL(KPwd2);
   113 	pwd.Set(auth->Password());
   114 	if(pwd.Compare(KPwd2) != 0)
   115 		{
   116 		INFO_PRINTF1(KPasswordNotRetreivedProperly); 
   117 		SetTestStepResult(EFail);		
   118 		}
   119 		
   120 	// change and check new method
   121 	auth->SetMethod(CAuthentication::EBasic);
   122 	if(auth->Method() != CAuthentication::EBasic)
   123 		{
   124 		INFO_PRINTF1(KMethodNotRetreivedProperly); 
   125 		SetTestStepResult(EFail);
   126 		}
   127 		
   128 	CleanupStack::PopAndDestroy(auth);
   129 		
   130 	// *********** test default parameters set using TUriC *********** //
   131 	
   132 	TUriParser8 uriParser;
   133 	uriParser.Parse(KUriUserInfoComplete);
   134 	uri = CUri8::NewLC(uriParser);
   135 	TUriC8 tUri = uri->Uri();
   136 	
   137 	auth = CAuthentication::NewL(tUri);
   138 	CleanupStack::PushL(auth);
   139 	
   140 	name.Set(auth->Name());
   141 	if(name.Compare(KUser1) != 0)
   142 		{
   143 		INFO_PRINTF1(KNameNotRetreivedProperly); 
   144 		SetTestStepResult(EFail);		
   145 		}
   146 	
   147 	// get pwd and compare to expected
   148 	pwd.Set(auth->Password());
   149 	if(pwd.Compare(KPwd1) != 0)
   150 		{
   151 		INFO_PRINTF1(KPasswordNotRetreivedProperly); 
   152 		SetTestStepResult(EFail);
   153 		}
   154 		
   155 	// compare default method to expected
   156 	if(auth->Method() != CAuthentication::EDigest)
   157 		{
   158 		INFO_PRINTF1(KMethodNotRetreivedProperly); 
   159 		SetTestStepResult(EFail);
   160 		}
   161 	
   162 	CleanupStack::PopAndDestroy(2, uri);
   163 		
   164 	// *********** test with incomplete or missing User Info *********** //
   165 	
   166 	TUriParser8 incompleteUriParser;
   167 	CUri8* incompleteUri;
   168 	
   169 	// *** test incomplete uri type 1
   170 	incompleteUriParser.Parse(KUriUserInfoIncomplete1);
   171 	incompleteUri = CUri8::NewLC(incompleteUriParser);
   172 	TUriC8 tIncompleteUri = incompleteUri->Uri();
   173 	
   174 	// create from uri type 1
   175 	auth = CAuthentication::NewL(tIncompleteUri);
   176 	CleanupStack::PushL(auth);
   177 	
   178 	// check has user and no pwd
   179 	name.Set(auth->Name());
   180 	if(name.Compare(KUser1) != 0)
   181 		{
   182 		INFO_PRINTF1(KNameNotRetreivedProperly); 
   183 		SetTestStepResult(EFail);		
   184 		}
   185 	pwd.Set(auth->Password());
   186 	if(pwd.Compare(KNullDesC8) != 0)
   187 		{
   188 		INFO_PRINTF1(KPasswordNotRetreivedProperly); 
   189 		SetTestStepResult(EFail);		
   190 		}
   191 	CleanupStack::PopAndDestroy(2, incompleteUri);
   192 	
   193 	// *** test incomplete uri type 2
   194 	incompleteUriParser.Parse(KUriUserInfoIncomplete2);
   195 	incompleteUri = CUri8::NewLC(incompleteUriParser);
   196 	TUriC8 tIncompleteUri2 = incompleteUri->Uri();
   197 	
   198 	// create from uri type 2
   199 	auth = CAuthentication::NewL(tIncompleteUri2);
   200 	CleanupStack::PushL(auth);	
   201 	
   202 	// check has user and no pwd
   203 	name.Set(auth->Name());
   204 	if(name.Compare(KUser1) != 0)
   205 		{
   206 		INFO_PRINTF1(KNameNotRetreivedProperly); 
   207 		SetTestStepResult(EFail);		
   208 		}		
   209 	pwd.Set(auth->Password());
   210 	if(pwd.Compare(KNullDesC8) != 0)
   211 		{
   212 		INFO_PRINTF1(KPasswordNotRetreivedProperly); 
   213 		SetTestStepResult(EFail);		
   214 		}	
   215 	CleanupStack::PopAndDestroy(2, incompleteUri);
   216 	
   217 	// *** test incomplete uri type 3
   218 	incompleteUriParser.Parse(KUriUserInfoIncomplete3);
   219 	incompleteUri = CUri8::NewLC(incompleteUriParser);
   220 	TUriC8 tIncompleteUri3 = incompleteUri->Uri();
   221 	
   222 	// create from uri type 3
   223 	auth = CAuthentication::NewL(tIncompleteUri3);
   224 	CleanupStack::PushL(auth);
   225 	
   226 	// check no user name but has pwd
   227 	name.Set(auth->Name());
   228 	if(name.Compare(KNullDesC8) != 0)
   229 		{
   230 		INFO_PRINTF1(KNameNotRetreivedProperly); 
   231 		SetTestStepResult(EFail);		
   232 		}
   233 	pwd.Set(auth->Password());
   234 	if(pwd.Compare(KPwd1) != 0)
   235 		{
   236 		INFO_PRINTF1(KPasswordNotRetreivedProperly); 
   237 		SetTestStepResult(EFail);		
   238 		}
   239 	CleanupStack::PopAndDestroy(2, incompleteUri);
   240 	
   241 	// *** test incomplete uri type 4
   242 	incompleteUriParser.Parse(KUriUserInfoIncomplete4);
   243 	incompleteUri = CUri8::NewLC(incompleteUriParser);
   244 	TUriC8 tIncompleteUri4 = incompleteUri->Uri();
   245 	
   246 	// create from uri type 4
   247 	auth = CAuthentication::NewL(tIncompleteUri4);
   248 	CleanupStack::PushL(auth);
   249 	
   250 	// check there is neither user nor pwd
   251 	name.Set(auth->Name());
   252 	if(name.Compare(KNullDesC8) != 0)
   253 		{
   254 		INFO_PRINTF1(KNameNotRetreivedProperly); 
   255 		SetTestStepResult(EFail);		
   256 		}		
   257 	pwd.Set(auth->Password());
   258 	if(pwd.Compare(KNullDesC8) != 0)
   259 		{
   260 		INFO_PRINTF1(KPasswordNotRetreivedProperly); 
   261 		SetTestStepResult(EFail);		
   262 		}
   263 	CleanupStack::PopAndDestroy(2, incompleteUri);
   264 	
   265 	// *** test incomplete uri type 5
   266 	incompleteUriParser.Parse(KUriUserInfoIncomplete4);
   267 	incompleteUri = CUri8::NewLC(incompleteUriParser);
   268 	TUriC8 tIncompleteUri5 = incompleteUri->Uri();
   269 	
   270 	// create from uri type 5
   271 	auth = CAuthentication::NewL(tIncompleteUri5);
   272 	CleanupStack::PushL(auth);
   273 	
   274 	// check there is neither user nor pwd
   275 	name.Set(auth->Name());
   276 	if(name.Compare(KNullDesC8) != 0)
   277 		{
   278 		INFO_PRINTF1(KNameNotRetreivedProperly); 
   279 		SetTestStepResult(EFail);		
   280 		}		
   281 	pwd.Set(auth->Password());
   282 	if(pwd.Compare(KNullDesC8) != 0)
   283 		{
   284 		INFO_PRINTF1(KPasswordNotRetreivedProperly); 
   285 		SetTestStepResult(EFail);		
   286 		}	
   287 	CleanupStack::PopAndDestroy(2, incompleteUri);
   288 	
   289 	// *** test no user info. Must Leave with KErrNotFound.
   290 	incompleteUriParser.Parse(KUriNoUserInfo);
   291 	incompleteUri = CUri8::NewLC(incompleteUriParser);
   292 	TUriC8 tNoUserInfo = incompleteUri->Uri();
   293 	
   294 	// create from uri with no user info
   295 	TRAPD(err, auth = CAuthentication::NewL(tNoUserInfo));
   296 	if(err != KErrNotFound)
   297 		{
   298 		INFO_PRINTF1(KFailedToLeaveWithKErrNotFound); 
   299 		SetTestStepResult(EFail);
   300 		delete auth;
   301 		}	
   302 	CleanupStack::PopAndDestroy(incompleteUri);
   303 		
   304 	__UHEAP_MARKEND;
   305 	return TestStepResult();
   306 	}
   307 
   308 TVerdict CAuthentication_TEF0Step::doTestStepPostambleL()
   309 /**
   310  * @return - TVerdict code
   311  * Override of base class virtual
   312  */
   313 	{
   314 	return TestStepResult();
   315 	}