stdcpp/tsrc/Stdcpp_test/bcdrivers/twiostreams/src/twiostreamsblocks.cpp
changeset 31 ce057bb09d0b
child 45 4b03adbd26ca
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     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<string>
       
    27 #include <vector>
       
    28 #include<algorithm>
       
    29 #include<fstream>
       
    30 #include<sstream>
       
    31 #include<istream>
       
    32 
       
    33 #include<locale>
       
    34 #include "twiostreams.h"
       
    35 #define STDCPP_OOM FALSE
       
    36 using namespace std;
       
    37 
       
    38 
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CCtwiostreams::Delete
       
    44 // Delete here all resources allocated and opened from test methods. 
       
    45 // Called from destructor. 
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void Ctwiostreams::Delete() 
       
    49     {
       
    50 
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CCtwiostreams::RunMethodL
       
    55 // Run specified method. Contains also table of test mothods and their names.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 TInt Ctwiostreams::RunMethodL( 
       
    59     CStifItemParser& aItem ) 
       
    60     {
       
    61 
       
    62     static TStifFunctionInfo const KFunctions[] =
       
    63         {  
       
    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 ),
       
    79          
       
    80 
       
    81         };
       
    82 
       
    83     const TInt count = sizeof( KFunctions ) / 
       
    84                         sizeof( TStifFunctionInfo );
       
    85 
       
    86     return RunInternalL( KFunctions, count, aItem );
       
    87 
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // Ctwiostreams::basic_string
       
    92 // Example test method function.
       
    93 // 
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 TInt Ctwiostreams::basicstring( CStifItemParser& aItem )
       
    97     {
       
    98 				int failures =0;
       
    99 				
       
   100 				try
       
   101 				{
       
   102 					
       
   103 				
       
   104 			    const char *cstr1a = "Hello Out There.";
       
   105 			    cout<<"";
       
   106 			    #if  STDCPP_OOM
       
   107 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   108   #endif 
       
   109 			   basic_string<char> str1a(cstr1a ,5);
       
   110 	 
       
   111 			   if(str1a.compare("Hello")!=0)
       
   112 			   failures++;
       
   113 			    
       
   114 			    str1a.append("Out There");
       
   115 			    if(!str1a.compare("Hello Out There"))
       
   116 			    failures++;
       
   117 			    
       
   118 			    
       
   119 			   string  str2a ( "How Do You Do?" );
       
   120 			   basic_string <char> str2b ( str2a , 7 , 7 );
       
   121 			   
       
   122 			    if(str2b.compare("You Do?")!=0)
       
   123 			   failures++;
       
   124 			   
       
   125 			    
       
   126 			 
       
   127 			   basic_string <char> str3a ( 5, '9' );
       
   128 			   if(str3a.compare("99999")!=0)
       
   129 			   failures++;
       
   130 			   
       
   131 
       
   132 			   
       
   133 			   basic_string <char> str4a;
       
   134 			   string str4b;
       
   135 			   basic_string <char> str4c ( str4b.get_allocator( ) );
       
   136 			   if (!str4c.empty ())
       
   137 			   failures++;
       
   138 			      
       
   139 
       
   140 			  
       
   141 			   string str5a ( "Hello World");
       
   142 			    basic_string <char>::iterator strp_Iter;
       
   143 			   
       
   144 			   
       
   145 			   
       
   146 			   strp_Iter = str5a.begin();
       
   147 			   if(*strp_Iter != 'H' )
       
   148 				failures++;
       
   149 			   
       
   150 			   
       
   151 			   
       
   152 			   
       
   153 			   basic_string <char>::reference refStr2 = str5a.at ( 3 );
       
   154 			   
       
   155 			   if(refStr2 != 'l')
       
   156 			   failures++;
       
   157 			   
       
   158 			   
       
   159 			   if(str5a.size()!=11)
       
   160 			   failures++;
       
   161 			   if(str5a.length()!=11)
       
   162 			   failures++;
       
   163 			   if(str5a.capacity()!=11)
       
   164 			   failures++;
       
   165 			   
       
   166 
       
   167 
       
   168 		#if  STDCPP_OOM
       
   169 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   170   #endif 	   
       
   171 			  /*  if(failures)
       
   172 			    return  KErrGeneral;
       
   173 			    return KErrNone;
       
   174 			    */
       
   175 
       
   176     }
       
   177 
       
   178   catch(bad_alloc&)
       
   179    {
       
   180    	//do nothing
       
   181     }
       
   182    catch(...)
       
   183    {
       
   184    	failures++;
       
   185    	
       
   186    }
       
   187    
       
   188 	if( failures == 0 )
       
   189 		return KErrNone;
       
   190   else  
       
   191 		return KErrGeneral;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // Ctwiostreams::basic_filebuf
       
   196 // Example test method function.
       
   197 // 
       
   198 // -----------------------------------------------------------------------------
       
   199 // 
       
   200  
       
   201  TInt Ctwiostreams::basicfilebufL( CStifItemParser& aItem )
       
   202  {
       
   203  	
       
   204 	 int failures=0;
       
   205 	 try
       
   206 	 {
       
   207 	 	
       
   208 	 
       
   209    	 char* wszHello = "Hello World";
       
   210 //   	 char wBuffer[128];
       
   211    	  cout<<"";
       
   212 		    #if  STDCPP_OOM
       
   213 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   214   #endif 
       
   215 		
       
   216      basic_filebuf<char> wOutFile;
       
   217 	 
       
   218 		
       
   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())
       
   223     failures++;
       
   224     
       
   225     wOutFile.sputn(wszHello, 11);
       
   226     wOutFile.close();
       
   227  	if(wOutFile.is_open())
       
   228  	failures++;
       
   229  #if  STDCPP_OOM
       
   230 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   231   #endif 
       
   232  /*	if(failures)
       
   233 	return KErrGeneral;
       
   234  	else
       
   235  	return KErrNone;
       
   236  
       
   237  */
       
   238   
       
   239  
       
   240  
       
   241  
       
   242  }
       
   243  
       
   244   catch(bad_alloc&)
       
   245    {
       
   246    	//do nothing
       
   247     }
       
   248    catch(...)
       
   249    {
       
   250    	failures++;
       
   251    	
       
   252    }
       
   253    
       
   254 	if( failures == 0 )
       
   255 		return KErrNone;
       
   256   else  
       
   257 		return KErrGeneral;
       
   258     }
       
   259  
       
   260 // -----------------------------------------------------------------------------
       
   261 // Ctwiostreams::basic_istream
       
   262 // Example test method function.
       
   263 // 
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266  
       
   267  TInt Ctwiostreams::basicistreamL( CStifItemParser& aItem )
       
   268  {
       
   269  
       
   270  
       
   271  		int failures = 0;
       
   272  		try
       
   273  		{
       
   274  		 cout<<"";
       
   275  				    #if  STDCPP_OOM
       
   276 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   277   #endif 
       
   278 			
       
   279  		
       
   280      typedef std::basic_istream<char, std::char_traits<char> >         Input;
       
   281     typedef std::basic_ofstream<Input::char_type, Input::traits_type> Output;
       
   282 	 
       
   283 		
       
   284 //    Input::char_type s [200];
       
   285  
       
   286     Output out ("c:\\TestFramework\\docs\\basicistream.txt", std::ios::in | std::ios::out | std::ios::trunc);
       
   287 
       
   288      Input in (out.rdbuf ());
       
   289 
       
   290     float f = 3.14159;
       
   291     int   i = 3;
       
   292 
       
   293     // output to the file
       
   294     out << "He lifted his head and pondered.\n"
       
   295         << f << std::endl << i << std::endl;
       
   296   
       
   297     // seek to the beginning of the file
       
   298     in.seekg (0);
       
   299   
       
   300   if(!out.is_open())
       
   301   failures++;
       
   302   
       
   303   out.close();
       
   304   
       
   305   if(out.is_open())
       
   306   failures++;
       
   307   #if  STDCPP_OOM
       
   308 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   309   #endif 
       
   310   /*if(failures)
       
   311    return KErrGeneral;
       
   312   else
       
   313   return KErrNone;
       
   314  
       
   315   */
       
   316  
       
   317  	
       
   318  }
       
   319  
       
   320   catch(bad_alloc&)
       
   321    {
       
   322    	//do nothing
       
   323     }
       
   324    catch(...)
       
   325    {
       
   326    	failures++;
       
   327    	
       
   328    }
       
   329    
       
   330 	if( failures == 0 )
       
   331 		return KErrNone;
       
   332   else  
       
   333 		return KErrGeneral;
       
   334     }
       
   335 // -----------------------------------------------------------------------------
       
   336 // Ctwiostreams::wfstream
       
   337 // Example test method function.
       
   338 // 
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341  TInt Ctwiostreams::wfstreamL( CStifItemParser& aItem )
       
   342  
       
   343  {
       
   344  	
       
   345  int failures=0;
       
   346  
       
   347  try
       
   348  {
       
   349  	 cout<<"";
       
   350  		    #if  STDCPP_OOM
       
   351 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   352   #endif 
       
   353 		
       
   354  wfstream file;
       
   355  	  
       
   356 		
       
   357  file.open("c:\\TestFramework\\docs\\wfstream.txt");
       
   358  file.rdbuf();
       
   359  if(!file.is_open())
       
   360  failures++;
       
   361  
       
   362  file.close();
       
   363  
       
   364  if(file.is_open())
       
   365  failures++;
       
   366  #if  STDCPP_OOM
       
   367 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   368   #endif 
       
   369 /* if(failures)
       
   370  return KErrGeneral;
       
   371  return KErrNone;
       
   372  
       
   373  */
       
   374  
       
   375  }
       
   376  
       
   377   catch(bad_alloc&)
       
   378    {
       
   379    	//do nothing
       
   380     }
       
   381    catch(...)
       
   382    {
       
   383    	failures++;
       
   384    	
       
   385    }
       
   386    
       
   387 	if( failures == 0 )
       
   388 		return KErrNone;
       
   389   else  
       
   390 		return KErrGeneral;
       
   391     }
       
   392  
       
   393  
       
   394 // -----------------------------------------------------------------------------
       
   395 // Ctwiostreams::wifstream
       
   396 // Example test method function.
       
   397 // 
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400  TInt Ctwiostreams::wifstreamL( CStifItemParser& aItem )
       
   401  
       
   402  {
       
   403  int failures =0;
       
   404  
       
   405  try
       
   406  {
       
   407  	 cout<<"";
       
   408  		    #if  STDCPP_OOM
       
   409 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   410   #endif 
       
   411 		
       
   412  wifstream file;
       
   413  		    
       
   414 		
       
   415  file.open("c:\\TestFramework\\docs\\wifstream.txt");
       
   416  
       
   417  
       
   418  file.rdbuf();
       
   419  if(!file.is_open())
       
   420  failures++;
       
   421  
       
   422  file.close();
       
   423  
       
   424  if(file.is_open())
       
   425  failures++;
       
   426  #if  STDCPP_OOM
       
   427 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   428   #endif 
       
   429 /* if(failures)
       
   430  return KErrGeneral;
       
   431  return KErrNone;
       
   432  
       
   433  */
       
   434  	
       
   435  }
       
   436   catch(bad_alloc&)
       
   437    {
       
   438    	//do nothing
       
   439     }
       
   440    catch(...)
       
   441    {
       
   442    	failures++;
       
   443    	
       
   444    }
       
   445    
       
   446 	if( failures == 0 )
       
   447 		return KErrNone;
       
   448   else  
       
   449 		return KErrGeneral;
       
   450     }
       
   451  
       
   452  
       
   453 // -----------------------------------------------------------------------------
       
   454 // Ctwiostreams::wfilebuf,wistream
       
   455 // Example test method function.
       
   456 // 
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459  TInt Ctwiostreams::wistreamL( CStifItemParser& aItem )
       
   460  
       
   461  {
       
   462  	int failures=0;
       
   463  	try
       
   464  	{
       
   465  		
       
   466  	
       
   467  int length;
       
   468 //wchar_t * buffer;
       
   469 wchar_t getl[16] ;
       
   470  
       
   471  wfilebuf fb;
       
   472   fb.open ("c:\\TestFramework\\docs\\wistream.txt",ios::in);
       
   473    cout<<"";
       
   474    #if  STDCPP_OOM
       
   475 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   476   #endif 
       
   477   wistream is(&fb);
       
   478   
       
   479   if(!fb.is_open())
       
   480   failures++;
       
   481   
       
   482   //if( char(is.get())!= 'S')
       
   483  // failures++;
       
   484   
       
   485 //if(sizeof(fb)!=140)  
       
   486 //failures++;
       
   487 
       
   488 
       
   489 
       
   490 
       
   491   // get length of file:
       
   492   is.seekg (0, ios::end);
       
   493   length = is.tellg();
       
   494   is.seekg (0, ios::beg);
       
   495   
       
   496   
       
   497   
       
   498 
       
   499 
       
   500 if(length != 15)
       
   501 failures++;
       
   502 
       
   503  wchar_t ch = is.get();
       
   504   
       
   505    
       
   506  if(is.gcount() != 1)
       
   507  failures++;
       
   508  
       
   509   
       
   510  if( ch != L'S')
       
   511  failures++;
       
   512  
       
   513  
       
   514 
       
   515  
       
   516  
       
   517  
       
   518  
       
   519  wchar_t pk1 = is.peek();
       
   520  
       
   521  if(pk1!= 'a')
       
   522  failures++;
       
   523  
       
   524  
       
   525  is.unget();
       
   526  
       
   527  wchar_t pk2 = is.peek();
       
   528  if(pk2!= 'S')
       
   529  failures++;
       
   530  
       
   531  is.get();
       
   532  is.putback('K');
       
   533  
       
   534  is.getline(getl,16,'\0');
       
   535  
       
   536  if(getl == L"Kample sentence")
       
   537  failures++;
       
   538  
       
   539 
       
   540 
       
   541 fb.close();
       
   542 
       
   543 if(fb.is_open())
       
   544 failures++;
       
   545  #if  STDCPP_OOM
       
   546 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   547   #endif 
       
   548 /*
       
   549  if(failures)
       
   550  
       
   551  return sizeof(fb);
       
   552  return KErrNone;
       
   553   
       
   554  */
       
   555  
       
   556  
       
   557  
       
   558  
       
   559  }
       
   560  
       
   561  catch(bad_alloc&)
       
   562    {
       
   563    	//do nothing
       
   564     }
       
   565    catch(...)
       
   566    {
       
   567    	failures++;
       
   568    	
       
   569    }
       
   570    
       
   571 	if( failures == 0 )
       
   572 		return KErrNone;
       
   573   else  
       
   574 		return KErrGeneral;
       
   575     } 
       
   576  
       
   577 // -----------------------------------------------------------------------------
       
   578 // Ctwiostreams::wofstream
       
   579 // Example test method function.
       
   580 // 
       
   581 // -----------------------------------------------------------------------------
       
   582 //
       
   583  
       
   584   TInt Ctwiostreams::wofstreamL( CStifItemParser& aItem )
       
   585   {
       
   586   	
       
   587   	int failures=0;
       
   588   	try
       
   589   	{
       
   590   	 cout<<"";	
       
   591   	 #if  STDCPP_OOM
       
   592 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   593   #endif 
       
   594   	
       
   595   	wofstream outfile;
       
   596   	
       
   597   	outfile.open("c:\\TestFramework\\docs\\wostream.txt");
       
   598   	outfile.write(L"This is an ostreamfile",22);
       
   599   	
       
   600   	outfile.rdbuf();
       
   601   	if(!outfile.is_open())
       
   602   	failures++;
       
   603   	
       
   604   	outfile.close();
       
   605   	
       
   606   	
       
   607   	if(outfile.is_open())
       
   608   	failures++;
       
   609    #if  STDCPP_OOM
       
   610 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   611   #endif 
       
   612  /* 	if(failures)
       
   613   	return KErrGeneral;
       
   614   	else
       
   615   	return KErrNone;
       
   616   
       
   617   */
       
   618   
       
   619   
       
   620   }
       
   621   
       
   622   catch(bad_alloc&)
       
   623    {
       
   624    	//do nothing
       
   625     }
       
   626    catch(...)
       
   627    {
       
   628    	failures++;
       
   629    	
       
   630    }
       
   631    
       
   632 	if( failures == 0 )
       
   633 		return KErrNone;
       
   634   else  
       
   635 		return KErrGeneral;
       
   636     } 
       
   637   
       
   638 // -----------------------------------------------------------------------------
       
   639 // Ctwiostreams::wistringstream
       
   640 // Example test method function.
       
   641 // 
       
   642 // -----------------------------------------------------------------------------
       
   643 //
       
   644    TInt Ctwiostreams::wistringstreamL( CStifItemParser& aItem )
       
   645    {
       
   646    int failures=0;
       
   647    try
       
   648    {
       
   649    	
       
   650    
       
   651    	int output[5];
       
   652    int n = 0,val = 0;
       
   653    wstring strvalues ;
       
   654    
       
   655    strvalues = L"1 2 3 4 5";
       
   656     cout<<"";
       
   657     #if  STDCPP_OOM
       
   658 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   659   #endif 
       
   660    wistringstream iss(strvalues,wistringstream::in);
       
   661    #if  STDCPP_OOM
       
   662 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   663   #endif 
       
   664    
       
   665    for(n=0;n<5;n++)
       
   666    {
       
   667    	
       
   668    static int j;
       
   669    
       
   670    iss>>val;
       
   671    
       
   672    output[j]=val;
       
   673    
       
   674    j++;
       
   675    
       
   676    
       
   677    }
       
   678    
       
   679       if(iss.str()!=L"1 2 3 4 5")
       
   680       failures++;
       
   681 /*
       
   682    if(output[0]== 1)
       
   683    if(output[1]== 2)
       
   684    if(output[2]== 3)
       
   685    if(output[3]== 4 )
       
   686    if(output[4]== 5)
       
   687    
       
   688    return KErrNone;
       
   689    else 
       
   690    return  KErrGeneral;
       
   691    */
       
   692    
       
   693     if(output[0]!= 1)
       
   694     failures++;
       
   695    if(output[1]!= 2)
       
   696    failures++;
       
   697    if(output[2]!= 3)
       
   698    failures++;
       
   699    if(output[3]!= 4 )
       
   700    failures++;
       
   701    if(output[4]!= 5)
       
   702    failures++;
       
   703    }
       
   704   
       
   705    catch(bad_alloc&)
       
   706    {
       
   707    	//do nothing
       
   708     }
       
   709    catch(...)
       
   710    {
       
   711    	failures++;
       
   712    	
       
   713    }
       
   714    
       
   715 	if( failures == 0 )
       
   716 		return KErrNone;
       
   717   else  
       
   718 		return KErrGeneral;
       
   719     } 
       
   720 // -----------------------------------------------------------------------------
       
   721 // Ctwiostreams::wostringstream,wstring
       
   722 // Example test method function.
       
   723 // 
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726   TInt Ctwiostreams::wostringstreamL( CStifItemParser& aItem )
       
   727   {
       
   728   	int failures=0;
       
   729   	try
       
   730   	{ cout<<"";
       
   731    #if  STDCPP_OOM
       
   732 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   733   #endif 		
       
   734   	
       
   735   
       
   736 wostringstream oss;
       
   737 wstring mystr;
       
   738 
       
   739 oss << L"wostringstream testcase";
       
   740 oss.rdbuf();
       
   741 mystr=oss.str();
       
   742  #if  STDCPP_OOM
       
   743 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   744   #endif 
       
   745 /*if(mystr.compare(L"wostringstream testcase")==0)
       
   746 return KErrNone;
       
   747 return KErrGeneral;
       
   748 */
       
   749 if(mystr.compare(L"wostringstream testcase")!=0)
       
   750 failures++;
       
   751 
       
   752   }
       
   753   
       
   754   
       
   755    catch(bad_alloc&)
       
   756    {
       
   757    	//do nothing
       
   758     }
       
   759    catch(...)
       
   760    {
       
   761    	failures++;
       
   762    	
       
   763    }
       
   764    
       
   765 	if( failures == 0 )
       
   766 		return KErrNone;
       
   767   else  
       
   768 		return KErrGeneral;
       
   769     } 
       
   770 // -----------------------------------------------------------------------------
       
   771 // Ctwiostreams::wstreambuf,wofstreams
       
   772 // Example test method function.
       
   773 // 
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776    
       
   777   TInt Ctwiostreams::wstreambufL( CStifItemParser& aItem )
       
   778   {
       
   779 
       
   780 
       
   781 //locale   loc ("en_GB.UTF-8");
       
   782 
       
   783  
       
   784  
       
   785  int failures = 0;
       
   786  try
       
   787  {
       
   788  	
       
   789  
       
   790  wchar_t a[4]=
       
   791  {
       
   792  	0
       
   793  };
       
   794  
       
   795  wchar_t sentence[]= L"Sample sentence"; cout<<"";
       
   796   #if  STDCPP_OOM
       
   797 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   798   #endif 
       
   799  wstreambuf * pbuf;
       
   800  wofstream ostr ("c:\\TestFramework\\docs\\wstreambuf.txt");
       
   801  
       
   802  
       
   803   
       
   804 // if(cout.rdbuf( )->getloc( ).name( ).c_str( ) != "C") //failing
       
   805  //failures++;
       
   806  
       
   807  wchar_t ch[28];
       
   808  //rdbuf()s
       
   809  pbuf = ostr.rdbuf();
       
   810 
       
   811 
       
   812 //sputn()
       
   813 
       
   814 
       
   815 
       
   816 
       
   817  pbuf->sputn (sentence,sizeof(sentence)-1);
       
   818 
       
   819   
       
   820  ostr.open("c:\\TestFramework\\docs\\wstreambuf.txt");
       
   821   
       
   822  if(!ostr.is_open())
       
   823  failures++;
       
   824    
       
   825 
       
   826  long size1 = pbuf->pubseekoff(0,ios_base::end);
       
   827  if(size1!=31)
       
   828  failures++;
       
   829   
       
   830 
       
   831   pbuf->sputc('a');
       
   832   
       
   833 
       
   834  long size2 = pbuf->pubseekoff(0,ios_base::end);
       
   835  if(size2!=32)
       
   836  failures++;
       
   837   
       
   838  wifstream istr("c:\\TestFramework\\docs\\wstreambuf.txt");
       
   839  pbuf = istr.rdbuf();
       
   840 
       
   841 streamsize i = istr.rdbuf()->sgetn(&a[0], 3);   
       
   842     //a[i] = istr.widen('\0');
       
   843 
       
   844     // Display the size and contents of the buffer passed to sgetn.
       
   845    if(i!=3)
       
   846    failures++;
       
   847   
       
   848  
       
   849  int k = pbuf->snextc();
       
   850  
       
   851  
       
   852  //sgetc()
       
   853  while (pbuf->sgetc()!=EOF)
       
   854   {
       
   855      static int i;
       
   856       //sbumpc()
       
   857      ch[i] = pbuf->sbumpc();
       
   858      i++;
       
   859   }
       
   860 
       
   861   
       
   862   if(ch[0]!='l' )
       
   863   failures++;
       
   864   
       
   865  
       
   866   
       
   867   
       
   868   
       
   869   
       
   870   istr.close();
       
   871   ostr.close();
       
   872    #if  STDCPP_OOM
       
   873 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   874   #endif 
       
   875  /* if(failures)
       
   876   return KErrGeneral;
       
   877   else
       
   878   return KErrNone;
       
   879    */
       
   880  
       
   881 
       
   882 
       
   883   }
       
   884   
       
   885    catch(bad_alloc&)
       
   886    {
       
   887    	//do nothing
       
   888     }
       
   889    catch(...)
       
   890    {
       
   891    	failures++;
       
   892    	
       
   893    }
       
   894    
       
   895 	if( failures == 0 )
       
   896 		return KErrNone;
       
   897   else  
       
   898 		return KErrGeneral;
       
   899     } 
       
   900 
       
   901 // -----------------------------------------------------------------------------
       
   902 // Ctwiostreams::wostream
       
   903 // Example test method function.
       
   904 // 
       
   905 // -----------------------------------------------------------------------------
       
   906 //
       
   907 
       
   908  TInt Ctwiostreams::wostreamL( CStifItemParser& aItem )  
       
   909  {
       
   910  	
       
   911 
       
   912  
       
   913  int failures = 0;
       
   914  try
       
   915  {
       
   916  	
       
   917 
       
   918  wfilebuf fb;
       
   919 wchar_t input[18] = L"wostream testcase";
       
   920 streamsize size = 5;
       
   921   fb.open ("c:\\TestFramework\\docs\\wostream.txt",ios::out); cout<<"";
       
   922    #if  STDCPP_OOM
       
   923 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   924   #endif 
       
   925   wostream os(&fb);
       
   926   
       
   927   os.write(input,size);
       
   928   streamoff i = os.tellp();
       
   929   if(i!= 5)
       
   930   failures++;
       
   931   
       
   932   os.put('K');
       
   933   streamoff j = os.tellp();
       
   934   if(j!=6)
       
   935   failures++;
       
   936 
       
   937   os.seekp(2);
       
   938     os<<"i";
       
   939   streamoff k = os.tellp();
       
   940 
       
   941   if(k!=3)
       
   942   failures++;
       
   943   
       
   944   os.flush();
       
   945   
       
   946  #if  STDCPP_OOM
       
   947 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
   948   #endif 
       
   949   
       
   950  
       
   951   /*
       
   952 if(failures)
       
   953 return KErrGeneral;
       
   954 return KErrNone;
       
   955 */
       
   956  
       
   957   
       
   958  }
       
   959  
       
   960   catch(bad_alloc&)
       
   961    {
       
   962    	//do nothing
       
   963     }
       
   964    catch(...)
       
   965    {
       
   966    	failures++;
       
   967    	
       
   968    }
       
   969    
       
   970 	if( failures == 0 )
       
   971 		return KErrNone;
       
   972   else  
       
   973 		return KErrGeneral;
       
   974     } 
       
   975 
       
   976 // -----------------------------------------------------------------------------
       
   977 // Ctwiostreams::wstringbuf
       
   978 // Example test method function.
       
   979 // 
       
   980 // -----------------------------------------------------------------------------
       
   981 // 
       
   982  
       
   983   TInt Ctwiostreams::wstringbufL( CStifItemParser& aItem )  
       
   984   {
       
   985   int failures=0;
       
   986   try
       
   987   {
       
   988    cout<<"";	
       
   989  #if  STDCPP_OOM
       
   990 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
       
   991   #endif  
       
   992 wstringbuf sb;
       
   993 wstring mystr;
       
   994 
       
   995   
       
   996 sb.sputn (L"Sample string",13);
       
   997 mystr=sb.str();
       
   998 
       
   999 /*if(mystr.compare(L"Sample string") == 0)
       
  1000 return KErrNone;
       
  1001 else
       
  1002 return KErrGeneral;
       
  1003   */
       
  1004   #if  STDCPP_OOM
       
  1005 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
       
  1006   #endif 
       
  1007   if(mystr.compare(L"Sample string") != 0)
       
  1008   failures++;
       
  1009   
       
  1010   }
       
  1011   
       
  1012    catch(bad_alloc&)
       
  1013    {
       
  1014    	//do nothing
       
  1015     }
       
  1016    catch(...)
       
  1017    {
       
  1018    	failures++;
       
  1019    	
       
  1020    }
       
  1021    
       
  1022 	if( failures == 0 )
       
  1023 		return KErrNone;
       
  1024   else  
       
  1025 		return KErrGeneral;
       
  1026     } 
       
  1027   
       
  1028 //  End of File
       
  1029 
       
  1030 //  End of File