|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32math.h> |
|
23 #include "FavouritesEngineTest.h" |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 // None |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 // None |
|
30 |
|
31 // CONSTANTS |
|
32 // None |
|
33 |
|
34 // MACROS |
|
35 // None |
|
36 |
|
37 // LOCAL CONSTANTS AND MACROS |
|
38 // None |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 // None |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 // None |
|
45 |
|
46 // FORWARD DECLARATIONS |
|
47 // None |
|
48 |
|
49 // ==================== LOCAL FUNCTIONS ======================================= |
|
50 |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 /* |
|
55 ------------------------------------------------------------------------------- |
|
56 |
|
57 Class: CFavouritesEngineTest |
|
58 |
|
59 Method: FileCloseTestL |
|
60 |
|
61 Description: Test the RFavouritesFile Close method. |
|
62 |
|
63 Parameters: TTestResult& aErrorDescription: out: |
|
64 Test result and on error case a short description of error |
|
65 |
|
66 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
67 |
|
68 Errors/Exceptions: None |
|
69 |
|
70 Status: Approved |
|
71 |
|
72 ------------------------------------------------------------------------------- |
|
73 */ |
|
74 TInt CFavouritesEngineTest::FileCloseTestL( TTestResult& aResult ) |
|
75 { |
|
76 /* Simple server connect */ |
|
77 _LIT( KDefinition ,"State" ); |
|
78 _LIT( KData ,"Test the RFavouritesFile Close method" ); |
|
79 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
80 |
|
81 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
82 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
83 |
|
84 CreatePopulatedDbL(); |
|
85 |
|
86 RFavouritesFile file; |
|
87 file.Open( iFavouritesDb, iItem1->Uid() ); |
|
88 |
|
89 file.Close(); // Close returns void, so we have to assume success |
|
90 |
|
91 _LIT( KData2 ,"Finished" ); |
|
92 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
93 |
|
94 _LIT( KDescription , "Test case passed" ); |
|
95 aResult.SetResult( KErrNone, KDescription ); |
|
96 |
|
97 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
98 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
99 |
|
100 // Case was executed |
|
101 return KErrNone; |
|
102 } |
|
103 |
|
104 /* |
|
105 ------------------------------------------------------------------------------- |
|
106 |
|
107 Class: CFavouritesEngineTest |
|
108 |
|
109 Method: FileOpenTestL |
|
110 |
|
111 Description: Test the RFavouritesFile Open method. |
|
112 |
|
113 Parameters: TTestResult& aErrorDescription: out: |
|
114 Test result and on error case a short description of error |
|
115 |
|
116 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
117 |
|
118 Errors/Exceptions: None |
|
119 |
|
120 Status: Approved |
|
121 |
|
122 ------------------------------------------------------------------------------- |
|
123 */ |
|
124 TInt CFavouritesEngineTest::FileOpenTestL( TTestResult& aResult ) |
|
125 { |
|
126 /* Simple server connect */ |
|
127 _LIT( KDefinition ,"State" ); |
|
128 _LIT( KData ,"Test the RFavouritesFile Open method" ); |
|
129 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
130 |
|
131 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
132 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
133 |
|
134 CreatePopulatedDbL(); |
|
135 |
|
136 RFavouritesFile file; |
|
137 TInt result = file.Open( iFavouritesDb, iItem1->Uid() ); |
|
138 |
|
139 _LIT( KData2 ,"Finished" ); |
|
140 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
141 |
|
142 file.Close(); |
|
143 |
|
144 if( result == KErrNotFound ) |
|
145 { |
|
146 _LIT( KDescription , "Test case passed" ); |
|
147 aResult.SetResult( KErrNone, KDescription ); |
|
148 } |
|
149 else |
|
150 { |
|
151 _LIT( KDescription , "Test case failed" ); |
|
152 aResult.SetResult( KErrGeneral, KDescription ); |
|
153 } |
|
154 |
|
155 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
156 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
157 |
|
158 // Case was executed |
|
159 return KErrNone; |
|
160 } |
|
161 |
|
162 /* |
|
163 ------------------------------------------------------------------------------- |
|
164 |
|
165 Class: CFavouritesEngineTest |
|
166 |
|
167 Method: FileReplaceTestL |
|
168 |
|
169 Description: Test the RFavouritesFile Replace method. |
|
170 |
|
171 Parameters: TTestResult& aErrorDescription: out: |
|
172 Test result and on error case a short description of error |
|
173 |
|
174 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
175 |
|
176 Errors/Exceptions: None |
|
177 |
|
178 Status: Approved |
|
179 |
|
180 ------------------------------------------------------------------------------- |
|
181 */ |
|
182 TInt CFavouritesEngineTest::FileReplaceTestL( TTestResult& aResult ) |
|
183 { |
|
184 /* Simple server connect */ |
|
185 _LIT( KDefinition ,"State" ); |
|
186 _LIT( KData ,"Test the RFavouritesFile Replace method" ); |
|
187 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
188 |
|
189 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
190 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
191 |
|
192 CreatePopulatedDbL(); |
|
193 |
|
194 RFavouritesFile file; |
|
195 TInt result = file.Replace( iFavouritesDb, KFavouritesRootUid ); |
|
196 |
|
197 _LIT( KData2 ,"Finished" ); |
|
198 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
199 |
|
200 file.Close(); |
|
201 |
|
202 if( result == KErrNone ) |
|
203 { |
|
204 _LIT( KDescription , "Test case passed" ); |
|
205 aResult.SetResult( KErrNone, KDescription ); |
|
206 } |
|
207 else |
|
208 { |
|
209 _LIT( KDescription , "Test case failed" ); |
|
210 aResult.SetResult( KErrGeneral, KDescription ); |
|
211 } |
|
212 |
|
213 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
214 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
215 |
|
216 // Case was executed |
|
217 return KErrNone; |
|
218 } |
|
219 |
|
220 /* |
|
221 ------------------------------------------------------------------------------- |
|
222 |
|
223 Class: CFavouritesEngineTest |
|
224 |
|
225 Method: FileReadTestL |
|
226 |
|
227 Description: Test the RFavouritesFile Read method. |
|
228 |
|
229 Parameters: TTestResult& aErrorDescription: out: |
|
230 Test result and on error case a short description of error |
|
231 |
|
232 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
233 |
|
234 Errors/Exceptions: None |
|
235 |
|
236 Status: Approved |
|
237 |
|
238 ------------------------------------------------------------------------------- |
|
239 */ |
|
240 TInt CFavouritesEngineTest::FileReadTestL( TTestResult& aResult ) |
|
241 { |
|
242 /* Simple server connect */ |
|
243 _LIT( KDefinition ,"State" ); |
|
244 _LIT( KData ,"Test the RFavouritesFile Read method" ); |
|
245 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
246 |
|
247 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
248 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
249 |
|
250 CreatePopulatedDbL(); |
|
251 |
|
252 RFavouritesFile fileToWrite; |
|
253 TPtrC8 testString = _L8("Once upon a time"); |
|
254 |
|
255 fileToWrite.Replace( iFavouritesDb, iItem1->Uid() ); |
|
256 |
|
257 fileToWrite.Write(testString); |
|
258 |
|
259 fileToWrite.Close(); |
|
260 |
|
261 RFavouritesFile fileToRead; |
|
262 HBufC8 *readBuf = HBufC8::NewLC(testString.Length()); |
|
263 TPtr8 readPtr(readBuf->Des()); |
|
264 |
|
265 fileToRead.Open( iFavouritesDb, iItem1->Uid() ); |
|
266 |
|
267 TInt result = fileToRead.Read( readPtr ); |
|
268 |
|
269 _LIT( KData2 ,"Finished" ); |
|
270 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
271 |
|
272 fileToRead.Close(); |
|
273 |
|
274 if( result == KErrNone ) |
|
275 { |
|
276 _LIT( KDescription , "Test case passed" ); |
|
277 aResult.SetResult( KErrNone, KDescription ); |
|
278 } |
|
279 else |
|
280 { |
|
281 _LIT( KDescription , "Test case failed" ); |
|
282 aResult.SetResult( KErrGeneral, KDescription ); |
|
283 } |
|
284 |
|
285 CleanupStack::PopAndDestroy(2); // iFavouritesDb, readBuf |
|
286 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
287 |
|
288 // Case was executed |
|
289 return KErrNone; |
|
290 } |
|
291 |
|
292 /* |
|
293 ------------------------------------------------------------------------------- |
|
294 |
|
295 Class: CFavouritesEngineTest |
|
296 |
|
297 Method: FileWriteTestL |
|
298 |
|
299 Description: Test the RFavouritesFile Write method. |
|
300 |
|
301 Parameters: TTestResult& aErrorDescription: out: |
|
302 Test result and on error case a short description of error |
|
303 |
|
304 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
305 |
|
306 Errors/Exceptions: None |
|
307 |
|
308 Status: Approved |
|
309 |
|
310 ------------------------------------------------------------------------------- |
|
311 */ |
|
312 TInt CFavouritesEngineTest::FileWriteTestL( TTestResult& aResult ) |
|
313 { |
|
314 /* Simple server connect */ |
|
315 _LIT( KDefinition ,"State" ); |
|
316 _LIT( KData ,"Test the RFavouritesFile Write method" ); |
|
317 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
318 |
|
319 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
320 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
321 |
|
322 CreatePopulatedDbL(); |
|
323 |
|
324 RFavouritesFile fileToWrite; |
|
325 TPtrC8 testString = _L8("Once upon a time"); |
|
326 |
|
327 fileToWrite.Replace( iFavouritesDb, iItem1->Uid() ); |
|
328 |
|
329 TInt result = fileToWrite.Write(testString); |
|
330 |
|
331 _LIT( KData2 ,"Finished" ); |
|
332 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
333 |
|
334 fileToWrite.Close(); |
|
335 |
|
336 if( result == KErrNone ) |
|
337 { |
|
338 _LIT( KDescription , "Test case passed" ); |
|
339 aResult.SetResult( KErrNone, KDescription ); |
|
340 } |
|
341 else |
|
342 { |
|
343 _LIT( KDescription , "Test case failed" ); |
|
344 aResult.SetResult( KErrGeneral, KDescription ); |
|
345 } |
|
346 |
|
347 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
348 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
349 |
|
350 // Case was executed |
|
351 return KErrNone; |
|
352 } |
|
353 |
|
354 /* |
|
355 ------------------------------------------------------------------------------- |
|
356 |
|
357 Class: CFavouritesEngineTest |
|
358 |
|
359 Method: FileSizeTestL |
|
360 |
|
361 Description: Test the RFavouritesFile Size method. |
|
362 |
|
363 Parameters: TTestResult& aErrorDescription: out: |
|
364 Test result and on error case a short description of error |
|
365 |
|
366 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
367 |
|
368 Errors/Exceptions: None |
|
369 |
|
370 Status: Approved |
|
371 |
|
372 ------------------------------------------------------------------------------- |
|
373 */ |
|
374 TInt CFavouritesEngineTest::FileSizeTestL( TTestResult& aResult ) |
|
375 { |
|
376 /* Simple server connect */ |
|
377 _LIT( KDefinition ,"State" ); |
|
378 _LIT( KData ,"Test the RFavouritesFile Size method" ); |
|
379 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
380 |
|
381 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
382 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
383 |
|
384 CreatePopulatedDbL(); |
|
385 |
|
386 RFavouritesFile file; |
|
387 |
|
388 TPtrC8 testString = _L8("Once upon a time"); |
|
389 |
|
390 file.Replace( iFavouritesDb, iItem1->Uid() ); |
|
391 |
|
392 file.Write(testString); |
|
393 |
|
394 TInt dbSize; |
|
395 |
|
396 TInt result = file.Size( dbSize ); |
|
397 |
|
398 _LIT( KData2 ,"Finished" ); |
|
399 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
400 |
|
401 file.Close(); |
|
402 |
|
403 if( result == KErrNone ) |
|
404 { |
|
405 _LIT( KDescription , "Test case passed" ); |
|
406 aResult.SetResult( KErrNone, KDescription ); |
|
407 } |
|
408 else |
|
409 { |
|
410 _LIT( KDescription , "Test case failed" ); |
|
411 aResult.SetResult( KErrGeneral, KDescription ); |
|
412 } |
|
413 |
|
414 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
415 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
416 |
|
417 // Case was executed |
|
418 return KErrNone; |
|
419 } |
|
420 |
|
421 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
422 |
|
423 // End of File |