os/ossrv/genericservices/httputils/Test/te_authentication/src/authentication_TEF0Step.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/Test/te_authentication/src/authentication_TEF0Step.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,315 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Example CTestStep derived implementation
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file Authentication_TEF0Step.cpp
1.23 +*/
1.24 +#include "authentication_TEF0Step.h"
1.25 +#include "Te_authentication_TEFSuiteDefs.h"
1.26 +
1.27 +#include <cauthentication.h>
1.28 +
1.29 +CAuthentication_TEF0Step::~CAuthentication_TEF0Step()
1.30 +/**
1.31 + * Destructor
1.32 + */
1.33 + {
1.34 + }
1.35 +
1.36 +CAuthentication_TEF0Step::CAuthentication_TEF0Step()
1.37 +/**
1.38 + * Constructor
1.39 + */
1.40 + {
1.41 + // **MUST** call SetTestStepName in the constructor as the controlling
1.42 + // framework uses the test step name immediately following construction to set
1.43 + // up the step's unique logging ID.
1.44 + SetTestStepName(KAuthentication_TEF0Step);
1.45 + }
1.46 +
1.47 +TVerdict CAuthentication_TEF0Step::doTestStepPreambleL()
1.48 +/**
1.49 + * @return - TVerdict code
1.50 + * Override of base class virtual
1.51 + */
1.52 + {
1.53 + SetTestStepResult(EPass);
1.54 + return TestStepResult();
1.55 + }
1.56 +
1.57 +
1.58 +TVerdict CAuthentication_TEF0Step::doTestStepL()
1.59 +/**
1.60 + * @return - TVerdict code
1.61 + * Override of base class pure virtual
1.62 + * Our implementation only gets called if the base class doTestStepPreambleL() did
1.63 + * not leave. That being the case, the current test result value will be EPass.
1.64 + */
1.65 + {
1.66 + __UHEAP_MARK;
1.67 +
1.68 + CAuthentication* auth;
1.69 + CUri8* uri;
1.70 + TPtrC8 name;
1.71 + TPtrC8 pwd;
1.72 +
1.73 + // create auth obj from name and pwd
1.74 + auth = CAuthentication::NewL(KUser1, KPwd1);
1.75 + CleanupStack::PushL(auth);
1.76 +
1.77 +
1.78 + // *********** test default parameters *********** //
1.79 +
1.80 + // get name and compare to expected
1.81 + name.Set(auth->Name());
1.82 + if(name.Compare(KUser1) != 0)
1.83 + {
1.84 + INFO_PRINTF1(KNameNotRetreivedProperly);
1.85 + SetTestStepResult(EFail);
1.86 + }
1.87 +
1.88 + // get pwd and compare to expected
1.89 + pwd.Set(auth->Password());
1.90 + if(pwd.Compare(KPwd1) != 0)
1.91 + {
1.92 + INFO_PRINTF1(KPasswordNotRetreivedProperly);
1.93 + SetTestStepResult(EFail);
1.94 + }
1.95 +
1.96 + // compare default method to expected
1.97 + if(auth->Method() != CAuthentication::EDigest)
1.98 + {
1.99 + INFO_PRINTF1(KMethodNotRetreivedProperly);
1.100 + SetTestStepResult(EFail);
1.101 + }
1.102 +
1.103 + // *********** test changing parameters *********** //
1.104 +
1.105 + // change and check new name
1.106 + auth->SetNameL(KUser2);
1.107 + name.Set(auth->Name());
1.108 + if(name.Compare(KUser2) != 0)
1.109 + {
1.110 + INFO_PRINTF1(KNameNotRetreivedProperly);
1.111 + SetTestStepResult(EFail);
1.112 + }
1.113 +
1.114 + // change and check new pwd
1.115 + auth->SetPasswordL(KPwd2);
1.116 + pwd.Set(auth->Password());
1.117 + if(pwd.Compare(KPwd2) != 0)
1.118 + {
1.119 + INFO_PRINTF1(KPasswordNotRetreivedProperly);
1.120 + SetTestStepResult(EFail);
1.121 + }
1.122 +
1.123 + // change and check new method
1.124 + auth->SetMethod(CAuthentication::EBasic);
1.125 + if(auth->Method() != CAuthentication::EBasic)
1.126 + {
1.127 + INFO_PRINTF1(KMethodNotRetreivedProperly);
1.128 + SetTestStepResult(EFail);
1.129 + }
1.130 +
1.131 + CleanupStack::PopAndDestroy(auth);
1.132 +
1.133 + // *********** test default parameters set using TUriC *********** //
1.134 +
1.135 + TUriParser8 uriParser;
1.136 + uriParser.Parse(KUriUserInfoComplete);
1.137 + uri = CUri8::NewLC(uriParser);
1.138 + TUriC8 tUri = uri->Uri();
1.139 +
1.140 + auth = CAuthentication::NewL(tUri);
1.141 + CleanupStack::PushL(auth);
1.142 +
1.143 + name.Set(auth->Name());
1.144 + if(name.Compare(KUser1) != 0)
1.145 + {
1.146 + INFO_PRINTF1(KNameNotRetreivedProperly);
1.147 + SetTestStepResult(EFail);
1.148 + }
1.149 +
1.150 + // get pwd and compare to expected
1.151 + pwd.Set(auth->Password());
1.152 + if(pwd.Compare(KPwd1) != 0)
1.153 + {
1.154 + INFO_PRINTF1(KPasswordNotRetreivedProperly);
1.155 + SetTestStepResult(EFail);
1.156 + }
1.157 +
1.158 + // compare default method to expected
1.159 + if(auth->Method() != CAuthentication::EDigest)
1.160 + {
1.161 + INFO_PRINTF1(KMethodNotRetreivedProperly);
1.162 + SetTestStepResult(EFail);
1.163 + }
1.164 +
1.165 + CleanupStack::PopAndDestroy(2, uri);
1.166 +
1.167 + // *********** test with incomplete or missing User Info *********** //
1.168 +
1.169 + TUriParser8 incompleteUriParser;
1.170 + CUri8* incompleteUri;
1.171 +
1.172 + // *** test incomplete uri type 1
1.173 + incompleteUriParser.Parse(KUriUserInfoIncomplete1);
1.174 + incompleteUri = CUri8::NewLC(incompleteUriParser);
1.175 + TUriC8 tIncompleteUri = incompleteUri->Uri();
1.176 +
1.177 + // create from uri type 1
1.178 + auth = CAuthentication::NewL(tIncompleteUri);
1.179 + CleanupStack::PushL(auth);
1.180 +
1.181 + // check has user and no pwd
1.182 + name.Set(auth->Name());
1.183 + if(name.Compare(KUser1) != 0)
1.184 + {
1.185 + INFO_PRINTF1(KNameNotRetreivedProperly);
1.186 + SetTestStepResult(EFail);
1.187 + }
1.188 + pwd.Set(auth->Password());
1.189 + if(pwd.Compare(KNullDesC8) != 0)
1.190 + {
1.191 + INFO_PRINTF1(KPasswordNotRetreivedProperly);
1.192 + SetTestStepResult(EFail);
1.193 + }
1.194 + CleanupStack::PopAndDestroy(2, incompleteUri);
1.195 +
1.196 + // *** test incomplete uri type 2
1.197 + incompleteUriParser.Parse(KUriUserInfoIncomplete2);
1.198 + incompleteUri = CUri8::NewLC(incompleteUriParser);
1.199 + TUriC8 tIncompleteUri2 = incompleteUri->Uri();
1.200 +
1.201 + // create from uri type 2
1.202 + auth = CAuthentication::NewL(tIncompleteUri2);
1.203 + CleanupStack::PushL(auth);
1.204 +
1.205 + // check has user and no pwd
1.206 + name.Set(auth->Name());
1.207 + if(name.Compare(KUser1) != 0)
1.208 + {
1.209 + INFO_PRINTF1(KNameNotRetreivedProperly);
1.210 + SetTestStepResult(EFail);
1.211 + }
1.212 + pwd.Set(auth->Password());
1.213 + if(pwd.Compare(KNullDesC8) != 0)
1.214 + {
1.215 + INFO_PRINTF1(KPasswordNotRetreivedProperly);
1.216 + SetTestStepResult(EFail);
1.217 + }
1.218 + CleanupStack::PopAndDestroy(2, incompleteUri);
1.219 +
1.220 + // *** test incomplete uri type 3
1.221 + incompleteUriParser.Parse(KUriUserInfoIncomplete3);
1.222 + incompleteUri = CUri8::NewLC(incompleteUriParser);
1.223 + TUriC8 tIncompleteUri3 = incompleteUri->Uri();
1.224 +
1.225 + // create from uri type 3
1.226 + auth = CAuthentication::NewL(tIncompleteUri3);
1.227 + CleanupStack::PushL(auth);
1.228 +
1.229 + // check no user name but has pwd
1.230 + name.Set(auth->Name());
1.231 + if(name.Compare(KNullDesC8) != 0)
1.232 + {
1.233 + INFO_PRINTF1(KNameNotRetreivedProperly);
1.234 + SetTestStepResult(EFail);
1.235 + }
1.236 + pwd.Set(auth->Password());
1.237 + if(pwd.Compare(KPwd1) != 0)
1.238 + {
1.239 + INFO_PRINTF1(KPasswordNotRetreivedProperly);
1.240 + SetTestStepResult(EFail);
1.241 + }
1.242 + CleanupStack::PopAndDestroy(2, incompleteUri);
1.243 +
1.244 + // *** test incomplete uri type 4
1.245 + incompleteUriParser.Parse(KUriUserInfoIncomplete4);
1.246 + incompleteUri = CUri8::NewLC(incompleteUriParser);
1.247 + TUriC8 tIncompleteUri4 = incompleteUri->Uri();
1.248 +
1.249 + // create from uri type 4
1.250 + auth = CAuthentication::NewL(tIncompleteUri4);
1.251 + CleanupStack::PushL(auth);
1.252 +
1.253 + // check there is neither user nor pwd
1.254 + name.Set(auth->Name());
1.255 + if(name.Compare(KNullDesC8) != 0)
1.256 + {
1.257 + INFO_PRINTF1(KNameNotRetreivedProperly);
1.258 + SetTestStepResult(EFail);
1.259 + }
1.260 + pwd.Set(auth->Password());
1.261 + if(pwd.Compare(KNullDesC8) != 0)
1.262 + {
1.263 + INFO_PRINTF1(KPasswordNotRetreivedProperly);
1.264 + SetTestStepResult(EFail);
1.265 + }
1.266 + CleanupStack::PopAndDestroy(2, incompleteUri);
1.267 +
1.268 + // *** test incomplete uri type 5
1.269 + incompleteUriParser.Parse(KUriUserInfoIncomplete4);
1.270 + incompleteUri = CUri8::NewLC(incompleteUriParser);
1.271 + TUriC8 tIncompleteUri5 = incompleteUri->Uri();
1.272 +
1.273 + // create from uri type 5
1.274 + auth = CAuthentication::NewL(tIncompleteUri5);
1.275 + CleanupStack::PushL(auth);
1.276 +
1.277 + // check there is neither user nor pwd
1.278 + name.Set(auth->Name());
1.279 + if(name.Compare(KNullDesC8) != 0)
1.280 + {
1.281 + INFO_PRINTF1(KNameNotRetreivedProperly);
1.282 + SetTestStepResult(EFail);
1.283 + }
1.284 + pwd.Set(auth->Password());
1.285 + if(pwd.Compare(KNullDesC8) != 0)
1.286 + {
1.287 + INFO_PRINTF1(KPasswordNotRetreivedProperly);
1.288 + SetTestStepResult(EFail);
1.289 + }
1.290 + CleanupStack::PopAndDestroy(2, incompleteUri);
1.291 +
1.292 + // *** test no user info. Must Leave with KErrNotFound.
1.293 + incompleteUriParser.Parse(KUriNoUserInfo);
1.294 + incompleteUri = CUri8::NewLC(incompleteUriParser);
1.295 + TUriC8 tNoUserInfo = incompleteUri->Uri();
1.296 +
1.297 + // create from uri with no user info
1.298 + TRAPD(err, auth = CAuthentication::NewL(tNoUserInfo));
1.299 + if(err != KErrNotFound)
1.300 + {
1.301 + INFO_PRINTF1(KFailedToLeaveWithKErrNotFound);
1.302 + SetTestStepResult(EFail);
1.303 + delete auth;
1.304 + }
1.305 + CleanupStack::PopAndDestroy(incompleteUri);
1.306 +
1.307 + __UHEAP_MARKEND;
1.308 + return TestStepResult();
1.309 + }
1.310 +
1.311 +TVerdict CAuthentication_TEF0Step::doTestStepPostambleL()
1.312 +/**
1.313 + * @return - TVerdict code
1.314 + * Override of base class virtual
1.315 + */
1.316 + {
1.317 + return TestStepResult();
1.318 + }