Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 #include <StifParser.h>
24 #include <Stiftestinterface.h>
34 #include "twiostreams.h"
35 #define STDCPP_OOM FALSE
40 // ============================ MEMBER FUNCTIONS ===============================
42 // -----------------------------------------------------------------------------
43 // CCtwiostreams::Delete
44 // Delete here all resources allocated and opened from test methods.
45 // Called from destructor.
46 // -----------------------------------------------------------------------------
48 void Ctwiostreams::Delete()
53 // -----------------------------------------------------------------------------
54 // CCtwiostreams::RunMethodL
55 // Run specified method. Contains also table of test mothods and their names.
56 // -----------------------------------------------------------------------------
58 TInt Ctwiostreams::RunMethodL(
59 CStifItemParser& aItem )
62 static TStifFunctionInfo const KFunctions[] =
64 // Copy this line for every implemented function.
65 // First string is the function name used in TestScripter script file.
66 // Second is the actual implementation member function.
67 ENTRY( "basicstring", Ctwiostreams::basicstring ),
68 ENTRY( "basicfilebufL", Ctwiostreams::basicfilebufL ),
69 ENTRY( "basicistreamL", Ctwiostreams::basicistreamL ),
70 ENTRY( "wfstreamL", Ctwiostreams::wfstreamL ),
71 ENTRY( "wifstreamL", Ctwiostreams::wifstreamL ),
72 ENTRY( "wistreamL", Ctwiostreams::wistreamL ),
73 ENTRY( "wofstreamL", Ctwiostreams::wofstreamL ),
74 ENTRY( "wistringstreamL", Ctwiostreams::wistringstreamL ),
75 ENTRY( "wostringstreamL", Ctwiostreams::wostringstreamL ),
76 ENTRY( "wstreambufL", Ctwiostreams::wstreambufL ),
77 ENTRY( "wostreamL", Ctwiostreams::wostreamL ),
78 ENTRY( "wstringbufL", Ctwiostreams::wstringbufL ),
83 const TInt count = sizeof( KFunctions ) /
84 sizeof( TStifFunctionInfo );
86 return RunInternalL( KFunctions, count, aItem );
90 // -----------------------------------------------------------------------------
91 // Ctwiostreams::basic_string
92 // Example test method function.
94 // -----------------------------------------------------------------------------
96 TInt Ctwiostreams::basicstring( CStifItemParser& aItem )
104 const char *cstr1a = "Hello Out There.";
107 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
109 basic_string<char> str1a(cstr1a ,5);
111 if(str1a.compare("Hello")!=0)
114 str1a.append("Out There");
115 if(!str1a.compare("Hello Out There"))
119 string str2a ( "How Do You Do?" );
120 basic_string <char> str2b ( str2a , 7 , 7 );
122 if(str2b.compare("You Do?")!=0)
127 basic_string <char> str3a ( 5, '9' );
128 if(str3a.compare("99999")!=0)
133 basic_string <char> str4a;
135 basic_string <char> str4c ( str4b.get_allocator( ) );
141 string str5a ( "Hello World");
142 basic_string <char>::iterator strp_Iter;
146 strp_Iter = str5a.begin();
147 if(*strp_Iter != 'H' )
153 basic_string <char>::reference refStr2 = str5a.at ( 3 );
161 if(str5a.length()!=11)
163 if(str5a.capacity()!=11)
169 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
194 // -----------------------------------------------------------------------------
195 // Ctwiostreams::basic_filebuf
196 // Example test method function.
198 // -----------------------------------------------------------------------------
201 TInt Ctwiostreams::basicfilebufL( CStifItemParser& aItem )
209 char* wszHello = "Hello World";
210 // char wBuffer[128];
213 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
216 basic_filebuf<char> wOutFile;
219 // Open a file, wcHello.txt, then write to it, then dump the
220 // file's contents in hex
221 wOutFile.open("c:\\TestFramework\\docs\\basicfilebuf.txt",ios_base::out | ios_base::trunc | ios_base::binary);
222 if(!wOutFile.is_open())
225 wOutFile.sputn(wszHello, 11);
227 if(wOutFile.is_open())
230 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
260 // -----------------------------------------------------------------------------
261 // Ctwiostreams::basic_istream
262 // Example test method function.
264 // -----------------------------------------------------------------------------
267 TInt Ctwiostreams::basicistreamL( CStifItemParser& aItem )
276 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
280 typedef std::basic_istream<char, std::char_traits<char> > Input;
281 typedef std::basic_ofstream<Input::char_type, Input::traits_type> Output;
284 // Input::char_type s [200];
286 Output out ("c:\\TestFramework\\docs\\basicistream.txt", std::ios::in | std::ios::out | std::ios::trunc);
288 Input in (out.rdbuf ());
293 // output to the file
294 out << "He lifted his head and pondered.\n"
295 << f << std::endl << i << std::endl;
297 // seek to the beginning of the file
308 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
335 // -----------------------------------------------------------------------------
336 // Ctwiostreams::wfstream
337 // Example test method function.
339 // -----------------------------------------------------------------------------
341 TInt Ctwiostreams::wfstreamL( CStifItemParser& aItem )
351 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
357 file.open("c:\\TestFramework\\docs\\wfstream.txt");
367 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
394 // -----------------------------------------------------------------------------
395 // Ctwiostreams::wifstream
396 // Example test method function.
398 // -----------------------------------------------------------------------------
400 TInt Ctwiostreams::wifstreamL( CStifItemParser& aItem )
409 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
415 file.open("c:\\TestFramework\\docs\\wifstream.txt");
427 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
453 // -----------------------------------------------------------------------------
454 // Ctwiostreams::wfilebuf,wistream
455 // Example test method function.
457 // -----------------------------------------------------------------------------
459 TInt Ctwiostreams::wistreamL( CStifItemParser& aItem )
472 fb.open ("c:\\TestFramework\\docs\\wistream.txt",ios::in);
475 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
482 //if( char(is.get())!= 'S')
485 //if(sizeof(fb)!=140)
491 // get length of file:
492 is.seekg (0, ios::end);
494 is.seekg (0, ios::beg);
503 wchar_t ch = is.get();
519 wchar_t pk1 = is.peek();
527 wchar_t pk2 = is.peek();
534 is.getline(getl,16,'\0');
536 if(getl == L"Kample sentence")
546 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
577 // -----------------------------------------------------------------------------
578 // Ctwiostreams::wofstream
579 // Example test method function.
581 // -----------------------------------------------------------------------------
584 TInt Ctwiostreams::wofstreamL( CStifItemParser& aItem )
592 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
597 outfile.open("c:\\TestFramework\\docs\\wostream.txt");
598 outfile.write(L"This is an ostreamfile",22);
601 if(!outfile.is_open())
607 if(outfile.is_open())
610 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
638 // -----------------------------------------------------------------------------
639 // Ctwiostreams::wistringstream
640 // Example test method function.
642 // -----------------------------------------------------------------------------
644 TInt Ctwiostreams::wistringstreamL( CStifItemParser& aItem )
655 strvalues = L"1 2 3 4 5";
658 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
660 wistringstream iss(strvalues,wistringstream::in);
662 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
679 if(iss.str()!=L"1 2 3 4 5")
720 // -----------------------------------------------------------------------------
721 // Ctwiostreams::wostringstream,wstring
722 // Example test method function.
724 // -----------------------------------------------------------------------------
726 TInt Ctwiostreams::wostringstreamL( CStifItemParser& aItem )
732 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
739 oss << L"wostringstream testcase";
743 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
745 /*if(mystr.compare(L"wostringstream testcase")==0)
749 if(mystr.compare(L"wostringstream testcase")!=0)
770 // -----------------------------------------------------------------------------
771 // Ctwiostreams::wstreambuf,wofstreams
772 // Example test method function.
774 // -----------------------------------------------------------------------------
777 TInt Ctwiostreams::wstreambufL( CStifItemParser& aItem )
781 //locale loc ("en_GB.UTF-8");
795 wchar_t sentence[]= L"Sample sentence"; cout<<"";
797 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
800 wofstream ostr ("c:\\TestFramework\\docs\\wstreambuf.txt");
804 // if(cout.rdbuf( )->getloc( ).name( ).c_str( ) != "C") //failing
817 pbuf->sputn (sentence,sizeof(sentence)-1);
820 ostr.open("c:\\TestFramework\\docs\\wstreambuf.txt");
826 long size1 = pbuf->pubseekoff(0,ios_base::end);
834 long size2 = pbuf->pubseekoff(0,ios_base::end);
838 wifstream istr("c:\\TestFramework\\docs\\wstreambuf.txt");
841 streamsize i = istr.rdbuf()->sgetn(&a[0], 3);
842 //a[i] = istr.widen('\0');
844 // Display the size and contents of the buffer passed to sgetn.
849 int k = pbuf->snextc();
853 while (pbuf->sgetc()!=EOF)
857 ch[i] = pbuf->sbumpc();
873 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
901 // -----------------------------------------------------------------------------
902 // Ctwiostreams::wostream
903 // Example test method function.
905 // -----------------------------------------------------------------------------
908 TInt Ctwiostreams::wostreamL( CStifItemParser& aItem )
919 wchar_t input[18] = L"wostream testcase";
921 fb.open ("c:\\TestFramework\\docs\\wostream.txt",ios::out); cout<<"";
923 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
927 os.write(input,size);
928 streamoff i = os.tellp();
933 streamoff j = os.tellp();
939 streamoff k = os.tellp();
947 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
976 // -----------------------------------------------------------------------------
977 // Ctwiostreams::wstringbuf
978 // Example test method function.
980 // -----------------------------------------------------------------------------
983 TInt Ctwiostreams::wstringbufL( CStifItemParser& aItem )
990 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
996 sb.sputn (L"Sample string",13);
999 /*if(mystr.compare(L"Sample string") == 0)
1005 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1007 if(mystr.compare(L"Sample string") != 0)