|
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 "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Test function for notepad api |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // [INCLUDE FILES] - do not remove |
|
21 #include <e32svr.h> |
|
22 #include <e32cmn.h> |
|
23 #include <f32file.h> |
|
24 #include <StifParser.h> |
|
25 #include <Stiftestinterface.h> |
|
26 #include "TestNpdApi.h" |
|
27 #include <CommonContentPolicy.h> |
|
28 |
|
29 // CONSTANTS |
|
30 //const ?type ?constant_var = ?constant; |
|
31 |
|
32 // LOCAL CONSTANTS AND MACROS |
|
33 //const ?type ?constant_var = ?constant; |
|
34 //#define ?macro_name ?macro_def |
|
35 |
|
36 // ============================= LOCAL FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // ?function_name ?description. |
|
40 // ?description |
|
41 // Returns: ?value_1: ?description |
|
42 // ?value_n: ?description_line1 |
|
43 // ?description_line2 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 /* |
|
47 ?type ?function_name( |
|
48 ?arg_type arg, // ?description |
|
49 ?arg_type arg) // ?description |
|
50 { |
|
51 |
|
52 ?code // ?comment |
|
53 |
|
54 // ?comment |
|
55 ?code |
|
56 } |
|
57 */ |
|
58 |
|
59 // ============================ MEMBER FUNCTIONS =============================== |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CTestNpdApi::Delete |
|
63 // Delete here all resources allocated and opened from test methods. |
|
64 // Called from destructor. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CTestNpdApi::Delete() |
|
68 { |
|
69 |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CTestNpdApi::RunMethodL |
|
74 // Run specified method. Contains also table of test mothods and their names. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 TInt CTestNpdApi::RunMethodL( |
|
78 CStifItemParser& aItem ) |
|
79 { |
|
80 |
|
81 static TStifFunctionInfo const KFunctions[] = |
|
82 { |
|
83 // Copy this line for every implemented function. |
|
84 // First string is the function name used in TestScripter script file. |
|
85 // Second is the actual implementation member function. |
|
86 ENTRY( "TestFetchTemplate", CTestNpdApi::FetchTemplate ), |
|
87 ENTRY( "TestFetchMemo", CTestNpdApi::FetchMemo ), |
|
88 ENTRY( "TestNoOfTemplates", CTestNpdApi::NoOfTemplates ), |
|
89 ENTRY( "SaveFileAsMemoUsingFileName", CTestNpdApi::SaveFileAsMemoUsingFileName ), |
|
90 ENTRY( "SaveFileAsMemoUsingHandle", CTestNpdApi::SaveFileAsMemoUsingHandle ), |
|
91 ENTRY( "TestAddContent", CTestNpdApi::AddContent ), |
|
92 ENTRY( "Model", CTestNpdApi::Model ), |
|
93 ENTRY( "TestDialog", CTestNpdApi::Dialog ), |
|
94 ENTRY( "TestExistsMemoL", CTestNpdApi::ExistsMemoL ), |
|
95 ENTRY( "TestNumberOfTemplates", CTestNpdApi::NumberOfTemplates ), |
|
96 ENTRY( "TestCreateModelL", CTestNpdApi::CreateModelL ), |
|
97 ENTRY( "TestExecTemplatesL", CTestNpdApi::ExecTemplatesL ), |
|
98 ENTRY( "TestNewL", CTestNpdApi::NewL ), |
|
99 ENTRY( "TestProbeMemoL", CTestNpdApi::ProbeMemoL ), |
|
100 ENTRY( "TestNewLC", CTestNpdApi::NewLC ), |
|
101 ENTRY( "TestCNotepadApiDestruction", CTestNpdApi::CNotepadApiDestruction ), |
|
102 ENTRY( "TestCreateListDialogL", CTestNpdApi::CreateListDialogL ), |
|
103 ENTRY( "TestCreateViewerDialogL", CTestNpdApi::CreateViewerDialogL ), |
|
104 ENTRY( "TestExecTemplatesL", CTestNpdApi::ExecTemplatesL ), |
|
105 ENTRY( "TestExecFileViewerUsingFilename", CTestNpdApi::ExecFileViewerUsingFilename ), |
|
106 ENTRY( "TestExecFileViewerUsingHandle", CTestNpdApi::ExecFileViewerUsingHandle ), |
|
107 ENTRY( "TestCreateViewer", CTestNpdApi::CreateViewer ), |
|
108 ENTRY( "TestExecTextViewerL", CTestNpdApi::ExecTextViewerL ), |
|
109 ENTRY( "TestExecTextEditorL", CTestNpdApi::ExecTextEditorL ), |
|
110 ENTRY( "TestExecReadOnlyTextViewerL", CTestNpdApi::ExecReadOnlyTextViewerL ) |
|
111 //ADD NEW ENTRY HERE |
|
112 // [test cases entries] - Do not remove |
|
113 |
|
114 }; |
|
115 |
|
116 const TInt count = sizeof( KFunctions ) / |
|
117 sizeof( TStifFunctionInfo ); |
|
118 |
|
119 return RunInternalL( KFunctions, count, aItem ); |
|
120 |
|
121 } |
|
122 |
|
123 //Funcs Defns |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CTestNpdApi::FetchTemplate |
|
126 // ----------------------------------------------------------------------------- |
|
127 TInt CTestNpdApi::FetchTemplate( CStifItemParser& aItem ) |
|
128 { |
|
129 HBufC* retData = CNotepadApi::FetchTemplateL(); |
|
130 if( retData ) |
|
131 { |
|
132 delete retData; |
|
133 return KErrNone; |
|
134 } |
|
135 return KErrGeneral; |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CTestNpdApi::FetchMemo |
|
140 // ----------------------------------------------------------------------------- |
|
141 TInt CTestNpdApi::FetchMemo( CStifItemParser& aItem ) |
|
142 { |
|
143 HBufC* retData = CNotepadApi::FetchMemoL(); |
|
144 if( retData ) |
|
145 { |
|
146 delete retData; |
|
147 return KErrNone; |
|
148 } |
|
149 return KErrGeneral; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CTestNpdApi::NoOfTemplates |
|
154 // ----------------------------------------------------------------------------- |
|
155 TInt CTestNpdApi::NoOfTemplates( CStifItemParser& aItem ) |
|
156 { |
|
157 TInt noOfTmplts = CNotepadApi::NumberOfTemplates(); |
|
158 //By default there will be a 10 templates, so verifying for more than 0 |
|
159 if ( noOfTmplts >= 0 ) |
|
160 { |
|
161 return KErrNone; |
|
162 } |
|
163 return KErrGeneral; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CTestNpdApi::SaveFileAsMemoUsingFileName |
|
168 // ----------------------------------------------------------------------------- |
|
169 TInt CTestNpdApi::SaveFileAsMemoUsingFileName( CStifItemParser& aItem ) |
|
170 { |
|
171 TInt err = 0; |
|
172 TInt encoding; |
|
173 aItem.GetNextInt(encoding); |
|
174 |
|
175 //Verifying parameter for correct value |
|
176 if ( (encoding != 0) && (encoding != 1) ) |
|
177 { |
|
178 iLog->Log( _L("Wrong parameter, please give either 0 or 1(encoding)") ); |
|
179 return KErrGeneral; |
|
180 } |
|
181 |
|
182 TFileName fileName; |
|
183 fileName.Append(KExampleFilePath); |
|
184 //If 0, no encoding |
|
185 if(encoding == 0) |
|
186 { |
|
187 TRAP(err, CNotepadApi::SaveFileAsMemoL(fileName)); |
|
188 } |
|
189 else |
|
190 { |
|
191 TRAP(err, CNotepadApi::SaveFileAsMemoL(fileName, KCharacterSetIdentifierIso88591)); |
|
192 } |
|
193 |
|
194 if(err == KErrNone) |
|
195 { |
|
196 return KErrNone; |
|
197 } |
|
198 return err; |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CTestNpdApi::SaveFileAsMemoUsingHandle |
|
203 // ----------------------------------------------------------------------------- |
|
204 TInt CTestNpdApi::SaveFileAsMemoUsingHandle( CStifItemParser& aItem ) |
|
205 { |
|
206 TInt err = 0; |
|
207 TInt encoding; |
|
208 aItem.GetNextInt(encoding); |
|
209 |
|
210 //Verifying parameter for correct value |
|
211 if ( (encoding != 0) && (encoding != 1) ) |
|
212 { |
|
213 iLog->Log( _L("Wrong parameter, please give either 0 or 1(encoding)") ); |
|
214 return KErrGeneral; |
|
215 } |
|
216 |
|
217 TFileName fileName; |
|
218 fileName.Append( KExampleFilePath ); |
|
219 |
|
220 RFile data; |
|
221 RFs session; |
|
222 User::LeaveIfError( session.Connect() ); |
|
223 CleanupClosePushL( session ); |
|
224 User::LeaveIfError( data.Open( session, fileName, EFileRead ) ); |
|
225 CleanupClosePushL( data ); |
|
226 |
|
227 //If 0, no encoding |
|
228 if(encoding == 0) |
|
229 { |
|
230 TRAP(err, CNotepadApi::SaveFileAsMemoL(data)); |
|
231 } |
|
232 else |
|
233 { |
|
234 TRAP(err, CNotepadApi::SaveFileAsMemoL(data, KCharacterSetIdentifierIso88591)); |
|
235 } |
|
236 |
|
237 CleanupStack::PopAndDestroy( &data ); //data, |
|
238 CleanupStack::PopAndDestroy( &session ); //session |
|
239 |
|
240 if(err == KErrNone) |
|
241 { |
|
242 return KErrNone; |
|
243 } |
|
244 return err; |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CTestNpdApi::AddContent |
|
249 // ----------------------------------------------------------------------------- |
|
250 TInt CTestNpdApi::AddContent( CStifItemParser& aItem ) |
|
251 { |
|
252 _LIT( KNote, "Saving this text as Notes/Memo"); |
|
253 TRAPD(err, CNotepadApi::AddContentL( KNote )); |
|
254 //Just verifying the error code |
|
255 if(err == KErrNone) |
|
256 { |
|
257 return KErrNone; |
|
258 } |
|
259 return err; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CTestNpdApi::Model |
|
264 // ----------------------------------------------------------------------------- |
|
265 TInt CTestNpdApi::Model( CStifItemParser& aItem ) |
|
266 { |
|
267 |
|
268 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
269 //Not testing the ProbeMemoL() function, but just using to test Model() function. |
|
270 TInt key = 327; |
|
271 ptrToNpd->ProbeMemoL(key); |
|
272 CNotepadModel* retData = ptrToNpd->Model(); |
|
273 //deleting the pointer as it is not used anymore. |
|
274 delete ptrToNpd; |
|
275 //Verifying the pointer, is exist means model() is created properly |
|
276 if( retData ) |
|
277 { |
|
278 return KErrNone; |
|
279 } |
|
280 return KErrGeneral; |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CTestNpdApi::Dialog |
|
285 // ----------------------------------------------------------------------------- |
|
286 TInt CTestNpdApi::Dialog( CStifItemParser& aItem ) |
|
287 { |
|
288 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
289 CEikDialog* Dialog = ptrToNpd->Dialog(); |
|
290 |
|
291 delete ptrToNpd; |
|
292 if ( !Dialog ) |
|
293 { |
|
294 return KErrNone; |
|
295 } |
|
296 return KErrGeneral; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CTestNpdApi::ExistsMemoL |
|
301 // ----------------------------------------------------------------------------- |
|
302 TInt CTestNpdApi::ExistsMemoL( CStifItemParser& aItem ) |
|
303 { |
|
304 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
305 |
|
306 TInt key = 327; |
|
307 TBool IsFound = ptrToNpd->ExistsMemoL( key ); |
|
308 |
|
309 //deleting the pointer as it is not used anymore. |
|
310 delete ptrToNpd; |
|
311 |
|
312 if ( IsFound >= 0 ) |
|
313 { |
|
314 return KErrNone; |
|
315 } |
|
316 return KErrGeneral; |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CTestNpdApi::NumberOfTemplates |
|
321 // ----------------------------------------------------------------------------- |
|
322 TInt CTestNpdApi::NumberOfTemplates(CStifItemParser& aItem) |
|
323 { |
|
324 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
325 TInt Num = ptrToNpd->NumberOfTemplates(); |
|
326 delete ptrToNpd; |
|
327 if( Num > 0 ) |
|
328 { |
|
329 return KErrNone; |
|
330 } |
|
331 return KErrGeneral; |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CTestNpdApi::CreateModelL |
|
336 // ----------------------------------------------------------------------------- |
|
337 TInt CTestNpdApi::CreateModelL( CStifItemParser& aItem ) |
|
338 { |
|
339 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
340 TInt modelResId = R_NOTEPAD_FETCH_MEMO_MODEL; |
|
341 TRAPD( err, ptrToNpd->CreateModelL(modelResId)); |
|
342 return err ; |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CTestNpdApi::NewL |
|
347 // ----------------------------------------------------------------------------- |
|
348 TInt CTestNpdApi::NewL( CStifItemParser& aItem ) |
|
349 { |
|
350 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
351 if ( ptrToNpd ) |
|
352 { |
|
353 return KErrNone; |
|
354 } |
|
355 return KErrGeneral; |
|
356 } |
|
357 |
|
358 // ----------------------------------------------------------------------------- |
|
359 // CTestNpdApi::ProbeMemoL |
|
360 // ----------------------------------------------------------------------------- |
|
361 TInt CTestNpdApi::ProbeMemoL( CStifItemParser& aItem ) |
|
362 { |
|
363 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
364 TInt key = 327; |
|
365 TInt err = 0; |
|
366 TRAP( err, ptrToNpd->ProbeMemoL( key ) ); |
|
367 delete ptrToNpd; |
|
368 |
|
369 if(err == KErrNone) |
|
370 { |
|
371 return KErrNone; |
|
372 } |
|
373 return err; |
|
374 } |
|
375 TInt CTestNpdApi::NewLC( CStifItemParser& aItem ) |
|
376 { |
|
377 CNotepadApi* ptrToNpd = CNotepadApi::NewLC(); |
|
378 CleanupStack::Pop(); |
|
379 if( ptrToNpd ) |
|
380 { |
|
381 delete ptrToNpd ; |
|
382 return KErrNone ; |
|
383 } |
|
384 delete ptrToNpd ; |
|
385 return KErrGeneral; |
|
386 } |
|
387 |
|
388 TInt CTestNpdApi::CNotepadApiDestruction(CStifItemParser& aItem) |
|
389 { |
|
390 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
391 TRAPD( err, delete ptrToNpd ); |
|
392 return err; |
|
393 } |
|
394 |
|
395 TInt CTestNpdApi::CreateListDialogL(CStifItemParser& aItem) |
|
396 { |
|
397 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
398 TRAPD( err, ptrToNpd->CreateListDialogL(R_NOTEPAD_TEMPLATE_LIST_DIALOG);); |
|
399 delete ptrToNpd; |
|
400 return err; |
|
401 } |
|
402 TInt CTestNpdApi::CreateViewerDialogL(CStifItemParser& aItem) |
|
403 { |
|
404 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
405 TBool aDoWait = ETrue; |
|
406 TRAPD( err, ptrToNpd->CreateViewerDialogL( aDoWait )); |
|
407 delete ptrToNpd; |
|
408 return err ; |
|
409 } |
|
410 TInt CTestNpdApi::ExecTemplatesL( CStifItemParser& aItem ) |
|
411 { |
|
412 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
413 TInt returnValueOfDialogExecuteLD = ptrToNpd->ExecTemplatesL(); |
|
414 delete ptrToNpd; |
|
415 if(returnValueOfDialogExecuteLD >= 0 ) |
|
416 { |
|
417 return KErrNone; |
|
418 } |
|
419 return KErrGeneral; |
|
420 } |
|
421 TInt CTestNpdApi::CreateViewer(CStifItemParser& aItem) |
|
422 { |
|
423 TFileName fileName; |
|
424 fileName.Append( KCcpFilePath ); |
|
425 RFile data; |
|
426 RFs session; |
|
427 User::LeaveIfError( session.Connect() ); |
|
428 CleanupClosePushL( session ); |
|
429 User::LeaveIfError(session.ShareProtected()); |
|
430 User::LeaveIfError( data.Open( session, fileName, EFileRead ) ); |
|
431 CleanupClosePushL( data ); |
|
432 TDesC* aTitle = NULL; |
|
433 TBool aDoWait = ETrue; |
|
434 TBool aGuessEncoding = EFalse; |
|
435 TUint aEncoding = 0; |
|
436 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
437 TInt err = 0; |
|
438 TRAP( err, ptrToNpd->CreateViewerDialogL(data, aTitle, aDoWait, aGuessEncoding, aEncoding )); |
|
439 CleanupStack::PopAndDestroy( &data ); |
|
440 CleanupStack::PopAndDestroy( &session ); |
|
441 return err; |
|
442 } |
|
443 |
|
444 |
|
445 TInt CTestNpdApi::ExecFileViewerUsingFilename( CStifItemParser& aItem ) |
|
446 { |
|
447 TFileName fileName( KCcpFilePath ); |
|
448 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
449 TDesC *title = NULL; |
|
450 TBool doWait(ETrue); |
|
451 TBool guessEncoding(EFalse); |
|
452 TUint aEncoding = KCharacterSetIdentifierIso88591; |
|
453 TInt returnValueOfDialogExecuteLD = 0; |
|
454 TInt err = 0; |
|
455 TRAP( err, ptrToNpd->ExecFileViewerL( fileName, title, doWait, guessEncoding, aEncoding) ); |
|
456 delete ptrToNpd; |
|
457 |
|
458 return returnValueOfDialogExecuteLD; |
|
459 } |
|
460 |
|
461 |
|
462 TInt CTestNpdApi::ExecFileViewerUsingHandle( CStifItemParser& aItem ) |
|
463 { |
|
464 TFileName fileName( KCcpFilePath ); |
|
465 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
466 RFs fileSession; |
|
467 User::LeaveIfError(fileSession.Connect()); |
|
468 CleanupClosePushL(fileSession); |
|
469 User::LeaveIfError(fileSession.ShareProtected()); |
|
470 RFile file; |
|
471 User::LeaveIfError(file.Open(fileSession, fileName, EFileRead)); |
|
472 CleanupClosePushL(file); |
|
473 TDesC *title = NULL; |
|
474 TBool doWait(ETrue); |
|
475 TBool guessEncoding(EFalse); |
|
476 TUint aEncoding = KCharacterSetIdentifierIso88591; |
|
477 TInt returnValueOfDialogExecuteLD = 0; |
|
478 returnValueOfDialogExecuteLD = ptrToNpd->ExecFileViewerL( file, title, doWait, guessEncoding, aEncoding); |
|
479 delete ptrToNpd; |
|
480 CleanupStack::PopAndDestroy(2); |
|
481 if( returnValueOfDialogExecuteLD >= 0) |
|
482 { |
|
483 return KErrNone; |
|
484 } |
|
485 return KErrGeneral; |
|
486 } |
|
487 |
|
488 |
|
489 TInt CTestNpdApi::ExecTextViewerL (CStifItemParser& aItem ) |
|
490 { |
|
491 TDesC text( KExampleFilePath ); |
|
492 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
493 TInt returnStatus = 0; |
|
494 TRAPD( err,ptrToNpd->ExecTextViewerL( returnStatus,text ); ); |
|
495 delete ptrToNpd; |
|
496 return err; |
|
497 |
|
498 } |
|
499 |
|
500 |
|
501 TInt CTestNpdApi::ExecTextEditorL(CStifItemParser& aItem ) |
|
502 { |
|
503 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
504 TInt returnStatus = 0; |
|
505 TRAPD( err,ptrToNpd->ExecTextEditorL( returnStatus ); ); |
|
506 delete ptrToNpd; |
|
507 return err; |
|
508 } |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 TInt CTestNpdApi::ExecReadOnlyTextViewerL(CStifItemParser& aItem ) |
|
514 { |
|
515 TDesC text( KExampleFilePath ); |
|
516 CNotepadApi* ptrToNpd = CNotepadApi::NewL(); |
|
517 TInt returnStatus = 0; |
|
518 TRAPD( err,ptrToNpd->ExecReadOnlyTextViewerL(text ); ); |
|
519 delete ptrToNpd; |
|
520 return err; |
|
521 } |
|
522 // ----------------------------------------------------------------------------- |
|
523 // CTestNpdApi::?member_function |
|
524 // ?implementation_description |
|
525 // (other items were commented in a header). |
|
526 // ----------------------------------------------------------------------------- |
|
527 // |
|
528 /* |
|
529 TInt CTestNpdApi::?member_function( |
|
530 CItemParser& aItem ) |
|
531 { |
|
532 |
|
533 ?code |
|
534 |
|
535 } |
|
536 */ |
|
537 |
|
538 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
539 // None |
|
540 |
|
541 // [End of File] - Do not remove |