14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <e32test.h> |
|
20 //#include /**/ <s32mem.h> |
|
21 #include <s32file.h> |
19 #include <s32file.h> |
22 #include <flddef.h> |
20 #include <flddef.h> |
23 #include <fldbase.h> |
21 #include <fldbase.h> |
24 #include <fldset.h> |
22 #include <fldset.h> |
25 #include "TESTFAC.H" |
23 #include "TESTFAC.H" |
|
24 #include "T_STREAM.h" |
|
25 |
|
26 #define test(cond) \ |
|
27 { \ |
|
28 TBool __bb = (cond); \ |
|
29 TEST(__bb); \ |
|
30 if (!__bb) \ |
|
31 { \ |
|
32 ERR_PRINTF1(_L("ERROR: Test Failed")); \ |
|
33 User::Leave(1); \ |
|
34 } \ |
|
35 } |
26 |
36 |
27 const TInt KTestCleanupStack=0x20; |
37 const TInt KTestCleanupStack=0x20; |
28 |
38 |
29 LOCAL_D RTest test(_L("T_STREAM - Fields Persistence")); |
|
30 LOCAL_D CTrapCleanup* TheTrapCleanup; |
39 LOCAL_D CTrapCleanup* TheTrapCleanup; |
31 LOCAL_D CTextFieldSet* TheFieldSetOriginal; |
40 LOCAL_D CTextFieldSet* TheFieldSetOriginal; |
32 LOCAL_D CTextFieldSet* TheFieldSetCopy; |
41 LOCAL_D CTextFieldSet* TheFieldSetCopy; |
33 LOCAL_D TTestFieldFactory* TheFactory; |
42 LOCAL_D TTestFieldFactory* TheFactory; |
34 |
43 |
35 _LIT(KTFieldOutputFile, "c:\\etext\\tfield.tst"); |
44 _LIT(KTFieldOutputFile, "c:\\etext\\tfield.tst"); |
36 // Test Picture persistance. |
45 // Test Picture persistance. |
37 LOCAL_C void testStoreRestore(CTextFieldSet* aCopy,const CTextFieldSet* aOriginal) |
46 void CT_STREAM::testStoreRestore(CTextFieldSet* aCopy,const CTextFieldSet* aOriginal) |
38 { |
47 { |
39 // set up the store |
48 // set up the store |
40 RFs theFs; |
49 RFs theFs; |
41 theFs.Connect(); |
50 theFs.Connect(); |
42 theFs.Delete(KTFieldOutputFile); |
51 theFs.Delete(KTFieldOutputFile); |
134 CleanupStack::PopAndDestroy(); |
143 CleanupStack::PopAndDestroy(); |
135 return ret; |
144 return ret; |
136 } |
145 } |
137 |
146 |
138 |
147 |
139 LOCAL_C void test2() |
148 void CT_STREAM::test2() |
140 // Streams an empty field set |
149 // Streams an empty field set |
141 // |
150 // |
142 { |
151 { |
143 test.Next(_L("- streaming of a default FieldSet (no fields)")); |
152 INFO_PRINTF1(_L("- streaming of a default FieldSet (no fields)")); |
144 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
153 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
145 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
154 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
146 TheFieldSetOriginal->Reset(); |
155 TheFieldSetOriginal->Reset(); |
147 TheFieldSetCopy->Reset(); |
156 TheFieldSetCopy->Reset(); |
148 } |
157 } |
149 |
158 |
150 |
159 |
151 LOCAL_C void test3() |
160 void CT_STREAM::test3() |
152 // Streams a field set containing 100 chars & 1 field |
161 // Streams a field set containing 100 chars & 1 field |
153 // |
162 // |
154 { |
163 { |
155 test.Next(_L("- streaming with a field")); |
164 INFO_PRINTF1(_L("- streaming with a field")); |
156 |
165 |
157 // insert a block of text into the original |
166 // insert a block of text into the original |
158 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
167 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
159 // insert a field into the original |
168 // insert a field into the original |
160 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
169 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
170 TheFieldSetOriginal->Reset(); |
179 TheFieldSetOriginal->Reset(); |
171 TheFieldSetCopy->Reset(); |
180 TheFieldSetCopy->Reset(); |
172 } |
181 } |
173 |
182 |
174 |
183 |
175 LOCAL_C void test4() |
184 void CT_STREAM::test4() |
176 // Streams a field set into a non-empty target |
185 // Streams a field set into a non-empty target |
177 // |
186 // |
178 { |
187 { |
179 test.Next(_L("- streaming into a non-empty target")); |
188 INFO_PRINTF1(_L("- streaming into a non-empty target")); |
180 |
189 |
181 // insert a block of text into the original |
190 // insert a block of text into the original |
182 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
191 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
183 // insert a field into the original |
192 // insert a field into the original |
184 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
193 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
208 TheFieldSetOriginal->Reset(); |
217 TheFieldSetOriginal->Reset(); |
209 TheFieldSetCopy->Reset(); |
218 TheFieldSetCopy->Reset(); |
210 } |
219 } |
211 |
220 |
212 |
221 |
213 LOCAL_C void test5() |
222 void CT_STREAM::test5() |
214 // Streams a field set containing an out of date field |
223 // Streams a field set containing an out of date field |
215 // |
224 // |
216 { |
225 { |
217 test.Next(_L("- streaming an out of date field")); |
226 INFO_PRINTF1(_L("- streaming an out of date field")); |
218 |
227 |
219 // insert a block of text into the original |
228 // insert a block of text into the original |
220 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
229 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
221 // insert a field into the original |
230 // insert a field into the original |
222 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
231 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
234 TheFieldSetOriginal->Reset(); |
243 TheFieldSetOriginal->Reset(); |
235 TheFieldSetCopy->Reset(); |
244 TheFieldSetCopy->Reset(); |
236 } |
245 } |
237 |
246 |
238 |
247 |
239 LOCAL_C void test6() |
248 void CT_STREAM::test6() |
240 // Tests that copy/paste methods exist |
249 // Tests that copy/paste methods exist |
241 // |
250 // |
242 { |
251 { |
243 test.Next(_L("- testing copy/paste methods with empty array")); |
252 INFO_PRINTF1(_L("- testing copy/paste methods with empty array")); |
244 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,0,0,0); // copyPos,Len,PastePos |
253 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,0,0,0); // copyPos,Len,PastePos |
245 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
254 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
246 TheFieldSetOriginal->Reset(); |
255 TheFieldSetOriginal->Reset(); |
247 TheFieldSetCopy->Reset(); |
256 TheFieldSetCopy->Reset(); |
248 } |
257 } |
249 |
258 |
250 |
259 |
251 LOCAL_C void test7() |
260 void CT_STREAM::test7() |
252 // Tests copy/paste methods in detail |
261 // Tests copy/paste methods in detail |
253 // |
262 // |
254 { |
263 { |
255 test.Next(_L("- testing copy/paste methods in detail")); |
264 INFO_PRINTF1(_L("- testing copy/paste methods in detail")); |
256 // insert a block of text into the original |
265 // insert a block of text into the original |
257 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
266 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
258 // insert a field into the original |
267 // insert a field into the original |
259 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
268 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
260 test(field!=NULL); |
269 test(field!=NULL); |
344 TheFieldSetOriginal->Reset(); |
353 TheFieldSetOriginal->Reset(); |
345 TheFieldSetCopy->Reset(); |
354 TheFieldSetCopy->Reset(); |
346 } |
355 } |
347 |
356 |
348 |
357 |
349 LOCAL_C void test8() |
358 void CT_STREAM::test8() |
350 // Tests paste method with restricted target length |
359 // Tests paste method with restricted target length |
351 // |
360 // |
352 { |
361 { |
353 test.Next(_L("- testing paste method with restricted length")); |
362 INFO_PRINTF1(_L("- testing paste method with restricted length")); |
354 // insert a block of text into the original |
363 // insert a block of text into the original |
355 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
364 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
356 // insert 2 fields into the original |
365 // insert 2 fields into the original |
357 // 1... |
366 // 1... |
358 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
367 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
411 TheFieldSetOriginal->Reset(); |
420 TheFieldSetOriginal->Reset(); |
412 TheFieldSetCopy->Reset(); |
421 TheFieldSetCopy->Reset(); |
413 } |
422 } |
414 |
423 |
415 |
424 |
416 LOCAL_C void test9() |
425 void CT_STREAM::test9() |
417 // Tests paste into set with no field factory |
426 // Tests paste into set with no field factory |
418 // Should convert all pasted fields to text... |
427 // Should convert all pasted fields to text... |
419 // |
428 // |
420 { |
429 { |
421 test.Next(_L("- testing paste into set with no field factory")); |
430 INFO_PRINTF1(_L("- testing paste into set with no field factory")); |
422 TheFieldSetCopy->SetFieldFactory(NULL); |
431 TheFieldSetCopy->SetFieldFactory(NULL); |
423 // insert a block of text into the original |
432 // insert a block of text into the original |
424 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
433 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
425 // insert a field into the original |
434 // insert a field into the original |
426 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
435 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
440 TheFieldSetCopy->Reset(); |
449 TheFieldSetCopy->Reset(); |
441 TheFieldSetCopy->SetFieldFactory(TheFactory); |
450 TheFieldSetCopy->SetFieldFactory(TheFactory); |
442 } |
451 } |
443 |
452 |
444 |
453 |
445 LOCAL_C void test10() |
454 void CT_STREAM::test10() |
446 // Streams a field set containing 100 chars & 1 field |
455 // Streams a field set containing 100 chars & 1 field |
447 // |
456 // |
448 { |
457 { |
449 test.Next(_L("- streaming CDateTimeField")); |
458 INFO_PRINTF1(_L("- streaming CDateTimeField")); |
450 |
459 |
451 // insert a block of text into the original |
460 // insert a block of text into the original |
452 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
461 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
453 // insert a field into the original |
462 // insert a field into the original |
454 CTextField* field=TheFieldSetOriginal->NewFieldL(KDateTimeFieldUid); |
463 CTextField* field=TheFieldSetOriginal->NewFieldL(KDateTimeFieldUid); |
463 HBufC* miniBuf = HBufC::NewL(5); |
472 HBufC* miniBuf = HBufC::NewL(5); |
464 CleanupStack::PushL(miniBuf); |
473 CleanupStack::PushL(miniBuf); |
465 ret=TheFieldSetOriginal->NewFieldValueL(miniBuf,10); // pos=10 |
474 ret=TheFieldSetOriginal->NewFieldValueL(miniBuf,10); // pos=10 |
466 test(ret==KErrNone); |
475 test(ret==KErrNone); |
467 TPtr buf = miniBuf->Des(); |
476 TPtr buf = miniBuf->Des(); |
468 test.Printf(_L(" Value before streaming: ")); |
477 INFO_PRINTF1(_L(" Value before streaming: ")); |
469 test.Printf(buf); |
478 INFO_PRINTF1(buf); |
470 test.Printf(_L("\n")); |
479 INFO_PRINTF1(_L("\n")); |
471 // test streaming |
480 // test streaming |
472 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
481 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
473 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
482 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
474 // value after |
483 // value after |
475 ret=TheFieldSetCopy->NewFieldValueL(miniBuf,10); // pos=10 |
484 ret=TheFieldSetCopy->NewFieldValueL(miniBuf,10); // pos=10 |
476 test(ret==KErrNone); |
485 test(ret==KErrNone); |
477 buf = miniBuf->Des(); |
486 buf = miniBuf->Des(); |
478 test.Printf(_L(" Value after streaming: ")); |
487 INFO_PRINTF1(_L(" Value after streaming: ")); |
479 test.Printf(buf); |
488 INFO_PRINTF1(buf); |
480 test.Printf(_L("\n")); |
489 INFO_PRINTF1(_L("\n")); |
481 CleanupStack::PopAndDestroy(); // miniBuf |
490 CleanupStack::PopAndDestroy(); // miniBuf |
482 TheFieldSetOriginal->Reset(); |
491 TheFieldSetOriginal->Reset(); |
483 TheFieldSetCopy->Reset(); |
492 TheFieldSetCopy->Reset(); |
484 } |
493 } |
485 |
494 |
486 |
495 |
487 void TestStreamingL() |
496 void CT_STREAM::TestStreamingL() |
488 // |
497 // |
489 // Test streaming of PrintSetup info. |
498 // Test streaming of PrintSetup info. |
490 // Stream from one copy to another, then compare |
499 // Stream from one copy to another, then compare |
491 // |
500 // |
492 { |
501 { |
493 // create the PrintSetups |
502 // create the PrintSetups |
494 test.Start(_L("Streaming CTextFieldSet")); |
503 INFO_PRINTF1(_L("Streaming CTextFieldSet")); |
495 |
504 |
496 // instantiate the factory and FieldSet |
505 // instantiate the factory and FieldSet |
497 TheFactory = new(ELeave) TTestFieldFactory(); |
506 TheFactory = new(ELeave) TTestFieldFactory(); |
498 TheFieldSetOriginal = CTextFieldSet::NewL(); |
507 TheFieldSetOriginal = CTextFieldSet::NewL(); |
499 TheFieldSetOriginal->SetFieldFactory(TheFactory); |
508 TheFieldSetOriginal->SetFieldFactory(TheFactory); |
578 { |
587 { |
579 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); |
588 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); |
580 } |
589 } |
581 } |
590 } |
582 |
591 |
583 GLDEF_C TInt E32Main() |
592 |
584 // |
593 CT_STREAM::CT_STREAM() |
585 // Test streaming conversions. |
|
586 // |
|
587 { |
594 { |
588 test.Title(); |
595 SetTestStepName(KTestStep_T_STREAM); |
589 |
596 } |
590 __UHEAP_MARK; |
597 |
|
598 TVerdict CT_STREAM::doTestStepL() |
|
599 { |
|
600 INFO_PRINTF1(_L("T_STREAM - Fields Persistence")); |
|
601 SetTestStepResult(EFail); |
|
602 |
|
603 __UHEAP_MARK; |
|
604 |
591 setupCleanup(); |
605 setupCleanup(); |
592 |
606 |
593 TRAPD(r,TestStreamingL()); |
607 TRAPD(error1, TestStreamingL()); |
594 test(r==KErrNone); |
|
595 |
608 |
596 delete TheTrapCleanup; |
609 delete TheTrapCleanup; |
597 |
610 |
598 __UHEAP_MARKEND; |
611 __UHEAP_MARKEND; |
599 |
612 DeleteDataFile(KTFieldOutputFile); //deletion of data files must be before call to End() - DEF047652 |
600 ::DeleteDataFile(KTFieldOutputFile); //deletion of data files must be before call to End() - DEF047652 |
613 |
601 |
614 if(error1 == KErrNone) |
602 test.End(); |
615 { |
603 test.Close(); |
616 SetTestStepResult(EPass); |
604 |
617 } |
605 return 0; |
618 |
|
619 return TestStepResult(); |
606 } |
620 } |
607 |
|