|
1 /* |
|
2 * Copyright (c) 1997-2009 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 "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 #include <e32test.h> |
|
20 //#include /**/ <s32mem.h> |
|
21 #include <s32file.h> |
|
22 #include <flddef.h> |
|
23 #include <fldbase.h> |
|
24 #include <fldset.h> |
|
25 #include "TESTFAC.H" |
|
26 |
|
27 const TInt KTestCleanupStack=0x20; |
|
28 |
|
29 LOCAL_D RTest test(_L("T_STREAM - Fields Persistence")); |
|
30 LOCAL_D CTrapCleanup* TheTrapCleanup; |
|
31 LOCAL_D CTextFieldSet* TheFieldSetOriginal; |
|
32 LOCAL_D CTextFieldSet* TheFieldSetCopy; |
|
33 LOCAL_D TTestFieldFactory* TheFactory; |
|
34 |
|
35 _LIT(KTFieldOutputFile, "c:\\etext\\tfield.tst"); |
|
36 // Test Picture persistance. |
|
37 LOCAL_C void testStoreRestore(CTextFieldSet* aCopy,const CTextFieldSet* aOriginal) |
|
38 { |
|
39 // set up the store |
|
40 RFs theFs; |
|
41 theFs.Connect(); |
|
42 theFs.Delete(KTFieldOutputFile); |
|
43 theFs.MkDirAll(KTFieldOutputFile); |
|
44 CFileStore* theStore=CDirectFileStore::CreateL(theFs, KTFieldOutputFile, EFileRead | EFileWrite); |
|
45 CleanupStack::PushL(theStore); |
|
46 theStore->SetTypeL(KDirectFileStoreLayoutUid); |
|
47 // |
|
48 // store the original |
|
49 TStreamId id(0); |
|
50 TRAPD(ret,id=aOriginal->StoreL(*theStore)); |
|
51 test(ret==KErrNone); |
|
52 // |
|
53 // restore into the copy |
|
54 TRAP(ret,aCopy->RestoreL(*theStore,id)); |
|
55 test(ret==KErrNone); |
|
56 // |
|
57 // tidy up |
|
58 CleanupStack::PopAndDestroy(); // theStore |
|
59 theFs.Close(); |
|
60 } |
|
61 |
|
62 |
|
63 |
|
64 template <class T> |
|
65 void testCopyPaste(T* aCopy, T* aOriginal,TInt aCopyPos,TInt aLen,TInt aPastePos,TInt aPasteLen=-1) |
|
66 // Copy part of anOriginal to aCopy using memory-based streams. |
|
67 // |
|
68 { |
|
69 // set up the store |
|
70 RFs theFs; |
|
71 theFs.Connect(); |
|
72 CFileStore* theStore=CDirectFileStore::ReplaceL(theFs,KTFieldOutputFile,EFileRead|EFileWrite); |
|
73 CleanupStack::PushL(theStore); |
|
74 theStore->SetTypeL(KDirectFileStoreLayoutUid); |
|
75 // |
|
76 // Copy anOriginal out to the buffer |
|
77 TStreamId id(0); |
|
78 TRAPD(ret,id=aOriginal->CopyToStoreL(*theStore,aCopyPos,aLen)); |
|
79 test(ret==KErrNone); |
|
80 // |
|
81 // paste into the copy |
|
82 TRAP(ret,aCopy->PasteFromStoreL(*theStore,id,aPastePos,aPasteLen)); |
|
83 test(ret==KErrNone); |
|
84 // |
|
85 // tidy up |
|
86 CleanupStack::PopAndDestroy(); // theStore |
|
87 theFs.Close(); |
|
88 |
|
89 } |
|
90 |
|
91 |
|
92 LOCAL_C TBool IsEqual(const CTextFieldSet* aCopy,const CTextFieldSet* anOriginal) |
|
93 // |
|
94 // Returns true if aCopy contents matches anOriginal contents. |
|
95 // |
|
96 { |
|
97 // test the num chars and num fields |
|
98 TInt charCount = anOriginal->CharCount(); |
|
99 TInt fieldCount = anOriginal->FieldCount(); |
|
100 test(charCount==aCopy->CharCount()); |
|
101 test(fieldCount==aCopy->FieldCount()); |
|
102 |
|
103 // test each entry in the array |
|
104 for (TInt pos=0 ; pos<charCount ;) |
|
105 { |
|
106 TFindFieldInfo infoOrig,infoCopy; |
|
107 anOriginal->FindFields(infoOrig,pos,charCount-pos); |
|
108 aCopy->FindFields(infoCopy,pos,charCount-pos); |
|
109 test(infoOrig==infoCopy); |
|
110 pos += infoOrig.iFirstFieldPos+infoOrig.iFirstFieldLen; |
|
111 if (infoOrig.iFieldCountInRange==0) |
|
112 break; |
|
113 } |
|
114 |
|
115 return ETrue; |
|
116 } |
|
117 |
|
118 |
|
119 LOCAL_C TBool UpdateField(TInt aPos,CTextFieldSet* aSet) |
|
120 { |
|
121 // find out which field aPos is in |
|
122 TFindFieldInfo info; |
|
123 TBool ret; |
|
124 ret=aSet->FindFields(info,aPos); |
|
125 test(ret); |
|
126 // get the new value |
|
127 HBufC* buf = HBufC::NewL(5); |
|
128 CleanupStack::PushL(buf); |
|
129 TInt err=aSet->NewFieldValueL(buf,aPos); |
|
130 test(err==KErrNone); |
|
131 // Notify FieldSet of update |
|
132 aSet->NotifyFieldUpdate(aPos,buf->Length()); |
|
133 // tidy up |
|
134 CleanupStack::PopAndDestroy(); |
|
135 return ret; |
|
136 } |
|
137 |
|
138 |
|
139 LOCAL_C void test2() |
|
140 // Streams an empty field set |
|
141 // |
|
142 { |
|
143 test.Next(_L("- streaming of a default FieldSet (no fields)")); |
|
144 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
|
145 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
|
146 TheFieldSetOriginal->Reset(); |
|
147 TheFieldSetCopy->Reset(); |
|
148 } |
|
149 |
|
150 |
|
151 LOCAL_C void test3() |
|
152 // Streams a field set containing 100 chars & 1 field |
|
153 // |
|
154 { |
|
155 test.Next(_L("- streaming with a field")); |
|
156 |
|
157 // insert a block of text into the original |
|
158 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
|
159 // insert a field into the original |
|
160 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
|
161 test(field!=NULL); |
|
162 TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 |
|
163 test(ret==KErrNone); |
|
164 ret=UpdateField(10,TheFieldSetOriginal); |
|
165 test(ret); |
|
166 |
|
167 // test streaming |
|
168 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
|
169 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
|
170 TheFieldSetOriginal->Reset(); |
|
171 TheFieldSetCopy->Reset(); |
|
172 } |
|
173 |
|
174 |
|
175 LOCAL_C void test4() |
|
176 // Streams a field set into a non-empty target |
|
177 // |
|
178 { |
|
179 test.Next(_L("- streaming into a non-empty target")); |
|
180 |
|
181 // insert a block of text into the original |
|
182 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
|
183 // insert a field into the original |
|
184 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
|
185 test(field!=NULL); |
|
186 TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 |
|
187 test(ret==KErrNone); |
|
188 ret=UpdateField(10,TheFieldSetOriginal); |
|
189 test(ret); |
|
190 |
|
191 // insert a block of text into the copy |
|
192 TheFieldSetCopy->NotifyInsertion(0,40); // pos=0, len=40 |
|
193 // insert two fields into the copy |
|
194 CTextField* field2 = TheFieldSetCopy->NewFieldL(KDummyFieldUid); |
|
195 CTextField* field3 = TheFieldSetCopy->NewFieldL(KDummyFieldUid); |
|
196 ret=TheFieldSetCopy->InsertFieldL(20,field2,KDummyFieldUid); |
|
197 test(ret==KErrNone); |
|
198 ret=TheFieldSetCopy->InsertFieldL(30,field3,KDummyFieldUid); |
|
199 test(ret==KErrNone); |
|
200 ret=UpdateField(20,TheFieldSetCopy); |
|
201 test(ret); |
|
202 ret=UpdateField(33,TheFieldSetCopy); |
|
203 test(ret); |
|
204 |
|
205 // test streaming |
|
206 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
|
207 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
|
208 TheFieldSetOriginal->Reset(); |
|
209 TheFieldSetCopy->Reset(); |
|
210 } |
|
211 |
|
212 |
|
213 LOCAL_C void test5() |
|
214 // Streams a field set containing an out of date field |
|
215 // |
|
216 { |
|
217 test.Next(_L("- streaming an out of date field")); |
|
218 |
|
219 // insert a block of text into the original |
|
220 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
|
221 // insert a field into the original |
|
222 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
|
223 test(field!=NULL); |
|
224 TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 |
|
225 test(ret==KErrNone); |
|
226 ret=UpdateField(10,TheFieldSetOriginal); |
|
227 test(ret); |
|
228 // invalidate the field |
|
229 TheFieldSetOriginal->NotifyInsertion(11,7); // pos=11, len=7 |
|
230 |
|
231 // test streaming |
|
232 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
|
233 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
|
234 TheFieldSetOriginal->Reset(); |
|
235 TheFieldSetCopy->Reset(); |
|
236 } |
|
237 |
|
238 |
|
239 LOCAL_C void test6() |
|
240 // Tests that copy/paste methods exist |
|
241 // |
|
242 { |
|
243 test.Next(_L("- testing copy/paste methods with empty array")); |
|
244 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,0,0,0); // copyPos,Len,PastePos |
|
245 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
|
246 TheFieldSetOriginal->Reset(); |
|
247 TheFieldSetCopy->Reset(); |
|
248 } |
|
249 |
|
250 |
|
251 LOCAL_C void test7() |
|
252 // Tests copy/paste methods in detail |
|
253 // |
|
254 { |
|
255 test.Next(_L("- testing copy/paste methods in detail")); |
|
256 // insert a block of text into the original |
|
257 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
|
258 // insert a field into the original |
|
259 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
|
260 test(field!=NULL); |
|
261 TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 |
|
262 test(ret==KErrNone); |
|
263 TBool ok=UpdateField(10,TheFieldSetOriginal); |
|
264 test(ok); |
|
265 test(TheFieldSetOriginal->CharCount()==103); |
|
266 // copy out of that into an empty array |
|
267 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,0); // copyPos,Len,PastePos |
|
268 // check that the contents of the array are as expected |
|
269 TFindFieldInfo info; |
|
270 TheFieldSetCopy->FindFields(info,0,15); |
|
271 test(TheFieldSetCopy->CharCount()==15); |
|
272 test(TheFieldSetCopy->FieldCount()==1); |
|
273 test(info.iFieldCountInRange==1); |
|
274 test(info.iFirstFieldPos==5); |
|
275 test(info.iFirstFieldLen==3); |
|
276 TheFieldSetCopy->Reset(); |
|
277 // test copying part of a field |
|
278 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,6,0); // copyPos,Len,PastePos |
|
279 TheFieldSetCopy->FindFields(info,0,6); |
|
280 test(TheFieldSetCopy->CharCount()==6); |
|
281 test(TheFieldSetCopy->FieldCount()==0); |
|
282 test(info.iFieldCountInRange==0); |
|
283 TheFieldSetCopy->Reset(); |
|
284 // test copying exactly one field |
|
285 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,0); // copyPos,Len,PastePos |
|
286 TheFieldSetCopy->FindFields(info,0,3); |
|
287 test(TheFieldSetCopy->CharCount()==3); |
|
288 test(TheFieldSetCopy->FieldCount()==1); |
|
289 test(info.iFieldCountInRange==1); |
|
290 test(info.iFirstFieldPos==0); |
|
291 test(info.iFirstFieldLen==3); |
|
292 TheFieldSetCopy->Reset(); |
|
293 // test pasting into text in a non-empty array |
|
294 TheFieldSetCopy->NotifyInsertion(0,50); // pos=0, len=50 |
|
295 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,10); // copyPos,Len,PastePos |
|
296 TheFieldSetCopy->FindFields(info,0,65); |
|
297 test(TheFieldSetCopy->CharCount()==65); |
|
298 test(TheFieldSetCopy->FieldCount()==1); |
|
299 test(info.iFieldCountInRange==1); |
|
300 test(info.iFirstFieldPos==15); |
|
301 test(info.iFirstFieldLen==3); |
|
302 TheFieldSetCopy->Reset(); |
|
303 // test pasting into a field |
|
304 TheFieldSetCopy->NotifyInsertion(0,50); // pos=0, len=50 |
|
305 field=TheFieldSetCopy->NewFieldL(KDummyFieldUid); |
|
306 test(field!=NULL); |
|
307 ret=TheFieldSetCopy->InsertFieldL(10,field,KDummyFieldUid); // pos=10 |
|
308 test(ret==KErrNone); |
|
309 ok=UpdateField(10,TheFieldSetCopy); |
|
310 test(ok); |
|
311 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,11); // copyPos,Len,PastePos |
|
312 TheFieldSetCopy->FindFields(info,0,68); |
|
313 test(TheFieldSetCopy->CharCount()==68); |
|
314 test(TheFieldSetCopy->FieldCount()==1); |
|
315 test(info.iFieldCountInRange==1); |
|
316 test(info.iFirstFieldPos==10); |
|
317 test(info.iFirstFieldLen==18); |
|
318 TheFieldSetCopy->Reset(); |
|
319 // test pasting at the start & end of a field |
|
320 TheFieldSetCopy->NotifyInsertion(0,10); // pos=0, len=10 |
|
321 field=TheFieldSetCopy->NewFieldL(KDummyFieldUid); |
|
322 test(field!=NULL); |
|
323 ret=TheFieldSetCopy->InsertFieldL(5,field,KDummyFieldUid); // pos=5 |
|
324 test(ret==KErrNone); |
|
325 ok=UpdateField(5,TheFieldSetCopy); |
|
326 test(ok); |
|
327 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,8); // copyPos,Len,PastePos |
|
328 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,5); // copyPos,Len,PastePos |
|
329 TheFieldSetCopy->FindFields(info,0,19); |
|
330 test(TheFieldSetCopy->CharCount()==19); |
|
331 test(TheFieldSetCopy->FieldCount()==3); |
|
332 test(info.iFieldCountInRange==3); |
|
333 test(info.iFirstFieldPos==5); |
|
334 test(info.iFirstFieldLen==3); |
|
335 TheFieldSetCopy->FindFields(info,8,11); |
|
336 test(info.iFieldCountInRange==2); |
|
337 test(info.iFirstFieldPos==8); |
|
338 test(info.iFirstFieldLen==3); |
|
339 TheFieldSetCopy->FindFields(info,11,8); |
|
340 test(info.iFieldCountInRange==1); |
|
341 test(info.iFirstFieldPos==11); |
|
342 test(info.iFirstFieldLen==3); |
|
343 // tidy up |
|
344 TheFieldSetOriginal->Reset(); |
|
345 TheFieldSetCopy->Reset(); |
|
346 } |
|
347 |
|
348 |
|
349 LOCAL_C void test8() |
|
350 // Tests paste method with restricted target length |
|
351 // |
|
352 { |
|
353 test.Next(_L("- testing paste method with restricted length")); |
|
354 // insert a block of text into the original |
|
355 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
|
356 // insert 2 fields into the original |
|
357 // 1... |
|
358 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
|
359 test(field!=NULL); |
|
360 TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 |
|
361 test(ret==KErrNone); |
|
362 TBool ok=UpdateField(10,TheFieldSetOriginal); |
|
363 test(ok); |
|
364 // 2.. |
|
365 field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
|
366 test(field!=NULL); |
|
367 ret=TheFieldSetOriginal->InsertFieldL(20,field,KDummyFieldUid); // pos=20 |
|
368 test(ret==KErrNone); |
|
369 ok=UpdateField(20,TheFieldSetOriginal); |
|
370 test(ok); |
|
371 // paste part of original into copy with length greater than required |
|
372 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,7); // copyPos,Len,PastePos,PasteLen |
|
373 TFindFieldInfo info; |
|
374 TheFieldSetCopy->FindFields(info,0,5); |
|
375 test(TheFieldSetCopy->CharCount()==5); |
|
376 test(TheFieldSetCopy->FieldCount()==1); |
|
377 test(info.iFieldCountInRange==1); |
|
378 test(info.iFirstFieldPos==0); |
|
379 test(info.iFirstFieldLen==3); |
|
380 TheFieldSetCopy->Reset(); |
|
381 // paste part of original into copy with length equal to that required |
|
382 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,5); // copyPos,Len,PastePos,PasteLen |
|
383 TheFieldSetCopy->FindFields(info,0,5); |
|
384 test(TheFieldSetCopy->CharCount()==5); |
|
385 test(TheFieldSetCopy->FieldCount()==1); |
|
386 test(info.iFieldCountInRange==1); |
|
387 test(info.iFirstFieldPos==0); |
|
388 test(info.iFirstFieldLen==3); |
|
389 TheFieldSetCopy->Reset(); |
|
390 // paste part of original into copy with length zero |
|
391 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,0); // copyPos,Len,PastePos,PasteLen |
|
392 test(TheFieldSetCopy->CharCount()==0); |
|
393 test(TheFieldSetCopy->FieldCount()==0); |
|
394 TheFieldSetCopy->Reset(); |
|
395 // paste part of original into copy with length st field is chopped |
|
396 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,10,0,6); // copyPos,Len,PastePos,PasteLen |
|
397 TheFieldSetCopy->FindFields(info,0,6); |
|
398 test(TheFieldSetCopy->CharCount()==6); |
|
399 test(TheFieldSetCopy->FieldCount()==0); |
|
400 test(info.iFieldCountInRange==0); |
|
401 TheFieldSetCopy->Reset(); |
|
402 // paste part of original into copy with length st one field is left off, the other pasted in |
|
403 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,20,0,10); // copyPos,Len,PastePos,PasteLen |
|
404 TheFieldSetCopy->FindFields(info,0,10); |
|
405 test(TheFieldSetCopy->CharCount()==10); |
|
406 test(TheFieldSetCopy->FieldCount()==1); |
|
407 test(info.iFieldCountInRange==1); |
|
408 test(info.iFirstFieldPos==5); |
|
409 test(info.iFirstFieldLen==3); |
|
410 // tidy up |
|
411 TheFieldSetOriginal->Reset(); |
|
412 TheFieldSetCopy->Reset(); |
|
413 } |
|
414 |
|
415 |
|
416 LOCAL_C void test9() |
|
417 // Tests paste into set with no field factory |
|
418 // Should convert all pasted fields to text... |
|
419 // |
|
420 { |
|
421 test.Next(_L("- testing paste into set with no field factory")); |
|
422 TheFieldSetCopy->SetFieldFactory(NULL); |
|
423 // insert a block of text into the original |
|
424 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
|
425 // insert a field into the original |
|
426 CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); |
|
427 test(field!=NULL); |
|
428 TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 |
|
429 test(ret==KErrNone); |
|
430 TBool ok=UpdateField(10,TheFieldSetOriginal); |
|
431 test(ok); |
|
432 // paste part of original into copy |
|
433 testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,25,0); // copyPos,Len,PastePos |
|
434 TFindFieldInfo info; |
|
435 TheFieldSetCopy->FindFields(info,0,25); |
|
436 test(TheFieldSetCopy->CharCount()==25); |
|
437 test(TheFieldSetCopy->FieldCount()==0); |
|
438 // tidy up |
|
439 TheFieldSetOriginal->Reset(); |
|
440 TheFieldSetCopy->Reset(); |
|
441 TheFieldSetCopy->SetFieldFactory(TheFactory); |
|
442 } |
|
443 |
|
444 |
|
445 LOCAL_C void test10() |
|
446 // Streams a field set containing 100 chars & 1 field |
|
447 // |
|
448 { |
|
449 test.Next(_L("- streaming CDateTimeField")); |
|
450 |
|
451 // insert a block of text into the original |
|
452 TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 |
|
453 // insert a field into the original |
|
454 CTextField* field=TheFieldSetOriginal->NewFieldL(KDateTimeFieldUid); |
|
455 test(field!=NULL); |
|
456 TBuf<14> buff = _L("%-A%*I%:1%T%+A"); |
|
457 ((CDateTimeField*)field)->SetFormat(buff); // 01:53pm |
|
458 TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDateTimeFieldUid); // pos=10 |
|
459 test(ret==KErrNone); |
|
460 ret=UpdateField(10,TheFieldSetOriginal); |
|
461 test(ret); |
|
462 // value before |
|
463 HBufC* miniBuf = HBufC::NewL(5); |
|
464 CleanupStack::PushL(miniBuf); |
|
465 ret=TheFieldSetOriginal->NewFieldValueL(miniBuf,10); // pos=10 |
|
466 test(ret==KErrNone); |
|
467 TPtr buf = miniBuf->Des(); |
|
468 test.Printf(_L(" Value before streaming: ")); |
|
469 test.Printf(buf); |
|
470 test.Printf(_L("\n")); |
|
471 // test streaming |
|
472 testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); |
|
473 test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); |
|
474 // value after |
|
475 ret=TheFieldSetCopy->NewFieldValueL(miniBuf,10); // pos=10 |
|
476 test(ret==KErrNone); |
|
477 buf = miniBuf->Des(); |
|
478 test.Printf(_L(" Value after streaming: ")); |
|
479 test.Printf(buf); |
|
480 test.Printf(_L("\n")); |
|
481 CleanupStack::PopAndDestroy(); // miniBuf |
|
482 TheFieldSetOriginal->Reset(); |
|
483 TheFieldSetCopy->Reset(); |
|
484 } |
|
485 |
|
486 |
|
487 void TestStreamingL() |
|
488 // |
|
489 // Test streaming of PrintSetup info. |
|
490 // Stream from one copy to another, then compare |
|
491 // |
|
492 { |
|
493 // create the PrintSetups |
|
494 test.Start(_L("Streaming CTextFieldSet")); |
|
495 |
|
496 // instantiate the factory and FieldSet |
|
497 TheFactory = new(ELeave) TTestFieldFactory(); |
|
498 TheFieldSetOriginal = CTextFieldSet::NewL(); |
|
499 TheFieldSetOriginal->SetFieldFactory(TheFactory); |
|
500 TheFieldSetCopy = CTextFieldSet::NewL(); |
|
501 TheFieldSetCopy->SetFieldFactory(TheFactory); |
|
502 |
|
503 // Use "original" with default settings & test stream |
|
504 test2(); |
|
505 |
|
506 // change data in original and test stream again |
|
507 test3(); |
|
508 |
|
509 // Stream a field set into a non-empty target |
|
510 test4(); |
|
511 |
|
512 // Stream a field set containing an out of date field |
|
513 test5(); |
|
514 |
|
515 // Test that copy/paste methods exist |
|
516 test6(); |
|
517 |
|
518 // Test copy/paste methods in detail |
|
519 test7(); |
|
520 |
|
521 // Test paste with limited target area |
|
522 test8(); |
|
523 |
|
524 // Test paste into set with no field factory |
|
525 test9(); |
|
526 |
|
527 // Test streaming of built-in types |
|
528 test10(); |
|
529 |
|
530 // end |
|
531 delete TheFieldSetOriginal; |
|
532 delete TheFieldSetCopy; |
|
533 delete TheFactory; |
|
534 } |
|
535 |
|
536 |
|
537 LOCAL_C void setupCleanup() |
|
538 // |
|
539 // Initialise the cleanup stack. |
|
540 // |
|
541 { |
|
542 |
|
543 TheTrapCleanup=CTrapCleanup::New(); |
|
544 TRAPD(r,\ |
|
545 {\ |
|
546 for (TInt i=KTestCleanupStack;i>0;i--)\ |
|
547 CleanupStack::PushL((TAny*)1);\ |
|
548 test(r==KErrNone);\ |
|
549 CleanupStack::Pop(KTestCleanupStack);\ |
|
550 }); |
|
551 } |
|
552 |
|
553 |
|
554 LOCAL_C void DeleteDataFile(const TDesC& aFullName) |
|
555 { |
|
556 RFs fsSession; |
|
557 TInt err = fsSession.Connect(); |
|
558 if(err == KErrNone) |
|
559 { |
|
560 TEntry entry; |
|
561 if(fsSession.Entry(aFullName, entry) == KErrNone) |
|
562 { |
|
563 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); |
|
564 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); |
|
565 if(err != KErrNone) |
|
566 { |
|
567 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); |
|
568 } |
|
569 err = fsSession.Delete(aFullName); |
|
570 if(err != KErrNone) |
|
571 { |
|
572 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); |
|
573 } |
|
574 } |
|
575 fsSession.Close(); |
|
576 } |
|
577 else |
|
578 { |
|
579 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); |
|
580 } |
|
581 } |
|
582 |
|
583 GLDEF_C TInt E32Main() |
|
584 // |
|
585 // Test streaming conversions. |
|
586 // |
|
587 { |
|
588 test.Title(); |
|
589 |
|
590 __UHEAP_MARK; |
|
591 setupCleanup(); |
|
592 |
|
593 TRAPD(r,TestStreamingL()); |
|
594 test(r==KErrNone); |
|
595 |
|
596 delete TheTrapCleanup; |
|
597 |
|
598 __UHEAP_MARKEND; |
|
599 |
|
600 ::DeleteDataFile(KTFieldOutputFile); //deletion of data files must be before call to End() - DEF047652 |
|
601 |
|
602 test.End(); |
|
603 test.Close(); |
|
604 |
|
605 return 0; |
|
606 } |
|
607 |