|
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 // Implementation of those test steps for bearermobility covering the AO based API which is not suitable for |
|
15 // testing under esock test steps |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file te_BearerMobilityTestSuite.cpp |
|
21 @file |
|
22 */ |
|
23 |
|
24 #include "te_BearerMobilityTestSuite.h" |
|
25 #include <ecom/ecom.h> |
|
26 |
|
27 |
|
28 using namespace ESock; |
|
29 |
|
30 // CBearerMobilityTestStep_761402 |
|
31 //------------------------------- |
|
32 static const TInt KPreferredAccessPointId = 4; |
|
33 static const TInt KLessPreferredAccessPointId = 5; |
|
34 |
|
35 static const TInt KSnapTwoPreferences = 15; |
|
36 |
|
37 enum TVerdict CBearerMobilityTestStep_761402::doTestStepL(void) |
|
38 { |
|
39 // Create and install an active scheduler as we are testing an AO api |
|
40 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
41 CleanupStack::PushL(scheduler); |
|
42 CActiveScheduler::Install(scheduler); |
|
43 |
|
44 // Create and connect the socket server |
|
45 TInt err; |
|
46 err = iSocketServ.Connect(); |
|
47 TESTEL(err == KErrNone, err); |
|
48 |
|
49 // Create and open the connection |
|
50 err = iConnection.Open(iSocketServ); |
|
51 TESTEL(err == KErrNone, err); |
|
52 |
|
53 // Set the availability of each access point of significance |
|
54 SetAvailabilityL( |
|
55 KPreferredAccessPointId, |
|
56 TAvailabilityStatus(TAvailabilityStatus::EMaxAvailabilityScore)); |
|
57 SetAvailabilityL( |
|
58 KLessPreferredAccessPointId, |
|
59 TAvailabilityStatus(TAvailabilityStatus::EMaxAvailabilityScore)); |
|
60 |
|
61 // Start the connection |
|
62 TCommSnapPref prefs; |
|
63 prefs.SetSnap(KSnapTwoPreferences); |
|
64 err = iConnection.Start(prefs); |
|
65 TESTEL(err == KErrNone, err); |
|
66 |
|
67 // Now create the mobility notification AO |
|
68 iMobilityExtension = CActiveCommsMobilityApiExt::NewL(iConnection, *this); |
|
69 |
|
70 // Make the preferred become unavailable |
|
71 SetAvailabilityL(KPreferredAccessPointId, TAvailabilityStatus(TAvailabilityStatus::EMinAvailabilityScore)); |
|
72 |
|
73 // Bump the state |
|
74 BumpTestStepState(); |
|
75 |
|
76 // Start the scheduler which will ultimately run the rest of the test |
|
77 TRAP_IGNORE(CActiveScheduler::Start()) |
|
78 |
|
79 CleanupStack::PopAndDestroy(scheduler); |
|
80 |
|
81 iConnection.Close(); |
|
82 iSocketServ.Close(); |
|
83 |
|
84 return TestStepResult(); |
|
85 } |
|
86 |
|
87 // From MMobilityProtocolResp |
|
88 void CBearerMobilityTestStep_761402::PreferredCarrierAvailable(TAccessPointInfo aOldAP, TAccessPointInfo aNewAP, TBool aIsUpgrade, TBool aIsSeamless) |
|
89 { |
|
90 switch(GetTestStepState()) |
|
91 { |
|
92 case 1: |
|
93 // Check that we got what we expected |
|
94 TEST(aOldAP == KPreferredAccessPointId); |
|
95 TEST(aNewAP == KLessPreferredAccessPointId); |
|
96 TEST(aIsUpgrade == EFalse); |
|
97 TEST(aIsSeamless == EFalse); |
|
98 |
|
99 // Arrange for migration |
|
100 iMobilityExtension->MigrateToPreferredCarrier(); |
|
101 |
|
102 BumpTestStepState(); |
|
103 break; |
|
104 |
|
105 default: |
|
106 INFO_PRINTF1(KErrTestStepAstray); |
|
107 SetTestStepResult(EFail); |
|
108 break; |
|
109 } |
|
110 } |
|
111 |
|
112 void CBearerMobilityTestStep_761402::NewCarrierActive(TAccessPointInfo aNewAP, TBool aIsSeamless) |
|
113 { |
|
114 switch(GetTestStepState()) |
|
115 { |
|
116 case 2: |
|
117 // Check we got what we expected first |
|
118 TEST(aNewAP == KLessPreferredAccessPointId); |
|
119 TEST(aIsSeamless == EFalse); |
|
120 |
|
121 // Accept the new carrier and we are done so stop the scheduler |
|
122 iMobilityExtension->NewCarrierAccepted(); |
|
123 CActiveScheduler::Stop(); |
|
124 |
|
125 BumpTestStepState(); |
|
126 break; |
|
127 |
|
128 default: |
|
129 INFO_PRINTF1(KErrTestStepAstray); |
|
130 SetTestStepResult(EFail); |
|
131 break; |
|
132 } |
|
133 } |
|
134 |
|
135 void CBearerMobilityTestStep_761402::Error(TInt aError) |
|
136 { |
|
137 // Most likely a cancel but check for any kind of error |
|
138 if(aError == KErrCancel) |
|
139 { |
|
140 INFO_PRINTF1(_L("Mobility extension cancelled")); |
|
141 } |
|
142 else |
|
143 { |
|
144 // Some kind of unexpected error during mobility migration |
|
145 INFO_PRINTF2(_L("Unexpected error (ordinarily KErrCancel) from mobility extension. error:%d"), aError); |
|
146 SetTestStepError(aError); |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 // CBearerMobilityTestStep_761403 |
|
152 //------------------------------- |
|
153 |
|
154 enum TVerdict CBearerMobilityTestStep_761403::doTestStepL(void) |
|
155 { |
|
156 // Fail by default |
|
157 SetTestStepResult(EFail); |
|
158 |
|
159 // Create and connect the socket server |
|
160 TInt err; |
|
161 RSocketServ sockServ; |
|
162 err = sockServ.Connect(); |
|
163 TESTEL(err == KErrNone, err); |
|
164 |
|
165 // Create and open the connection |
|
166 RConnection conn; |
|
167 err = conn.Open(sockServ); |
|
168 TESTEL(err == KErrNone, err); |
|
169 |
|
170 // Set the availability of each access point of significance |
|
171 SetAvailabilityL(KPreferredAccessPointId, TAvailabilityStatus(TAvailabilityStatus::EMaxAvailabilityScore)); |
|
172 SetAvailabilityL(KLessPreferredAccessPointId, TAvailabilityStatus(TAvailabilityStatus::EMaxAvailabilityScore)); |
|
173 |
|
174 // Start the connection |
|
175 TCommSnapPref prefs; |
|
176 prefs.SetSnap(KSnapTwoPreferences); |
|
177 err = conn.Start(prefs); |
|
178 TESTEL(err == KErrNone, err); |
|
179 |
|
180 // Attach a subconn to the default |
|
181 RSubConnection subConn; |
|
182 err = subConn.Open(sockServ, RSubConnection::EAttachToDefault, conn); |
|
183 TESTEL(err == KErrNone, err); |
|
184 |
|
185 // Now create the mobility notification and try to open on the subconnection! |
|
186 RCommsMobilityApiExt mobExtension; |
|
187 err = mobExtension.Open(subConn); |
|
188 if(err == KErrNotSupported) |
|
189 { |
|
190 INFO_PRINTF1(_L("Received KErrNotSupported as expected")); |
|
191 SetTestStepResult(EPass); |
|
192 } |
|
193 else |
|
194 { |
|
195 INFO_PRINTF2(_L("Negative test: Expect KErrNotSupported. error:%d"), err); |
|
196 SetTestStepError(err); |
|
197 } |
|
198 |
|
199 // Close the resources we opened and out of here |
|
200 subConn.Close(); |
|
201 conn.Close(); |
|
202 sockServ.Close(); |
|
203 |
|
204 return TestStepResult(); |
|
205 } |
|
206 |
|
207 // CBearerMobilityTestStepBase |
|
208 //---------------------------- |
|
209 const TUid KAvailabilityTestingPubSubUid = {0x10272F42}; |
|
210 |
|
211 void CBearerMobilityTestStepBase::SetAvailabilityL(TInt aAccessPointId, ESock::TAvailabilityStatus aStatus) |
|
212 { |
|
213 RProperty a; |
|
214 |
|
215 // Set the availability of the access point as prescribed |
|
216 TInt error = a.Define(KAvailabilityTestingPubSubUid, aAccessPointId, RProperty::EInt); |
|
217 if((error != KErrAlreadyExists) && (error != KErrNone)) |
|
218 { |
|
219 INFO_PRINTF1(_L("Could not define property used for availability simulation")); |
|
220 User::Leave(KErrGeneral); |
|
221 } |
|
222 |
|
223 // Successfully created the property so attach to it for use |
|
224 error = a.Attach(KAvailabilityTestingPubSubUid, aAccessPointId); |
|
225 TESTEL(error == KErrNone, error); |
|
226 |
|
227 // Now set the availability as prescribed |
|
228 a.Set(aStatus.Score()); |
|
229 } |
|
230 |
|
231 |
|
232 // Entry point |
|
233 //------------ |
|
234 |
|
235 LOCAL_C void MainL() |
|
236 { |
|
237 CActiveScheduler* sched=NULL; |
|
238 sched=new(ELeave) CActiveScheduler; |
|
239 CActiveScheduler::Install(sched); |
|
240 CBearerMobilitySuiteTestServer* server = NULL; |
|
241 |
|
242 // Create the CTestServer derived server |
|
243 TRAPD(err, server = CBearerMobilitySuiteTestServer::NewL()); |
|
244 if(!err) |
|
245 { |
|
246 // Sync with the client and enter the active scheduler |
|
247 RProcess::Rendezvous(KErrNone); |
|
248 sched->Start(); |
|
249 } |
|
250 delete server; |
|
251 delete sched; |
|
252 } |
|
253 |
|
254 |
|
255 |
|
256 GLDEF_C TInt E32Main() |
|
257 /** |
|
258 * @return - Standard Epoc error code on process exit |
|
259 * Secure variant only |
|
260 * Process entry point. Called by client using RProcess API |
|
261 */ |
|
262 { |
|
263 __UHEAP_MARK; |
|
264 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
265 if(cleanup == NULL) |
|
266 { |
|
267 return KErrNoMemory; |
|
268 } |
|
269 TRAPD(err,MainL()); |
|
270 delete cleanup; |
|
271 REComSession::FinalClose(); |
|
272 __UHEAP_MARKEND; |
|
273 return err; |
|
274 } |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 // Test suite server |
|
280 //------------------ |
|
281 |
|
282 _LIT(KServerName, "te_BearerMobilityTestSuite"); |
|
283 |
|
284 CBearerMobilitySuiteTestServer* CBearerMobilitySuiteTestServer::NewL() |
|
285 /** |
|
286 * @return - Instance of the test server |
|
287 * Same code for Secure and non-secure variants |
|
288 * Called inside the MainL() function to create and start the |
|
289 * CTestServer derived server. |
|
290 */ |
|
291 { |
|
292 CBearerMobilitySuiteTestServer* server = new (ELeave) CBearerMobilitySuiteTestServer(); |
|
293 CleanupStack::PushL(server); |
|
294 server->ConstructL(KServerName); |
|
295 CleanupStack::Pop(); |
|
296 return server; |
|
297 } |
|
298 |
|
299 CBearerMobilitySuiteTestServer::~CBearerMobilitySuiteTestServer() |
|
300 { |
|
301 } |
|
302 |
|
303 CTestStep* CBearerMobilitySuiteTestServer::CreateTestStep(const TDesC& aStepName) |
|
304 /** |
|
305 * @return - A CTestStep derived instance |
|
306 * Implementation of CTestServer pure virtual |
|
307 */ |
|
308 { |
|
309 CTestStep* testStep = NULL; |
|
310 if(aStepName.Compare(_L("NET_BMOBILITY_761402")) == 0) |
|
311 testStep = new CBearerMobilityTestStep_761402(); |
|
312 else if(aStepName.Compare(_L("NET_BMOBILITY_761403")) == 0) |
|
313 testStep = new CBearerMobilityTestStep_761403(); |
|
314 |
|
315 return testStep; |
|
316 } |
|
317 |