os/ossrv/stdcpp/tsrc/BC/apps/tiostreams/src/tiostreamsblocks.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 // INCLUDE FILES
    21 #include <e32svr.h>
    22 #include <StifParser.h>
    23 #include <Stiftestinterface.h>
    24 #include<iostream>
    25 #include<fstream>
    26 #include<string>
    27 #include<ostream>
    28 #include <sstream>
    29 #include<strstream>
    30 #include<deque>
    31 #include<iterator>
    32 #include<vector>
    33 #include <ios>
    34 #include <iostream>
    35 #include <fstream>
    36 #include <stl\char_traits.h>
    37  #include<e32std.h>
    38 
    39 #include<exception>
    40 
    41 #include "tiostreams.h"
    42 using namespace std;
    43  #define STDCPP_OOM FALSE// TRUE for OOM testing
    44  
    45 
    46 // ============================ MEMBER FUNCTIONS ===============================
    47 
    48 // -----------------------------------------------------------------------------
    49 // Ctiostreams::Delete
    50 // Delete here all resources allocated and opened from test methods. 
    51 // Called from destructor. 
    52 // -----------------------------------------------------------------------------
    53 //
    54 void Ctiostreams::Delete() 
    55     {
    56 
    57     }
    58 
    59 // -----------------------------------------------------------------------------
    60 // Ctiostreams::RunMethodL
    61 // Run specified method. Contains also table of test mothods and their names.
    62 // -----------------------------------------------------------------------------
    63 //
    64 TInt Ctiostreams::RunMethodL( 
    65     CStifItemParser& aItem ) 
    66     {
    67 
    68     static TStifFunctionInfo const KFunctions[] =
    69         {  
    70         // Copy this line for every implemented function.
    71         // First string is the function name used in TestScripter script file.
    72         // Second is the actual implementation member function. 
    73               // Second is the actual implementation member function. 
    74  ENTRY( "iofstreamL", Ctiostreams::iofstreamL ),
    75  ENTRY( "stringbufL", Ctiostreams::stringbufL ),
    76  ENTRY( "stringstreamL", Ctiostreams::stringstreamL ),
    77  ENTRY( "streambufL", Ctiostreams:: streambufL ),
    78  ENTRY( "ostreamL", Ctiostreams:: ostreamL ),
    79  ENTRY( "istreamL", Ctiostreams:: istreamL ),
    80  ENTRY( "istringstreamL", Ctiostreams:: istringstreamL ),
    81  ENTRY( "ostringstreamL", Ctiostreams:: ostringstreamL ),
    82  ENTRY( "ostreamiterators", Ctiostreams::ostreamiterators ),
    83  ENTRY( "fstreamL", Ctiostreams::fstreamL),
    84  ENTRY( "istrstreamL", Ctiostreams::istrstreamL),
    85  ENTRY( "strstreamL", Ctiostreams::strstreamL),
    86  ENTRY( "ostrstreamL", Ctiostreams::ostrstreamL),
    87  ENTRY( "istreamiterators", Ctiostreams::istreamiterators ),
    88  ENTRY( "istreambufiterators", Ctiostreams::istreambufiterators ),
    89  ENTRY( "strstreambufL", Ctiostreams::strstreambufL ),
    90  ENTRY( "freezeL", Ctiostreams::freezeL ),
    91  ENTRY( "fposL", Ctiostreams::fposL ),
    92   ENTRY( "filebufL", Ctiostreams::filebufL ),
    93           ENTRY( "basicstring", Ctiostreams::basicstring ),
    94         ENTRY( "basicfilebufL", Ctiostreams::basicfilebufL ),
    95         ENTRY( "basicistreamL", Ctiostreams::basicistreamL ),
    96         ENTRY( "wfstreamL", Ctiostreams::wfstreamL ),
    97         ENTRY( "wifstreamL", Ctiostreams::wifstreamL ),
    98         ENTRY( "wistreamL", Ctiostreams::wistreamL ),
    99 		ENTRY( "wofstreamL", Ctiostreams::wofstreamL ),
   100  		ENTRY( "wistringstreamL", Ctiostreams::wistringstreamL ),
   101  		ENTRY( "wostringstreamL", Ctiostreams::wostringstreamL ),
   102  		ENTRY( "wstreambufL", Ctiostreams::wstreambufL ),
   103  		ENTRY( "wostreamL", Ctiostreams::wostreamL ),
   104  		ENTRY( "wstringbufL", Ctiostreams::wstringbufL ),
   105       
   106 
   107 
   108         };
   109 
   110     const TInt count = sizeof( KFunctions ) / 
   111                         sizeof( TStifFunctionInfo );
   112 
   113     return RunInternalL( KFunctions, count, aItem );
   114 
   115     }
   116 
   117 
   118 // -----------------------------------------------------------------------------
   119 // Ctiostreams:: ofstream,ifstream
   120 // Example test method function.
   121 // (other items were commented in a header).
   122 // -----------------------------------------------------------------------------
   123 //
   124 
   125 
   126 TInt Ctiostreams::iofstreamL( CStifItemParser& aItem )
   127     {
   128  
   129  
   130 //__UHEAP_MARK;
   131 int failures=0 ;
   132 try
   133 {
   134 cout<<"";	
   135 #if  STDCPP_OOM
   136 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   137   #endif 
   138     ofstream myfile;
   139     filebuf *fbuf;
   140     char * buffer;
   141   long size;
   142     //ifstream 
   143   myfile.open ("c:\\TestFramework\\docs\\example.txt");
   144   if(!myfile.is_open())
   145   failures++;
   146  
   147   myfile << "Writing this to a file.";
   148   myfile<<"\0";
   149    myfile.close();
   150   if(myfile.is_open())
   151   failures++;
   152   
   153   
   154   
   155   
   156  // string line;
   157    ifstream myfile1; 
   158  
   159  
   160  myfile1.open("c:\\TestFramework\\docs\\example.txt" );
   161 
   162 fbuf=myfile1.rdbuf();
   163 
   164  
   165  // get file size using buffer's members
   166   size=fbuf->pubseekoff (0,ios::end,ios::in);
   167   fbuf->pubseekpos (0,ios::in);
   168 
   169   // allocate memory to contain file data
   170   buffer=new char[size];
   171 
   172   // get file data  
   173   fbuf->sgetn (buffer,size);
   174   
   175 #if  STDCPP_OOM
   176 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   177   #endif 
   178   
   179   
   180   if(buffer != "Writing this to a file.");
   181   else
   182   failures++;
   183   
   184   if(size!= 23)
   185   failures++;
   186   
   187 
   188 if(!myfile1.is_open())
   189 failures++;
   190 myfile1.close();
   191 if(myfile1.is_open())
   192 failures++;
   193   
   194    delete buffer;
   195 ios_base::Init();  // 0 -   218 FUNCTION Init()  iostream.cpp
   196 filebuf*  _Stl_create_filebuf(FILE* f, ios_base::openmode mode );  // 0 -   225 FUNCTION _Stl_create_filebuf() iostream.cpp
   197 ios_base::sync_with_stdio();//0 -   445 FUNCTION ios_base::sync_with_stdio()
   198 /* 
   199  if(failures)
   200  
   201   return KErrGeneral;
   202  return KErrNone;
   203 
   204 */
   205 
   206  
   207   //#if STDCPP_OOM
   208 //failures++;
   209 // #endif
   210 
   211     }
   212  
   213  catch(bad_alloc&)
   214    {
   215    	//do nothing
   216     }
   217    catch(...)
   218    {
   219    	failures++;
   220    	
   221    }
   222    
   223 	if( failures == 0 )
   224 		return KErrNone;
   225   else  
   226 		return KErrGeneral;
   227 		  
   228     }
   229 
   230  
   231 // -----------------------------------------------------------------------------
   232 // Ctiostreams:: stringbuf
   233 // Example test method function.
   234 // (other items were commented in a header).
   235 // -----------------------------------------------------------------------------
   236 //
   237  
   238  TInt Ctiostreams::stringbufL(CStifItemParser& aItem )
   239  {
   240  
   241  	int failures = 0;
   242  	try
   243  	{
   244  cout<<"";		
   245  #if  STDCPP_OOM
   246 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   247   #endif 	
   248 stringbuf sb;
   249   string mystr;
   250 
   251   sb.sputn("Sample string",13);
   252   mystr=sb.str();
   253 
   254     
   255    
   256    if(sb.in_avail()!=13)
   257   failures++;
   258    
   259    
   260     char ch = sb.sgetc();
   261    if(ch!= 'S')
   262    failures++;
   263    
   264    
   265   
   266   
   267   
   268   
   269    if(mystr.compare("Sample string") != 0)
   270    failures++;
   271   
   272   #if  STDCPP_OOM
   273 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   274   #endif 
   275   /* if(failures)
   276     
   277   return KErrGeneral;
   278   else
   279   return KErrNone;
   280  */
   281  
   282  
   283    //#if STDCPP_OOM
   284 //failures++;
   285 // #endif
   286  
   287  }
   288  
   289  catch(bad_alloc&)
   290    {
   291    	//do nothing
   292     }
   293    catch(...)
   294    {
   295    	failures++;
   296    	
   297    }
   298    
   299 	if( failures == 0 )
   300 		return KErrNone;
   301   else  
   302 		return KErrGeneral;
   303     }
   304 // -----------------------------------------------------------------------------
   305 // Ctiostreams:: stringstream
   306 // Example test method function.
   307 // (other items were commented in a header).
   308 // -----------------------------------------------------------------------------
   309 //
   310  
   311  
   312  TInt Ctiostreams::stringstreamL(CStifItemParser& aItem )
   313  {
   314  	
   315  	int val;
   316   string  teststr;
   317   int failures = 0;
   318   try
   319   {
   320   cout<<"";	
   321   #if  STDCPP_OOM
   322 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   323   #endif 
   324    stringstream ss (stringstream::in | stringstream::out);
   325    stringstream teststring;
   326    
   327     
   328    teststring<<"stringstream testcase";
   329    
   330    teststr = teststring.str();
   331    
   332    if(!teststr.compare("stringstream testcase"))
   333    ;
   334    else
   335    failures++;
   336 
   337  ss << "120 42 377 6 5 2000";
   338 #if  STDCPP_OOM
   339 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   340   #endif 
   341  for (int n=0; n<6; n++)
   342   {
   343     ss >> val;
   344     
   345     switch(n)
   346     {
   347     	case 0://precision 
   348     	if(val!=120)
   349     	failures++;
   350     	break;
   351     	case 1:
   352     	if(val!=42)
   353     	failures++;
   354     	break;
   355     	case 2:
   356     	if(val!=377)
   357     	failures++;
   358     	break;
   359     	case 3:
   360     	if(val!=6)
   361     	failures++;
   362     	break;
   363     	
   364     	case 4:
   365     	if(val!=5)
   366     	failures++;
   367     	break;
   368        
   369     	case 5:
   370     	if(val!=2000)
   371     	failures++;
   372     	break;
   373     
   374     default:
   375     break;
   376     }
   377     
   378    
   379   }
   380 
   381  /* if(failures)
   382    return KErrGeneral;
   383   return KErrNone;
   384  */
   385  
   386  
   387   
   388   //#if STDCPP_OOM
   389 //failures++;
   390 // #endif
   391  }
   392 
   393 catch(bad_alloc&)
   394    {
   395    	//do nothing
   396     }
   397    catch(...)
   398    {
   399    	failures++;
   400    	
   401    }
   402    
   403 	if( failures == 0 )
   404 		return KErrNone;
   405   else  
   406 		return KErrGeneral;
   407     }
   408 
   409 // -----------------------------------------------------------------------------
   410 // Ctiostreams:: streambuf
   411 // Example test method function.
   412 // (other items were commented in a header).
   413 // -----------------------------------------------------------------------------
   414 //
   415 
   416  TInt Ctiostreams::streambufL(CStifItemParser& aItem )
   417  {
   418 //    locale   loc ("en_GB.UTF-8");
   419 
   420  
   421  
   422  int failures = 0;
   423  try
   424  {
   425  	
   426  
   427  char a[4]=
   428  {
   429  	0
   430  };
   431  
   432  char sentence[]= "Sample sentence";
   433  cout<<"";
   434  #if  STDCPP_OOM
   435 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   436   #endif 
   437  streambuf * pbuf;
   438  ofstream ostr ("c:\\TestFramework\\docs\\streambuf.txt");
   439  
   440  
   441   
   442  if(!cout.rdbuf( )->getloc( ).name( ).c_str( ))    //failing
   443 // failures++;
   444  ;
   445  char ch[14];
   446  //rdbuf()s
   447  pbuf = ostr.rdbuf();
   448 
   449 
   450 //sputn()
   451 
   452 
   453 
   454 
   455  pbuf->sputn (sentence,sizeof(sentence)-1);
   456 
   457   
   458  ostr.open("c:\\TestFramework\\docs\\streambuf.txt");
   459   
   460  if(!ostr.is_open())
   461  failures++;
   462    
   463 
   464  long size1 = pbuf->pubseekoff(0,ios_base::end);
   465  if(size1!=15)
   466  failures++;
   467   
   468 
   469   pbuf->sputc('a');
   470   
   471 
   472  long size2 = pbuf->pubseekoff(0,ios_base::end);
   473  if(size2!=16)
   474  failures++;
   475   
   476  ifstream istr("c:\\TestFramework\\docs\\streambuf.txt");
   477  pbuf = istr.rdbuf();
   478 
   479 streamsize i = istr.rdbuf()->sgetn(&a[0], 3);   
   480  
   481     // Display the size and contents of the buffer passed to sgetn.
   482    if(i!=3)
   483    failures++;
   484   
   485  
   486  int k = pbuf->snextc();
   487  
   488  
   489  //sgetc()
   490  while (pbuf->sgetc()!=EOF)
   491   {
   492     // static int i;
   493     int  i=0;
   494       //sbumpc()
   495      ch[i] = pbuf->sbumpc();
   496      i++;
   497   }
   498 
   499   
   500   if(ch[0]!='a' )
   501   failures++;
   502   
   503  
   504   
   505   
   506   
   507   
   508   istr.close();
   509   #if  STDCPP_OOM
   510 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   511   #endif 
   512   /*
   513   if(failures)
   514   return KErrGeneral;
   515   else
   516   return KErrNone;
   517    
   518    */
   519 
   520   
   521   //#if STDCPP_OOM
   522 //failures++;
   523 // #endif
   524  
   525  }
   526  catch(bad_alloc&)
   527    {
   528    	//do nothing
   529     }
   530    catch(...)
   531    {
   532    	failures++;
   533    	
   534    }
   535    
   536 	if( failures == 0 )
   537 		return KErrNone;
   538   else  
   539 		return KErrGeneral;
   540     }
   541  
   542  
   543 // -----------------------------------------------------------------------------
   544 // Ctiostreams:: ostream
   545 // Example test method function.
   546 // (other items were commented in a header).
   547 // -----------------------------------------------------------------------------
   548 //
   549  
   550  TInt Ctiostreams::ostreamL(CStifItemParser& aItem )
   551  
   552  {
   553  
   554   
   555  int failures = 0;
   556  try
   557  {
   558  	
   559  
   560  filebuf fb;
   561 char input[17] = "ostream testcase";
   562 streamsize size = 5;
   563   fb.open ("c:\\TestFramework\\docs\\ostream.txt",ios::out);
   564   cout<<"";
   565   #if  STDCPP_OOM
   566 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   567   #endif 
   568   ostream os(&fb);
   569   
   570   os.write(input,size);
   571   streamoff i = os.tellp();
   572   if(i!= 5)
   573   failures++;
   574   
   575   os.put('K');
   576   streamoff j = os.tellp();
   577   if(j!=6)
   578   failures++;
   579 
   580   os.seekp(2);
   581     os<<"i";
   582   streamoff k = os.tellp();
   583 
   584   if(k!=3)
   585   failures++;
   586   
   587  os.flush();
   588   
   589    #if  STDCPP_OOM
   590 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   591   #endif 
   592   
   593    
   594   /*
   595   if(failures)
   596   return KErrGeneral;
   597   return KErrNone;
   598   */
   599  
   600   
   601    //#if STDCPP_OOM
   602 //failures++;
   603 // #endif
   604  }
   605  
   606  catch(bad_alloc&)
   607    {
   608    	//do nothing
   609     }
   610    catch(...)
   611    {
   612    	failures++;
   613    	
   614    }
   615    
   616 	if( failures == 0 )
   617 		return KErrNone;
   618   else  
   619 		return KErrGeneral;
   620     }
   621  
   622 // -----------------------------------------------------------------------------
   623 // Ctiostreams:: istream
   624 // Example test method function.
   625 // (other items were commented in a header).
   626 // -----------------------------------------------------------------------------
   627 //
   628   TInt Ctiostreams::istreamL(CStifItemParser& aItem )
   629   {
   630  
   631 int failures =0;
   632 try
   633 {
   634 	
   635 
   636 int length;
   637 char * buffer;
   638 char getl[8] ;
   639  filebuf fb;
   640  fb.open ("c:\\TestFramework\\docs\\istream.txt",ios::in);
   641  cout<<"";
   642  #if  STDCPP_OOM
   643 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   644   #endif 
   645  istream is(&fb);
   646  
   647  //needs to rewrite
   648 
   649 
   650   // get length of file:
   651   is.seekg (0, ios::end);
   652   length = is.tellg();
   653   is.seekg (0, ios::beg);
   654   
   655   
   656   
   657 
   658 
   659 if(length != 7)
   660 failures++;
   661 
   662  char ch = is.get();
   663   
   664    
   665  if(is.gcount() != 1)
   666  failures++;
   667  
   668   
   669  if( ch != 'S')
   670  failures++;
   671  
   672  
   673 
   674  
   675  
   676  
   677  
   678  char pk1 = is.peek();
   679  
   680  if(pk1!= 'h')
   681  failures++;
   682  
   683  
   684  is.unget();
   685  
   686  char pk2 = is.peek();
   687  if(pk2!= 'S')
   688  failures++;
   689  
   690  is.get();
   691  is.putback('K');
   692  
   693  is.getline(getl,8,'\0');
   694  
   695  if(getl == "Khaheen")
   696  failures++;
   697  
   698  if(is.gcount() != 7)
   699  failures++;
   700  
   701  
   702   fb.close();
   703   /*if(failures)
   704  
   705  
   706   return KErrGeneral;
   707   return KErrNone;
   708   
   709  */
   710    
   711    #if  STDCPP_OOM
   712 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   713   #endif 
   714    //#if STDCPP_OOM
   715 //failures++;
   716 // #endif
   717 	  
   718   }
   719   
   720   catch(bad_alloc&)
   721    {
   722    	//do nothing
   723     }
   724    catch(...)
   725    {
   726    	failures++;
   727    	
   728    }
   729    
   730 	if( failures == 0 )
   731 		return KErrNone;
   732   else  
   733 		return KErrGeneral;
   734     }
   735 
   736 // -----------------------------------------------------------------------------
   737 // Ctiostreams:: istringstream
   738 // Example test method function.
   739 // (other items were commented in a header).
   740 // -----------------------------------------------------------------------------
   741 //  
   742   
   743    TInt Ctiostreams::istringstreamL(CStifItemParser& aItem )
   744    {
   745    	int n,val;
   746  	int failures =0;
   747  	try
   748  	{
   749  	string strvalues = "125 320 512 750 333";
   750  	cout<<"";	
   751  	#if  STDCPP_OOM
   752 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   753   #endif 
   754 	
   755   	istringstream iss (strvalues,istringstream::in);
   756 
   757 if(iss.str()  != "125 320 512 750 333")
   758 failures++;
   759 
   760 #if  STDCPP_OOM
   761 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   762   #endif 
   763   for (n=0; n<5; n++)
   764   {
   765     iss >> val;
   766      switch(n)
   767     {
   768     	case 0:
   769     	if(val!=125)
   770     	failures++;
   771     	break;
   772     	case 1:
   773     	if(val!=320)
   774     	failures++;
   775     	break;
   776     	case 2:
   777     	if(val!=512)
   778     	failures++;
   779     	break;
   780     	case 3:
   781     	if(val!=750)
   782     	failures++;
   783     	break;
   784     	
   785     	case 4:
   786     	if(val!=333)
   787     	failures++;
   788     	break;
   789        
   790     	    
   791     default:
   792     break;
   793     }
   794     
   795   }
   796   
   797    
   798    //#if STDCPP_OOM
   799 //failures++;
   800 // #endif
   801 
   802 /* if(failures)
   803  return KErrGeneral;
   804  else
   805  return KErrNone;*/
   806    }
   807    
   808    catch(bad_alloc&)
   809    {
   810    	//do nothing
   811     }
   812    catch(...)
   813    {
   814    	failures++;
   815    	
   816    }
   817    
   818 	if( failures == 0 )
   819 		return KErrNone;
   820   else  
   821 		return KErrGeneral;
   822     }
   823    
   824    
   825    
   826    
   827    
   828    
   829 // -----------------------------------------------------------------------------
   830 // Ctiostreams:: ostringstream,
   831 // Example test method function.
   832 // (other items were commented in a header).
   833 // -----------------------------------------------------------------------------
   834 //
   835    
   836    TInt Ctiostreams::ostringstreamL(CStifItemParser& aItem )
   837    {
   838  	int failures =0 ;
   839  	try
   840  	{
   841  		
   842  	
   843  	basic_string<char> i( "test" );
   844  	cout<<"";
   845  	#if  STDCPP_OOM
   846 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   847   #endif 
   848    ostringstream ss;
   849    
   850    ss.rdbuf( )->str( i );
   851    if(ss.str( ).compare("test") != 0)
   852    failures++; 
   853 
   854    ss << "z";
   855    if(ss.str( ) .compare("zest")!=0)
   856    failures++;
   857       
   858    ss.rdbuf( )->str( "be" );
   859    if(ss.str( ).compare("be")!=0)
   860    failures++;
   861    
   862    #if  STDCPP_OOM
   863 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   864   #endif 
   865    /*
   866    if(failures)
   867    
   868 	return KErrGeneral;
   869 	else
   870 	return KErrNone;
   871 */
   872 
   873 
   874  
   875    //#if STDCPP_OOM
   876 //failures++;
   877 // #endif
   878    }
   879    
   880    catch(bad_alloc&)
   881    {
   882    	//do nothing
   883     }
   884    catch(...)
   885    {
   886    	failures++;
   887    	
   888    }
   889    
   890 	if( failures == 0 )
   891 		return KErrNone;
   892   else  
   893 		return KErrGeneral;
   894     }
   895    
   896     TInt Ctiostreams::ostreamiterators(CStifItemParser& aItem )
   897     {
   898     	
   899     
   900   //needs to rewrite
   901   //____________________
   902    
   903    int arr[4] = { 3,4,7,8 };
   904    int total=0;
   905    deque<int> d(arr+0, arr+4);
   906    //
   907    // stream the whole vector and a sum to cout
   908    //
   909   
   910    copy(d.begin(),(d.end()-1),ostream_iterator<int,char>(cout,""));
   911   
   912   
   913   if( *(d.end()-1) == 8)
   914   return KErrNone;
   915   return KErrGeneral;
   916 
   917 
   918  }
   919 
   920     
   921     
   922 // -----------------------------------------------------------------------------
   923 // Ctiostreams:: fstream
   924 // Example test method function.
   925 // (other items were commented in a header).
   926 // -----------------------------------------------------------------------------
   927 //
   928     
   929     
   930     TInt Ctiostreams::fstreamL(CStifItemParser& aItem ) 
   931     {
   932    //  __UHEAP_MARK;
   933 int failures =0;
   934 try
   935 {
   936 cout<<"";	
   937 #if  STDCPP_OOM
   938 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   939   #endif 
   940 fstream filestr ("c:\\TestFramework\\docs\\fstream.txt", fstream::in | fstream::out);
   941 
   942 if(!filestr.is_open())
   943 failures++;
   944  
   945 filestr.close();
   946 if(filestr.is_open())
   947 failures++;
   948   
   949  // __UHEAP_MARKEND;
   950   
   951   /*if(failures)
   952 return KErrNone;
   953 return KErrGeneral;
   954     */  
   955  #if  STDCPP_OOM
   956 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   957   #endif    
   958    //#if STDCPP_OOM
   959 //failures++;
   960 // #endif
   961     
   962     }
   963    catch(bad_alloc&)
   964    {
   965    	//do nothing
   966     }
   967    catch(...)
   968    {
   969    	failures++;
   970    	
   971    }
   972    
   973 	if( failures == 0 )
   974 		return KErrNone;
   975   else  
   976 		return KErrGeneral;
   977     } 
   978  
   979 // -----------------------------------------------------------------------------
   980 // Ctiostreams:: istrstream
   981 // Example test method function.
   982 // (other items were commented in a header).
   983 // -----------------------------------------------------------------------------
   984 //   
   985     TInt Ctiostreams::istrstreamL(CStifItemParser& aItem ) 
   986     {
   987   //  __UHEAP_MARK;	
   988   int failures=0;
   989   try
   990   {
   991   	
   992   
   993     char* p = "This is first string";
   994     char* q = "This is second string";
   995     char* r = "";
   996     const char* s ="const char";
   997     streamsize  n =10;
   998     cout<<"";
   999     #if  STDCPP_OOM
  1000 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1001   #endif 
  1002     istrstream first(p);
  1003     istrstream second(q);
  1004     istrstream third(r);
  1005     
  1006     istrstream four(s);
  1007     
  1008     istrstream  five(p,n);
  1009     istrstream six(s,n);
  1010  /*   if(first.str() == "This is first string")
  1011     if(second.str()!= " This is second string")
  1012     if(third.str() == "")
  1013  //   __UHEAP_MARKEND;
  1014     
  1015     return KErrNone;
  1016     return KErrGeneral;
  1017    */ 
  1018        first.rdbuf();
  1019     second.rdbuf();
  1020     third.rdbuf();
  1021     
  1022      if(first.str() != "This is first string")
  1023     if(second.str()== " This is second string")
  1024     if(third.str() != "")
  1025     failures++;
  1026     
  1027     #if  STDCPP_OOM
  1028 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1029   #endif 
  1030   //#if STDCPP_OOM
  1031 //failures++;
  1032 // #endif
  1033      
  1034     }
  1035     
  1036     
  1037     catch(bad_alloc&)
  1038    {
  1039    	//do nothing
  1040     }
  1041    catch(...)
  1042    {
  1043    	failures++;
  1044    	
  1045    }
  1046    
  1047 	if( failures == 0 )
  1048 		return KErrNone;
  1049   else  
  1050 		return KErrGeneral;
  1051     }
  1052     
  1053 TInt Ctiostreams::strstreamL(CStifItemParser& aItem ) 
  1054       {
  1055     // __UHEAP_MARK; 	
  1056      
  1057   	int failures = 0;
  1058   	try
  1059   	{
  1060   	cout<<"";	
  1061   	#if  STDCPP_OOM
  1062 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1063   #endif 
  1064   char* s;
  1065    int n;
  1066    ios_base::openmode mode;
  1067 //  strstream ss3(s, n, mode);
  1068   	strstream ss1,ss2;
  1069   	 ss1 << "";
  1070   	 ss1.rdbuf();
  1071   	 if(ss1.rdbuf( )->pcount( ) != 0)
  1072   	 failures++;
  1073   	 
  1074   	 string str1= ss1.str();
  1075   	 if(str1.compare("")!=0)
  1076   	 failures++;
  1077   	 
  1078   	 ss2 << "strstream testcase";
  1079   	 ss2 << '\0';
  1080   	 if( ss2.rdbuf( )->pcount( ) != sizeof("strstream testcase\0")-1)
  1081   	 failures++;
  1082   	 
  1083   	 string str = ss2.str();
  1084   	 
  1085   	 if(str.compare("strstream testcase")!= 0)
  1086   	 failures++;
  1087   	 ss1.freeze();
  1088   	 //__UHEAP_MARKEND;
  1089   /*	 
  1090   	 if(failures)
  1091   	 return KErrGeneral;
  1092   	 else
  1093   	return KErrNone;
  1094   */
  1095   
  1096   
  1097   #if  STDCPP_OOM
  1098 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1099   #endif 
  1100   
  1101     //#if STDCPP_OOM
  1102 //failures++;
  1103 // #endif
  1104       }
  1105       
  1106       catch(bad_alloc&)
  1107    {
  1108    	//do nothing
  1109     }
  1110    catch(...)
  1111    {
  1112    	failures++;
  1113    	
  1114    }
  1115    
  1116 	if( failures == 0 )
  1117 		return KErrNone;
  1118   else  
  1119 		return KErrGeneral;
  1120     }
  1121     
  1122     
  1123 TInt Ctiostreams::ostrstreamL(CStifItemParser& aItem ) 
  1124       {
  1125       	
  1126      //__UHEAP_MARK;
  1127      int failures = 0;
  1128      try
  1129      {
  1130      cout<<"";	
  1131      #if  STDCPP_OOM
  1132 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1133   #endif 
  1134   	char* s;
  1135   	int n;
  1136   	ios_base::openmode mode;
  1137 //  	ostrstream  oss3( s, n, mode);
  1138   	ostrstream  oss1 ,oss2;
  1139   	string str;
  1140   	 oss1 << "";
  1141   	 oss1.rdbuf();
  1142   	 if(oss1.rdbuf( )->pcount( ) != 0)
  1143   	 failures++;
  1144   	 
  1145   	 oss2 << "ostrstream testcase";
  1146   	 oss2<<'\0';
  1147   	 str = oss2.str();
  1148   	 
  1149   	 if(str.compare("ostrstream testcase") !=0)
  1150   	 failures++;
  1151   	 
  1152    oss2.freeze();
  1153   	 
  1154   	 #if  STDCPP_OOM
  1155 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1156   #endif 
  1157   	
  1158   	// __UHEAP_MARKEND;
  1159   /*	 
  1160   	 if(failures)
  1161   	 return KErrGeneral;
  1162   	 else
  1163   	return KErrNone;
  1164   */
  1165   
  1166     //#if STDCPP_OOM
  1167 //failures++;
  1168 // #endif
  1169       }
  1170       
  1171       catch(bad_alloc&)
  1172    {
  1173    	//do nothing
  1174     }
  1175    catch(...)
  1176    {
  1177    	failures++;
  1178    	
  1179    }
  1180    
  1181 	if( failures == 0 )
  1182 		return KErrNone;
  1183   else  
  1184 		return KErrGeneral;
  1185     }
  1186    
  1187 
  1188 
  1189  TInt Ctiostreams::istreamiterators(CStifItemParser& aItem )
  1190     {
  1191     	
  1192    // __UHEAP_MARK;
  1193    // Typedefs for convenience.
  1194    int failures=0;
  1195    try
  1196    {
  1197    cout<<"";
  1198    	#if  STDCPP_OOM
  1199 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1200   #endif 
  1201    
  1202     typedef std::vector<int, std::allocator<int> >    Vector;
  1203 
  1204     typedef std::istream_iterator<Vector::value_type,char, std::char_traits<char>, ptrdiff_t>        is_iter;
  1205 
  1206  #if  STDCPP_OOM
  1207 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1208   #endif 
  1209     Vector v;
  1210 //__UHEAP_MARKEND;
  1211  
  1212     //#if STDCPP_OOM
  1213 //failures++;
  1214 // #endif
  1215  
  1216 
  1217 
  1218  }
  1219 
  1220 
  1221 catch(bad_alloc&)
  1222    {
  1223    	//do nothing
  1224     }
  1225    catch(...)
  1226    {
  1227    	failures++;
  1228    	
  1229    }
  1230    
  1231 	if( failures == 0 )
  1232 		return KErrNone;
  1233   else  
  1234 		return KErrGeneral;
  1235     }
  1236    
  1237    
  1238  TInt Ctiostreams::istreambufiterators(CStifItemParser& aItem )
  1239     {
  1240     	
  1241       
  1242    //   __UHEAP_MARK;
  1243        // create a temporary filename
  1244        
  1245        int failures=0;
  1246        try
  1247        {
  1248        	
  1249        
  1250     const char *fname = tmpnam (0);
  1251 
  1252     if (!fname)
  1253         return 1;
  1254 
  1255     // open the file is_iter.out for reading and writing
  1256     std::ofstream out (fname, std::ios::out | std::ios::in | 
  1257                               std::ios::trunc);
  1258 
  1259     // output the example sentence into the file
  1260 
  1261     // seek to the beginning of the file
  1262     out.seekp (0);
  1263     cout<<"";
  1264 #if  STDCPP_OOM
  1265 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1266   #endif 
  1267     // construct an istreambuf_iterator pointing to
  1268     // the ofstream object underlying streambuffer
  1269     std::istreambuf_iterator<char, std::char_traits<char> >iter (out.rdbuf ());
  1270 
  1271     // construct an end of stream iterator
  1272     const std::istreambuf_iterator<char,std::char_traits<char> > end;
  1273 #if  STDCPP_OOM
  1274 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1275   #endif 
  1276     std::cout << std::endl;
  1277 
  1278     // output the content of the file
  1279     while (!iter.equal (end)) {
  1280 
  1281         // use both operator++ and operator*
  1282         std::cout << *iter++;
  1283     }
  1284 
  1285     std::cout << std::endl; 
  1286 
  1287     // remove temporary file
  1288     remove (fname);
  1289 //__UHEAP_MARKEND;
  1290  
  1291  //#if STDCPP_OOM
  1292 //failures++;
  1293 // #endif
  1294 
  1295  }
  1296 
  1297 catch(bad_alloc&)
  1298    {
  1299    	//do nothing
  1300     }
  1301    catch(...)
  1302    {
  1303    	failures++;
  1304    	
  1305    }
  1306    
  1307 	if( failures == 0 )
  1308 		return KErrNone;
  1309   else  
  1310 		return KErrGeneral;
  1311     }
  1312     
  1313     
  1314     
  1315  TInt Ctiostreams::strstreambufL(CStifItemParser& aItem )
  1316  
  1317  
  1318  {
  1319 // 	__UHEAP_MARK;
  1320  	
  1321  int failures =0;
  1322  try
  1323  {
  1324  	
  1325  cout<<"";
  1326 
  1327   	#if  STDCPP_OOM
  1328 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1329   #endif 
  1330   
  1331   signed char* get;
  1332   streamsize n=10;
  1333   signed char* put;
  1334    unsigned char* uget;
  1335    unsigned char* uput;
  1336   const char* cget;
  1337   const signed char* csget;
  1338   
  1339   const unsigned char* cucget;
  1340   
  1341   
  1342   typedef void* (*__alloc_fn)(size_t);
  1343   typedef void (*__free_fn)(void*);
  1344  
  1345   __alloc_fn  alloc_f;
  1346  
  1347   __free_fn free_f;
  1348   
  1349   	//overloaded
  1350   	strstreambuf  buf1(get, n,put);
  1351   	
  1352   	//overloaded
  1353   	
  1354   	strstreambuf buf2(uget,n,uput);
  1355   	
  1356   	  	//overloaded
  1357   	strstreambuf buf3(cget,n);
  1358   	//onverloaded
  1359   	strstreambuf buf4(csget,n);
  1360   	//overloaded
  1361   	strstreambuf buf5(cucget,n);
  1362   	
  1363   	
  1364 //  	strstreambuf buf6( alloc_f, free_f);
  1365   	  	strstreambuf buf7(n);
  1366 
  1367   	strstreambuf  buf;
  1368   string str;
  1369  int i = buf.sputn("strstreambuf testcase", sizeof("strstreambuf testcase")-1);
  1370  
  1371 if((buf.pcount())!= i) 
  1372 failures++;
  1373  
  1374  buf.freeze();
  1375 //if(buf.str() != "strstreambuf testcase")   //fails
  1376 //failures++;
  1377 
  1378 #if  STDCPP_OOM
  1379 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1380   #endif 
  1381 
  1382 //__UHEAP_MARKEND; 
  1383 /*if(failures)
  1384 return KErrGeneral;
  1385 else
  1386  return KErrNone;
  1387   */
  1388   
  1389   //#if STDCPP_OOM
  1390 //failures++;
  1391 // #endif
  1392  
  1393  }
  1394  catch(bad_alloc&)
  1395    {
  1396    	//do nothing
  1397     }
  1398    catch(...)
  1399    {
  1400    	failures++;
  1401    	
  1402    }
  1403    
  1404 	if( failures == 0 )
  1405 		return KErrNone;
  1406   else  
  1407 		return KErrGeneral;
  1408     }
  1409     
  1410     
  1411     
  1412 
  1413  TInt Ctiostreams::freezeL(CStifItemParser& aItem )
  1414  {
  1415  
  1416  int failures=0;
  1417  try
  1418  {
  1419  	
  1420   strstream  x;
  1421 int failures =0;
  1422     x << "test1";
  1423    
  1424 if(!x.good())
  1425 failures++;    
  1426 cout<<"";
  1427  
  1428   #if  STDCPP_OOM
  1429 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1430   #endif  
  1431    
  1432   x.rdbuf()->freeze();
  1433  #if  STDCPP_OOM
  1434 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1435   #endif 
  1436 if(!x.good())
  1437 failures++;
  1438 
  1439     // Stream is bad now, wrote on frozen stream
  1440     x << "test1.5";
  1441     
  1442 //  report(x);
  1443 if(!x.good())
  1444 failures++;
  1445     // Unfreeze stream, but it is still bad
  1446     x.rdbuf()->freeze(false);
  1447  if(!x.good())
  1448 failures++;
  1449 
  1450     // Clear stream
  1451     x.clear();
  1452  
  1453 if(!x.good())
  1454 failures++;
  1455 
  1456 
  1457     x << "test3";
  1458 
  1459 
  1460 
  1461 
  1462     // Clean up.  Failure to unfreeze stream will cause a
  1463     // memory leak.
  1464     x.rdbuf()->freeze(false);
  1465     /*
  1466 if(failures)
  1467 return KErrGeneral;
  1468 else
  1469 return KErrNone;
  1470 
  1471 */
  1472 
  1473  //#if STDCPP_OOM
  1474 //failures++;
  1475 // #endif
  1476   }
  1477   
  1478   
  1479   
  1480   catch(bad_alloc&)
  1481    {
  1482    	//do nothing
  1483     }
  1484    catch(...)
  1485    {
  1486    	failures++;
  1487    	
  1488    }
  1489    
  1490 	if( failures == 0 )
  1491 		return KErrNone;
  1492   else  
  1493 		return KErrGeneral;
  1494     }
  1495  
  1496 
  1497  TInt Ctiostreams::fposL(CStifItemParser& aItem )
  1498  {
  1499  int failures=0;
  1500  try
  1501  {
  1502  	
  1503  
  1504  streamoff s;
  1505    ifstream file( "c:\\TestFramework\\docs\\fpos_state.txt" );
  1506   cout<<"";
  1507     #if  STDCPP_OOM
  1508 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1509   #endif
  1510    fpos<mbstate_t> f = file.tellg( );
  1511    char ch;
  1512    while ( !file.eof( ) )
  1513       file.get( ch );
  1514   
  1515   f.state();
  1516     cout<<"";
  1517     #if  STDCPP_OOM
  1518 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1519   #endif
  1520    //s = f;
  1521   // if(f.state( ))
  1522   // failures++;
  1523   // f.state( 9 );
  1524  //  if( f.state( ))
  1525  //  failures++;
  1526    /*if(failures)
  1527    return KErrGeneral;
  1528    return KErrNone;*/
  1529    
  1530    //#if STDCPP_OOM
  1531 //failures++;
  1532 // #endif
  1533  }
  1534 
  1535  catch(bad_alloc&)
  1536    {
  1537    	//do nothing
  1538     }
  1539    catch(...)
  1540    {
  1541    	failures++;
  1542    	
  1543    }
  1544    
  1545 	if( failures == 0 )
  1546 		return KErrNone;
  1547   else  
  1548 		return KErrGeneral;
  1549     }
  1550  
  1551  
  1552  
  1553  
  1554 // -----------------------------------------------------------------------------
  1555 // Cstdcpp_filebuf::filebufL
  1556 // Example test method function.
  1557 // (other items were commented in a header).
  1558 // -----------------------------------------------------------------------------
  1559 //
  1560 TInt Ctiostreams::filebufL( CStifItemParser& aItem )
  1561     {
  1562    int failures=0;
  1563 try
  1564 {
  1565 	
  1566 
  1567 
  1568     ifstream is;
  1569     cout<<"";
  1570     #if  STDCPP_OOM
  1571 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1572   #endif 
  1573   filebuf * fb;
  1574 
  1575   fb = is.rdbuf();
  1576   fb->open ("c:\\TestFramework\\docs\\filebuf.txt",ios::in);
  1577 
  1578    if(!fb->is_open())
  1579    failures++;
  1580    
  1581 
  1582   fb->close();
  1583 if(fb->is_open())
  1584 failures++;
  1585 
  1586 
  1587 #if  STDCPP_OOM
  1588 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1589   #endif 
  1590 /*
  1591 if(failures)
  1592 return KErrGeneral;
  1593 return KErrNone;
  1594  */
  1595  
  1596   //#if STDCPP_OOM
  1597 //failures++;
  1598 // #endif
  1599  
  1600     }
  1601     
  1602     catch(bad_alloc&)
  1603    {
  1604    	//do nothing
  1605     }
  1606    catch(...)
  1607    {
  1608    	failures++;
  1609    	
  1610    }
  1611    
  1612 	if( failures == 0 )
  1613 		return KErrNone;
  1614   else  
  1615 		return KErrGeneral;
  1616     }
  1617  
  1618  
  1619     
  1620 TInt Ctiostreams::basicstring( CStifItemParser& aItem )
  1621     {
  1622 				int failures =0;
  1623 				
  1624 				try
  1625 				{
  1626 					
  1627 				
  1628 			    const char *cstr1a = "Hello Out There.";
  1629 			    cout<<"";
  1630 			    #if  STDCPP_OOM
  1631 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1632   #endif 
  1633 			   basic_string<char> str1a(cstr1a ,5);
  1634 	 
  1635 			   if(str1a.compare("Hello")!=0)
  1636 			   failures++;
  1637 			    
  1638 			    str1a.append("Out There");
  1639 			    if(!str1a.compare("Hello Out There"))
  1640 			    failures++;
  1641 			    
  1642 			    
  1643 			   string  str2a ( "How Do You Do?" );
  1644 			   basic_string <char> str2b ( str2a , 7 , 7 );
  1645 			   
  1646 			    if(str2b.compare("You Do?")!=0)
  1647 			   failures++;
  1648 			   
  1649 			    
  1650 			 
  1651 			   basic_string <char> str3a ( 5, '9' );
  1652 			   if(str3a.compare("99999")!=0)
  1653 			   failures++;
  1654 			   
  1655 
  1656 			   
  1657 			   basic_string <char> str4a;
  1658 			   string str4b;
  1659 			   basic_string <char> str4c ( str4b.get_allocator( ) );
  1660 			   if (!str4c.empty ())
  1661 			   failures++;
  1662 			      
  1663 
  1664 			  
  1665 			   string str5a ( "Hello World");
  1666 			    basic_string <char>::iterator strp_Iter, str1_Iter, str2_Iter;
  1667 			   
  1668 			   
  1669 			   
  1670 			   strp_Iter = str5a.begin();
  1671 			   if(*strp_Iter != 'H' )
  1672 				failures++;
  1673 			   
  1674 			   
  1675 			   
  1676 			   
  1677 			   basic_string <char>::reference refStr2 = str5a.at ( 3 );
  1678 			   
  1679 			   if(refStr2 != 'l')
  1680 			   failures++;
  1681 			   
  1682 			   
  1683 			   if(str5a.size()!=11)
  1684 			   failures++;
  1685 			   if(str5a.length()!=11)
  1686 			   failures++;
  1687 			   if(str5a.capacity()!=11)
  1688 			   failures++;
  1689 			   
  1690 
  1691 
  1692 		#if  STDCPP_OOM
  1693 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1694   #endif 	   
  1695 			  /*  if(failures)
  1696 			    return  KErrGeneral;
  1697 			    return KErrNone;
  1698 			    */
  1699 
  1700     }
  1701 
  1702   catch(bad_alloc&)
  1703    {
  1704    	//do nothing
  1705     }
  1706    catch(...)
  1707    {
  1708    	failures++;
  1709    	
  1710    }
  1711    
  1712 	if( failures == 0 )
  1713 		return KErrNone;
  1714   else  
  1715 		return KErrGeneral;
  1716     }
  1717 
  1718 // -----------------------------------------------------------------------------
  1719 // Ctwiostreams::basic_filebuf
  1720 // Example test method function.
  1721 // 
  1722 // -----------------------------------------------------------------------------
  1723 // 
  1724  
  1725  TInt Ctiostreams::basicfilebufL( CStifItemParser& aItem )
  1726  {
  1727  	
  1728 	 int failures=0;
  1729 	 try
  1730 	 {
  1731 	 	
  1732 	 
  1733    	 char* wszHello = "Hello World";
  1734    	 char wBuffer[128];
  1735    	  cout<<"";
  1736 		    #if  STDCPP_OOM
  1737 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1738   #endif 
  1739 		
  1740      basic_filebuf<char> wOutFile;
  1741 	 
  1742 		
  1743     // Open a file, wcHello.txt, then write to it, then dump the
  1744     // file's contents in hex
  1745     wOutFile.open("c:\\TestFramework\\docs\\basicfilebuf.txt",ios_base::out | ios_base::trunc | ios_base::binary);
  1746     if(!wOutFile.is_open())
  1747     failures++;
  1748     
  1749     wOutFile.sputn(wszHello, 11);
  1750     wOutFile.close();
  1751  	if(wOutFile.is_open())
  1752  	failures++;
  1753  #if  STDCPP_OOM
  1754 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1755   #endif 
  1756  /*	if(failures)
  1757 	return KErrGeneral;
  1758  	else
  1759  	return KErrNone;
  1760  
  1761  */
  1762   
  1763  
  1764  
  1765  
  1766  }
  1767  
  1768   catch(bad_alloc&)
  1769    {
  1770    	//do nothing
  1771     }
  1772    catch(...)
  1773    {
  1774    	failures++;
  1775    	
  1776    }
  1777    
  1778 	if( failures == 0 )
  1779 		return KErrNone;
  1780   else  
  1781 		return KErrGeneral;
  1782     }
  1783  
  1784 // -----------------------------------------------------------------------------
  1785 // Ctwiostreams::basic_istream
  1786 // Example test method function.
  1787 // 
  1788 // -----------------------------------------------------------------------------
  1789 //
  1790  
  1791  TInt Ctiostreams::basicistreamL( CStifItemParser& aItem )
  1792  {
  1793  
  1794  
  1795  		int failures = 0;
  1796  		try
  1797  		{
  1798  		 cout<<"";
  1799  				    #if  STDCPP_OOM
  1800 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1801   #endif 
  1802 			
  1803  		
  1804      typedef std::basic_istream<char, std::char_traits<char> >         Input;
  1805     typedef std::basic_ofstream<Input::char_type, Input::traits_type> Output;
  1806 	 
  1807 		
  1808     Input::char_type s [200];
  1809  
  1810     Output out ("c:\\TestFramework\\docs\\basicistream.txt", std::ios::in | std::ios::out | std::ios::trunc);
  1811 
  1812      Input in (out.rdbuf ());
  1813 
  1814     float f = 3.14159;
  1815     int   i = 3;
  1816 
  1817     // output to the file
  1818     out << "He lifted his head and pondered.\n"
  1819         << f << std::endl << i << std::endl;
  1820   
  1821     // seek to the beginning of the file
  1822     in.seekg (0);
  1823   
  1824   if(!out.is_open())
  1825   failures++;
  1826   
  1827   out.close();
  1828   
  1829   if(out.is_open())
  1830   failures++;
  1831   #if  STDCPP_OOM
  1832 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1833   #endif 
  1834   /*if(failures)
  1835    return KErrGeneral;
  1836   else
  1837   return KErrNone;
  1838  
  1839   */
  1840  
  1841  	
  1842  }
  1843  
  1844   catch(bad_alloc&)
  1845    {
  1846    	//do nothing
  1847     }
  1848    catch(...)
  1849    {
  1850    	failures++;
  1851    	
  1852    }
  1853    
  1854 	if( failures == 0 )
  1855 		return KErrNone;
  1856   else  
  1857 		return KErrGeneral;
  1858     }
  1859 // -----------------------------------------------------------------------------
  1860 // Ctwiostreams::wfstream
  1861 // Example test method function.
  1862 // 
  1863 // -----------------------------------------------------------------------------
  1864 //
  1865  TInt Ctiostreams::wfstreamL( CStifItemParser& aItem )
  1866  
  1867  {
  1868  	
  1869  int failures=0;
  1870  
  1871  try
  1872  {
  1873  	 cout<<"";
  1874  		    #if  STDCPP_OOM
  1875 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1876   #endif 
  1877 		
  1878  wfstream file;
  1879  	  
  1880 		
  1881  file.open("c:\\TestFramework\\docs\\wfstream.txt");
  1882  file.rdbuf();
  1883  if(!file.is_open())
  1884  failures++;
  1885  
  1886  file.close();
  1887  
  1888  if(file.is_open())
  1889  failures++;
  1890  #if  STDCPP_OOM
  1891 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1892   #endif 
  1893 /* if(failures)
  1894  return KErrGeneral;
  1895  return KErrNone;
  1896  
  1897  */
  1898  
  1899  }
  1900  
  1901   catch(bad_alloc&)
  1902    {
  1903    	//do nothing
  1904     }
  1905    catch(...)
  1906    {
  1907    	failures++;
  1908    	
  1909    }
  1910    
  1911 	if( failures == 0 )
  1912 		return KErrNone;
  1913   else  
  1914 		return KErrGeneral;
  1915     }
  1916  
  1917  
  1918 // -----------------------------------------------------------------------------
  1919 // Ctwiostreams::wifstream
  1920 // Example test method function.
  1921 // 
  1922 // -----------------------------------------------------------------------------
  1923 //
  1924  TInt Ctiostreams::wifstreamL( CStifItemParser& aItem )
  1925  
  1926  {
  1927  int failures =0;
  1928  
  1929  try
  1930  {
  1931  	 cout<<"";
  1932  		    #if  STDCPP_OOM
  1933 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  1934   #endif 
  1935 		
  1936  wifstream file;
  1937  		    
  1938 		
  1939  file.open("c:\\TestFramework\\docs\\wifstream.txt");
  1940  
  1941  
  1942  file.rdbuf();
  1943  if(!file.is_open())
  1944  failures++;
  1945  
  1946  file.close();
  1947  
  1948  if(file.is_open())
  1949  failures++;
  1950  #if  STDCPP_OOM
  1951 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1952   #endif 
  1953 /* if(failures)
  1954  return KErrGeneral;
  1955  return KErrNone;
  1956  
  1957  */
  1958  	
  1959  }
  1960   catch(bad_alloc&)
  1961    {
  1962    	//do nothing
  1963     }
  1964    catch(...)
  1965    {
  1966    	failures++;
  1967    	
  1968    }
  1969    
  1970 	if( failures == 0 )
  1971 		return KErrNone;
  1972   else  
  1973 		return KErrGeneral;
  1974     }
  1975  
  1976  
  1977 // -----------------------------------------------------------------------------
  1978 // Ctwiostreams::wfilebuf,wistream
  1979 // Example test method function.
  1980 // 
  1981 // -----------------------------------------------------------------------------
  1982 //
  1983  TInt Ctiostreams::wistreamL( CStifItemParser& aItem )
  1984  
  1985  {
  1986  	int failures=0;
  1987  	try
  1988  	{
  1989  		
  1990  	
  1991  int length;
  1992 wchar_t * buffer;
  1993 wchar_t getl[16] ;
  1994  
  1995  wfilebuf fb;
  1996   fb.open ("c:\\TestFramework\\docs\\wistream.txt",ios::in);
  1997    cout<<"";
  1998    #if  STDCPP_OOM
  1999 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  2000   #endif 
  2001   wistream is(&fb);
  2002   
  2003   if(!fb.is_open())
  2004   failures++;
  2005   
  2006   //if( char(is.get())!= 'S')
  2007  // failures++;
  2008   
  2009 //if(sizeof(fb)!=140)  
  2010 //failures++;
  2011 
  2012 
  2013 
  2014 
  2015   // get length of file:
  2016   is.seekg (0, ios::end);
  2017   length = is.tellg();
  2018   is.seekg (0, ios::beg);
  2019   
  2020   
  2021   
  2022 
  2023 
  2024 if(length != 15)
  2025 failures++;
  2026 
  2027  wchar_t ch = is.get();
  2028   
  2029    
  2030  if(is.gcount() != 1)
  2031  failures++;
  2032  
  2033   
  2034  if( ch != L'S')
  2035  failures++;
  2036  
  2037  
  2038 
  2039  
  2040  
  2041  
  2042  
  2043  wchar_t pk1 = is.peek();
  2044  
  2045  if(pk1!= 'a')
  2046  failures++;
  2047  
  2048  
  2049  is.unget();
  2050  
  2051  wchar_t pk2 = is.peek();
  2052  if(pk2!= 'S')
  2053  failures++;
  2054  
  2055  is.get();
  2056  is.putback('K');
  2057  
  2058  is.getline(getl,16,'\0');
  2059  
  2060  if(getl == L"Kample sentence")
  2061  failures++;
  2062  
  2063 
  2064 
  2065 fb.close();
  2066 
  2067 if(fb.is_open())
  2068 failures++;
  2069  #if  STDCPP_OOM
  2070 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  2071   #endif 
  2072 /*
  2073  if(failures)
  2074  
  2075  return sizeof(fb);
  2076  return KErrNone;
  2077   
  2078  */
  2079  
  2080  
  2081  
  2082  
  2083  }
  2084  
  2085  catch(bad_alloc&)
  2086    {
  2087    	//do nothing
  2088     }
  2089    catch(...)
  2090    {
  2091    	failures++;
  2092    	
  2093    }
  2094    
  2095 	if( failures == 0 )
  2096 		return KErrNone;
  2097   else  
  2098 		return KErrGeneral;
  2099     } 
  2100  
  2101 // -----------------------------------------------------------------------------
  2102 // Ctwiostreams::wofstream
  2103 // Example test method function.
  2104 // 
  2105 // -----------------------------------------------------------------------------
  2106 //
  2107  
  2108   TInt Ctiostreams::wofstreamL( CStifItemParser& aItem )
  2109   {
  2110   	
  2111   	int failures=0;
  2112   	try
  2113   	{
  2114   	 cout<<"";	
  2115   	 #if  STDCPP_OOM
  2116 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  2117   #endif 
  2118   	
  2119   	wofstream outfile;
  2120   	
  2121   	outfile.open("c:\\TestFramework\\docs\\wostream.txt");
  2122   	outfile.write(L"This is an ostreamfile",22);
  2123   	
  2124   	outfile.rdbuf();
  2125   	if(!outfile.is_open())
  2126   	failures++;
  2127   	
  2128   	outfile.close();
  2129   	
  2130   	
  2131   	if(outfile.is_open())
  2132   	failures++;
  2133    #if  STDCPP_OOM
  2134 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  2135   #endif 
  2136  /* 	if(failures)
  2137   	return KErrGeneral;
  2138   	else
  2139   	return KErrNone;
  2140   
  2141   */
  2142   
  2143   
  2144   }
  2145   
  2146   catch(bad_alloc&)
  2147    {
  2148    	//do nothing
  2149     }
  2150    catch(...)
  2151    {
  2152    	failures++;
  2153    	
  2154    }
  2155    
  2156 	if( failures == 0 )
  2157 		return KErrNone;
  2158   else  
  2159 		return KErrGeneral;
  2160     } 
  2161   
  2162 // -----------------------------------------------------------------------------
  2163 // Ctwiostreams::wistringstream
  2164 // Example test method function.
  2165 // 
  2166 // -----------------------------------------------------------------------------
  2167 //
  2168    TInt Ctiostreams::wistringstreamL( CStifItemParser& aItem )
  2169    {
  2170    int failures=0;
  2171    try
  2172    {
  2173    	
  2174    
  2175    	int output[5];
  2176    int n,val;
  2177    wstring strvalues ;
  2178    
  2179    strvalues = L"1 2 3 4 5";
  2180     cout<<"";
  2181     #if  STDCPP_OOM
  2182 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  2183   #endif 
  2184    wistringstream iss(strvalues,wistringstream::in);
  2185    #if  STDCPP_OOM
  2186 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  2187   #endif 
  2188    
  2189    for(n=0;n<5;n++)
  2190    {
  2191    	
  2192    static int j;
  2193    
  2194    iss>>val;
  2195    
  2196    output[j]=val;
  2197    
  2198    j++;
  2199    
  2200    
  2201    }
  2202    
  2203       if(iss.str()!=L"1 2 3 4 5")
  2204       failures++;
  2205 /*
  2206    if(output[0]== 1)
  2207    if(output[1]== 2)
  2208    if(output[2]== 3)
  2209    if(output[3]== 4 )
  2210    if(output[4]== 5)
  2211    
  2212    return KErrNone;
  2213    else 
  2214    return  KErrGeneral;
  2215    */
  2216    
  2217     if(output[0]!= 1)
  2218     failures++;
  2219    if(output[1]!= 2)
  2220    failures++;
  2221    if(output[2]!= 3)
  2222    failures++;
  2223    if(output[3]!= 4 )
  2224    failures++;
  2225    if(output[4]!= 5)
  2226    failures++;
  2227    }
  2228   
  2229    catch(bad_alloc&)
  2230    {
  2231    	//do nothing
  2232     }
  2233    catch(...)
  2234    {
  2235    	failures++;
  2236    	
  2237    }
  2238    
  2239 	if( failures == 0 )
  2240 		return KErrNone;
  2241   else  
  2242 		return KErrGeneral;
  2243     } 
  2244 // -----------------------------------------------------------------------------
  2245 // Ctwiostreams::wostringstream,wstring
  2246 // Example test method function.
  2247 // 
  2248 // -----------------------------------------------------------------------------
  2249 //
  2250   TInt Ctiostreams::wostringstreamL( CStifItemParser& aItem )
  2251   {
  2252   	int failures=0;
  2253   	try
  2254   	{ cout<<"";
  2255    #if  STDCPP_OOM
  2256 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  2257   #endif 		
  2258   	
  2259   
  2260 wostringstream oss;
  2261 wstring mystr;
  2262 
  2263 oss << L"wostringstream testcase";
  2264 oss.rdbuf();
  2265 mystr=oss.str();
  2266  #if  STDCPP_OOM
  2267 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  2268   #endif 
  2269 /*if(mystr.compare(L"wostringstream testcase")==0)
  2270 return KErrNone;
  2271 return KErrGeneral;
  2272 */
  2273 if(mystr.compare(L"wostringstream testcase")!=0)
  2274 failures++;
  2275 
  2276   }
  2277   
  2278   
  2279    catch(bad_alloc&)
  2280    {
  2281    	//do nothing
  2282     }
  2283    catch(...)
  2284    {
  2285    	failures++;
  2286    	
  2287    }
  2288    
  2289 	if( failures == 0 )
  2290 		return KErrNone;
  2291   else  
  2292 		return KErrGeneral;
  2293     } 
  2294 // -----------------------------------------------------------------------------
  2295 // Ctwiostreams::wstreambuf,wofstreams
  2296 // Example test method function.
  2297 // 
  2298 // -----------------------------------------------------------------------------
  2299 //
  2300    
  2301   TInt Ctiostreams::wstreambufL( CStifItemParser& aItem )
  2302   {
  2303 
  2304 
  2305 //locale   loc ("en_GB.UTF-8");
  2306 
  2307  
  2308  
  2309  int failures = 0;
  2310  try
  2311  {
  2312  	
  2313  
  2314  wchar_t a[4]=
  2315  {
  2316  	0
  2317  };
  2318  
  2319  wchar_t sentence[]= L"Sample sentence"; cout<<"";
  2320   #if  STDCPP_OOM
  2321 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  2322   #endif 
  2323  wstreambuf * pbuf;
  2324  wofstream ostr ("c:\\TestFramework\\docs\\wstreambuf.txt");
  2325  
  2326  
  2327   
  2328 // if(cout.rdbuf( )->getloc( ).name( ).c_str( ) != "C") //failing
  2329  //failures++;
  2330  
  2331  wchar_t ch[28];
  2332  //rdbuf()s
  2333  pbuf = ostr.rdbuf();
  2334 
  2335 
  2336 //sputn()
  2337 
  2338 
  2339 
  2340 
  2341  pbuf->sputn (sentence,sizeof(sentence)-1);
  2342 
  2343   
  2344  ostr.open("c:\\TestFramework\\docs\\wstreambuf.txt");
  2345   
  2346  if(!ostr.is_open())
  2347  failures++;
  2348    
  2349 
  2350  long size1 = pbuf->pubseekoff(0,ios_base::end);
  2351  if(size1!=31)
  2352  failures++;
  2353   
  2354 
  2355   pbuf->sputc('a');
  2356   
  2357 
  2358  long size2 = pbuf->pubseekoff(0,ios_base::end);
  2359  if(size2!=32)
  2360  failures++;
  2361   
  2362  wifstream istr("c:\\TestFramework\\docs\\wstreambuf.txt");
  2363  pbuf = istr.rdbuf();
  2364 
  2365 streamsize i = istr.rdbuf()->sgetn(&a[0], 3);   
  2366     //a[i] = istr.widen('\0');
  2367 
  2368     // Display the size and contents of the buffer passed to sgetn.
  2369    if(i!=3)
  2370    failures++;
  2371   
  2372  
  2373  int k = pbuf->snextc();
  2374  
  2375  
  2376  //sgetc()
  2377  while (pbuf->sgetc()!=EOF)
  2378   {
  2379      static int i;
  2380       //sbumpc()
  2381      ch[i] = pbuf->sbumpc();
  2382      i++;
  2383   }
  2384 
  2385   
  2386   if(ch[0]!='l' )
  2387   failures++;
  2388   
  2389  
  2390   
  2391   
  2392   
  2393   
  2394   istr.close();
  2395   ostr.close();
  2396    #if  STDCPP_OOM
  2397 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  2398   #endif 
  2399  /* if(failures)
  2400   return KErrGeneral;
  2401   else
  2402   return KErrNone;
  2403    */
  2404  
  2405 
  2406 
  2407   }
  2408   
  2409    catch(bad_alloc&)
  2410    {
  2411    	//do nothing
  2412     }
  2413    catch(...)
  2414    {
  2415    	failures++;
  2416    	
  2417    }
  2418    
  2419 	if( failures == 0 )
  2420 		return KErrNone;
  2421   else  
  2422 		return KErrGeneral;
  2423     } 
  2424 
  2425 // -----------------------------------------------------------------------------
  2426 // Ctwiostreams::wostream
  2427 // Example test method function.
  2428 // 
  2429 // -----------------------------------------------------------------------------
  2430 //
  2431 
  2432  TInt Ctiostreams::wostreamL( CStifItemParser& aItem )  
  2433  {
  2434  	
  2435 
  2436  
  2437  int failures = 0;
  2438  try
  2439  {
  2440  	
  2441 
  2442  wfilebuf fb;
  2443 wchar_t input[18] = L"wostream testcase";
  2444 streamsize size = 5;
  2445   fb.open ("c:\\TestFramework\\docs\\wostream.txt",ios::out); cout<<"";
  2446    #if  STDCPP_OOM
  2447 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  2448   #endif 
  2449   wostream os(&fb);
  2450   
  2451   os.write(input,size);
  2452   streamoff i = os.tellp();
  2453   if(i!= 5)
  2454   failures++;
  2455   
  2456   os.put('K');
  2457   streamoff j = os.tellp();
  2458   if(j!=6)
  2459   failures++;
  2460 
  2461   os.seekp(2);
  2462     os<<"i";
  2463   streamoff k = os.tellp();
  2464 
  2465   if(k!=3)
  2466   failures++;
  2467   
  2468   os.flush();
  2469   
  2470  #if  STDCPP_OOM
  2471 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  2472   #endif 
  2473   
  2474  
  2475   /*
  2476 if(failures)
  2477 return KErrGeneral;
  2478 return KErrNone;
  2479 */
  2480  
  2481   
  2482  }
  2483  
  2484   catch(bad_alloc&)
  2485    {
  2486    	//do nothing
  2487     }
  2488    catch(...)
  2489    {
  2490    	failures++;
  2491    	
  2492    }
  2493    
  2494 	if( failures == 0 )
  2495 		return KErrNone;
  2496   else  
  2497 		return KErrGeneral;
  2498     } 
  2499 
  2500 // -----------------------------------------------------------------------------
  2501 // Ctwiostreams::wstringbuf
  2502 // Example test method function.
  2503 // 
  2504 // -----------------------------------------------------------------------------
  2505 // 
  2506  
  2507   TInt Ctiostreams::wstringbufL( CStifItemParser& aItem )  
  2508   {
  2509   int failures=0;
  2510   try
  2511   {
  2512    cout<<"";	
  2513  #if  STDCPP_OOM
  2514 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
  2515   #endif  
  2516 wstringbuf sb;
  2517 wstring mystr;
  2518 
  2519   
  2520 sb.sputn (L"Sample string",13);
  2521 mystr=sb.str();
  2522 
  2523 /*if(mystr.compare(L"Sample string") == 0)
  2524 return KErrNone;
  2525 else
  2526 return KErrGeneral;
  2527   */
  2528   #if  STDCPP_OOM
  2529 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  2530   #endif 
  2531   if(mystr.compare(L"Sample string") != 0)
  2532   failures++;
  2533   
  2534   }
  2535   
  2536    catch(bad_alloc&)
  2537    {
  2538    	//do nothing
  2539     }
  2540    catch(...)
  2541    {
  2542    	failures++;
  2543    	
  2544    }
  2545    
  2546 	if( failures == 0 )
  2547 		return KErrNone;
  2548   else  
  2549 		return KErrGeneral;
  2550     } 
  2551   
  2552 //  End of File
  2553 
  2554 //  End of File
  2555     
  2556     
  2557  
  2558 //  End of File