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