|
1 /* |
|
2 /* |
|
3 * Copyright (c) 2002 - 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * This component and the accompanying materials are made available |
|
6 * under the terms of "Eclipse Public License v1.0"" |
|
7 * which accompanies this distribution, and is available |
|
8 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 * |
|
10 * Initial Contributors: |
|
11 * Nokia Corporation - initial contribution. |
|
12 * |
|
13 * Contributors: |
|
14 * |
|
15 * Description: This cpp file has the functions to test Das Client API. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // [INCLUDE FILES] |
|
21 #include <e32svr.h> |
|
22 #include <StifParser.h> |
|
23 #include <StifTestInterface.h> |
|
24 #include "DasClientApiTest.h" |
|
25 |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CDasClientApiTest::Delete |
|
32 // Delete here all resources allocated and opened from test methods. |
|
33 // Called from destructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 void CDasClientApiTest::Delete() |
|
37 { |
|
38 if( iLauncher ) |
|
39 { |
|
40 delete iLauncher; |
|
41 iLauncher = NULL; |
|
42 } |
|
43 |
|
44 if( iClient ) |
|
45 { |
|
46 delete iClient; |
|
47 iClient = NULL; |
|
48 } |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CDasClientApiTest::RunMethodL |
|
53 // Run specified method. Contains also table of test mothods and their names. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 TInt CDasClientApiTest::RunMethodL( |
|
57 CStifItemParser& aItem ) |
|
58 { |
|
59 |
|
60 static TStifFunctionInfo const KFunctions[] = |
|
61 { |
|
62 // First string is the function name used in TestScripter script file. |
|
63 // Second is the actual implementation member function. |
|
64 ENTRY( "CallClientNewLL", CDasClientApiTest::CallClientNewLL ), |
|
65 ENTRY( "CallClientNewLCL", CDasClientApiTest::CallClientNewLCL ), |
|
66 ENTRY( "CallServiceAvailableL", CDasClientApiTest::CallServiceAvailableL ), |
|
67 ENTRY( "CallChangeDefaultsLL", CDasClientApiTest::CallChangeDefaultsLL ), |
|
68 // [test cases entries] |
|
69 |
|
70 }; |
|
71 |
|
72 const TInt count = sizeof( KFunctions ) / sizeof( TStifFunctionInfo ); |
|
73 |
|
74 return RunInternalL( KFunctions, count, aItem ); |
|
75 |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CDasClientApiTest::CallNewlcL |
|
80 // This function is used because we can not TRAP CServicesDB::NewLC |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CDasClientApiTest::CallNewlcL( MAknServerAppExitObserver* aObserver ) |
|
84 { |
|
85 iClient = CDefaultAppClient::NewLC( aObserver ); |
|
86 CleanupStack::Pop( iClient ); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CServicesDbApiTest::InitialClientL |
|
91 // This function is used to create CDefaultAppClient object. This function is used |
|
92 // to call CDefaultAppClient::NewL and CDefaultAppClient::NewLC functions. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 TInt CDasClientApiTest::InitialClientL( TInt aOption ) |
|
96 { |
|
97 //launcher of the client; |
|
98 if( aOption == KFirstOption ) |
|
99 { |
|
100 TRAPD( error, iClient = CDefaultAppClient::NewL( NULL ) ); |
|
101 if( KErrNone != error ) |
|
102 { |
|
103 iLog->Log( _L( "=>CDefaultAppClient::NewL leaves" ) ); |
|
104 return error; |
|
105 } |
|
106 } |
|
107 else |
|
108 { |
|
109 TRAPD( error1, CallNewlcL( NULL ) ); |
|
110 if( KErrNone != error1 ) |
|
111 { |
|
112 iLog->Log( _L( "=>CDefaultAppClient::NewLC leaves" ) ); |
|
113 return error1; |
|
114 } |
|
115 } |
|
116 return KErrNone; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CServicesDbApiTest::CallClientNewLL |
|
121 // Is used to test CDefaultAppClient::NewL |
|
122 // ----------------------------------------------------------------------------- |
|
123 TInt CDasClientApiTest::CallClientNewLL( CStifItemParser& /*aItem*/ ) |
|
124 { |
|
125 TInt result; |
|
126 |
|
127 TRAPD( error, result = InitialClientL( KFirstOption ) ); |
|
128 if( KErrNone != error ) |
|
129 { |
|
130 iLog->Log( _L( "CDefaultAppClient object not created with NewL." ) ); |
|
131 return error; |
|
132 } |
|
133 else |
|
134 { |
|
135 if( KErrNone != result ) |
|
136 { |
|
137 iLog->Log( _L( "CDefaultAppClient object not created with NewL." ) ); |
|
138 return result; |
|
139 } |
|
140 else |
|
141 { |
|
142 iLog->Log( _L( "CDefaultAppClient object created with NewL." ) ); |
|
143 } |
|
144 }; |
|
145 return KErrNone; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CServicesDbApiTest::CallClientNewLCL |
|
150 // Is used to test CDefaultAppClient::NewLC |
|
151 // ----------------------------------------------------------------------------- |
|
152 TInt CDasClientApiTest::CallClientNewLCL( CStifItemParser& /*aItem*/ ) |
|
153 { |
|
154 TInt result; |
|
155 TRAPD( error, result = InitialClientL( KSecondtOption ) ); |
|
156 if( KErrNone != error ) |
|
157 { |
|
158 return error; |
|
159 } |
|
160 else |
|
161 { |
|
162 if( KErrNone != result ) |
|
163 { |
|
164 return result; |
|
165 } |
|
166 } |
|
167 return KErrNone; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CServicesDbApiTest::CallServiceAvailableL |
|
172 // Is used to test CDefaultAppClient::ServiceAvailableL |
|
173 // ----------------------------------------------------------------------------- |
|
174 TInt CDasClientApiTest::CallServiceAvailableL( CStifItemParser& /*aItem*/ ) |
|
175 { |
|
176 //Initial the iClient |
|
177 TInt result; |
|
178 TRAPD( error, result = InitialClientL( KFirstOption ) ); |
|
179 if( KErrNone != error ) |
|
180 { |
|
181 return error; |
|
182 } |
|
183 else |
|
184 { |
|
185 if( KErrNone != result ) |
|
186 { |
|
187 return result; |
|
188 } |
|
189 }; |
|
190 //call the function |
|
191 |
|
192 TInt errcode; |
|
193 TBool returnvalue; |
|
194 TRAPD( callerror, returnvalue = CDefaultAppClient::ServiceAvailable( errcode ) ); |
|
195 if( KErrNone != callerror ) |
|
196 { |
|
197 iLog->Log(_L( "Call function ServiceAvailable failed.The function leaves,the leace code is %d"), callerror ); |
|
198 return callerror; |
|
199 } |
|
200 else |
|
201 { |
|
202 if( returnvalue != KErrNone ) |
|
203 { |
|
204 iLog->Log( _L( "The function returned sucessfully,But the service is not available. The error code is %d" ), errcode ); |
|
205 return errcode; |
|
206 } |
|
207 else |
|
208 { |
|
209 iLog->Log( _L( "The function ServiceAvailable called success, and the service is available! " ) ); |
|
210 } |
|
211 } |
|
212 return KErrNone; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CServicesDbApiTest::CallChangeDefaultsLL |
|
217 // Is used to test CDefaultAppClient::ChangeDefaultsL |
|
218 // ----------------------------------------------------------------------------- |
|
219 TInt CDasClientApiTest::CallChangeDefaultsLL( CStifItemParser& /*aItem*/ ) |
|
220 { |
|
221 // |
|
222 TInt result; |
|
223 TRAPD( error, result = InitialClientL( KFirstOption ) ); |
|
224 if(KErrNone != error) |
|
225 { |
|
226 iLog->Log( _L( "Initial the iClient failed,the failed code is %d" ), error ); |
|
227 return error; |
|
228 } |
|
229 else |
|
230 { |
|
231 if( KErrNone != result ) |
|
232 { |
|
233 return result; |
|
234 } |
|
235 }; |
|
236 TRAPD( errorCall, iClient->ChangeDefaultsL() ); |
|
237 if( errorCall != KErrNone ) |
|
238 { |
|
239 iLog->Log( _L( "Function ChangeDefaultsL is called failed. The failed code is %d" ), errorCall ); |
|
240 return errorCall; |
|
241 } |
|
242 else |
|
243 { |
|
244 iLog->Log( _L( "The Function is called successfully." ) ); |
|
245 } |
|
246 return KErrNone; |
|
247 } |
|
248 |
|
249 // |
|
250 // [End of File] |