os/ossrv/stdcpp/tsrc/Stdcpp_test/bcdrivers/twiostreams/src/twiostreamsblocks.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/stdcpp/tsrc/Stdcpp_test/bcdrivers/twiostreams/src/twiostreamsblocks.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1030 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +
    1.24 +// INCLUDE FILES
    1.25 +#include <e32svr.h>
    1.26 +#include <StifParser.h>
    1.27 +#include <Stiftestinterface.h>
    1.28 +#include<iostream>
    1.29 +#include<string>
    1.30 +#include <vector>
    1.31 +#include<algorithm>
    1.32 +#include<fstream>
    1.33 +#include<sstream>
    1.34 +#include<istream>
    1.35 +
    1.36 +#include<locale>
    1.37 +#include "twiostreams.h"
    1.38 +#define STDCPP_OOM FALSE
    1.39 +using namespace std;
    1.40 +
    1.41 +
    1.42 +
    1.43 +// ============================ MEMBER FUNCTIONS ===============================
    1.44 +
    1.45 +// -----------------------------------------------------------------------------
    1.46 +// CCtwiostreams::Delete
    1.47 +// Delete here all resources allocated and opened from test methods. 
    1.48 +// Called from destructor. 
    1.49 +// -----------------------------------------------------------------------------
    1.50 +//
    1.51 +void Ctwiostreams::Delete() 
    1.52 +    {
    1.53 +
    1.54 +    }
    1.55 +
    1.56 +// -----------------------------------------------------------------------------
    1.57 +// CCtwiostreams::RunMethodL
    1.58 +// Run specified method. Contains also table of test mothods and their names.
    1.59 +// -----------------------------------------------------------------------------
    1.60 +//
    1.61 +TInt Ctwiostreams::RunMethodL( 
    1.62 +    CStifItemParser& aItem ) 
    1.63 +    {
    1.64 +
    1.65 +    static TStifFunctionInfo const KFunctions[] =
    1.66 +        {  
    1.67 +        // Copy this line for every implemented function.
    1.68 +        // First string is the function name used in TestScripter script file.
    1.69 +        // Second is the actual implementation member function. 
    1.70 +        ENTRY( "basicstring", Ctwiostreams::basicstring ),
    1.71 +        ENTRY( "basicfilebufL", Ctwiostreams::basicfilebufL ),
    1.72 +        ENTRY( "basicistreamL", Ctwiostreams::basicistreamL ),
    1.73 +        ENTRY( "wfstreamL", Ctwiostreams::wfstreamL ),
    1.74 +        ENTRY( "wifstreamL", Ctwiostreams::wifstreamL ),
    1.75 +        ENTRY( "wistreamL", Ctwiostreams::wistreamL ),
    1.76 +		ENTRY( "wofstreamL", Ctwiostreams::wofstreamL ),
    1.77 + 		ENTRY( "wistringstreamL", Ctwiostreams::wistringstreamL ),
    1.78 + 		ENTRY( "wostringstreamL", Ctwiostreams::wostringstreamL ),
    1.79 + 		ENTRY( "wstreambufL", Ctwiostreams::wstreambufL ),
    1.80 + 		ENTRY( "wostreamL", Ctwiostreams::wostreamL ),
    1.81 + 		ENTRY( "wstringbufL", Ctwiostreams::wstringbufL ),
    1.82 +         
    1.83 +
    1.84 +        };
    1.85 +
    1.86 +    const TInt count = sizeof( KFunctions ) / 
    1.87 +                        sizeof( TStifFunctionInfo );
    1.88 +
    1.89 +    return RunInternalL( KFunctions, count, aItem );
    1.90 +
    1.91 +    }
    1.92 +
    1.93 +// -----------------------------------------------------------------------------
    1.94 +// Ctwiostreams::basic_string
    1.95 +// Example test method function.
    1.96 +// 
    1.97 +// -----------------------------------------------------------------------------
    1.98 +//
    1.99 +TInt Ctwiostreams::basicstring( CStifItemParser& aItem )
   1.100 +    {
   1.101 +				int failures =0;
   1.102 +				
   1.103 +				try
   1.104 +				{
   1.105 +					
   1.106 +				
   1.107 +			    const char *cstr1a = "Hello Out There.";
   1.108 +			    cout<<"";
   1.109 +			    #if  STDCPP_OOM
   1.110 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.111 +  #endif 
   1.112 +			   basic_string<char> str1a(cstr1a ,5);
   1.113 +	 
   1.114 +			   if(str1a.compare("Hello")!=0)
   1.115 +			   failures++;
   1.116 +			    
   1.117 +			    str1a.append("Out There");
   1.118 +			    if(!str1a.compare("Hello Out There"))
   1.119 +			    failures++;
   1.120 +			    
   1.121 +			    
   1.122 +			   string  str2a ( "How Do You Do?" );
   1.123 +			   basic_string <char> str2b ( str2a , 7 , 7 );
   1.124 +			   
   1.125 +			    if(str2b.compare("You Do?")!=0)
   1.126 +			   failures++;
   1.127 +			   
   1.128 +			    
   1.129 +			 
   1.130 +			   basic_string <char> str3a ( 5, '9' );
   1.131 +			   if(str3a.compare("99999")!=0)
   1.132 +			   failures++;
   1.133 +			   
   1.134 +
   1.135 +			   
   1.136 +			   basic_string <char> str4a;
   1.137 +			   string str4b;
   1.138 +			   basic_string <char> str4c ( str4b.get_allocator( ) );
   1.139 +			   if (!str4c.empty ())
   1.140 +			   failures++;
   1.141 +			      
   1.142 +
   1.143 +			  
   1.144 +			   string str5a ( "Hello World");
   1.145 +			    basic_string <char>::iterator strp_Iter;
   1.146 +			   
   1.147 +			   
   1.148 +			   
   1.149 +			   strp_Iter = str5a.begin();
   1.150 +			   if(*strp_Iter != 'H' )
   1.151 +				failures++;
   1.152 +			   
   1.153 +			   
   1.154 +			   
   1.155 +			   
   1.156 +			   basic_string <char>::reference refStr2 = str5a.at ( 3 );
   1.157 +			   
   1.158 +			   if(refStr2 != 'l')
   1.159 +			   failures++;
   1.160 +			   
   1.161 +			   
   1.162 +			   if(str5a.size()!=11)
   1.163 +			   failures++;
   1.164 +			   if(str5a.length()!=11)
   1.165 +			   failures++;
   1.166 +			   if(str5a.capacity()!=11)
   1.167 +			   failures++;
   1.168 +			   
   1.169 +
   1.170 +
   1.171 +		#if  STDCPP_OOM
   1.172 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.173 +  #endif 	   
   1.174 +			  /*  if(failures)
   1.175 +			    return  KErrGeneral;
   1.176 +			    return KErrNone;
   1.177 +			    */
   1.178 +
   1.179 +    }
   1.180 +
   1.181 +  catch(bad_alloc&)
   1.182 +   {
   1.183 +   	//do nothing
   1.184 +    }
   1.185 +   catch(...)
   1.186 +   {
   1.187 +   	failures++;
   1.188 +   	
   1.189 +   }
   1.190 +   
   1.191 +	if( failures == 0 )
   1.192 +		return KErrNone;
   1.193 +  else  
   1.194 +		return KErrGeneral;
   1.195 +    }
   1.196 +
   1.197 +// -----------------------------------------------------------------------------
   1.198 +// Ctwiostreams::basic_filebuf
   1.199 +// Example test method function.
   1.200 +// 
   1.201 +// -----------------------------------------------------------------------------
   1.202 +// 
   1.203 + 
   1.204 + TInt Ctwiostreams::basicfilebufL( CStifItemParser& aItem )
   1.205 + {
   1.206 + 	
   1.207 +	 int failures=0;
   1.208 +	 try
   1.209 +	 {
   1.210 +	 	
   1.211 +	 
   1.212 +   	 char* wszHello = "Hello World";
   1.213 +//   	 char wBuffer[128];
   1.214 +   	  cout<<"";
   1.215 +		    #if  STDCPP_OOM
   1.216 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.217 +  #endif 
   1.218 +		
   1.219 +     basic_filebuf<char> wOutFile;
   1.220 +	 
   1.221 +		
   1.222 +    // Open a file, wcHello.txt, then write to it, then dump the
   1.223 +    // file's contents in hex
   1.224 +    wOutFile.open("c:\\TestFramework\\docs\\basicfilebuf.txt",ios_base::out | ios_base::trunc | ios_base::binary);
   1.225 +    if(!wOutFile.is_open())
   1.226 +    failures++;
   1.227 +    
   1.228 +    wOutFile.sputn(wszHello, 11);
   1.229 +    wOutFile.close();
   1.230 + 	if(wOutFile.is_open())
   1.231 + 	failures++;
   1.232 + #if  STDCPP_OOM
   1.233 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.234 +  #endif 
   1.235 + /*	if(failures)
   1.236 +	return KErrGeneral;
   1.237 + 	else
   1.238 + 	return KErrNone;
   1.239 + 
   1.240 + */
   1.241 +  
   1.242 + 
   1.243 + 
   1.244 + 
   1.245 + }
   1.246 + 
   1.247 +  catch(bad_alloc&)
   1.248 +   {
   1.249 +   	//do nothing
   1.250 +    }
   1.251 +   catch(...)
   1.252 +   {
   1.253 +   	failures++;
   1.254 +   	
   1.255 +   }
   1.256 +   
   1.257 +	if( failures == 0 )
   1.258 +		return KErrNone;
   1.259 +  else  
   1.260 +		return KErrGeneral;
   1.261 +    }
   1.262 + 
   1.263 +// -----------------------------------------------------------------------------
   1.264 +// Ctwiostreams::basic_istream
   1.265 +// Example test method function.
   1.266 +// 
   1.267 +// -----------------------------------------------------------------------------
   1.268 +//
   1.269 + 
   1.270 + TInt Ctwiostreams::basicistreamL( CStifItemParser& aItem )
   1.271 + {
   1.272 + 
   1.273 + 
   1.274 + 		int failures = 0;
   1.275 + 		try
   1.276 + 		{
   1.277 + 		 cout<<"";
   1.278 + 				    #if  STDCPP_OOM
   1.279 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.280 +  #endif 
   1.281 +			
   1.282 + 		
   1.283 +     typedef std::basic_istream<char, std::char_traits<char> >         Input;
   1.284 +    typedef std::basic_ofstream<Input::char_type, Input::traits_type> Output;
   1.285 +	 
   1.286 +		
   1.287 +//    Input::char_type s [200];
   1.288 + 
   1.289 +    Output out ("c:\\TestFramework\\docs\\basicistream.txt", std::ios::in | std::ios::out | std::ios::trunc);
   1.290 +
   1.291 +     Input in (out.rdbuf ());
   1.292 +
   1.293 +    float f = 3.14159;
   1.294 +    int   i = 3;
   1.295 +
   1.296 +    // output to the file
   1.297 +    out << "He lifted his head and pondered.\n"
   1.298 +        << f << std::endl << i << std::endl;
   1.299 +  
   1.300 +    // seek to the beginning of the file
   1.301 +    in.seekg (0);
   1.302 +  
   1.303 +  if(!out.is_open())
   1.304 +  failures++;
   1.305 +  
   1.306 +  out.close();
   1.307 +  
   1.308 +  if(out.is_open())
   1.309 +  failures++;
   1.310 +  #if  STDCPP_OOM
   1.311 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.312 +  #endif 
   1.313 +  /*if(failures)
   1.314 +   return KErrGeneral;
   1.315 +  else
   1.316 +  return KErrNone;
   1.317 + 
   1.318 +  */
   1.319 + 
   1.320 + 	
   1.321 + }
   1.322 + 
   1.323 +  catch(bad_alloc&)
   1.324 +   {
   1.325 +   	//do nothing
   1.326 +    }
   1.327 +   catch(...)
   1.328 +   {
   1.329 +   	failures++;
   1.330 +   	
   1.331 +   }
   1.332 +   
   1.333 +	if( failures == 0 )
   1.334 +		return KErrNone;
   1.335 +  else  
   1.336 +		return KErrGeneral;
   1.337 +    }
   1.338 +// -----------------------------------------------------------------------------
   1.339 +// Ctwiostreams::wfstream
   1.340 +// Example test method function.
   1.341 +// 
   1.342 +// -----------------------------------------------------------------------------
   1.343 +//
   1.344 + TInt Ctwiostreams::wfstreamL( CStifItemParser& aItem )
   1.345 + 
   1.346 + {
   1.347 + 	
   1.348 + int failures=0;
   1.349 + 
   1.350 + try
   1.351 + {
   1.352 + 	 cout<<"";
   1.353 + 		    #if  STDCPP_OOM
   1.354 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.355 +  #endif 
   1.356 +		
   1.357 + wfstream file;
   1.358 + 	  
   1.359 +		
   1.360 + file.open("c:\\TestFramework\\docs\\wfstream.txt");
   1.361 + file.rdbuf();
   1.362 + if(!file.is_open())
   1.363 + failures++;
   1.364 + 
   1.365 + file.close();
   1.366 + 
   1.367 + if(file.is_open())
   1.368 + failures++;
   1.369 + #if  STDCPP_OOM
   1.370 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.371 +  #endif 
   1.372 +/* if(failures)
   1.373 + return KErrGeneral;
   1.374 + return KErrNone;
   1.375 + 
   1.376 + */
   1.377 + 
   1.378 + }
   1.379 + 
   1.380 +  catch(bad_alloc&)
   1.381 +   {
   1.382 +   	//do nothing
   1.383 +    }
   1.384 +   catch(...)
   1.385 +   {
   1.386 +   	failures++;
   1.387 +   	
   1.388 +   }
   1.389 +   
   1.390 +	if( failures == 0 )
   1.391 +		return KErrNone;
   1.392 +  else  
   1.393 +		return KErrGeneral;
   1.394 +    }
   1.395 + 
   1.396 + 
   1.397 +// -----------------------------------------------------------------------------
   1.398 +// Ctwiostreams::wifstream
   1.399 +// Example test method function.
   1.400 +// 
   1.401 +// -----------------------------------------------------------------------------
   1.402 +//
   1.403 + TInt Ctwiostreams::wifstreamL( CStifItemParser& aItem )
   1.404 + 
   1.405 + {
   1.406 + int failures =0;
   1.407 + 
   1.408 + try
   1.409 + {
   1.410 + 	 cout<<"";
   1.411 + 		    #if  STDCPP_OOM
   1.412 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.413 +  #endif 
   1.414 +		
   1.415 + wifstream file;
   1.416 + 		    
   1.417 +		
   1.418 + file.open("c:\\TestFramework\\docs\\wifstream.txt");
   1.419 + 
   1.420 + 
   1.421 + file.rdbuf();
   1.422 + if(!file.is_open())
   1.423 + failures++;
   1.424 + 
   1.425 + file.close();
   1.426 + 
   1.427 + if(file.is_open())
   1.428 + failures++;
   1.429 + #if  STDCPP_OOM
   1.430 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.431 +  #endif 
   1.432 +/* if(failures)
   1.433 + return KErrGeneral;
   1.434 + return KErrNone;
   1.435 + 
   1.436 + */
   1.437 + 	
   1.438 + }
   1.439 +  catch(bad_alloc&)
   1.440 +   {
   1.441 +   	//do nothing
   1.442 +    }
   1.443 +   catch(...)
   1.444 +   {
   1.445 +   	failures++;
   1.446 +   	
   1.447 +   }
   1.448 +   
   1.449 +	if( failures == 0 )
   1.450 +		return KErrNone;
   1.451 +  else  
   1.452 +		return KErrGeneral;
   1.453 +    }
   1.454 + 
   1.455 + 
   1.456 +// -----------------------------------------------------------------------------
   1.457 +// Ctwiostreams::wfilebuf,wistream
   1.458 +// Example test method function.
   1.459 +// 
   1.460 +// -----------------------------------------------------------------------------
   1.461 +//
   1.462 + TInt Ctwiostreams::wistreamL( CStifItemParser& aItem )
   1.463 + 
   1.464 + {
   1.465 + 	int failures=0;
   1.466 + 	try
   1.467 + 	{
   1.468 + 		
   1.469 + 	
   1.470 + int length;
   1.471 +//wchar_t * buffer;
   1.472 +wchar_t getl[16] ;
   1.473 + 
   1.474 + wfilebuf fb;
   1.475 +  fb.open ("c:\\TestFramework\\docs\\wistream.txt",ios::in);
   1.476 +   cout<<"";
   1.477 +   #if  STDCPP_OOM
   1.478 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.479 +  #endif 
   1.480 +  wistream is(&fb);
   1.481 +  
   1.482 +  if(!fb.is_open())
   1.483 +  failures++;
   1.484 +  
   1.485 +  //if( char(is.get())!= 'S')
   1.486 + // failures++;
   1.487 +  
   1.488 +//if(sizeof(fb)!=140)  
   1.489 +//failures++;
   1.490 +
   1.491 +
   1.492 +
   1.493 +
   1.494 +  // get length of file:
   1.495 +  is.seekg (0, ios::end);
   1.496 +  length = is.tellg();
   1.497 +  is.seekg (0, ios::beg);
   1.498 +  
   1.499 +  
   1.500 +  
   1.501 +
   1.502 +
   1.503 +if(length != 15)
   1.504 +failures++;
   1.505 +
   1.506 + wchar_t ch = is.get();
   1.507 +  
   1.508 +   
   1.509 + if(is.gcount() != 1)
   1.510 + failures++;
   1.511 + 
   1.512 +  
   1.513 + if( ch != L'S')
   1.514 + failures++;
   1.515 + 
   1.516 + 
   1.517 +
   1.518 + 
   1.519 + 
   1.520 + 
   1.521 + 
   1.522 + wchar_t pk1 = is.peek();
   1.523 + 
   1.524 + if(pk1!= 'a')
   1.525 + failures++;
   1.526 + 
   1.527 + 
   1.528 + is.unget();
   1.529 + 
   1.530 + wchar_t pk2 = is.peek();
   1.531 + if(pk2!= 'S')
   1.532 + failures++;
   1.533 + 
   1.534 + is.get();
   1.535 + is.putback('K');
   1.536 + 
   1.537 + is.getline(getl,16,'\0');
   1.538 + 
   1.539 + if(getl == L"Kample sentence")
   1.540 + failures++;
   1.541 + 
   1.542 +
   1.543 +
   1.544 +fb.close();
   1.545 +
   1.546 +if(fb.is_open())
   1.547 +failures++;
   1.548 + #if  STDCPP_OOM
   1.549 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.550 +  #endif 
   1.551 +/*
   1.552 + if(failures)
   1.553 + 
   1.554 + return sizeof(fb);
   1.555 + return KErrNone;
   1.556 +  
   1.557 + */
   1.558 + 
   1.559 + 
   1.560 + 
   1.561 + 
   1.562 + }
   1.563 + 
   1.564 + catch(bad_alloc&)
   1.565 +   {
   1.566 +   	//do nothing
   1.567 +    }
   1.568 +   catch(...)
   1.569 +   {
   1.570 +   	failures++;
   1.571 +   	
   1.572 +   }
   1.573 +   
   1.574 +	if( failures == 0 )
   1.575 +		return KErrNone;
   1.576 +  else  
   1.577 +		return KErrGeneral;
   1.578 +    } 
   1.579 + 
   1.580 +// -----------------------------------------------------------------------------
   1.581 +// Ctwiostreams::wofstream
   1.582 +// Example test method function.
   1.583 +// 
   1.584 +// -----------------------------------------------------------------------------
   1.585 +//
   1.586 + 
   1.587 +  TInt Ctwiostreams::wofstreamL( CStifItemParser& aItem )
   1.588 +  {
   1.589 +  	
   1.590 +  	int failures=0;
   1.591 +  	try
   1.592 +  	{
   1.593 +  	 cout<<"";	
   1.594 +  	 #if  STDCPP_OOM
   1.595 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.596 +  #endif 
   1.597 +  	
   1.598 +  	wofstream outfile;
   1.599 +  	
   1.600 +  	outfile.open("c:\\TestFramework\\docs\\wostream.txt");
   1.601 +  	outfile.write(L"This is an ostreamfile",22);
   1.602 +  	
   1.603 +  	outfile.rdbuf();
   1.604 +  	if(!outfile.is_open())
   1.605 +  	failures++;
   1.606 +  	
   1.607 +  	outfile.close();
   1.608 +  	
   1.609 +  	
   1.610 +  	if(outfile.is_open())
   1.611 +  	failures++;
   1.612 +   #if  STDCPP_OOM
   1.613 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.614 +  #endif 
   1.615 + /* 	if(failures)
   1.616 +  	return KErrGeneral;
   1.617 +  	else
   1.618 +  	return KErrNone;
   1.619 +  
   1.620 +  */
   1.621 +  
   1.622 +  
   1.623 +  }
   1.624 +  
   1.625 +  catch(bad_alloc&)
   1.626 +   {
   1.627 +   	//do nothing
   1.628 +    }
   1.629 +   catch(...)
   1.630 +   {
   1.631 +   	failures++;
   1.632 +   	
   1.633 +   }
   1.634 +   
   1.635 +	if( failures == 0 )
   1.636 +		return KErrNone;
   1.637 +  else  
   1.638 +		return KErrGeneral;
   1.639 +    } 
   1.640 +  
   1.641 +// -----------------------------------------------------------------------------
   1.642 +// Ctwiostreams::wistringstream
   1.643 +// Example test method function.
   1.644 +// 
   1.645 +// -----------------------------------------------------------------------------
   1.646 +//
   1.647 +   TInt Ctwiostreams::wistringstreamL( CStifItemParser& aItem )
   1.648 +   {
   1.649 +   int failures=0;
   1.650 +   try
   1.651 +   {
   1.652 +   	
   1.653 +   
   1.654 +   	int output[5];
   1.655 +   int n = 0,val = 0;
   1.656 +   wstring strvalues ;
   1.657 +   
   1.658 +   strvalues = L"1 2 3 4 5";
   1.659 +    cout<<"";
   1.660 +    #if  STDCPP_OOM
   1.661 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.662 +  #endif 
   1.663 +   wistringstream iss(strvalues,wistringstream::in);
   1.664 +   #if  STDCPP_OOM
   1.665 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.666 +  #endif 
   1.667 +   
   1.668 +   for(n=0;n<5;n++)
   1.669 +   {
   1.670 +   	
   1.671 +   static int j;
   1.672 +   
   1.673 +   iss>>val;
   1.674 +   
   1.675 +   output[j]=val;
   1.676 +   
   1.677 +   j++;
   1.678 +   
   1.679 +   
   1.680 +   }
   1.681 +   
   1.682 +      if(iss.str()!=L"1 2 3 4 5")
   1.683 +      failures++;
   1.684 +/*
   1.685 +   if(output[0]== 1)
   1.686 +   if(output[1]== 2)
   1.687 +   if(output[2]== 3)
   1.688 +   if(output[3]== 4 )
   1.689 +   if(output[4]== 5)
   1.690 +   
   1.691 +   return KErrNone;
   1.692 +   else 
   1.693 +   return  KErrGeneral;
   1.694 +   */
   1.695 +   
   1.696 +    if(output[0]!= 1)
   1.697 +    failures++;
   1.698 +   if(output[1]!= 2)
   1.699 +   failures++;
   1.700 +   if(output[2]!= 3)
   1.701 +   failures++;
   1.702 +   if(output[3]!= 4 )
   1.703 +   failures++;
   1.704 +   if(output[4]!= 5)
   1.705 +   failures++;
   1.706 +   }
   1.707 +  
   1.708 +   catch(bad_alloc&)
   1.709 +   {
   1.710 +   	//do nothing
   1.711 +    }
   1.712 +   catch(...)
   1.713 +   {
   1.714 +   	failures++;
   1.715 +   	
   1.716 +   }
   1.717 +   
   1.718 +	if( failures == 0 )
   1.719 +		return KErrNone;
   1.720 +  else  
   1.721 +		return KErrGeneral;
   1.722 +    } 
   1.723 +// -----------------------------------------------------------------------------
   1.724 +// Ctwiostreams::wostringstream,wstring
   1.725 +// Example test method function.
   1.726 +// 
   1.727 +// -----------------------------------------------------------------------------
   1.728 +//
   1.729 +  TInt Ctwiostreams::wostringstreamL( CStifItemParser& aItem )
   1.730 +  {
   1.731 +  	int failures=0;
   1.732 +  	try
   1.733 +  	{ cout<<"";
   1.734 +   #if  STDCPP_OOM
   1.735 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.736 +  #endif 		
   1.737 +  	
   1.738 +  
   1.739 +wostringstream oss;
   1.740 +wstring mystr;
   1.741 +
   1.742 +oss << L"wostringstream testcase";
   1.743 +oss.rdbuf();
   1.744 +mystr=oss.str();
   1.745 + #if  STDCPP_OOM
   1.746 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.747 +  #endif 
   1.748 +/*if(mystr.compare(L"wostringstream testcase")==0)
   1.749 +return KErrNone;
   1.750 +return KErrGeneral;
   1.751 +*/
   1.752 +if(mystr.compare(L"wostringstream testcase")!=0)
   1.753 +failures++;
   1.754 +
   1.755 +  }
   1.756 +  
   1.757 +  
   1.758 +   catch(bad_alloc&)
   1.759 +   {
   1.760 +   	//do nothing
   1.761 +    }
   1.762 +   catch(...)
   1.763 +   {
   1.764 +   	failures++;
   1.765 +   	
   1.766 +   }
   1.767 +   
   1.768 +	if( failures == 0 )
   1.769 +		return KErrNone;
   1.770 +  else  
   1.771 +		return KErrGeneral;
   1.772 +    } 
   1.773 +// -----------------------------------------------------------------------------
   1.774 +// Ctwiostreams::wstreambuf,wofstreams
   1.775 +// Example test method function.
   1.776 +// 
   1.777 +// -----------------------------------------------------------------------------
   1.778 +//
   1.779 +   
   1.780 +  TInt Ctwiostreams::wstreambufL( CStifItemParser& aItem )
   1.781 +  {
   1.782 +
   1.783 +
   1.784 +//locale   loc ("en_GB.UTF-8");
   1.785 +
   1.786 + 
   1.787 + 
   1.788 + int failures = 0;
   1.789 + try
   1.790 + {
   1.791 + 	
   1.792 + 
   1.793 + wchar_t a[4]=
   1.794 + {
   1.795 + 	0
   1.796 + };
   1.797 + 
   1.798 + wchar_t sentence[]= L"Sample sentence"; cout<<"";
   1.799 +  #if  STDCPP_OOM
   1.800 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.801 +  #endif 
   1.802 + wstreambuf * pbuf;
   1.803 + wofstream ostr ("c:\\TestFramework\\docs\\wstreambuf.txt");
   1.804 + 
   1.805 + 
   1.806 +  
   1.807 +// if(cout.rdbuf( )->getloc( ).name( ).c_str( ) != "C") //failing
   1.808 + //failures++;
   1.809 + 
   1.810 + wchar_t ch[28];
   1.811 + //rdbuf()s
   1.812 + pbuf = ostr.rdbuf();
   1.813 +
   1.814 +
   1.815 +//sputn()
   1.816 +
   1.817 +
   1.818 +
   1.819 +
   1.820 + pbuf->sputn (sentence,sizeof(sentence)-1);
   1.821 +
   1.822 +  
   1.823 + ostr.open("c:\\TestFramework\\docs\\wstreambuf.txt");
   1.824 +  
   1.825 + if(!ostr.is_open())
   1.826 + failures++;
   1.827 +   
   1.828 +
   1.829 + long size1 = pbuf->pubseekoff(0,ios_base::end);
   1.830 + if(size1!=31)
   1.831 + failures++;
   1.832 +  
   1.833 +
   1.834 +  pbuf->sputc('a');
   1.835 +  
   1.836 +
   1.837 + long size2 = pbuf->pubseekoff(0,ios_base::end);
   1.838 + if(size2!=32)
   1.839 + failures++;
   1.840 +  
   1.841 + wifstream istr("c:\\TestFramework\\docs\\wstreambuf.txt");
   1.842 + pbuf = istr.rdbuf();
   1.843 +
   1.844 +streamsize i = istr.rdbuf()->sgetn(&a[0], 3);   
   1.845 +    //a[i] = istr.widen('\0');
   1.846 +
   1.847 +    // Display the size and contents of the buffer passed to sgetn.
   1.848 +   if(i!=3)
   1.849 +   failures++;
   1.850 +  
   1.851 + 
   1.852 + int k = pbuf->snextc();
   1.853 + 
   1.854 + 
   1.855 + //sgetc()
   1.856 + while (pbuf->sgetc()!=EOF)
   1.857 +  {
   1.858 +     static int i;
   1.859 +      //sbumpc()
   1.860 +     ch[i] = pbuf->sbumpc();
   1.861 +     i++;
   1.862 +  }
   1.863 +
   1.864 +  
   1.865 +  if(ch[0]!='l' )
   1.866 +  failures++;
   1.867 +  
   1.868 + 
   1.869 +  
   1.870 +  
   1.871 +  
   1.872 +  
   1.873 +  istr.close();
   1.874 +  ostr.close();
   1.875 +   #if  STDCPP_OOM
   1.876 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.877 +  #endif 
   1.878 + /* if(failures)
   1.879 +  return KErrGeneral;
   1.880 +  else
   1.881 +  return KErrNone;
   1.882 +   */
   1.883 + 
   1.884 +
   1.885 +
   1.886 +  }
   1.887 +  
   1.888 +   catch(bad_alloc&)
   1.889 +   {
   1.890 +   	//do nothing
   1.891 +    }
   1.892 +   catch(...)
   1.893 +   {
   1.894 +   	failures++;
   1.895 +   	
   1.896 +   }
   1.897 +   
   1.898 +	if( failures == 0 )
   1.899 +		return KErrNone;
   1.900 +  else  
   1.901 +		return KErrGeneral;
   1.902 +    } 
   1.903 +
   1.904 +// -----------------------------------------------------------------------------
   1.905 +// Ctwiostreams::wostream
   1.906 +// Example test method function.
   1.907 +// 
   1.908 +// -----------------------------------------------------------------------------
   1.909 +//
   1.910 +
   1.911 + TInt Ctwiostreams::wostreamL( CStifItemParser& aItem )  
   1.912 + {
   1.913 + 	
   1.914 +
   1.915 + 
   1.916 + int failures = 0;
   1.917 + try
   1.918 + {
   1.919 + 	
   1.920 +
   1.921 + wfilebuf fb;
   1.922 +wchar_t input[18] = L"wostream testcase";
   1.923 +streamsize size = 5;
   1.924 +  fb.open ("c:\\TestFramework\\docs\\wostream.txt",ios::out); cout<<"";
   1.925 +   #if  STDCPP_OOM
   1.926 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.927 +  #endif 
   1.928 +  wostream os(&fb);
   1.929 +  
   1.930 +  os.write(input,size);
   1.931 +  streamoff i = os.tellp();
   1.932 +  if(i!= 5)
   1.933 +  failures++;
   1.934 +  
   1.935 +  os.put('K');
   1.936 +  streamoff j = os.tellp();
   1.937 +  if(j!=6)
   1.938 +  failures++;
   1.939 +
   1.940 +  os.seekp(2);
   1.941 +    os<<"i";
   1.942 +  streamoff k = os.tellp();
   1.943 +
   1.944 +  if(k!=3)
   1.945 +  failures++;
   1.946 +  
   1.947 +  os.flush();
   1.948 +  
   1.949 + #if  STDCPP_OOM
   1.950 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
   1.951 +  #endif 
   1.952 +  
   1.953 + 
   1.954 +  /*
   1.955 +if(failures)
   1.956 +return KErrGeneral;
   1.957 +return KErrNone;
   1.958 +*/
   1.959 + 
   1.960 +  
   1.961 + }
   1.962 + 
   1.963 +  catch(bad_alloc&)
   1.964 +   {
   1.965 +   	//do nothing
   1.966 +    }
   1.967 +   catch(...)
   1.968 +   {
   1.969 +   	failures++;
   1.970 +   	
   1.971 +   }
   1.972 +   
   1.973 +	if( failures == 0 )
   1.974 +		return KErrNone;
   1.975 +  else  
   1.976 +		return KErrGeneral;
   1.977 +    } 
   1.978 +
   1.979 +// -----------------------------------------------------------------------------
   1.980 +// Ctwiostreams::wstringbuf
   1.981 +// Example test method function.
   1.982 +// 
   1.983 +// -----------------------------------------------------------------------------
   1.984 +// 
   1.985 + 
   1.986 +  TInt Ctwiostreams::wstringbufL( CStifItemParser& aItem )  
   1.987 +  {
   1.988 +  int failures=0;
   1.989 +  try
   1.990 +  {
   1.991 +   cout<<"";	
   1.992 + #if  STDCPP_OOM
   1.993 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
   1.994 +  #endif  
   1.995 +wstringbuf sb;
   1.996 +wstring mystr;
   1.997 +
   1.998 +  
   1.999 +sb.sputn (L"Sample string",13);
  1.1000 +mystr=sb.str();
  1.1001 +
  1.1002 +/*if(mystr.compare(L"Sample string") == 0)
  1.1003 +return KErrNone;
  1.1004 +else
  1.1005 +return KErrGeneral;
  1.1006 +  */
  1.1007 +  #if  STDCPP_OOM
  1.1008 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
  1.1009 +  #endif 
  1.1010 +  if(mystr.compare(L"Sample string") != 0)
  1.1011 +  failures++;
  1.1012 +  
  1.1013 +  }
  1.1014 +  
  1.1015 +   catch(bad_alloc&)
  1.1016 +   {
  1.1017 +   	//do nothing
  1.1018 +    }
  1.1019 +   catch(...)
  1.1020 +   {
  1.1021 +   	failures++;
  1.1022 +   	
  1.1023 +   }
  1.1024 +   
  1.1025 +	if( failures == 0 )
  1.1026 +		return KErrNone;
  1.1027 +  else  
  1.1028 +		return KErrGeneral;
  1.1029 +    } 
  1.1030 +  
  1.1031 +//  End of File
  1.1032 +
  1.1033 +//  End of File