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