|
1 // Copyright (c) 2006-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 // @file ctlbsclientstep_srvconnectclose.cpp |
|
15 // This is the class implementation for the Server Connect Close Tests |
|
16 // |
|
17 // |
|
18 |
|
19 #include "ctlbsclientstepsrvconnectclose.h" |
|
20 |
|
21 #include <lbs.h> |
|
22 |
|
23 /** |
|
24 * Destructor |
|
25 */ |
|
26 CT_LbsClientStep_SrvConnectClose::~CT_LbsClientStep_SrvConnectClose() |
|
27 { |
|
28 } |
|
29 |
|
30 |
|
31 /** |
|
32 * Constructor |
|
33 */ |
|
34 CT_LbsClientStep_SrvConnectClose::CT_LbsClientStep_SrvConnectClose(CT_LbsClientServer& aParent) : CT_LbsClientStep(aParent) |
|
35 { |
|
36 SetTestStepName(KLbsClientStep_SrvConnectClose); |
|
37 } |
|
38 |
|
39 |
|
40 /** |
|
41 Static Constructor |
|
42 */ |
|
43 CT_LbsClientStep_SrvConnectClose* CT_LbsClientStep_SrvConnectClose::New(CT_LbsClientServer& aParent) |
|
44 { |
|
45 return new CT_LbsClientStep_SrvConnectClose(aParent); |
|
46 // Note the lack of ELeave. |
|
47 // This means that having insufficient memory will return NULL; |
|
48 } |
|
49 |
|
50 |
|
51 |
|
52 /** |
|
53 * @return - TVerdict code |
|
54 * Override of base class pure virtual |
|
55 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
56 * not leave. That being the case, the current test result value will be EPass. |
|
57 */ |
|
58 TVerdict CT_LbsClientStep_SrvConnectClose::doTestStepL() |
|
59 { |
|
60 // Generic test step used to test the LBS Client server open and close APIs. |
|
61 INFO_PRINTF1(_L(">>CT_LbsClientStep_SrvConnectClose::doTestStepL()")); |
|
62 |
|
63 if (TestStepResult() == EPass) |
|
64 { |
|
65 TInt testCaseId; |
|
66 if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId)) |
|
67 { |
|
68 // Carryout common test action. |
|
69 TInt err = KErrNone; |
|
70 err = iServer.Connect(); // Function under test. |
|
71 |
|
72 if (KErrNone == err) |
|
73 { |
|
74 INFO_PRINTF1(_L("server opened")); |
|
75 CleanupClosePushL(iServer); |
|
76 // Carryout unique test actions. |
|
77 switch (testCaseId) |
|
78 { |
|
79 // Test case LBS-ConnectClose-0001 |
|
80 case 1: |
|
81 // Only requires create, connect and close for RPositionServer object |
|
82 // Connect and close occur outside the switch. |
|
83 break; |
|
84 |
|
85 // Test case LBS-ConnectClose-0002 |
|
86 case 2: |
|
87 { |
|
88 OpenNetSim(); |
|
89 RPositioner positioner; |
|
90 User::LeaveIfError(positioner.Open(iServer)); |
|
91 TPositionInfo posInfo; |
|
92 TRequestStatus status; |
|
93 |
|
94 TPositionUpdateOptions optsA; |
|
95 TTimeIntervalMicroSeconds interval = 60 * 1000000; // 1 minute interval |
|
96 // note: do 2 NPUDs because the first may complete before we close |
|
97 optsA.SetUpdateInterval(interval); |
|
98 positioner.NotifyPositionUpdate(posInfo, status); |
|
99 User::WaitForRequest(status); |
|
100 |
|
101 // this will not complete quickly, so we'll def have an outstanding request when we close |
|
102 positioner.NotifyPositionUpdate(posInfo, status); |
|
103 positioner.Close(); |
|
104 CloseNetSim(); |
|
105 } |
|
106 break; |
|
107 |
|
108 // Test case LBS-ConnectClose-0003 |
|
109 case 3: |
|
110 { |
|
111 // Will panic, not interested in any return err. |
|
112 iServer.Connect(); |
|
113 } |
|
114 break; |
|
115 |
|
116 // Test case LBS-ConnectClose-0004 |
|
117 case 4: |
|
118 { |
|
119 RPositionServer server2; |
|
120 |
|
121 err = server2.Connect(); |
|
122 if(err != KErrNone) |
|
123 { |
|
124 INFO_PRINTF1(_L("<FONT><B>Server2 connect() didn't return KErrNone</B></FONT>")); |
|
125 SetTestStepResult(EFail); |
|
126 } |
|
127 |
|
128 else |
|
129 { |
|
130 server2.Close(); |
|
131 } |
|
132 } |
|
133 break; |
|
134 //Test case LBS-ConnectClose-0005 |
|
135 case 5: |
|
136 { |
|
137 // look in the kernels process list for the server |
|
138 _LIT(KLocServerName, "*locserver*"); // NB you MUST use this server name for the location server. |
|
139 // see KPositionServerName in the location server code (server side) |
|
140 TFindThread serverSearcher(KLocServerName); |
|
141 TFileName matchingFileName; |
|
142 TInt matchCount = 0; |
|
143 while(serverSearcher.Next(matchingFileName) == KErrNone) |
|
144 { |
|
145 // we have a match, there should only be one |
|
146 matchCount++; |
|
147 } |
|
148 // start checking |
|
149 if(matchCount!=1) |
|
150 { |
|
151 /* fail the test - we somehow have more than one location server running. |
|
152 May have been one left over from a previous test */ |
|
153 INFO_PRINTF1(_L("somehow have more than one location server running")); |
|
154 SetTestStepResult(EFail); |
|
155 } |
|
156 RThread iserverThread; |
|
157 TInt err; |
|
158 err=iserverThread.Open(matchingFileName); |
|
159 User::LeaveIfError(err); |
|
160 TThreadId iserverThreadId = iserverThread.Id(); |
|
161 // log the thread ID |
|
162 // we now try and explicitly start a 2nd copy of the position server. |
|
163 //We expect not to get a 2nd copy, but to //connect to the existing copy. |
|
164 // create an connect to the lcoation server |
|
165 RPositionServer server2; |
|
166 User::LeaveIfError(server2.Connect()); |
|
167 CleanupClosePushL(server2); |
|
168 // search again |
|
169 serverSearcher.Find(KLocServerName); |
|
170 matchCount = 0; |
|
171 while(serverSearcher.Next(matchingFileName) == KErrNone) |
|
172 { |
|
173 // we have a match, there should only be one |
|
174 matchCount++; |
|
175 } |
|
176 // sanity check |
|
177 if(matchCount!=1) |
|
178 { |
|
179 /*SDA 3_50 Failure here |
|
180 fail the test - we have two servers.*/ |
|
181 INFO_PRINTF1(_L("we have two servers")); |
|
182 SetTestStepResult(EFail); |
|
183 |
|
184 } |
|
185 else |
|
186 { |
|
187 // we have one server so check the thread its match |
|
188 RThread server2Thread; |
|
189 err=server2Thread.Open(matchingFileName); |
|
190 User::LeaveIfError(err); |
|
191 TThreadId server2ThreadId = server2Thread.Id(); |
|
192 |
|
193 if(iserverThreadId != server2ThreadId) |
|
194 { |
|
195 /*different thread ids - somehow |
|
196 fail the test here */ |
|
197 INFO_PRINTF1(_L("Different thread ids ")); |
|
198 SetTestStepResult(EFail); |
|
199 } |
|
200 } |
|
201 CleanupStack::PopAndDestroy(&server2); |
|
202 } |
|
203 break; |
|
204 |
|
205 default: |
|
206 User::Leave(KErrArgument); |
|
207 break; |
|
208 |
|
209 } |
|
210 // Carryout final common test action. |
|
211 CleanupStack::PopAndDestroy(&iServer); |
|
212 } |
|
213 else if(testCaseId == 10) |
|
214 { |
|
215 // this test only valid on variant2 api: |
|
216 __ASSERT_DEBUG(iExpectedApiBehaviour == EApiVariant2, User::Panic(_L("Unrecognised 'Expected Api Behaviour'"), 1)); |
|
217 if(err != KErrNotReady) |
|
218 { |
|
219 INFO_PRINTF2(_L("<FONT><B>Didn't get KErrNotReady as expected. Err = %d</B></FONT>"), err); |
|
220 SetTestStepResult(EFail); |
|
221 } |
|
222 } |
|
223 else |
|
224 { |
|
225 INFO_PRINTF1(_L("<FONT><B>server failed to open</B></FONT>")); |
|
226 SetTestStepResult(EFail); |
|
227 } |
|
228 } |
|
229 else |
|
230 { |
|
231 INFO_PRINTF1(_L("<FONT><B>Failed to read from ini file correctly</B></FONT>")); |
|
232 SetTestStepResult(EFail); |
|
233 } |
|
234 } |
|
235 INFO_PRINTF1(_L("<<CT_LbsClientStep_SrvConnectClose::doTestStepL()")); |
|
236 |
|
237 return TestStepResult(); |
|
238 } |
|
239 |
|
240 |
|
241 |