|
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 <e32std.h> |
|
20 #include <e32base.h> |
|
21 |
|
22 #include <gdi.h> |
|
23 #include <s32file.h> |
|
24 #include <e32test.h> |
|
25 |
|
26 #include <txtrich.h> |
|
27 #include <txtfmlyr.h> |
|
28 #include <txtfrmat.h> |
|
29 #include <txtstyle.h> |
|
30 |
|
31 #define UNUSED_VAR(a) a = a |
|
32 |
|
33 const TInt KTestCleanupStack=0x40; |
|
34 |
|
35 LOCAL_D RTest test(_L("Testing Paragraph Styles")); |
|
36 LOCAL_D CTrapCleanup* TheTrapCleanup; |
|
37 |
|
38 LOCAL_D CRichText* TheText; |
|
39 LOCAL_D CStyleList* TheStyleList; |
|
40 LOCAL_D CParaFormatLayer* TheNormalParaLayer; |
|
41 LOCAL_D CCharFormatLayer* TheNormalCharLayer; |
|
42 LOCAL_D CParagraphStyle* TheStyleOne; |
|
43 LOCAL_D CParagraphStyle* TheStyleTwo; |
|
44 |
|
45 |
|
46 _LIT(KOutputFile, "c:\\etext\\t_style.tst"); |
|
47 template <class T> |
|
48 void testStoreRestoreL(T& aCopy,const T& aOriginal) |
|
49 // Test document persistance. |
|
50 // |
|
51 { |
|
52 // set up the store |
|
53 RFs theFs; |
|
54 theFs.Connect(); |
|
55 // |
|
56 theFs.Delete(KOutputFile); |
|
57 theFs.MkDirAll(KOutputFile); |
|
58 CFileStore* theStore=CDirectFileStore::CreateL(theFs,KOutputFile,EFileRead|EFileWrite); |
|
59 CleanupStack::PushL(theStore); |
|
60 theStore->SetTypeL(KDirectFileStoreLayoutUid); |
|
61 // |
|
62 // store the original |
|
63 TStreamId id(0); |
|
64 TRAPD(ret,id=aOriginal.StoreL(*theStore)); |
|
65 test(ret==KErrNone); |
|
66 // |
|
67 // restore into the copy |
|
68 TRAP(ret,aCopy.RestoreL(*theStore,id)); |
|
69 test(ret==KErrNone); |
|
70 // |
|
71 // tidy up |
|
72 CleanupStack::PopAndDestroy(); // theStore |
|
73 theFs.Close(); |
|
74 } |
|
75 |
|
76 |
|
77 LOCAL_C TInt IsEqual(const CRichText* aCopy,const CRichText* aOriginal) |
|
78 // |
|
79 // Returns true if aCopy contents matches aOriginal contents. |
|
80 // Takes account of multiple segments of a segmented text component. |
|
81 // |
|
82 { |
|
83 TInt lengthOfOriginal=aOriginal->DocumentLength(); |
|
84 TInt lengthOfCopy=aCopy->DocumentLength(); |
|
85 test(lengthOfOriginal==lengthOfCopy); |
|
86 // |
|
87 TPtrC copy,orig; |
|
88 // |
|
89 TInt lengthRead=0; |
|
90 while(lengthRead<=lengthOfOriginal) |
|
91 { |
|
92 copy.Set((aCopy->Read(lengthRead))); |
|
93 orig.Set((aOriginal->Read(lengthRead))); |
|
94 for (TInt offset=0; offset<orig.Length(); offset++) |
|
95 test(copy[offset]==orig[offset]); |
|
96 lengthRead+=orig.Length(); |
|
97 } |
|
98 test(lengthRead==lengthOfOriginal+1); |
|
99 // |
|
100 CStyleList* origStyle=aOriginal->StyleList(); |
|
101 CStyleList* copyStyle=aCopy->StyleList(); |
|
102 TInt origStyleCount=origStyle->Count(); |
|
103 TInt copyStyleCount=copyStyle->Count(); |
|
104 test(origStyleCount==copyStyleCount); |
|
105 for (TInt ii=0;ii<origStyleCount;ii++) |
|
106 { |
|
107 RParagraphStyleInfo oInfo=origStyle->At(ii); |
|
108 RParagraphStyleInfo cInfo=copyStyle->At(ii); |
|
109 test(oInfo.iStyle->iName==cInfo.iStyle->iName); |
|
110 if (oInfo.iStyleForNextPara==NULL) |
|
111 test(cInfo.iStyleForNextPara==NULL); |
|
112 } |
|
113 |
|
114 return 1; |
|
115 } |
|
116 |
|
117 |
|
118 LOCAL_C void ConstructEnvWithNullParaFormat() |
|
119 { |
|
120 // Create global layers |
|
121 CParaFormat* normalPara=CParaFormat::NewLC(); |
|
122 TParaFormatMask paraFormatMask; |
|
123 normalPara->iHorizontalAlignment=CParaFormat::ELeftAlign; |
|
124 paraFormatMask.SetAttrib(EAttAlignment); |
|
125 TheNormalParaLayer=CParaFormatLayer::NewL(normalPara,paraFormatMask); |
|
126 CleanupStack::PopAndDestroy(); // normalPara |
|
127 TCharFormat charFormat; |
|
128 TCharFormatMask charFormatMask; |
|
129 TheNormalCharLayer=CCharFormatLayer::NewL(charFormat,charFormatMask); |
|
130 // |
|
131 // Create some paragraph styles |
|
132 TheStyleOne=CParagraphStyle::NewL(*TheNormalParaLayer,*TheNormalCharLayer); |
|
133 TheStyleOne->iName=_L("Style1"); |
|
134 |
|
135 // Style two is based on style one |
|
136 TheStyleTwo=CParagraphStyle::NewL( *TheStyleOne, *(TheStyleOne->CharFormatLayer())); |
|
137 TheStyleTwo->iName=_L("Style2"); |
|
138 // |
|
139 CParaFormat* styleFormat=CParaFormat::NewLC(); |
|
140 TParaFormatMask styleMask; |
|
141 styleFormat->iHorizontalAlignment=CParaFormat::ECenterAlign; |
|
142 styleMask.SetAttrib(EAttAlignment); |
|
143 TheStyleOne->SetL(styleFormat,styleMask); |
|
144 // |
|
145 styleFormat->iHorizontalAlignment=CParaFormat::ERightAlign; |
|
146 // Set paragraph format to NULL |
|
147 TheStyleTwo->SetL( NULL,styleMask); |
|
148 CleanupStack::PopAndDestroy(); // styleFormat |
|
149 // |
|
150 // Create style table and insert styles. |
|
151 TheStyleList=CStyleList::NewL(); |
|
152 RParagraphStyleInfo info(TheStyleOne); |
|
153 TInt error=TheStyleList->AppendL(&info); |
|
154 test(error==KErrNone); |
|
155 RParagraphStyleInfo info1=TheStyleList->At(0); |
|
156 CParagraphStyle* style=info1.iStyle; |
|
157 style=NULL; |
|
158 |
|
159 RParagraphStyleInfo info2(TheStyleTwo,TheStyleOne); |
|
160 error=TheStyleList->AppendL(&info2); |
|
161 test(error==KErrNone); |
|
162 |
|
163 error=TheStyleList->AppendL(&info2); |
|
164 test(error==KErrAlreadyExists); |
|
165 test(TheStyleList->Count()==2); |
|
166 |
|
167 style=TheStyleList->At(1).iStyle; |
|
168 test(style->iName==_L("Style2")); |
|
169 // |
|
170 // Create the rich text with styles. |
|
171 TheText=CRichText::NewL(TheNormalParaLayer,TheNormalCharLayer,*TheStyleList); |
|
172 } |
|
173 |
|
174 LOCAL_C void ConstructEnvironment() |
|
175 // Create some styles. |
|
176 // |
|
177 { |
|
178 // Create global layers |
|
179 CParaFormat* normalPara=CParaFormat::NewLC(); |
|
180 TParaFormatMask paraFormatMask; |
|
181 normalPara->iHorizontalAlignment=CParaFormat::ELeftAlign; |
|
182 paraFormatMask.SetAttrib(EAttAlignment); |
|
183 TheNormalParaLayer=CParaFormatLayer::NewL(normalPara,paraFormatMask); |
|
184 CleanupStack::PopAndDestroy(); // normalPara |
|
185 TCharFormat charFormat; |
|
186 TCharFormatMask charFormatMask; |
|
187 TheNormalCharLayer=CCharFormatLayer::NewL(charFormat,charFormatMask); |
|
188 // |
|
189 // Create some paragraph styles |
|
190 TheStyleOne=CParagraphStyle::NewL(*TheNormalParaLayer,*TheNormalCharLayer); |
|
191 TheStyleOne->iName=_L("Style1"); |
|
192 TheStyleTwo=CParagraphStyle::NewL(*TheNormalParaLayer,*TheNormalCharLayer); |
|
193 TheStyleTwo->iName=_L("Style2"); |
|
194 // |
|
195 CParaFormat* styleFormat=CParaFormat::NewLC(); |
|
196 TParaFormatMask styleMask; |
|
197 styleFormat->iHorizontalAlignment=CParaFormat::ECenterAlign; |
|
198 styleMask.SetAttrib(EAttAlignment); |
|
199 TheStyleOne->SetL(styleFormat,styleMask); |
|
200 // |
|
201 styleFormat->iHorizontalAlignment=CParaFormat::ERightAlign; |
|
202 TheStyleTwo->SetL(styleFormat,styleMask); |
|
203 CleanupStack::PopAndDestroy(); // styleFormat |
|
204 // |
|
205 // Create style table and insert styles. |
|
206 TheStyleList=CStyleList::NewL(); |
|
207 RParagraphStyleInfo info(TheStyleOne); |
|
208 TInt error=TheStyleList->AppendL(&info); |
|
209 test(error==KErrNone); |
|
210 RParagraphStyleInfo info1=TheStyleList->At(0); |
|
211 CParagraphStyle* style=info1.iStyle; |
|
212 style=NULL; |
|
213 |
|
214 RParagraphStyleInfo info2(TheStyleTwo,TheStyleOne); |
|
215 error=TheStyleList->AppendL(&info2); |
|
216 test(error==KErrNone); |
|
217 |
|
218 error=TheStyleList->AppendL(&info2); |
|
219 test(error==KErrAlreadyExists); |
|
220 test(TheStyleList->Count()==2); |
|
221 |
|
222 style=TheStyleList->At(1).iStyle; |
|
223 test(style->iName==_L("Style2")); |
|
224 // |
|
225 // Create the rich text with styles. |
|
226 TheText=CRichText::NewL(TheNormalParaLayer,TheNormalCharLayer,*TheStyleList); |
|
227 } |
|
228 |
|
229 |
|
230 LOCAL_C void KillEnvironment() |
|
231 // Kill everything |
|
232 // |
|
233 { |
|
234 delete TheText; |
|
235 // the style table is owned by the rich text, and is destroyed there. |
|
236 delete TheNormalParaLayer; |
|
237 delete TheNormalCharLayer; |
|
238 } |
|
239 |
|
240 |
|
241 LOCAL_C void TestConstruction() |
|
242 // Test the construction/destruction of rich text with styles |
|
243 // |
|
244 { |
|
245 __UHEAP_MARK; |
|
246 |
|
247 ConstructEnvironment(); |
|
248 KillEnvironment(); |
|
249 |
|
250 __UHEAP_MARKEND; |
|
251 } |
|
252 |
|
253 |
|
254 LOCAL_C void TestParaWithNullParaFormat() |
|
255 { |
|
256 CParagraphStyle::TApplyParaStyleMode applyMode=CParagraphStyle::ERetainNoSpecificFormats; |
|
257 |
|
258 test.Next(_L("Apply style to paragraph with NULL para format")); |
|
259 ConstructEnvWithNullParaFormat(); |
|
260 TheText->InsertL(0,_L("HEADINGBODYTEXT")); |
|
261 // |
|
262 TheText->ApplyParagraphStyleL(*TheStyleList->At(1).iStyle,0,1,applyMode); |
|
263 CParaFormat* paraFormat=CParaFormat::NewLC(); |
|
264 TheText->GetParagraphFormatL(paraFormat,0); |
|
265 test(paraFormat->iHorizontalAlignment==CParaFormat::ECenterAlign); |
|
266 // |
|
267 TChar delimiter=CEditableText::EParagraphDelimiter; |
|
268 TheText->InsertL(7,delimiter); |
|
269 TheText->GetParagraphFormatL(paraFormat,6); |
|
270 test(paraFormat->iHorizontalAlignment==CParaFormat::ECenterAlign); |
|
271 TheText->GetParagraphFormatL(paraFormat,8); |
|
272 test(paraFormat->iHorizontalAlignment==CParaFormat::ECenterAlign); |
|
273 CleanupStack::PopAndDestroy(); |
|
274 KillEnvironment(); |
|
275 } |
|
276 |
|
277 LOCAL_C void TestSharedPara() |
|
278 // Test |
|
279 // |
|
280 { |
|
281 CParagraphStyle::TApplyParaStyleMode applyMode=CParagraphStyle::ERetainNoSpecificFormats; |
|
282 |
|
283 test.Next(_L("Apply style to shared paragraph")); |
|
284 ConstructEnvironment(); |
|
285 TheText->InsertL(0,_L("HEADINGBODYTEXT")); |
|
286 // |
|
287 TheText->ApplyParagraphStyleL(*TheStyleList->At(0).iStyle,0,1,applyMode); |
|
288 CParaFormat* paraFormat=CParaFormat::NewLC(); |
|
289 TheText->GetParagraphFormatL(paraFormat,0); |
|
290 test(paraFormat->iHorizontalAlignment==CParaFormat::ECenterAlign); |
|
291 // |
|
292 TChar delimiter=CEditableText::EParagraphDelimiter; |
|
293 TheText->InsertL(7,delimiter); |
|
294 TheText->GetParagraphFormatL(paraFormat,6); |
|
295 test(paraFormat->iHorizontalAlignment==CParaFormat::ECenterAlign); |
|
296 TheText->GetParagraphFormatL(paraFormat,8); |
|
297 test(paraFormat->iHorizontalAlignment==CParaFormat::ECenterAlign); |
|
298 CleanupStack::PopAndDestroy(); |
|
299 KillEnvironment(); |
|
300 } |
|
301 |
|
302 |
|
303 LOCAL_C void TestNonSharedPara() |
|
304 // |
|
305 { |
|
306 CParagraphStyle::TApplyParaStyleMode applyMode=CParagraphStyle::ERetainNoSpecificFormats; |
|
307 |
|
308 test.Next(_L("Apply style to non-shared paragraph")); |
|
309 ConstructEnvironment(); |
|
310 // |
|
311 TheText->InsertL(0,_L("This is paragraph one.This is paragraph number two.")); |
|
312 TChar delimiter=CEditableText::EParagraphDelimiter; |
|
313 TheText->InsertL(22,delimiter); |
|
314 // |
|
315 TCharFormat charFormat; |
|
316 TCharFormatMask charFormatMask; |
|
317 charFormat.iFontPresentation.iStrikethrough=EStrikethroughOn; |
|
318 charFormatMask.SetAttrib(EAttFontStrikethrough); |
|
319 TheText->ApplyCharFormatL(charFormat,charFormatMask,0,4); |
|
320 // |
|
321 TheText->ApplyParagraphStyleL(*(TheStyleList->At(1).iStyle),0,TheText->DocumentLength(),applyMode); |
|
322 // |
|
323 CParaFormat* paraFormat=CParaFormat::NewLC(); |
|
324 TheText->GetParagraphFormatL(paraFormat,0); |
|
325 test(paraFormat->iHorizontalAlignment=CParaFormat::ERightAlign); |
|
326 // |
|
327 TheText->GetParagraphFormatL(paraFormat,10); |
|
328 test(paraFormat->iHorizontalAlignment=CParaFormat::ERightAlign); |
|
329 // |
|
330 TheText->GetParagraphFormatL(paraFormat,30); |
|
331 test(paraFormat->iHorizontalAlignment=CParaFormat::ERightAlign); |
|
332 // |
|
333 CleanupStack::PopAndDestroy(); // para format |
|
334 // |
|
335 /*TEtextComponentInfo info=*/TheText->ComponentInfo(); |
|
336 CRichText* theCopy=CRichText::NewL(TheNormalParaLayer,TheNormalCharLayer); |
|
337 testStoreRestoreL(*theCopy,*TheText); |
|
338 test(IsEqual(theCopy,TheText)); |
|
339 // |
|
340 theCopy->ApplyParagraphStyleL(*(TheStyleList->At(0).iStyle),25,1,applyMode); |
|
341 CParagraphStyle* tempStyle = CParagraphStyle::NewL(*TheNormalParaLayer,*TheNormalCharLayer); |
|
342 theCopy->InsertL(28,delimiter); |
|
343 theCopy->InsertL(31,delimiter); |
|
344 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
345 charFormatMask.ClearAll(); |
|
346 charFormatMask.SetAttrib(EAttFontStrokeWeight); |
|
347 theCopy->ApplyCharFormatL(charFormat, charFormatMask, 33, 1); |
|
348 theCopy->NotifyStyleChangedL(tempStyle, TheStyleList->At(0).iStyle); |
|
349 // |
|
350 delete theCopy; |
|
351 delete tempStyle; |
|
352 KillEnvironment(); |
|
353 } |
|
354 |
|
355 |
|
356 LOCAL_C void TestStyles() |
|
357 // Perform tests |
|
358 // |
|
359 { |
|
360 TestSharedPara(); |
|
361 TestNonSharedPara(); |
|
362 } |
|
363 |
|
364 LOCAL_C void TestStyleWithNullParaFormat() |
|
365 { |
|
366 TestParaWithNullParaFormat(); |
|
367 } |
|
368 |
|
369 LOCAL_C void TestStyleList() |
|
370 { |
|
371 __UHEAP_MARK; |
|
372 // Test 1 |
|
373 // Construction under OOM |
|
374 test.Start(_L("Construction under OOM")); |
|
375 CStyleList* list=NULL; |
|
376 TInt nn; |
|
377 for (nn=0; ;nn++) |
|
378 { |
|
379 __UHEAP_RESET; |
|
380 __UHEAP_SETFAIL(RHeap::EDeterministic,nn); |
|
381 __UHEAP_MARK; |
|
382 TRAPD(ret, |
|
383 list=CStyleList::NewL()); |
|
384 if (ret!=KErrNone) |
|
385 { |
|
386 __UHEAP_MARKEND; |
|
387 test(list==NULL); |
|
388 } |
|
389 else |
|
390 { |
|
391 test(list!=NULL); |
|
392 delete list; |
|
393 list=NULL; |
|
394 __UHEAP_MARKEND; |
|
395 break; |
|
396 } |
|
397 } |
|
398 __UHEAP_RESET; |
|
399 TBuf<36> answer; |
|
400 answer.Format(_L(" #allocs for full c'tion: %d\n"),nn-1); |
|
401 test.Printf(answer); |
|
402 |
|
403 |
|
404 // Test 2 |
|
405 // Populated style list, Append under OOM; |
|
406 test.Next(_L("AppendL() under OOM")); |
|
407 CParaFormatLayer* paraLayer=CParaFormatLayer::NewL(); |
|
408 CCharFormatLayer* charLayer=CCharFormatLayer::NewL(); |
|
409 __UHEAP_MARK; |
|
410 list=CStyleList::NewL(); |
|
411 CParagraphStyle* style=NULL; |
|
412 for (TInt mm=0;mm<KMaxStyleListGranularity;mm++) |
|
413 { |
|
414 style=CParagraphStyle::NewL(*paraLayer,*charLayer); |
|
415 RParagraphStyleInfo info(style,NULL); |
|
416 TInt r=list->AppendL(&info); |
|
417 test(r==KErrNone); |
|
418 } |
|
419 test(list->Count()==KMaxStyleListGranularity); |
|
420 |
|
421 for (TInt oo=0; ;oo++) |
|
422 { |
|
423 style=CParagraphStyle::NewL(*paraLayer,*charLayer); |
|
424 RParagraphStyleInfo info(style); |
|
425 __UHEAP_RESET; |
|
426 __UHEAP_SETFAIL(RHeap::EDeterministic,oo); |
|
427 TInt r=KErrNone; |
|
428 TRAPD(ret, |
|
429 r=list->AppendL(&info)); |
|
430 if (ret!=KErrNone) |
|
431 { |
|
432 test(r!=KErrAlreadyExists); |
|
433 test(list->Count()==KMaxStyleListGranularity); |
|
434 } |
|
435 else |
|
436 { |
|
437 test(r==KErrNone); |
|
438 test(list->Count()==KMaxStyleListGranularity+1); |
|
439 break; |
|
440 } |
|
441 __UHEAP_RESET; |
|
442 } |
|
443 delete list; |
|
444 list=NULL; |
|
445 style=NULL; |
|
446 __UHEAP_MARKEND; |
|
447 __UHEAP_RESET; |
|
448 |
|
449 |
|
450 // Test 3 |
|
451 // Inserting a duplicate |
|
452 test.Next(_L("AppendL() a duplicate")); |
|
453 list=CStyleList::NewL(); |
|
454 style=NULL; |
|
455 for (TInt pp=0;pp<KMaxStyleListGranularity;pp++) |
|
456 { |
|
457 style=CParagraphStyle::NewL(*paraLayer,*charLayer); |
|
458 RParagraphStyleInfo info(style,NULL); |
|
459 list->AppendL(&info); |
|
460 } |
|
461 test(list->Count()==KMaxStyleListGranularity); |
|
462 RParagraphStyleInfo info=list->At(0); |
|
463 TInt r=list->AppendL(&info); |
|
464 test(r==KErrAlreadyExists); |
|
465 test(list->Count()==KMaxStyleListGranularity); |
|
466 test(info.iStyle->CharFormatLayer()!=NULL); // the duplicate style has not been deleted. |
|
467 delete list; |
|
468 |
|
469 |
|
470 // Test 4 |
|
471 // Looking for a style by name that does not exist. |
|
472 test.Next(_L("IndexByName() where style not present")); |
|
473 list=CStyleList::NewL(); |
|
474 style=NULL; |
|
475 TUint name='A'; |
|
476 for (TInt qq=0;qq<KMaxStyleListGranularity;qq++) |
|
477 { |
|
478 style=CParagraphStyle::NewL(*paraLayer,*charLayer); |
|
479 style->iName.Append(name); |
|
480 name++; |
|
481 RParagraphStyleInfo info(style,NULL); |
|
482 list->AppendL(&info); |
|
483 } |
|
484 test(list->Count()==KMaxStyleListGranularity); |
|
485 TParagraphStyleName search=_L("not present"); |
|
486 /*TInt index=*/list->IndexByName(search); |
|
487 |
|
488 delete list; |
|
489 |
|
490 delete paraLayer; |
|
491 delete charLayer; |
|
492 |
|
493 __UHEAP_MARKEND; |
|
494 test.End(); |
|
495 } |
|
496 |
|
497 |
|
498 LOCAL_C void TestHarness() |
|
499 // Test rich text style usage. |
|
500 // |
|
501 { |
|
502 test.Start(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_STYLE-0001 RichText Styles ")); |
|
503 // Do the tests. |
|
504 TestConstruction(); |
|
505 TestStyles(); |
|
506 TestStyleWithNullParaFormat(); |
|
507 test.Next(_L("CStyleList")); |
|
508 TestStyleList(); |
|
509 // |
|
510 } |
|
511 |
|
512 |
|
513 LOCAL_C void setupCleanup() |
|
514 // |
|
515 // Initialise the cleanup stack. |
|
516 // |
|
517 { |
|
518 |
|
519 TheTrapCleanup=CTrapCleanup::New(); |
|
520 TRAPD(r,\ |
|
521 {\ |
|
522 for (TInt i=KTestCleanupStack;i>0;i--)\ |
|
523 CleanupStack::PushL((TAny*)1);\ |
|
524 test(r==KErrNone);\ |
|
525 CleanupStack::Pop(KTestCleanupStack);\ |
|
526 }); |
|
527 } |
|
528 |
|
529 |
|
530 LOCAL_C void DeleteDataFile(const TDesC& aFullName) |
|
531 { |
|
532 RFs fsSession; |
|
533 TInt err = fsSession.Connect(); |
|
534 if(err == KErrNone) |
|
535 { |
|
536 TEntry entry; |
|
537 if(fsSession.Entry(aFullName, entry) == KErrNone) |
|
538 { |
|
539 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); |
|
540 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); |
|
541 if(err != KErrNone) |
|
542 { |
|
543 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); |
|
544 } |
|
545 err = fsSession.Delete(aFullName); |
|
546 if(err != KErrNone) |
|
547 { |
|
548 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); |
|
549 } |
|
550 } |
|
551 fsSession.Close(); |
|
552 } |
|
553 else |
|
554 { |
|
555 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); |
|
556 } |
|
557 } |
|
558 |
|
559 GLDEF_C TInt E32Main() |
|
560 // |
|
561 // Test the streaming framework. |
|
562 // |
|
563 { |
|
564 |
|
565 test.Title(); |
|
566 __UHEAP_MARK; |
|
567 setupCleanup(); |
|
568 TRAPD(r,TestHarness()); |
|
569 test(r == KErrNone); |
|
570 |
|
571 delete TheTrapCleanup; |
|
572 |
|
573 __UHEAP_MARKEND; |
|
574 |
|
575 ::DeleteDataFile(KOutputFile); //deletion of data files must be before call to End() - DEF047652 |
|
576 |
|
577 test.End(); |
|
578 test.Close(); |
|
579 |
|
580 return 0; |
|
581 } |