|
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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-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 // Carryout common test action. |
|
66 TInt err = KErrNone; |
|
67 err = iServer.Connect(); // Function under test. |
|
68 CleanupClosePushL(iServer); |
|
69 |
|
70 if (KErrNone == err) |
|
71 { |
|
72 INFO_PRINTF1(_L("server opened")); |
|
73 |
|
74 // Carryout unique test actions. |
|
75 TInt testCaseId; |
|
76 if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId)) |
|
77 { |
|
78 switch (testCaseId) |
|
79 { |
|
80 // Test case LBS-ConnectClose-0001 |
|
81 case 1: |
|
82 // Only requires create, connect and close for RPositionServer object |
|
83 // Connect and close occur outside the switch. |
|
84 break; |
|
85 |
|
86 // Test case LBS-ConnectClose-0002 |
|
87 case 2: |
|
88 { |
|
89 OpenNetSim(); |
|
90 RPositioner positioner; |
|
91 User::LeaveIfError(positioner.Open(iServer)); |
|
92 TPositionInfo posInfo; |
|
93 TRequestStatus status; |
|
94 |
|
95 TPositionUpdateOptions optsA; |
|
96 TTimeIntervalMicroSeconds interval = 60 * 1000000; // 1 minute interval |
|
97 // note: do 2 NPUDs because the first may complete before we close |
|
98 optsA.SetUpdateInterval(interval); |
|
99 positioner.NotifyPositionUpdate(posInfo, status); |
|
100 User::WaitForRequest(status); |
|
101 |
|
102 // this will not complete quickly, so we'll def have an outstanding request when we close |
|
103 positioner.NotifyPositionUpdate(posInfo, status); |
|
104 positioner.Close(); |
|
105 CloseNetSim(); |
|
106 } |
|
107 break; |
|
108 |
|
109 // Test case LBS-ConnectClose-0003 |
|
110 case 3: |
|
111 { |
|
112 // Will panic, not interested in any return err. |
|
113 iServer.Connect(); |
|
114 } |
|
115 break; |
|
116 |
|
117 // Test case LBS-ConnectClose-0004 |
|
118 case 4: |
|
119 { |
|
120 RPositionServer server2; |
|
121 |
|
122 err = server2.Connect(); |
|
123 if(err != KErrNone) |
|
124 { |
|
125 INFO_PRINTF1(_L("<FONT><B>Server2 connect() didn't return KErrNone</B></FONT>")); |
|
126 SetTestStepResult(EFail); |
|
127 } |
|
128 |
|
129 else |
|
130 { |
|
131 server2.Close(); |
|
132 } |
|
133 } |
|
134 break; |
|
135 //Test case LBS-ConnectClose-0005 |
|
136 case 5: |
|
137 { |
|
138 // look in the kernels process list for the server |
|
139 _LIT(KLocServerName, "*locserver*"); // NB you MUST use this server name for the location server. |
|
140 // see KPositionServerName in the location server code (server side) |
|
141 TFindThread serverSearcher(KLocServerName); |
|
142 TFileName matchingFileName; |
|
143 TInt matchCount = 0; |
|
144 while(serverSearcher.Next(matchingFileName) == KErrNone) |
|
145 { |
|
146 // we have a match, there should only be one |
|
147 matchCount++; |
|
148 } |
|
149 // start checking |
|
150 if(matchCount!=1) |
|
151 { |
|
152 /* fail the test - we somehow have more than one location server running. |
|
153 May have been one left over from a previous test */ |
|
154 INFO_PRINTF1(_L("somehow have more than one location server running")); |
|
155 SetTestStepResult(EFail); |
|
156 } |
|
157 RThread iserverThread; |
|
158 TInt err; |
|
159 err=iserverThread.Open(matchingFileName); |
|
160 User::LeaveIfError(err); |
|
161 TThreadId iserverThreadId = iserverThread.Id(); |
|
162 // log the thread ID |
|
163 // we now try and explicitly start a 2nd copy of the position server. |
|
164 //We expect not to get a 2nd copy, but to //connect to the existing copy. |
|
165 // create an connect to the lcoation server |
|
166 RPositionServer server2; |
|
167 User::LeaveIfError(server2.Connect()); |
|
168 CleanupClosePushL(server2); |
|
169 // search again |
|
170 serverSearcher.Find(KLocServerName); |
|
171 matchCount = 0; |
|
172 while(serverSearcher.Next(matchingFileName) == KErrNone) |
|
173 { |
|
174 // we have a match, there should only be one |
|
175 matchCount++; |
|
176 } |
|
177 // sanity check |
|
178 if(matchCount!=1) |
|
179 { |
|
180 /*SDA 3_50 Failure here |
|
181 fail the test - we have two servers.*/ |
|
182 INFO_PRINTF1(_L("we have two servers")); |
|
183 SetTestStepResult(EFail); |
|
184 |
|
185 } |
|
186 else |
|
187 { |
|
188 // we have one server so check the thread its match |
|
189 RThread server2Thread; |
|
190 err=server2Thread.Open(matchingFileName); |
|
191 User::LeaveIfError(err); |
|
192 TThreadId server2ThreadId = server2Thread.Id(); |
|
193 |
|
194 if(iserverThreadId != server2ThreadId) |
|
195 { |
|
196 /*different thread ids - somehow |
|
197 fail the test here */ |
|
198 INFO_PRINTF1(_L("Different thread ids ")); |
|
199 SetTestStepResult(EFail); |
|
200 } |
|
201 } |
|
202 CleanupStack::PopAndDestroy(&server2); |
|
203 } |
|
204 break; |
|
205 default: |
|
206 User::Leave(KErrArgument); |
|
207 break; |
|
208 |
|
209 } |
|
210 } |
|
211 else |
|
212 { |
|
213 INFO_PRINTF1(_L("<FONT><B>Failed to read from ini file correctly</B></FONT>")); |
|
214 SetTestStepResult(EFail); |
|
215 } |
|
216 } |
|
217 else |
|
218 { |
|
219 INFO_PRINTF1(_L("<FONT><B>server failed to open</B></FONT>")); |
|
220 SetTestStepResult(EFail); |
|
221 } |
|
222 |
|
223 // Carryout final common test action. |
|
224 CleanupStack::PopAndDestroy(&iServer); |
|
225 } |
|
226 |
|
227 INFO_PRINTF1(_L("<<CT_LbsClientStep_SrvConnectClose::doTestStepL()")); |
|
228 |
|
229 return TestStepResult(); |
|
230 } |