|
1 /* |
|
2 * Copyright (c) 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 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32svr.h> |
|
23 #include <StifParser.h> |
|
24 #include <Stiftestinterface.h> |
|
25 #include<iostream> |
|
26 #include<fstream> |
|
27 #include<string> |
|
28 #include<ostream> |
|
29 #include <sstream> |
|
30 #include<strstream> |
|
31 #include<deque> |
|
32 #include<iterator> |
|
33 #include<vector> |
|
34 #include <ios> |
|
35 #include <iostream> |
|
36 #include <fstream> |
|
37 #include <stl/char_traits.h> |
|
38 #include <new> |
|
39 #include<e32std.h> |
|
40 |
|
41 #include<exception> |
|
42 |
|
43 #include "tiostreams.h" |
|
44 using namespace std; |
|
45 #define STDCPP_OOM FALSE// TRUE for OOM testing |
|
46 |
|
47 |
|
48 // ============================ MEMBER FUNCTIONS =============================== |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // Ctiostreams::Delete |
|
52 // Delete here all resources allocated and opened from test methods. |
|
53 // Called from destructor. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void Ctiostreams::Delete() |
|
57 { |
|
58 |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // Ctiostreams::RunMethodL |
|
63 // Run specified method. Contains also table of test mothods and their names. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 TInt Ctiostreams::RunMethodL( |
|
67 CStifItemParser& aItem ) |
|
68 { |
|
69 |
|
70 static TStifFunctionInfo const KFunctions[] = |
|
71 { |
|
72 // Copy this line for every implemented function. |
|
73 // First string is the function name used in TestScripter script file. |
|
74 // Second is the actual implementation member function. |
|
75 // Second is the actual implementation member function. |
|
76 ENTRY( "iofstreamL", Ctiostreams::iofstreamL ), |
|
77 ENTRY( "stringbufL", Ctiostreams::stringbufL ), |
|
78 ENTRY( "stringstreamL", Ctiostreams::stringstreamL ), |
|
79 ENTRY( "streambufL", Ctiostreams:: streambufL ), |
|
80 ENTRY( "ostreamL", Ctiostreams:: ostreamL ), |
|
81 ENTRY( "istreamL", Ctiostreams:: istreamL ), |
|
82 ENTRY( "istringstreamL", Ctiostreams:: istringstreamL ), |
|
83 ENTRY( "ostringstreamL", Ctiostreams:: ostringstreamL ), |
|
84 ENTRY( "ostreamiterators", Ctiostreams::ostreamiterators ), |
|
85 ENTRY( "fstreamL", Ctiostreams::fstreamL), |
|
86 ENTRY( "istrstreamL", Ctiostreams::istrstreamL), |
|
87 ENTRY( "strstreamL", Ctiostreams::strstreamL), |
|
88 ENTRY( "ostrstreamL", Ctiostreams::ostrstreamL), |
|
89 ENTRY( "istreamiterators", Ctiostreams::istreamiterators ), |
|
90 ENTRY( "istreambufiterators", Ctiostreams::istreambufiterators ), |
|
91 ENTRY( "strstreambufL", Ctiostreams::strstreambufL ), |
|
92 ENTRY( "freezeL", Ctiostreams::freezeL ), |
|
93 ENTRY( "fposL", Ctiostreams::fposL ), |
|
94 ENTRY( "filebufL", Ctiostreams::filebufL ), |
|
95 ENTRY( "seekpL", Ctiostreams::seekpL ), |
|
96 |
|
97 |
|
98 }; |
|
99 |
|
100 const TInt count = sizeof( KFunctions ) / |
|
101 sizeof( TStifFunctionInfo ); |
|
102 |
|
103 return RunInternalL( KFunctions, count, aItem ); |
|
104 |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // Ctiostreams:: ofstream,ifstream |
|
110 // Example test method function. |
|
111 // (other items were commented in a header). |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 |
|
115 |
|
116 TInt Ctiostreams::iofstreamL( CStifItemParser& aItem ) |
|
117 { |
|
118 |
|
119 |
|
120 //__UHEAP_MARK; |
|
121 int failures=0 ; |
|
122 try |
|
123 { |
|
124 cout<<""; |
|
125 #if STDCPP_OOM |
|
126 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
127 #endif |
|
128 ofstream myfile; |
|
129 filebuf *fbuf; |
|
130 char * buffer; |
|
131 long size; |
|
132 //ifstream |
|
133 myfile.open ("c:\\TestFramework\\docs\\example.txt"); |
|
134 if(!myfile.is_open()) |
|
135 failures++; |
|
136 |
|
137 myfile << "Writing this to a file."; |
|
138 myfile<<"\0"; |
|
139 myfile.close(); |
|
140 if(myfile.is_open()) |
|
141 failures++; |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 // string line; |
|
147 ifstream myfile1; |
|
148 |
|
149 |
|
150 myfile1.open("c:\\TestFramework\\docs\\example.txt" ); |
|
151 |
|
152 fbuf=myfile1.rdbuf(); |
|
153 |
|
154 |
|
155 // get file size using buffer's members |
|
156 size=fbuf->pubseekoff (0,ios::end,ios::in); |
|
157 fbuf->pubseekpos (0,ios::in); |
|
158 |
|
159 // allocate memory to contain file data |
|
160 buffer=new char[size]; |
|
161 |
|
162 // get file data |
|
163 fbuf->sgetn (buffer,size); |
|
164 |
|
165 #if STDCPP_OOM |
|
166 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
167 #endif |
|
168 |
|
169 |
|
170 if(buffer != "Writing this to a file."); |
|
171 else |
|
172 failures++; |
|
173 |
|
174 if(size!= 23) |
|
175 failures++; |
|
176 |
|
177 |
|
178 if(!myfile1.is_open()) |
|
179 failures++; |
|
180 myfile1.close(); |
|
181 if(myfile1.is_open()) |
|
182 failures++; |
|
183 |
|
184 delete buffer; |
|
185 ios_base::Init(); // 0 - 218 FUNCTION Init() iostream.cpp |
|
186 filebuf* _Stl_create_filebuf(FILE* f, ios_base::openmode mode ); // 0 - 225 FUNCTION _Stl_create_filebuf() iostream.cpp |
|
187 ios_base::sync_with_stdio();//0 - 445 FUNCTION ios_base::sync_with_stdio() |
|
188 /* |
|
189 if(failures) |
|
190 |
|
191 return KErrGeneral; |
|
192 return KErrNone; |
|
193 |
|
194 */ |
|
195 |
|
196 |
|
197 //#if STDCPP_OOM |
|
198 //failures++; |
|
199 // #endif |
|
200 |
|
201 } |
|
202 |
|
203 catch(bad_alloc&) |
|
204 { |
|
205 //do nothing |
|
206 } |
|
207 catch(...) |
|
208 { |
|
209 failures++; |
|
210 |
|
211 } |
|
212 |
|
213 if( failures == 0 ) |
|
214 return KErrNone; |
|
215 else |
|
216 return KErrGeneral; |
|
217 |
|
218 } |
|
219 |
|
220 |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // Ctiostreams:: stringbuf |
|
224 // Example test method function. |
|
225 // (other items were commented in a header). |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 |
|
229 TInt Ctiostreams::stringbufL(CStifItemParser& aItem ) |
|
230 { |
|
231 |
|
232 int failures = 0; |
|
233 try |
|
234 { |
|
235 cout<<""; |
|
236 #if STDCPP_OOM |
|
237 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
238 #endif |
|
239 stringbuf sb; |
|
240 string mystr; |
|
241 |
|
242 sb.sputn("Sample string",13); |
|
243 mystr=sb.str(); |
|
244 |
|
245 |
|
246 |
|
247 if(sb.in_avail()!=13) |
|
248 failures++; |
|
249 |
|
250 |
|
251 char ch = sb.sgetc(); |
|
252 if(ch!= 'S') |
|
253 failures++; |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 if(mystr.compare("Sample string") != 0) |
|
261 failures++; |
|
262 |
|
263 #if STDCPP_OOM |
|
264 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
265 #endif |
|
266 /* if(failures) |
|
267 |
|
268 return KErrGeneral; |
|
269 else |
|
270 return KErrNone; |
|
271 */ |
|
272 |
|
273 |
|
274 //#if STDCPP_OOM |
|
275 //failures++; |
|
276 // #endif |
|
277 |
|
278 } |
|
279 |
|
280 catch(bad_alloc&) |
|
281 { |
|
282 //do nothing |
|
283 } |
|
284 catch(...) |
|
285 { |
|
286 failures++; |
|
287 |
|
288 } |
|
289 |
|
290 if( failures == 0 ) |
|
291 return KErrNone; |
|
292 else |
|
293 return KErrGeneral; |
|
294 } |
|
295 // ----------------------------------------------------------------------------- |
|
296 // Ctiostreams:: stringstream |
|
297 // Example test method function. |
|
298 // (other items were commented in a header). |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 |
|
302 |
|
303 TInt Ctiostreams::stringstreamL(CStifItemParser& aItem ) |
|
304 { |
|
305 |
|
306 int val; |
|
307 string teststr; |
|
308 int failures = 0; |
|
309 try |
|
310 { |
|
311 cout<<""; |
|
312 #if STDCPP_OOM |
|
313 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
314 #endif |
|
315 stringstream ss (stringstream::in | stringstream::out); |
|
316 stringstream teststring; |
|
317 |
|
318 |
|
319 teststring<<"stringstream testcase"; |
|
320 |
|
321 teststr = teststring.str(); |
|
322 |
|
323 if(!teststr.compare("stringstream testcase")) |
|
324 ; |
|
325 else |
|
326 failures++; |
|
327 |
|
328 ss << "120 42 377 6 5 2000"; |
|
329 #if STDCPP_OOM |
|
330 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
331 #endif |
|
332 for (int n=0; n<6; n++) |
|
333 { |
|
334 ss >> val; |
|
335 |
|
336 switch(n) |
|
337 { |
|
338 case 0://precision |
|
339 if(val!=120) |
|
340 failures++; |
|
341 break; |
|
342 case 1: |
|
343 if(val!=42) |
|
344 failures++; |
|
345 break; |
|
346 case 2: |
|
347 if(val!=377) |
|
348 failures++; |
|
349 break; |
|
350 case 3: |
|
351 if(val!=6) |
|
352 failures++; |
|
353 break; |
|
354 |
|
355 case 4: |
|
356 if(val!=5) |
|
357 failures++; |
|
358 break; |
|
359 |
|
360 case 5: |
|
361 if(val!=2000) |
|
362 failures++; |
|
363 break; |
|
364 |
|
365 default: |
|
366 break; |
|
367 } |
|
368 |
|
369 |
|
370 } |
|
371 |
|
372 /* if(failures) |
|
373 return KErrGeneral; |
|
374 return KErrNone; |
|
375 */ |
|
376 |
|
377 |
|
378 |
|
379 //#if STDCPP_OOM |
|
380 //failures++; |
|
381 // #endif |
|
382 } |
|
383 |
|
384 catch(bad_alloc&) |
|
385 { |
|
386 //do nothing |
|
387 } |
|
388 catch(...) |
|
389 { |
|
390 failures++; |
|
391 |
|
392 } |
|
393 |
|
394 if( failures == 0 ) |
|
395 return KErrNone; |
|
396 else |
|
397 return KErrGeneral; |
|
398 } |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // Ctiostreams:: streambuf |
|
402 // Example test method function. |
|
403 // (other items were commented in a header). |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 |
|
407 TInt Ctiostreams::streambufL(CStifItemParser& aItem ) |
|
408 { |
|
409 // locale loc ("en_GB.UTF-8"); |
|
410 |
|
411 |
|
412 |
|
413 int failures = 0; |
|
414 try |
|
415 { |
|
416 |
|
417 |
|
418 char a[4]= |
|
419 { |
|
420 0 |
|
421 }; |
|
422 |
|
423 char sentence[]= "Sample sentence"; |
|
424 cout<<""; |
|
425 #if STDCPP_OOM |
|
426 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
427 #endif |
|
428 streambuf * pbuf; |
|
429 ofstream ostr ("c:\\TestFramework\\docs\\streambuf.txt"); |
|
430 |
|
431 |
|
432 |
|
433 if(!cout.rdbuf( )->getloc( ).name( ).c_str( )) //failing |
|
434 // failures++; |
|
435 ; |
|
436 char ch[14]; |
|
437 //rdbuf()s |
|
438 pbuf = ostr.rdbuf(); |
|
439 |
|
440 |
|
441 //sputn() |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 pbuf->sputn (sentence,sizeof(sentence)-1); |
|
447 |
|
448 |
|
449 ostr.open("c:\\TestFramework\\docs\\streambuf.txt"); |
|
450 |
|
451 if(!ostr.is_open()) |
|
452 failures++; |
|
453 |
|
454 |
|
455 long size1 = pbuf->pubseekoff(0,ios_base::end); |
|
456 if(size1!=15) |
|
457 failures++; |
|
458 |
|
459 |
|
460 pbuf->sputc('a'); |
|
461 |
|
462 |
|
463 long size2 = pbuf->pubseekoff(0,ios_base::end); |
|
464 if(size2!=16) |
|
465 failures++; |
|
466 |
|
467 ifstream istr("c:\\TestFramework\\docs\\streambuf.txt"); |
|
468 pbuf = istr.rdbuf(); |
|
469 |
|
470 streamsize i = istr.rdbuf()->sgetn(&a[0], 3); |
|
471 |
|
472 // Display the size and contents of the buffer passed to sgetn. |
|
473 if(i!=3) |
|
474 failures++; |
|
475 |
|
476 |
|
477 int k = pbuf->snextc(); |
|
478 |
|
479 |
|
480 //sgetc() |
|
481 while (pbuf->sgetc()!=EOF) |
|
482 { |
|
483 // static int i; |
|
484 int i=0; |
|
485 //sbumpc() |
|
486 ch[i] = pbuf->sbumpc(); |
|
487 i++; |
|
488 } |
|
489 |
|
490 |
|
491 if(ch[0]!='a' ) |
|
492 failures++; |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 istr.close(); |
|
500 #if STDCPP_OOM |
|
501 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
502 #endif |
|
503 /* |
|
504 if(failures) |
|
505 return KErrGeneral; |
|
506 else |
|
507 return KErrNone; |
|
508 |
|
509 */ |
|
510 |
|
511 |
|
512 //#if STDCPP_OOM |
|
513 //failures++; |
|
514 // #endif |
|
515 |
|
516 } |
|
517 catch(bad_alloc&) |
|
518 { |
|
519 //do nothing |
|
520 } |
|
521 catch(...) |
|
522 { |
|
523 failures++; |
|
524 |
|
525 } |
|
526 |
|
527 if( failures == 0 ) |
|
528 return KErrNone; |
|
529 else |
|
530 return KErrGeneral; |
|
531 } |
|
532 |
|
533 |
|
534 // ----------------------------------------------------------------------------- |
|
535 // Ctiostreams:: ostream |
|
536 // Example test method function. |
|
537 // (other items were commented in a header). |
|
538 // ----------------------------------------------------------------------------- |
|
539 // |
|
540 |
|
541 TInt Ctiostreams::ostreamL(CStifItemParser& aItem ) |
|
542 |
|
543 { |
|
544 |
|
545 |
|
546 int failures = 0; |
|
547 try |
|
548 { |
|
549 |
|
550 |
|
551 filebuf fb; |
|
552 char input[17] = "ostream testcase"; |
|
553 streamsize size = 5; |
|
554 fb.open ("c:\\TestFramework\\docs\\ostream.txt",ios::out); |
|
555 cout<<""; |
|
556 #if STDCPP_OOM |
|
557 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
558 #endif |
|
559 ostream os(&fb); |
|
560 |
|
561 os.write(input,size); |
|
562 streamoff i = os.tellp(); |
|
563 if(i!= 5) |
|
564 failures++; |
|
565 |
|
566 os.put('K'); |
|
567 streamoff j = os.tellp(); |
|
568 if(j!=6) |
|
569 failures++; |
|
570 |
|
571 os.seekp(2); |
|
572 os<<"i"; |
|
573 streamoff k = os.tellp(); |
|
574 |
|
575 if(k!=3) |
|
576 failures++; |
|
577 |
|
578 os.flush(); |
|
579 |
|
580 #if STDCPP_OOM |
|
581 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
582 #endif |
|
583 |
|
584 |
|
585 /* |
|
586 if(failures) |
|
587 return KErrGeneral; |
|
588 return KErrNone; |
|
589 */ |
|
590 |
|
591 |
|
592 //#if STDCPP_OOM |
|
593 //failures++; |
|
594 // #endif |
|
595 } |
|
596 |
|
597 catch(bad_alloc&) |
|
598 { |
|
599 //do nothing |
|
600 } |
|
601 catch(...) |
|
602 { |
|
603 failures++; |
|
604 |
|
605 } |
|
606 |
|
607 if( failures == 0 ) |
|
608 return KErrNone; |
|
609 else |
|
610 return KErrGeneral; |
|
611 } |
|
612 |
|
613 // ----------------------------------------------------------------------------- |
|
614 // Ctiostreams:: istream |
|
615 // Example test method function. |
|
616 // (other items were commented in a header). |
|
617 // ----------------------------------------------------------------------------- |
|
618 // |
|
619 TInt Ctiostreams::istreamL(CStifItemParser& aItem ) |
|
620 { |
|
621 |
|
622 int failures =0; |
|
623 try |
|
624 { |
|
625 |
|
626 |
|
627 int length; |
|
628 //char * buffer; |
|
629 char getl[8] ; |
|
630 filebuf fb; |
|
631 fb.open ("c:\\TestFramework\\docs\\istream.txt",ios::in); |
|
632 cout<<""; |
|
633 #if STDCPP_OOM |
|
634 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
635 #endif |
|
636 istream is(&fb); |
|
637 |
|
638 //needs to rewrite |
|
639 |
|
640 |
|
641 // get length of file: |
|
642 is.seekg (0, ios::end); |
|
643 length = is.tellg(); |
|
644 is.seekg (0, ios::beg); |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 if(length != 7) |
|
651 failures++; |
|
652 |
|
653 char ch = is.get(); |
|
654 |
|
655 |
|
656 if(is.gcount() != 1) |
|
657 failures++; |
|
658 |
|
659 |
|
660 if( ch != 'S') |
|
661 failures++; |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 char pk1 = is.peek(); |
|
670 |
|
671 if(pk1!= 'h') |
|
672 failures++; |
|
673 |
|
674 |
|
675 is.unget(); |
|
676 |
|
677 char pk2 = is.peek(); |
|
678 if(pk2!= 'S') |
|
679 failures++; |
|
680 |
|
681 is.get(); |
|
682 is.putback('K'); |
|
683 |
|
684 is.getline(getl,8,'\0'); |
|
685 |
|
686 if(getl == "Khaheen") |
|
687 failures++; |
|
688 |
|
689 if(is.gcount() != 7) |
|
690 failures++; |
|
691 |
|
692 |
|
693 fb.close(); |
|
694 /*if(failures) |
|
695 |
|
696 |
|
697 return KErrGeneral; |
|
698 return KErrNone; |
|
699 |
|
700 */ |
|
701 |
|
702 #if STDCPP_OOM |
|
703 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
704 #endif |
|
705 //#if STDCPP_OOM |
|
706 //failures++; |
|
707 // #endif |
|
708 |
|
709 } |
|
710 |
|
711 catch(bad_alloc&) |
|
712 { |
|
713 //do nothing |
|
714 } |
|
715 catch(...) |
|
716 { |
|
717 failures++; |
|
718 |
|
719 } |
|
720 |
|
721 if( failures == 0 ) |
|
722 return KErrNone; |
|
723 else |
|
724 return KErrGeneral; |
|
725 } |
|
726 |
|
727 // ----------------------------------------------------------------------------- |
|
728 // Ctiostreams:: istringstream |
|
729 // Example test method function. |
|
730 // (other items were commented in a header). |
|
731 // ----------------------------------------------------------------------------- |
|
732 // |
|
733 |
|
734 TInt Ctiostreams::istringstreamL(CStifItemParser& aItem ) |
|
735 { |
|
736 int n,val; |
|
737 int failures =0; |
|
738 try |
|
739 { |
|
740 string strvalues = "125 320 512 750 333"; |
|
741 cout<<""; |
|
742 #if STDCPP_OOM |
|
743 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
744 #endif |
|
745 |
|
746 istringstream iss (strvalues,istringstream::in); |
|
747 |
|
748 if(iss.str() != "125 320 512 750 333") |
|
749 failures++; |
|
750 |
|
751 #if STDCPP_OOM |
|
752 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
753 #endif |
|
754 for (n=0; n<5; n++) |
|
755 { |
|
756 iss >> val; |
|
757 switch(n) |
|
758 { |
|
759 case 0: |
|
760 if(val!=125) |
|
761 failures++; |
|
762 break; |
|
763 case 1: |
|
764 if(val!=320) |
|
765 failures++; |
|
766 break; |
|
767 case 2: |
|
768 if(val!=512) |
|
769 failures++; |
|
770 break; |
|
771 case 3: |
|
772 if(val!=750) |
|
773 failures++; |
|
774 break; |
|
775 |
|
776 case 4: |
|
777 if(val!=333) |
|
778 failures++; |
|
779 break; |
|
780 |
|
781 |
|
782 default: |
|
783 break; |
|
784 } |
|
785 |
|
786 } |
|
787 |
|
788 |
|
789 //#if STDCPP_OOM |
|
790 //failures++; |
|
791 // #endif |
|
792 |
|
793 /* if(failures) |
|
794 return KErrGeneral; |
|
795 else |
|
796 return KErrNone;*/ |
|
797 } |
|
798 |
|
799 catch(bad_alloc&) |
|
800 { |
|
801 //do nothing |
|
802 } |
|
803 catch(...) |
|
804 { |
|
805 failures++; |
|
806 |
|
807 } |
|
808 |
|
809 if( failures == 0 ) |
|
810 return KErrNone; |
|
811 else |
|
812 return KErrGeneral; |
|
813 } |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 // ----------------------------------------------------------------------------- |
|
821 // Ctiostreams:: ostringstream, |
|
822 // Example test method function. |
|
823 // (other items were commented in a header). |
|
824 // ----------------------------------------------------------------------------- |
|
825 // |
|
826 |
|
827 TInt Ctiostreams::ostringstreamL(CStifItemParser& aItem ) |
|
828 { |
|
829 int failures =0 ; |
|
830 try |
|
831 { |
|
832 |
|
833 |
|
834 basic_string<char> i( "test" ); |
|
835 cout<<""; |
|
836 #if STDCPP_OOM |
|
837 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
838 #endif |
|
839 ostringstream ss; |
|
840 |
|
841 ss.rdbuf( )->str( i ); |
|
842 if(ss.str( ).compare("test") != 0) |
|
843 failures++; |
|
844 |
|
845 ss << "z"; |
|
846 if(ss.str( ) .compare("zest")!=0) |
|
847 failures++; |
|
848 |
|
849 ss.rdbuf( )->str( "be" ); |
|
850 if(ss.str( ).compare("be")!=0) |
|
851 failures++; |
|
852 |
|
853 #if STDCPP_OOM |
|
854 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
855 #endif |
|
856 /* |
|
857 if(failures) |
|
858 |
|
859 return KErrGeneral; |
|
860 else |
|
861 return KErrNone; |
|
862 */ |
|
863 |
|
864 |
|
865 |
|
866 //#if STDCPP_OOM |
|
867 //failures++; |
|
868 // #endif |
|
869 } |
|
870 |
|
871 catch(bad_alloc&) |
|
872 { |
|
873 //do nothing |
|
874 } |
|
875 catch(...) |
|
876 { |
|
877 failures++; |
|
878 |
|
879 } |
|
880 |
|
881 if( failures == 0 ) |
|
882 return KErrNone; |
|
883 else |
|
884 return KErrGeneral; |
|
885 } |
|
886 |
|
887 TInt Ctiostreams::ostreamiterators(CStifItemParser& aItem ) |
|
888 { |
|
889 |
|
890 |
|
891 //needs to rewrite |
|
892 //____________________ |
|
893 |
|
894 int arr[4] = { 3,4,7,8 }; |
|
895 // int total=0; |
|
896 deque<int> d(arr+0, arr+4); |
|
897 // |
|
898 // stream the whole vector and a sum to cout |
|
899 // |
|
900 |
|
901 copy(d.begin(),(d.end()-1),ostream_iterator<int,char>(cout,"")); |
|
902 |
|
903 |
|
904 if( *(d.end()-1) == 8) |
|
905 return KErrNone; |
|
906 return KErrGeneral; |
|
907 |
|
908 |
|
909 } |
|
910 |
|
911 |
|
912 |
|
913 // ----------------------------------------------------------------------------- |
|
914 // Ctiostreams:: fstream |
|
915 // Example test method function. |
|
916 // (other items were commented in a header). |
|
917 // ----------------------------------------------------------------------------- |
|
918 // |
|
919 |
|
920 |
|
921 TInt Ctiostreams::fstreamL(CStifItemParser& aItem ) |
|
922 { |
|
923 // __UHEAP_MARK; |
|
924 int failures =0; |
|
925 try |
|
926 { |
|
927 cout<<""; |
|
928 #if STDCPP_OOM |
|
929 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
930 #endif |
|
931 fstream filestr ("c:\\TestFramework\\docs\\fstream.txt", fstream::in | fstream::out); |
|
932 |
|
933 if(!filestr.is_open()) |
|
934 failures++; |
|
935 |
|
936 filestr.close(); |
|
937 if(filestr.is_open()) |
|
938 failures++; |
|
939 |
|
940 // __UHEAP_MARKEND; |
|
941 |
|
942 /*if(failures) |
|
943 return KErrNone; |
|
944 return KErrGeneral; |
|
945 */ |
|
946 #if STDCPP_OOM |
|
947 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
948 #endif |
|
949 //#if STDCPP_OOM |
|
950 //failures++; |
|
951 // #endif |
|
952 |
|
953 } |
|
954 catch(bad_alloc&) |
|
955 { |
|
956 //do nothing |
|
957 } |
|
958 catch(...) |
|
959 { |
|
960 failures++; |
|
961 |
|
962 } |
|
963 |
|
964 if( failures == 0 ) |
|
965 return KErrNone; |
|
966 else |
|
967 return KErrGeneral; |
|
968 } |
|
969 |
|
970 // ----------------------------------------------------------------------------- |
|
971 // Ctiostreams:: istrstream |
|
972 // Example test method function. |
|
973 // (other items were commented in a header). |
|
974 // ----------------------------------------------------------------------------- |
|
975 // |
|
976 TInt Ctiostreams::istrstreamL(CStifItemParser& aItem ) |
|
977 { |
|
978 // __UHEAP_MARK; |
|
979 int failures=0; |
|
980 try |
|
981 { |
|
982 |
|
983 |
|
984 char* p = "This is first string"; |
|
985 char* q = "This is second string"; |
|
986 char* r = ""; |
|
987 const char* s ="const char"; |
|
988 streamsize n =10; |
|
989 cout<<""; |
|
990 #if STDCPP_OOM |
|
991 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
992 #endif |
|
993 istrstream first(p); |
|
994 istrstream second(q); |
|
995 istrstream third(r); |
|
996 |
|
997 istrstream four(s); |
|
998 |
|
999 istrstream five(p,n); |
|
1000 istrstream six(s,n); |
|
1001 /* if(first.str() == "This is first string") |
|
1002 if(second.str()!= " This is second string") |
|
1003 if(third.str() == "") |
|
1004 // __UHEAP_MARKEND; |
|
1005 |
|
1006 return KErrNone; |
|
1007 return KErrGeneral; |
|
1008 */ |
|
1009 first.rdbuf(); |
|
1010 second.rdbuf(); |
|
1011 third.rdbuf(); |
|
1012 |
|
1013 if(first.str() != "This is first string") |
|
1014 if(second.str()== " This is second string") |
|
1015 if(third.str() != "") |
|
1016 failures++; |
|
1017 |
|
1018 #if STDCPP_OOM |
|
1019 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1020 #endif |
|
1021 //#if STDCPP_OOM |
|
1022 //failures++; |
|
1023 // #endif |
|
1024 |
|
1025 } |
|
1026 |
|
1027 |
|
1028 catch(bad_alloc&) |
|
1029 { |
|
1030 //do nothing |
|
1031 } |
|
1032 catch(...) |
|
1033 { |
|
1034 failures++; |
|
1035 |
|
1036 } |
|
1037 |
|
1038 if( failures == 0 ) |
|
1039 return KErrNone; |
|
1040 else |
|
1041 return KErrGeneral; |
|
1042 } |
|
1043 |
|
1044 TInt Ctiostreams::strstreamL(CStifItemParser& aItem ) |
|
1045 { |
|
1046 // __UHEAP_MARK; |
|
1047 |
|
1048 int failures = 0; |
|
1049 try |
|
1050 { |
|
1051 cout<<""; |
|
1052 #if STDCPP_OOM |
|
1053 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1054 #endif |
|
1055 // char* s; |
|
1056 // int n; |
|
1057 // ios_base::openmode mode; |
|
1058 // strstream ss3(s, n, mode); |
|
1059 strstream ss1,ss2; |
|
1060 ss1 << ""; |
|
1061 ss1.rdbuf(); |
|
1062 if(ss1.rdbuf( )->pcount( ) != 0) |
|
1063 failures++; |
|
1064 |
|
1065 string str1= ss1.str(); |
|
1066 if(str1.compare("")!=0) |
|
1067 failures++; |
|
1068 |
|
1069 ss2 << "strstream testcase"; |
|
1070 ss2 << '\0'; |
|
1071 if( ss2.rdbuf( )->pcount( ) != sizeof("strstream testcase\0")-1) |
|
1072 failures++; |
|
1073 |
|
1074 string str = ss2.str(); |
|
1075 |
|
1076 if(str.compare("strstream testcase")!= 0) |
|
1077 failures++; |
|
1078 ss1.freeze(); |
|
1079 //__UHEAP_MARKEND; |
|
1080 /* |
|
1081 if(failures) |
|
1082 return KErrGeneral; |
|
1083 else |
|
1084 return KErrNone; |
|
1085 */ |
|
1086 |
|
1087 |
|
1088 #if STDCPP_OOM |
|
1089 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1090 #endif |
|
1091 |
|
1092 //#if STDCPP_OOM |
|
1093 //failures++; |
|
1094 // #endif |
|
1095 } |
|
1096 |
|
1097 catch(bad_alloc&) |
|
1098 { |
|
1099 //do nothing |
|
1100 } |
|
1101 catch(...) |
|
1102 { |
|
1103 failures++; |
|
1104 |
|
1105 } |
|
1106 |
|
1107 if( failures == 0 ) |
|
1108 return KErrNone; |
|
1109 else |
|
1110 return KErrGeneral; |
|
1111 } |
|
1112 |
|
1113 |
|
1114 TInt Ctiostreams::ostrstreamL(CStifItemParser& aItem ) |
|
1115 { |
|
1116 |
|
1117 //__UHEAP_MARK; |
|
1118 int failures = 0; |
|
1119 try |
|
1120 { |
|
1121 cout<<""; |
|
1122 #if STDCPP_OOM |
|
1123 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1124 #endif |
|
1125 // char* s; |
|
1126 // int n; |
|
1127 // ios_base::openmode mode; |
|
1128 // ostrstream oss3( s, n, mode); |
|
1129 ostrstream oss1 ,oss2; |
|
1130 string str; |
|
1131 oss1 << ""; |
|
1132 oss1.rdbuf(); |
|
1133 if(oss1.rdbuf( )->pcount( ) != 0) |
|
1134 failures++; |
|
1135 |
|
1136 oss2 << "ostrstream testcase"; |
|
1137 oss2<<'\0'; |
|
1138 str = oss2.str(); |
|
1139 |
|
1140 if(str.compare("ostrstream testcase") !=0) |
|
1141 failures++; |
|
1142 |
|
1143 oss2.freeze(); |
|
1144 |
|
1145 #if STDCPP_OOM |
|
1146 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1147 #endif |
|
1148 |
|
1149 // __UHEAP_MARKEND; |
|
1150 /* |
|
1151 if(failures) |
|
1152 return KErrGeneral; |
|
1153 else |
|
1154 return KErrNone; |
|
1155 */ |
|
1156 |
|
1157 //#if STDCPP_OOM |
|
1158 //failures++; |
|
1159 // #endif |
|
1160 } |
|
1161 |
|
1162 catch(bad_alloc&) |
|
1163 { |
|
1164 //do nothing |
|
1165 } |
|
1166 catch(...) |
|
1167 { |
|
1168 failures++; |
|
1169 |
|
1170 } |
|
1171 |
|
1172 if( failures == 0 ) |
|
1173 return KErrNone; |
|
1174 else |
|
1175 return KErrGeneral; |
|
1176 } |
|
1177 |
|
1178 |
|
1179 |
|
1180 TInt Ctiostreams::istreamiterators(CStifItemParser& aItem ) |
|
1181 { |
|
1182 |
|
1183 // __UHEAP_MARK; |
|
1184 // Typedefs for convenience. |
|
1185 int failures=0; |
|
1186 try |
|
1187 { |
|
1188 cout<<""; |
|
1189 #if STDCPP_OOM |
|
1190 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1191 #endif |
|
1192 |
|
1193 typedef std::vector<int, std::allocator<int> > Vector; |
|
1194 |
|
1195 typedef std::istream_iterator<Vector::value_type,char, std::char_traits<char>, ptrdiff_t> is_iter; |
|
1196 |
|
1197 #if STDCPP_OOM |
|
1198 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1199 #endif |
|
1200 Vector v; |
|
1201 //__UHEAP_MARKEND; |
|
1202 |
|
1203 //#if STDCPP_OOM |
|
1204 //failures++; |
|
1205 // #endif |
|
1206 |
|
1207 |
|
1208 |
|
1209 } |
|
1210 |
|
1211 |
|
1212 catch(bad_alloc&) |
|
1213 { |
|
1214 //do nothing |
|
1215 } |
|
1216 catch(...) |
|
1217 { |
|
1218 failures++; |
|
1219 |
|
1220 } |
|
1221 |
|
1222 if( failures == 0 ) |
|
1223 return KErrNone; |
|
1224 else |
|
1225 return KErrGeneral; |
|
1226 } |
|
1227 |
|
1228 |
|
1229 TInt Ctiostreams::istreambufiterators(CStifItemParser& aItem ) |
|
1230 { |
|
1231 |
|
1232 |
|
1233 // __UHEAP_MARK; |
|
1234 // create a temporary filename |
|
1235 |
|
1236 int failures=0; |
|
1237 try |
|
1238 { |
|
1239 |
|
1240 |
|
1241 const char *fname = tmpnam (0); |
|
1242 |
|
1243 if (!fname) |
|
1244 return 1; |
|
1245 |
|
1246 // open the file is_iter.out for reading and writing |
|
1247 std::ofstream out (fname, std::ios::out | std::ios::in | |
|
1248 std::ios::trunc); |
|
1249 |
|
1250 // output the example sentence into the file |
|
1251 |
|
1252 // seek to the beginning of the file |
|
1253 out.seekp (0); |
|
1254 cout<<""; |
|
1255 #if STDCPP_OOM |
|
1256 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1257 #endif |
|
1258 // construct an istreambuf_iterator pointing to |
|
1259 // the ofstream object underlying streambuffer |
|
1260 std::istreambuf_iterator<char, std::char_traits<char> >iter (out.rdbuf ()); |
|
1261 |
|
1262 // construct an end of stream iterator |
|
1263 const std::istreambuf_iterator<char,std::char_traits<char> > end; |
|
1264 #if STDCPP_OOM |
|
1265 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1266 #endif |
|
1267 std::cout << std::endl; |
|
1268 |
|
1269 // output the content of the file |
|
1270 while (!iter.equal (end)) { |
|
1271 |
|
1272 // use both operator++ and operator* |
|
1273 std::cout << *iter++; |
|
1274 } |
|
1275 |
|
1276 std::cout << std::endl; |
|
1277 |
|
1278 // remove temporary file |
|
1279 remove (fname); |
|
1280 //__UHEAP_MARKEND; |
|
1281 |
|
1282 //#if STDCPP_OOM |
|
1283 //failures++; |
|
1284 // #endif |
|
1285 |
|
1286 } |
|
1287 |
|
1288 catch(bad_alloc&) |
|
1289 { |
|
1290 //do nothing |
|
1291 } |
|
1292 catch(...) |
|
1293 { |
|
1294 failures++; |
|
1295 |
|
1296 } |
|
1297 |
|
1298 if( failures == 0 ) |
|
1299 return KErrNone; |
|
1300 else |
|
1301 return KErrGeneral; |
|
1302 } |
|
1303 |
|
1304 |
|
1305 |
|
1306 TInt Ctiostreams::strstreambufL(CStifItemParser& aItem ) |
|
1307 |
|
1308 |
|
1309 { |
|
1310 // __UHEAP_MARK; |
|
1311 |
|
1312 int failures =0; |
|
1313 try |
|
1314 { |
|
1315 |
|
1316 cout<<""; |
|
1317 |
|
1318 #if STDCPP_OOM |
|
1319 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1320 #endif |
|
1321 |
|
1322 signed char* get = NULL; |
|
1323 streamsize n=10; |
|
1324 signed char* put = NULL; |
|
1325 unsigned char* uget = NULL; |
|
1326 unsigned char* uput = NULL; |
|
1327 const char* cget = NULL; |
|
1328 const signed char* csget = NULL; |
|
1329 |
|
1330 const unsigned char* cucget = NULL; |
|
1331 |
|
1332 |
|
1333 typedef void* (*__alloc_fn)(size_t); |
|
1334 typedef void (*__free_fn)(void*); |
|
1335 |
|
1336 // __alloc_fn alloc_f; |
|
1337 |
|
1338 // __free_fn free_f; |
|
1339 |
|
1340 //overloaded |
|
1341 strstreambuf buf1(get, n,put); |
|
1342 |
|
1343 //overloaded |
|
1344 |
|
1345 strstreambuf buf2(uget,n,uput); |
|
1346 |
|
1347 //overloaded |
|
1348 strstreambuf buf3(cget,n); |
|
1349 //onverloaded |
|
1350 strstreambuf buf4(csget,n); |
|
1351 //overloaded |
|
1352 strstreambuf buf5(cucget,n); |
|
1353 |
|
1354 |
|
1355 // strstreambuf buf6( alloc_f, free_f); |
|
1356 strstreambuf buf7(n); |
|
1357 |
|
1358 strstreambuf buf; |
|
1359 string str; |
|
1360 int i = buf.sputn("strstreambuf testcase", sizeof("strstreambuf testcase")-1); |
|
1361 |
|
1362 if((buf.pcount())!= i) |
|
1363 failures++; |
|
1364 |
|
1365 buf.freeze(); |
|
1366 //if(buf.str() != "strstreambuf testcase") //fails |
|
1367 //failures++; |
|
1368 |
|
1369 #if STDCPP_OOM |
|
1370 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1371 #endif |
|
1372 |
|
1373 //__UHEAP_MARKEND; |
|
1374 /*if(failures) |
|
1375 return KErrGeneral; |
|
1376 else |
|
1377 return KErrNone; |
|
1378 */ |
|
1379 |
|
1380 //#if STDCPP_OOM |
|
1381 //failures++; |
|
1382 // #endif |
|
1383 |
|
1384 } |
|
1385 catch(bad_alloc&) |
|
1386 { |
|
1387 //do nothing |
|
1388 } |
|
1389 catch(...) |
|
1390 { |
|
1391 failures++; |
|
1392 |
|
1393 } |
|
1394 |
|
1395 if( failures == 0 ) |
|
1396 return KErrNone; |
|
1397 else |
|
1398 return KErrGeneral; |
|
1399 } |
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 TInt Ctiostreams::freezeL(CStifItemParser& aItem ) |
|
1405 { |
|
1406 |
|
1407 int failures=0; |
|
1408 try |
|
1409 { |
|
1410 |
|
1411 strstream x; |
|
1412 int failures =0; |
|
1413 x << "test1"; |
|
1414 |
|
1415 if(!x.good()) |
|
1416 failures++; |
|
1417 cout<<""; |
|
1418 |
|
1419 #if STDCPP_OOM |
|
1420 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1421 #endif |
|
1422 |
|
1423 x.rdbuf()->freeze(); |
|
1424 #if STDCPP_OOM |
|
1425 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1426 #endif |
|
1427 if(!x.good()) |
|
1428 failures++; |
|
1429 |
|
1430 // Stream is bad now, wrote on frozen stream |
|
1431 x << "test1.5"; |
|
1432 |
|
1433 // report(x); |
|
1434 if(!x.good()) |
|
1435 failures++; |
|
1436 // Unfreeze stream, but it is still bad |
|
1437 x.rdbuf()->freeze(false); |
|
1438 if(!x.good()) |
|
1439 failures++; |
|
1440 |
|
1441 // Clear stream |
|
1442 x.clear(); |
|
1443 |
|
1444 if(!x.good()) |
|
1445 failures++; |
|
1446 |
|
1447 |
|
1448 x << "test3"; |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 // Clean up. Failure to unfreeze stream will cause a |
|
1454 // memory leak. |
|
1455 x.rdbuf()->freeze(false); |
|
1456 /* |
|
1457 if(failures) |
|
1458 return KErrGeneral; |
|
1459 else |
|
1460 return KErrNone; |
|
1461 |
|
1462 */ |
|
1463 |
|
1464 //#if STDCPP_OOM |
|
1465 //failures++; |
|
1466 // #endif |
|
1467 } |
|
1468 |
|
1469 |
|
1470 |
|
1471 catch(bad_alloc&) |
|
1472 { |
|
1473 //do nothing |
|
1474 } |
|
1475 catch(...) |
|
1476 { |
|
1477 failures++; |
|
1478 |
|
1479 } |
|
1480 |
|
1481 if( failures == 0 ) |
|
1482 return KErrNone; |
|
1483 else |
|
1484 return KErrGeneral; |
|
1485 } |
|
1486 |
|
1487 |
|
1488 TInt Ctiostreams::fposL(CStifItemParser& aItem ) |
|
1489 { |
|
1490 int failures=0; |
|
1491 try |
|
1492 { |
|
1493 |
|
1494 |
|
1495 // streamoff s; |
|
1496 ifstream file( "c:\\TestFramework\\docs\\fpos_state.txt" ); |
|
1497 cout<<""; |
|
1498 #if STDCPP_OOM |
|
1499 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1500 #endif |
|
1501 fpos<mbstate_t> f = file.tellg( ); |
|
1502 char ch; |
|
1503 while ( !file.eof( ) ) |
|
1504 file.get( ch ); |
|
1505 |
|
1506 f.state(); |
|
1507 cout<<""; |
|
1508 #if STDCPP_OOM |
|
1509 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1510 #endif |
|
1511 //s = f; |
|
1512 // if(f.state( )) |
|
1513 // failures++; |
|
1514 // f.state( 9 ); |
|
1515 // if( f.state( )) |
|
1516 // failures++; |
|
1517 /*if(failures) |
|
1518 return KErrGeneral; |
|
1519 return KErrNone;*/ |
|
1520 |
|
1521 //#if STDCPP_OOM |
|
1522 //failures++; |
|
1523 // #endif |
|
1524 } |
|
1525 |
|
1526 catch(bad_alloc&) |
|
1527 { |
|
1528 //do nothing |
|
1529 } |
|
1530 catch(...) |
|
1531 { |
|
1532 failures++; |
|
1533 |
|
1534 } |
|
1535 |
|
1536 if( failures == 0 ) |
|
1537 return KErrNone; |
|
1538 else |
|
1539 return KErrGeneral; |
|
1540 } |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 // ----------------------------------------------------------------------------- |
|
1546 // Cstdcpp_filebuf::filebufL |
|
1547 // Example test method function. |
|
1548 // (other items were commented in a header). |
|
1549 // ----------------------------------------------------------------------------- |
|
1550 // |
|
1551 TInt Ctiostreams::filebufL( CStifItemParser& aItem ) |
|
1552 { |
|
1553 int failures=0; |
|
1554 try |
|
1555 { |
|
1556 |
|
1557 |
|
1558 |
|
1559 ifstream is; |
|
1560 cout<<""; |
|
1561 #if STDCPP_OOM |
|
1562 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1563 #endif |
|
1564 filebuf * fb; |
|
1565 |
|
1566 fb = is.rdbuf(); |
|
1567 fb->open ("c:\\TestFramework\\docs\\filebuf.txt",ios::in); |
|
1568 |
|
1569 if(!fb->is_open()) |
|
1570 failures++; |
|
1571 |
|
1572 |
|
1573 fb->close(); |
|
1574 if(fb->is_open()) |
|
1575 failures++; |
|
1576 |
|
1577 |
|
1578 #if STDCPP_OOM |
|
1579 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1580 #endif |
|
1581 /* |
|
1582 if(failures) |
|
1583 return KErrGeneral; |
|
1584 return KErrNone; |
|
1585 */ |
|
1586 |
|
1587 //#if STDCPP_OOM |
|
1588 //failures++; |
|
1589 // #endif |
|
1590 |
|
1591 } |
|
1592 |
|
1593 catch(bad_alloc&) |
|
1594 { |
|
1595 //do nothing |
|
1596 } |
|
1597 catch(...) |
|
1598 { |
|
1599 failures++; |
|
1600 |
|
1601 } |
|
1602 |
|
1603 if( failures == 0 ) |
|
1604 return KErrNone; |
|
1605 else |
|
1606 return KErrGeneral; |
|
1607 } |
|
1608 |
|
1609 |
|
1610 TInt Ctiostreams::seekpL( CStifItemParser& aItem ) |
|
1611 { |
|
1612 |
|
1613 ostringstream oss2; |
|
1614 |
|
1615 oss2<<"Do me a favor"; |
|
1616 long pos2 = oss2.tellp(); // 13 |
|
1617 |
|
1618 oss2 << "pp"; |
|
1619 pos2 = oss2.tellp(); // 15 |
|
1620 oss2.seekp(pos2 - 2); |
|
1621 pos2 = oss2.tellp(); // 13 |
|
1622 string temp = "ss"; |
|
1623 oss2.write(temp.c_str(), temp.size()); |
|
1624 pos2 = oss2.tellp(); // 15 |
|
1625 oss2.seekp(pos2 - 2); |
|
1626 pos2 = oss2.tellp(); // 13 |
|
1627 oss2 << "ss"; |
|
1628 pos2 = oss2.tellp(); // 15 |
|
1629 oss2.seekp(pos2 - 2); |
|
1630 pos2 = oss2.tellp(); // 13 |
|
1631 oss2 << "ss"; |
|
1632 |
|
1633 pos2 = oss2.tellp(); |
|
1634 |
|
1635 oss2.seekp(pos2 - 2); |
|
1636 pos2 = oss2.tellp(); |
|
1637 oss2 << "pp"; |
|
1638 pos2 = oss2.tellp(); //15 |
|
1639 |
|
1640 oss2.seekp(pos2 - 5); |
|
1641 pos2 = oss2.tellp(); |
|
1642 oss2 << "pppp"; |
|
1643 pos2 = oss2.tellp(); //14 |
|
1644 oss2.seekp(pos2 - 3); |
|
1645 pos2 = oss2.tellp(); |
|
1646 oss2 << "ppp"; |
|
1647 pos2 = oss2.tellp(); //14 |
|
1648 oss2 << "pppppp"; |
|
1649 pos2 = oss2.tellp(); //20 |
|
1650 |
|
1651 |
|
1652 if( pos2 == 20 ) |
|
1653 return KErrNone; |
|
1654 else |
|
1655 return KErrGeneral; |
|
1656 } |
|
1657 |
|
1658 |
|
1659 |
|
1660 // End of File |