os/ossrv/genericservices/httputils/Test/te_authentication/src/authentication_TEF0Step.cpp
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Example CTestStep derived implementation
19 @file Authentication_TEF0Step.cpp
21 #include "authentication_TEF0Step.h"
22 #include "Te_authentication_TEFSuiteDefs.h"
24 #include <cauthentication.h>
26 CAuthentication_TEF0Step::~CAuthentication_TEF0Step()
33 CAuthentication_TEF0Step::CAuthentication_TEF0Step()
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);
44 TVerdict CAuthentication_TEF0Step::doTestStepPreambleL()
46 * @return - TVerdict code
47 * Override of base class virtual
50 SetTestStepResult(EPass);
51 return TestStepResult();
55 TVerdict CAuthentication_TEF0Step::doTestStepL()
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.
65 CAuthentication* auth;
70 // create auth obj from name and pwd
71 auth = CAuthentication::NewL(KUser1, KPwd1);
72 CleanupStack::PushL(auth);
75 // *********** test default parameters *********** //
77 // get name and compare to expected
78 name.Set(auth->Name());
79 if(name.Compare(KUser1) != 0)
81 INFO_PRINTF1(KNameNotRetreivedProperly);
82 SetTestStepResult(EFail);
85 // get pwd and compare to expected
86 pwd.Set(auth->Password());
87 if(pwd.Compare(KPwd1) != 0)
89 INFO_PRINTF1(KPasswordNotRetreivedProperly);
90 SetTestStepResult(EFail);
93 // compare default method to expected
94 if(auth->Method() != CAuthentication::EDigest)
96 INFO_PRINTF1(KMethodNotRetreivedProperly);
97 SetTestStepResult(EFail);
100 // *********** test changing parameters *********** //
102 // change and check new name
103 auth->SetNameL(KUser2);
104 name.Set(auth->Name());
105 if(name.Compare(KUser2) != 0)
107 INFO_PRINTF1(KNameNotRetreivedProperly);
108 SetTestStepResult(EFail);
111 // change and check new pwd
112 auth->SetPasswordL(KPwd2);
113 pwd.Set(auth->Password());
114 if(pwd.Compare(KPwd2) != 0)
116 INFO_PRINTF1(KPasswordNotRetreivedProperly);
117 SetTestStepResult(EFail);
120 // change and check new method
121 auth->SetMethod(CAuthentication::EBasic);
122 if(auth->Method() != CAuthentication::EBasic)
124 INFO_PRINTF1(KMethodNotRetreivedProperly);
125 SetTestStepResult(EFail);
128 CleanupStack::PopAndDestroy(auth);
130 // *********** test default parameters set using TUriC *********** //
132 TUriParser8 uriParser;
133 uriParser.Parse(KUriUserInfoComplete);
134 uri = CUri8::NewLC(uriParser);
135 TUriC8 tUri = uri->Uri();
137 auth = CAuthentication::NewL(tUri);
138 CleanupStack::PushL(auth);
140 name.Set(auth->Name());
141 if(name.Compare(KUser1) != 0)
143 INFO_PRINTF1(KNameNotRetreivedProperly);
144 SetTestStepResult(EFail);
147 // get pwd and compare to expected
148 pwd.Set(auth->Password());
149 if(pwd.Compare(KPwd1) != 0)
151 INFO_PRINTF1(KPasswordNotRetreivedProperly);
152 SetTestStepResult(EFail);
155 // compare default method to expected
156 if(auth->Method() != CAuthentication::EDigest)
158 INFO_PRINTF1(KMethodNotRetreivedProperly);
159 SetTestStepResult(EFail);
162 CleanupStack::PopAndDestroy(2, uri);
164 // *********** test with incomplete or missing User Info *********** //
166 TUriParser8 incompleteUriParser;
167 CUri8* incompleteUri;
169 // *** test incomplete uri type 1
170 incompleteUriParser.Parse(KUriUserInfoIncomplete1);
171 incompleteUri = CUri8::NewLC(incompleteUriParser);
172 TUriC8 tIncompleteUri = incompleteUri->Uri();
174 // create from uri type 1
175 auth = CAuthentication::NewL(tIncompleteUri);
176 CleanupStack::PushL(auth);
178 // check has user and no pwd
179 name.Set(auth->Name());
180 if(name.Compare(KUser1) != 0)
182 INFO_PRINTF1(KNameNotRetreivedProperly);
183 SetTestStepResult(EFail);
185 pwd.Set(auth->Password());
186 if(pwd.Compare(KNullDesC8) != 0)
188 INFO_PRINTF1(KPasswordNotRetreivedProperly);
189 SetTestStepResult(EFail);
191 CleanupStack::PopAndDestroy(2, incompleteUri);
193 // *** test incomplete uri type 2
194 incompleteUriParser.Parse(KUriUserInfoIncomplete2);
195 incompleteUri = CUri8::NewLC(incompleteUriParser);
196 TUriC8 tIncompleteUri2 = incompleteUri->Uri();
198 // create from uri type 2
199 auth = CAuthentication::NewL(tIncompleteUri2);
200 CleanupStack::PushL(auth);
202 // check has user and no pwd
203 name.Set(auth->Name());
204 if(name.Compare(KUser1) != 0)
206 INFO_PRINTF1(KNameNotRetreivedProperly);
207 SetTestStepResult(EFail);
209 pwd.Set(auth->Password());
210 if(pwd.Compare(KNullDesC8) != 0)
212 INFO_PRINTF1(KPasswordNotRetreivedProperly);
213 SetTestStepResult(EFail);
215 CleanupStack::PopAndDestroy(2, incompleteUri);
217 // *** test incomplete uri type 3
218 incompleteUriParser.Parse(KUriUserInfoIncomplete3);
219 incompleteUri = CUri8::NewLC(incompleteUriParser);
220 TUriC8 tIncompleteUri3 = incompleteUri->Uri();
222 // create from uri type 3
223 auth = CAuthentication::NewL(tIncompleteUri3);
224 CleanupStack::PushL(auth);
226 // check no user name but has pwd
227 name.Set(auth->Name());
228 if(name.Compare(KNullDesC8) != 0)
230 INFO_PRINTF1(KNameNotRetreivedProperly);
231 SetTestStepResult(EFail);
233 pwd.Set(auth->Password());
234 if(pwd.Compare(KPwd1) != 0)
236 INFO_PRINTF1(KPasswordNotRetreivedProperly);
237 SetTestStepResult(EFail);
239 CleanupStack::PopAndDestroy(2, incompleteUri);
241 // *** test incomplete uri type 4
242 incompleteUriParser.Parse(KUriUserInfoIncomplete4);
243 incompleteUri = CUri8::NewLC(incompleteUriParser);
244 TUriC8 tIncompleteUri4 = incompleteUri->Uri();
246 // create from uri type 4
247 auth = CAuthentication::NewL(tIncompleteUri4);
248 CleanupStack::PushL(auth);
250 // check there is neither user nor pwd
251 name.Set(auth->Name());
252 if(name.Compare(KNullDesC8) != 0)
254 INFO_PRINTF1(KNameNotRetreivedProperly);
255 SetTestStepResult(EFail);
257 pwd.Set(auth->Password());
258 if(pwd.Compare(KNullDesC8) != 0)
260 INFO_PRINTF1(KPasswordNotRetreivedProperly);
261 SetTestStepResult(EFail);
263 CleanupStack::PopAndDestroy(2, incompleteUri);
265 // *** test incomplete uri type 5
266 incompleteUriParser.Parse(KUriUserInfoIncomplete4);
267 incompleteUri = CUri8::NewLC(incompleteUriParser);
268 TUriC8 tIncompleteUri5 = incompleteUri->Uri();
270 // create from uri type 5
271 auth = CAuthentication::NewL(tIncompleteUri5);
272 CleanupStack::PushL(auth);
274 // check there is neither user nor pwd
275 name.Set(auth->Name());
276 if(name.Compare(KNullDesC8) != 0)
278 INFO_PRINTF1(KNameNotRetreivedProperly);
279 SetTestStepResult(EFail);
281 pwd.Set(auth->Password());
282 if(pwd.Compare(KNullDesC8) != 0)
284 INFO_PRINTF1(KPasswordNotRetreivedProperly);
285 SetTestStepResult(EFail);
287 CleanupStack::PopAndDestroy(2, incompleteUri);
289 // *** test no user info. Must Leave with KErrNotFound.
290 incompleteUriParser.Parse(KUriNoUserInfo);
291 incompleteUri = CUri8::NewLC(incompleteUriParser);
292 TUriC8 tNoUserInfo = incompleteUri->Uri();
294 // create from uri with no user info
295 TRAPD(err, auth = CAuthentication::NewL(tNoUserInfo));
296 if(err != KErrNotFound)
298 INFO_PRINTF1(KFailedToLeaveWithKErrNotFound);
299 SetTestStepResult(EFail);
302 CleanupStack::PopAndDestroy(incompleteUri);
305 return TestStepResult();
308 TVerdict CAuthentication_TEF0Step::doTestStepPostambleL()
310 * @return - TVerdict code
311 * Override of base class virtual
314 return TestStepResult();