1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/BC/apps/tiostreams/src/tiostreamsblocks.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,2558 @@
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 +// INCLUDE FILES
1.24 +#include <e32svr.h>
1.25 +#include <StifParser.h>
1.26 +#include <Stiftestinterface.h>
1.27 +#include<iostream>
1.28 +#include<fstream>
1.29 +#include<string>
1.30 +#include<ostream>
1.31 +#include <sstream>
1.32 +#include<strstream>
1.33 +#include<deque>
1.34 +#include<iterator>
1.35 +#include<vector>
1.36 +#include <ios>
1.37 +#include <iostream>
1.38 +#include <fstream>
1.39 +#include <stl\char_traits.h>
1.40 + #include<e32std.h>
1.41 +
1.42 +#include<exception>
1.43 +
1.44 +#include "tiostreams.h"
1.45 +using namespace std;
1.46 + #define STDCPP_OOM FALSE// TRUE for OOM testing
1.47 +
1.48 +
1.49 +// ============================ MEMBER FUNCTIONS ===============================
1.50 +
1.51 +// -----------------------------------------------------------------------------
1.52 +// Ctiostreams::Delete
1.53 +// Delete here all resources allocated and opened from test methods.
1.54 +// Called from destructor.
1.55 +// -----------------------------------------------------------------------------
1.56 +//
1.57 +void Ctiostreams::Delete()
1.58 + {
1.59 +
1.60 + }
1.61 +
1.62 +// -----------------------------------------------------------------------------
1.63 +// Ctiostreams::RunMethodL
1.64 +// Run specified method. Contains also table of test mothods and their names.
1.65 +// -----------------------------------------------------------------------------
1.66 +//
1.67 +TInt Ctiostreams::RunMethodL(
1.68 + CStifItemParser& aItem )
1.69 + {
1.70 +
1.71 + static TStifFunctionInfo const KFunctions[] =
1.72 + {
1.73 + // Copy this line for every implemented function.
1.74 + // First string is the function name used in TestScripter script file.
1.75 + // Second is the actual implementation member function.
1.76 + // Second is the actual implementation member function.
1.77 + ENTRY( "iofstreamL", Ctiostreams::iofstreamL ),
1.78 + ENTRY( "stringbufL", Ctiostreams::stringbufL ),
1.79 + ENTRY( "stringstreamL", Ctiostreams::stringstreamL ),
1.80 + ENTRY( "streambufL", Ctiostreams:: streambufL ),
1.81 + ENTRY( "ostreamL", Ctiostreams:: ostreamL ),
1.82 + ENTRY( "istreamL", Ctiostreams:: istreamL ),
1.83 + ENTRY( "istringstreamL", Ctiostreams:: istringstreamL ),
1.84 + ENTRY( "ostringstreamL", Ctiostreams:: ostringstreamL ),
1.85 + ENTRY( "ostreamiterators", Ctiostreams::ostreamiterators ),
1.86 + ENTRY( "fstreamL", Ctiostreams::fstreamL),
1.87 + ENTRY( "istrstreamL", Ctiostreams::istrstreamL),
1.88 + ENTRY( "strstreamL", Ctiostreams::strstreamL),
1.89 + ENTRY( "ostrstreamL", Ctiostreams::ostrstreamL),
1.90 + ENTRY( "istreamiterators", Ctiostreams::istreamiterators ),
1.91 + ENTRY( "istreambufiterators", Ctiostreams::istreambufiterators ),
1.92 + ENTRY( "strstreambufL", Ctiostreams::strstreambufL ),
1.93 + ENTRY( "freezeL", Ctiostreams::freezeL ),
1.94 + ENTRY( "fposL", Ctiostreams::fposL ),
1.95 + ENTRY( "filebufL", Ctiostreams::filebufL ),
1.96 + ENTRY( "basicstring", Ctiostreams::basicstring ),
1.97 + ENTRY( "basicfilebufL", Ctiostreams::basicfilebufL ),
1.98 + ENTRY( "basicistreamL", Ctiostreams::basicistreamL ),
1.99 + ENTRY( "wfstreamL", Ctiostreams::wfstreamL ),
1.100 + ENTRY( "wifstreamL", Ctiostreams::wifstreamL ),
1.101 + ENTRY( "wistreamL", Ctiostreams::wistreamL ),
1.102 + ENTRY( "wofstreamL", Ctiostreams::wofstreamL ),
1.103 + ENTRY( "wistringstreamL", Ctiostreams::wistringstreamL ),
1.104 + ENTRY( "wostringstreamL", Ctiostreams::wostringstreamL ),
1.105 + ENTRY( "wstreambufL", Ctiostreams::wstreambufL ),
1.106 + ENTRY( "wostreamL", Ctiostreams::wostreamL ),
1.107 + ENTRY( "wstringbufL", Ctiostreams::wstringbufL ),
1.108 +
1.109 +
1.110 +
1.111 + };
1.112 +
1.113 + const TInt count = sizeof( KFunctions ) /
1.114 + sizeof( TStifFunctionInfo );
1.115 +
1.116 + return RunInternalL( KFunctions, count, aItem );
1.117 +
1.118 + }
1.119 +
1.120 +
1.121 +// -----------------------------------------------------------------------------
1.122 +// Ctiostreams:: ofstream,ifstream
1.123 +// Example test method function.
1.124 +// (other items were commented in a header).
1.125 +// -----------------------------------------------------------------------------
1.126 +//
1.127 +
1.128 +
1.129 +TInt Ctiostreams::iofstreamL( CStifItemParser& aItem )
1.130 + {
1.131 +
1.132 +
1.133 +//__UHEAP_MARK;
1.134 +int failures=0 ;
1.135 +try
1.136 +{
1.137 +cout<<"";
1.138 +#if STDCPP_OOM
1.139 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.140 + #endif
1.141 + ofstream myfile;
1.142 + filebuf *fbuf;
1.143 + char * buffer;
1.144 + long size;
1.145 + //ifstream
1.146 + myfile.open ("c:\\TestFramework\\docs\\example.txt");
1.147 + if(!myfile.is_open())
1.148 + failures++;
1.149 +
1.150 + myfile << "Writing this to a file.";
1.151 + myfile<<"\0";
1.152 + myfile.close();
1.153 + if(myfile.is_open())
1.154 + failures++;
1.155 +
1.156 +
1.157 +
1.158 +
1.159 + // string line;
1.160 + ifstream myfile1;
1.161 +
1.162 +
1.163 + myfile1.open("c:\\TestFramework\\docs\\example.txt" );
1.164 +
1.165 +fbuf=myfile1.rdbuf();
1.166 +
1.167 +
1.168 + // get file size using buffer's members
1.169 + size=fbuf->pubseekoff (0,ios::end,ios::in);
1.170 + fbuf->pubseekpos (0,ios::in);
1.171 +
1.172 + // allocate memory to contain file data
1.173 + buffer=new char[size];
1.174 +
1.175 + // get file data
1.176 + fbuf->sgetn (buffer,size);
1.177 +
1.178 +#if STDCPP_OOM
1.179 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.180 + #endif
1.181 +
1.182 +
1.183 + if(buffer != "Writing this to a file.");
1.184 + else
1.185 + failures++;
1.186 +
1.187 + if(size!= 23)
1.188 + failures++;
1.189 +
1.190 +
1.191 +if(!myfile1.is_open())
1.192 +failures++;
1.193 +myfile1.close();
1.194 +if(myfile1.is_open())
1.195 +failures++;
1.196 +
1.197 + delete buffer;
1.198 +ios_base::Init(); // 0 - 218 FUNCTION Init() iostream.cpp
1.199 +filebuf* _Stl_create_filebuf(FILE* f, ios_base::openmode mode ); // 0 - 225 FUNCTION _Stl_create_filebuf() iostream.cpp
1.200 +ios_base::sync_with_stdio();//0 - 445 FUNCTION ios_base::sync_with_stdio()
1.201 +/*
1.202 + if(failures)
1.203 +
1.204 + return KErrGeneral;
1.205 + return KErrNone;
1.206 +
1.207 +*/
1.208 +
1.209 +
1.210 + //#if STDCPP_OOM
1.211 +//failures++;
1.212 +// #endif
1.213 +
1.214 + }
1.215 +
1.216 + catch(bad_alloc&)
1.217 + {
1.218 + //do nothing
1.219 + }
1.220 + catch(...)
1.221 + {
1.222 + failures++;
1.223 +
1.224 + }
1.225 +
1.226 + if( failures == 0 )
1.227 + return KErrNone;
1.228 + else
1.229 + return KErrGeneral;
1.230 +
1.231 + }
1.232 +
1.233 +
1.234 +// -----------------------------------------------------------------------------
1.235 +// Ctiostreams:: stringbuf
1.236 +// Example test method function.
1.237 +// (other items were commented in a header).
1.238 +// -----------------------------------------------------------------------------
1.239 +//
1.240 +
1.241 + TInt Ctiostreams::stringbufL(CStifItemParser& aItem )
1.242 + {
1.243 +
1.244 + int failures = 0;
1.245 + try
1.246 + {
1.247 + cout<<"";
1.248 + #if STDCPP_OOM
1.249 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.250 + #endif
1.251 +stringbuf sb;
1.252 + string mystr;
1.253 +
1.254 + sb.sputn("Sample string",13);
1.255 + mystr=sb.str();
1.256 +
1.257 +
1.258 +
1.259 + if(sb.in_avail()!=13)
1.260 + failures++;
1.261 +
1.262 +
1.263 + char ch = sb.sgetc();
1.264 + if(ch!= 'S')
1.265 + failures++;
1.266 +
1.267 +
1.268 +
1.269 +
1.270 +
1.271 +
1.272 + if(mystr.compare("Sample string") != 0)
1.273 + failures++;
1.274 +
1.275 + #if STDCPP_OOM
1.276 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.277 + #endif
1.278 + /* if(failures)
1.279 +
1.280 + return KErrGeneral;
1.281 + else
1.282 + return KErrNone;
1.283 + */
1.284 +
1.285 +
1.286 + //#if STDCPP_OOM
1.287 +//failures++;
1.288 +// #endif
1.289 +
1.290 + }
1.291 +
1.292 + catch(bad_alloc&)
1.293 + {
1.294 + //do nothing
1.295 + }
1.296 + catch(...)
1.297 + {
1.298 + failures++;
1.299 +
1.300 + }
1.301 +
1.302 + if( failures == 0 )
1.303 + return KErrNone;
1.304 + else
1.305 + return KErrGeneral;
1.306 + }
1.307 +// -----------------------------------------------------------------------------
1.308 +// Ctiostreams:: stringstream
1.309 +// Example test method function.
1.310 +// (other items were commented in a header).
1.311 +// -----------------------------------------------------------------------------
1.312 +//
1.313 +
1.314 +
1.315 + TInt Ctiostreams::stringstreamL(CStifItemParser& aItem )
1.316 + {
1.317 +
1.318 + int val;
1.319 + string teststr;
1.320 + int failures = 0;
1.321 + try
1.322 + {
1.323 + cout<<"";
1.324 + #if STDCPP_OOM
1.325 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.326 + #endif
1.327 + stringstream ss (stringstream::in | stringstream::out);
1.328 + stringstream teststring;
1.329 +
1.330 +
1.331 + teststring<<"stringstream testcase";
1.332 +
1.333 + teststr = teststring.str();
1.334 +
1.335 + if(!teststr.compare("stringstream testcase"))
1.336 + ;
1.337 + else
1.338 + failures++;
1.339 +
1.340 + ss << "120 42 377 6 5 2000";
1.341 +#if STDCPP_OOM
1.342 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.343 + #endif
1.344 + for (int n=0; n<6; n++)
1.345 + {
1.346 + ss >> val;
1.347 +
1.348 + switch(n)
1.349 + {
1.350 + case 0://precision
1.351 + if(val!=120)
1.352 + failures++;
1.353 + break;
1.354 + case 1:
1.355 + if(val!=42)
1.356 + failures++;
1.357 + break;
1.358 + case 2:
1.359 + if(val!=377)
1.360 + failures++;
1.361 + break;
1.362 + case 3:
1.363 + if(val!=6)
1.364 + failures++;
1.365 + break;
1.366 +
1.367 + case 4:
1.368 + if(val!=5)
1.369 + failures++;
1.370 + break;
1.371 +
1.372 + case 5:
1.373 + if(val!=2000)
1.374 + failures++;
1.375 + break;
1.376 +
1.377 + default:
1.378 + break;
1.379 + }
1.380 +
1.381 +
1.382 + }
1.383 +
1.384 + /* if(failures)
1.385 + return KErrGeneral;
1.386 + return KErrNone;
1.387 + */
1.388 +
1.389 +
1.390 +
1.391 + //#if STDCPP_OOM
1.392 +//failures++;
1.393 +// #endif
1.394 + }
1.395 +
1.396 +catch(bad_alloc&)
1.397 + {
1.398 + //do nothing
1.399 + }
1.400 + catch(...)
1.401 + {
1.402 + failures++;
1.403 +
1.404 + }
1.405 +
1.406 + if( failures == 0 )
1.407 + return KErrNone;
1.408 + else
1.409 + return KErrGeneral;
1.410 + }
1.411 +
1.412 +// -----------------------------------------------------------------------------
1.413 +// Ctiostreams:: streambuf
1.414 +// Example test method function.
1.415 +// (other items were commented in a header).
1.416 +// -----------------------------------------------------------------------------
1.417 +//
1.418 +
1.419 + TInt Ctiostreams::streambufL(CStifItemParser& aItem )
1.420 + {
1.421 +// locale loc ("en_GB.UTF-8");
1.422 +
1.423 +
1.424 +
1.425 + int failures = 0;
1.426 + try
1.427 + {
1.428 +
1.429 +
1.430 + char a[4]=
1.431 + {
1.432 + 0
1.433 + };
1.434 +
1.435 + char sentence[]= "Sample sentence";
1.436 + cout<<"";
1.437 + #if STDCPP_OOM
1.438 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.439 + #endif
1.440 + streambuf * pbuf;
1.441 + ofstream ostr ("c:\\TestFramework\\docs\\streambuf.txt");
1.442 +
1.443 +
1.444 +
1.445 + if(!cout.rdbuf( )->getloc( ).name( ).c_str( )) //failing
1.446 +// failures++;
1.447 + ;
1.448 + char ch[14];
1.449 + //rdbuf()s
1.450 + pbuf = ostr.rdbuf();
1.451 +
1.452 +
1.453 +//sputn()
1.454 +
1.455 +
1.456 +
1.457 +
1.458 + pbuf->sputn (sentence,sizeof(sentence)-1);
1.459 +
1.460 +
1.461 + ostr.open("c:\\TestFramework\\docs\\streambuf.txt");
1.462 +
1.463 + if(!ostr.is_open())
1.464 + failures++;
1.465 +
1.466 +
1.467 + long size1 = pbuf->pubseekoff(0,ios_base::end);
1.468 + if(size1!=15)
1.469 + failures++;
1.470 +
1.471 +
1.472 + pbuf->sputc('a');
1.473 +
1.474 +
1.475 + long size2 = pbuf->pubseekoff(0,ios_base::end);
1.476 + if(size2!=16)
1.477 + failures++;
1.478 +
1.479 + ifstream istr("c:\\TestFramework\\docs\\streambuf.txt");
1.480 + pbuf = istr.rdbuf();
1.481 +
1.482 +streamsize i = istr.rdbuf()->sgetn(&a[0], 3);
1.483 +
1.484 + // Display the size and contents of the buffer passed to sgetn.
1.485 + if(i!=3)
1.486 + failures++;
1.487 +
1.488 +
1.489 + int k = pbuf->snextc();
1.490 +
1.491 +
1.492 + //sgetc()
1.493 + while (pbuf->sgetc()!=EOF)
1.494 + {
1.495 + // static int i;
1.496 + int i=0;
1.497 + //sbumpc()
1.498 + ch[i] = pbuf->sbumpc();
1.499 + i++;
1.500 + }
1.501 +
1.502 +
1.503 + if(ch[0]!='a' )
1.504 + failures++;
1.505 +
1.506 +
1.507 +
1.508 +
1.509 +
1.510 +
1.511 + istr.close();
1.512 + #if STDCPP_OOM
1.513 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.514 + #endif
1.515 + /*
1.516 + if(failures)
1.517 + return KErrGeneral;
1.518 + else
1.519 + return KErrNone;
1.520 +
1.521 + */
1.522 +
1.523 +
1.524 + //#if STDCPP_OOM
1.525 +//failures++;
1.526 +// #endif
1.527 +
1.528 + }
1.529 + catch(bad_alloc&)
1.530 + {
1.531 + //do nothing
1.532 + }
1.533 + catch(...)
1.534 + {
1.535 + failures++;
1.536 +
1.537 + }
1.538 +
1.539 + if( failures == 0 )
1.540 + return KErrNone;
1.541 + else
1.542 + return KErrGeneral;
1.543 + }
1.544 +
1.545 +
1.546 +// -----------------------------------------------------------------------------
1.547 +// Ctiostreams:: ostream
1.548 +// Example test method function.
1.549 +// (other items were commented in a header).
1.550 +// -----------------------------------------------------------------------------
1.551 +//
1.552 +
1.553 + TInt Ctiostreams::ostreamL(CStifItemParser& aItem )
1.554 +
1.555 + {
1.556 +
1.557 +
1.558 + int failures = 0;
1.559 + try
1.560 + {
1.561 +
1.562 +
1.563 + filebuf fb;
1.564 +char input[17] = "ostream testcase";
1.565 +streamsize size = 5;
1.566 + fb.open ("c:\\TestFramework\\docs\\ostream.txt",ios::out);
1.567 + cout<<"";
1.568 + #if STDCPP_OOM
1.569 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.570 + #endif
1.571 + ostream os(&fb);
1.572 +
1.573 + os.write(input,size);
1.574 + streamoff i = os.tellp();
1.575 + if(i!= 5)
1.576 + failures++;
1.577 +
1.578 + os.put('K');
1.579 + streamoff j = os.tellp();
1.580 + if(j!=6)
1.581 + failures++;
1.582 +
1.583 + os.seekp(2);
1.584 + os<<"i";
1.585 + streamoff k = os.tellp();
1.586 +
1.587 + if(k!=3)
1.588 + failures++;
1.589 +
1.590 + os.flush();
1.591 +
1.592 + #if STDCPP_OOM
1.593 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.594 + #endif
1.595 +
1.596 +
1.597 + /*
1.598 + if(failures)
1.599 + return KErrGeneral;
1.600 + return KErrNone;
1.601 + */
1.602 +
1.603 +
1.604 + //#if STDCPP_OOM
1.605 +//failures++;
1.606 +// #endif
1.607 + }
1.608 +
1.609 + catch(bad_alloc&)
1.610 + {
1.611 + //do nothing
1.612 + }
1.613 + catch(...)
1.614 + {
1.615 + failures++;
1.616 +
1.617 + }
1.618 +
1.619 + if( failures == 0 )
1.620 + return KErrNone;
1.621 + else
1.622 + return KErrGeneral;
1.623 + }
1.624 +
1.625 +// -----------------------------------------------------------------------------
1.626 +// Ctiostreams:: istream
1.627 +// Example test method function.
1.628 +// (other items were commented in a header).
1.629 +// -----------------------------------------------------------------------------
1.630 +//
1.631 + TInt Ctiostreams::istreamL(CStifItemParser& aItem )
1.632 + {
1.633 +
1.634 +int failures =0;
1.635 +try
1.636 +{
1.637 +
1.638 +
1.639 +int length;
1.640 +char * buffer;
1.641 +char getl[8] ;
1.642 + filebuf fb;
1.643 + fb.open ("c:\\TestFramework\\docs\\istream.txt",ios::in);
1.644 + cout<<"";
1.645 + #if STDCPP_OOM
1.646 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.647 + #endif
1.648 + istream is(&fb);
1.649 +
1.650 + //needs to rewrite
1.651 +
1.652 +
1.653 + // get length of file:
1.654 + is.seekg (0, ios::end);
1.655 + length = is.tellg();
1.656 + is.seekg (0, ios::beg);
1.657 +
1.658 +
1.659 +
1.660 +
1.661 +
1.662 +if(length != 7)
1.663 +failures++;
1.664 +
1.665 + char ch = is.get();
1.666 +
1.667 +
1.668 + if(is.gcount() != 1)
1.669 + failures++;
1.670 +
1.671 +
1.672 + if( ch != 'S')
1.673 + failures++;
1.674 +
1.675 +
1.676 +
1.677 +
1.678 +
1.679 +
1.680 +
1.681 + char pk1 = is.peek();
1.682 +
1.683 + if(pk1!= 'h')
1.684 + failures++;
1.685 +
1.686 +
1.687 + is.unget();
1.688 +
1.689 + char pk2 = is.peek();
1.690 + if(pk2!= 'S')
1.691 + failures++;
1.692 +
1.693 + is.get();
1.694 + is.putback('K');
1.695 +
1.696 + is.getline(getl,8,'\0');
1.697 +
1.698 + if(getl == "Khaheen")
1.699 + failures++;
1.700 +
1.701 + if(is.gcount() != 7)
1.702 + failures++;
1.703 +
1.704 +
1.705 + fb.close();
1.706 + /*if(failures)
1.707 +
1.708 +
1.709 + return KErrGeneral;
1.710 + return KErrNone;
1.711 +
1.712 + */
1.713 +
1.714 + #if STDCPP_OOM
1.715 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.716 + #endif
1.717 + //#if STDCPP_OOM
1.718 +//failures++;
1.719 +// #endif
1.720 +
1.721 + }
1.722 +
1.723 + catch(bad_alloc&)
1.724 + {
1.725 + //do nothing
1.726 + }
1.727 + catch(...)
1.728 + {
1.729 + failures++;
1.730 +
1.731 + }
1.732 +
1.733 + if( failures == 0 )
1.734 + return KErrNone;
1.735 + else
1.736 + return KErrGeneral;
1.737 + }
1.738 +
1.739 +// -----------------------------------------------------------------------------
1.740 +// Ctiostreams:: istringstream
1.741 +// Example test method function.
1.742 +// (other items were commented in a header).
1.743 +// -----------------------------------------------------------------------------
1.744 +//
1.745 +
1.746 + TInt Ctiostreams::istringstreamL(CStifItemParser& aItem )
1.747 + {
1.748 + int n,val;
1.749 + int failures =0;
1.750 + try
1.751 + {
1.752 + string strvalues = "125 320 512 750 333";
1.753 + cout<<"";
1.754 + #if STDCPP_OOM
1.755 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.756 + #endif
1.757 +
1.758 + istringstream iss (strvalues,istringstream::in);
1.759 +
1.760 +if(iss.str() != "125 320 512 750 333")
1.761 +failures++;
1.762 +
1.763 +#if STDCPP_OOM
1.764 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.765 + #endif
1.766 + for (n=0; n<5; n++)
1.767 + {
1.768 + iss >> val;
1.769 + switch(n)
1.770 + {
1.771 + case 0:
1.772 + if(val!=125)
1.773 + failures++;
1.774 + break;
1.775 + case 1:
1.776 + if(val!=320)
1.777 + failures++;
1.778 + break;
1.779 + case 2:
1.780 + if(val!=512)
1.781 + failures++;
1.782 + break;
1.783 + case 3:
1.784 + if(val!=750)
1.785 + failures++;
1.786 + break;
1.787 +
1.788 + case 4:
1.789 + if(val!=333)
1.790 + failures++;
1.791 + break;
1.792 +
1.793 +
1.794 + default:
1.795 + break;
1.796 + }
1.797 +
1.798 + }
1.799 +
1.800 +
1.801 + //#if STDCPP_OOM
1.802 +//failures++;
1.803 +// #endif
1.804 +
1.805 +/* if(failures)
1.806 + return KErrGeneral;
1.807 + else
1.808 + return KErrNone;*/
1.809 + }
1.810 +
1.811 + catch(bad_alloc&)
1.812 + {
1.813 + //do nothing
1.814 + }
1.815 + catch(...)
1.816 + {
1.817 + failures++;
1.818 +
1.819 + }
1.820 +
1.821 + if( failures == 0 )
1.822 + return KErrNone;
1.823 + else
1.824 + return KErrGeneral;
1.825 + }
1.826 +
1.827 +
1.828 +
1.829 +
1.830 +
1.831 +
1.832 +// -----------------------------------------------------------------------------
1.833 +// Ctiostreams:: ostringstream,
1.834 +// Example test method function.
1.835 +// (other items were commented in a header).
1.836 +// -----------------------------------------------------------------------------
1.837 +//
1.838 +
1.839 + TInt Ctiostreams::ostringstreamL(CStifItemParser& aItem )
1.840 + {
1.841 + int failures =0 ;
1.842 + try
1.843 + {
1.844 +
1.845 +
1.846 + basic_string<char> i( "test" );
1.847 + cout<<"";
1.848 + #if STDCPP_OOM
1.849 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.850 + #endif
1.851 + ostringstream ss;
1.852 +
1.853 + ss.rdbuf( )->str( i );
1.854 + if(ss.str( ).compare("test") != 0)
1.855 + failures++;
1.856 +
1.857 + ss << "z";
1.858 + if(ss.str( ) .compare("zest")!=0)
1.859 + failures++;
1.860 +
1.861 + ss.rdbuf( )->str( "be" );
1.862 + if(ss.str( ).compare("be")!=0)
1.863 + failures++;
1.864 +
1.865 + #if STDCPP_OOM
1.866 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.867 + #endif
1.868 + /*
1.869 + if(failures)
1.870 +
1.871 + return KErrGeneral;
1.872 + else
1.873 + return KErrNone;
1.874 +*/
1.875 +
1.876 +
1.877 +
1.878 + //#if STDCPP_OOM
1.879 +//failures++;
1.880 +// #endif
1.881 + }
1.882 +
1.883 + catch(bad_alloc&)
1.884 + {
1.885 + //do nothing
1.886 + }
1.887 + catch(...)
1.888 + {
1.889 + failures++;
1.890 +
1.891 + }
1.892 +
1.893 + if( failures == 0 )
1.894 + return KErrNone;
1.895 + else
1.896 + return KErrGeneral;
1.897 + }
1.898 +
1.899 + TInt Ctiostreams::ostreamiterators(CStifItemParser& aItem )
1.900 + {
1.901 +
1.902 +
1.903 + //needs to rewrite
1.904 + //____________________
1.905 +
1.906 + int arr[4] = { 3,4,7,8 };
1.907 + int total=0;
1.908 + deque<int> d(arr+0, arr+4);
1.909 + //
1.910 + // stream the whole vector and a sum to cout
1.911 + //
1.912 +
1.913 + copy(d.begin(),(d.end()-1),ostream_iterator<int,char>(cout,""));
1.914 +
1.915 +
1.916 + if( *(d.end()-1) == 8)
1.917 + return KErrNone;
1.918 + return KErrGeneral;
1.919 +
1.920 +
1.921 + }
1.922 +
1.923 +
1.924 +
1.925 +// -----------------------------------------------------------------------------
1.926 +// Ctiostreams:: fstream
1.927 +// Example test method function.
1.928 +// (other items were commented in a header).
1.929 +// -----------------------------------------------------------------------------
1.930 +//
1.931 +
1.932 +
1.933 + TInt Ctiostreams::fstreamL(CStifItemParser& aItem )
1.934 + {
1.935 + // __UHEAP_MARK;
1.936 +int failures =0;
1.937 +try
1.938 +{
1.939 +cout<<"";
1.940 +#if STDCPP_OOM
1.941 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.942 + #endif
1.943 +fstream filestr ("c:\\TestFramework\\docs\\fstream.txt", fstream::in | fstream::out);
1.944 +
1.945 +if(!filestr.is_open())
1.946 +failures++;
1.947 +
1.948 +filestr.close();
1.949 +if(filestr.is_open())
1.950 +failures++;
1.951 +
1.952 + // __UHEAP_MARKEND;
1.953 +
1.954 + /*if(failures)
1.955 +return KErrNone;
1.956 +return KErrGeneral;
1.957 + */
1.958 + #if STDCPP_OOM
1.959 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.960 + #endif
1.961 + //#if STDCPP_OOM
1.962 +//failures++;
1.963 +// #endif
1.964 +
1.965 + }
1.966 + catch(bad_alloc&)
1.967 + {
1.968 + //do nothing
1.969 + }
1.970 + catch(...)
1.971 + {
1.972 + failures++;
1.973 +
1.974 + }
1.975 +
1.976 + if( failures == 0 )
1.977 + return KErrNone;
1.978 + else
1.979 + return KErrGeneral;
1.980 + }
1.981 +
1.982 +// -----------------------------------------------------------------------------
1.983 +// Ctiostreams:: istrstream
1.984 +// Example test method function.
1.985 +// (other items were commented in a header).
1.986 +// -----------------------------------------------------------------------------
1.987 +//
1.988 + TInt Ctiostreams::istrstreamL(CStifItemParser& aItem )
1.989 + {
1.990 + // __UHEAP_MARK;
1.991 + int failures=0;
1.992 + try
1.993 + {
1.994 +
1.995 +
1.996 + char* p = "This is first string";
1.997 + char* q = "This is second string";
1.998 + char* r = "";
1.999 + const char* s ="const char";
1.1000 + streamsize n =10;
1.1001 + cout<<"";
1.1002 + #if STDCPP_OOM
1.1003 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1004 + #endif
1.1005 + istrstream first(p);
1.1006 + istrstream second(q);
1.1007 + istrstream third(r);
1.1008 +
1.1009 + istrstream four(s);
1.1010 +
1.1011 + istrstream five(p,n);
1.1012 + istrstream six(s,n);
1.1013 + /* if(first.str() == "This is first string")
1.1014 + if(second.str()!= " This is second string")
1.1015 + if(third.str() == "")
1.1016 + // __UHEAP_MARKEND;
1.1017 +
1.1018 + return KErrNone;
1.1019 + return KErrGeneral;
1.1020 + */
1.1021 + first.rdbuf();
1.1022 + second.rdbuf();
1.1023 + third.rdbuf();
1.1024 +
1.1025 + if(first.str() != "This is first string")
1.1026 + if(second.str()== " This is second string")
1.1027 + if(third.str() != "")
1.1028 + failures++;
1.1029 +
1.1030 + #if STDCPP_OOM
1.1031 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1032 + #endif
1.1033 + //#if STDCPP_OOM
1.1034 +//failures++;
1.1035 +// #endif
1.1036 +
1.1037 + }
1.1038 +
1.1039 +
1.1040 + catch(bad_alloc&)
1.1041 + {
1.1042 + //do nothing
1.1043 + }
1.1044 + catch(...)
1.1045 + {
1.1046 + failures++;
1.1047 +
1.1048 + }
1.1049 +
1.1050 + if( failures == 0 )
1.1051 + return KErrNone;
1.1052 + else
1.1053 + return KErrGeneral;
1.1054 + }
1.1055 +
1.1056 +TInt Ctiostreams::strstreamL(CStifItemParser& aItem )
1.1057 + {
1.1058 + // __UHEAP_MARK;
1.1059 +
1.1060 + int failures = 0;
1.1061 + try
1.1062 + {
1.1063 + cout<<"";
1.1064 + #if STDCPP_OOM
1.1065 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1066 + #endif
1.1067 + char* s;
1.1068 + int n;
1.1069 + ios_base::openmode mode;
1.1070 +// strstream ss3(s, n, mode);
1.1071 + strstream ss1,ss2;
1.1072 + ss1 << "";
1.1073 + ss1.rdbuf();
1.1074 + if(ss1.rdbuf( )->pcount( ) != 0)
1.1075 + failures++;
1.1076 +
1.1077 + string str1= ss1.str();
1.1078 + if(str1.compare("")!=0)
1.1079 + failures++;
1.1080 +
1.1081 + ss2 << "strstream testcase";
1.1082 + ss2 << '\0';
1.1083 + if( ss2.rdbuf( )->pcount( ) != sizeof("strstream testcase\0")-1)
1.1084 + failures++;
1.1085 +
1.1086 + string str = ss2.str();
1.1087 +
1.1088 + if(str.compare("strstream testcase")!= 0)
1.1089 + failures++;
1.1090 + ss1.freeze();
1.1091 + //__UHEAP_MARKEND;
1.1092 + /*
1.1093 + if(failures)
1.1094 + return KErrGeneral;
1.1095 + else
1.1096 + return KErrNone;
1.1097 + */
1.1098 +
1.1099 +
1.1100 + #if STDCPP_OOM
1.1101 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1102 + #endif
1.1103 +
1.1104 + //#if STDCPP_OOM
1.1105 +//failures++;
1.1106 +// #endif
1.1107 + }
1.1108 +
1.1109 + catch(bad_alloc&)
1.1110 + {
1.1111 + //do nothing
1.1112 + }
1.1113 + catch(...)
1.1114 + {
1.1115 + failures++;
1.1116 +
1.1117 + }
1.1118 +
1.1119 + if( failures == 0 )
1.1120 + return KErrNone;
1.1121 + else
1.1122 + return KErrGeneral;
1.1123 + }
1.1124 +
1.1125 +
1.1126 +TInt Ctiostreams::ostrstreamL(CStifItemParser& aItem )
1.1127 + {
1.1128 +
1.1129 + //__UHEAP_MARK;
1.1130 + int failures = 0;
1.1131 + try
1.1132 + {
1.1133 + cout<<"";
1.1134 + #if STDCPP_OOM
1.1135 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1136 + #endif
1.1137 + char* s;
1.1138 + int n;
1.1139 + ios_base::openmode mode;
1.1140 +// ostrstream oss3( s, n, mode);
1.1141 + ostrstream oss1 ,oss2;
1.1142 + string str;
1.1143 + oss1 << "";
1.1144 + oss1.rdbuf();
1.1145 + if(oss1.rdbuf( )->pcount( ) != 0)
1.1146 + failures++;
1.1147 +
1.1148 + oss2 << "ostrstream testcase";
1.1149 + oss2<<'\0';
1.1150 + str = oss2.str();
1.1151 +
1.1152 + if(str.compare("ostrstream testcase") !=0)
1.1153 + failures++;
1.1154 +
1.1155 + oss2.freeze();
1.1156 +
1.1157 + #if STDCPP_OOM
1.1158 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1159 + #endif
1.1160 +
1.1161 + // __UHEAP_MARKEND;
1.1162 + /*
1.1163 + if(failures)
1.1164 + return KErrGeneral;
1.1165 + else
1.1166 + return KErrNone;
1.1167 + */
1.1168 +
1.1169 + //#if STDCPP_OOM
1.1170 +//failures++;
1.1171 +// #endif
1.1172 + }
1.1173 +
1.1174 + catch(bad_alloc&)
1.1175 + {
1.1176 + //do nothing
1.1177 + }
1.1178 + catch(...)
1.1179 + {
1.1180 + failures++;
1.1181 +
1.1182 + }
1.1183 +
1.1184 + if( failures == 0 )
1.1185 + return KErrNone;
1.1186 + else
1.1187 + return KErrGeneral;
1.1188 + }
1.1189 +
1.1190 +
1.1191 +
1.1192 + TInt Ctiostreams::istreamiterators(CStifItemParser& aItem )
1.1193 + {
1.1194 +
1.1195 + // __UHEAP_MARK;
1.1196 + // Typedefs for convenience.
1.1197 + int failures=0;
1.1198 + try
1.1199 + {
1.1200 + cout<<"";
1.1201 + #if STDCPP_OOM
1.1202 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1203 + #endif
1.1204 +
1.1205 + typedef std::vector<int, std::allocator<int> > Vector;
1.1206 +
1.1207 + typedef std::istream_iterator<Vector::value_type,char, std::char_traits<char>, ptrdiff_t> is_iter;
1.1208 +
1.1209 + #if STDCPP_OOM
1.1210 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1211 + #endif
1.1212 + Vector v;
1.1213 +//__UHEAP_MARKEND;
1.1214 +
1.1215 + //#if STDCPP_OOM
1.1216 +//failures++;
1.1217 +// #endif
1.1218 +
1.1219 +
1.1220 +
1.1221 + }
1.1222 +
1.1223 +
1.1224 +catch(bad_alloc&)
1.1225 + {
1.1226 + //do nothing
1.1227 + }
1.1228 + catch(...)
1.1229 + {
1.1230 + failures++;
1.1231 +
1.1232 + }
1.1233 +
1.1234 + if( failures == 0 )
1.1235 + return KErrNone;
1.1236 + else
1.1237 + return KErrGeneral;
1.1238 + }
1.1239 +
1.1240 +
1.1241 + TInt Ctiostreams::istreambufiterators(CStifItemParser& aItem )
1.1242 + {
1.1243 +
1.1244 +
1.1245 + // __UHEAP_MARK;
1.1246 + // create a temporary filename
1.1247 +
1.1248 + int failures=0;
1.1249 + try
1.1250 + {
1.1251 +
1.1252 +
1.1253 + const char *fname = tmpnam (0);
1.1254 +
1.1255 + if (!fname)
1.1256 + return 1;
1.1257 +
1.1258 + // open the file is_iter.out for reading and writing
1.1259 + std::ofstream out (fname, std::ios::out | std::ios::in |
1.1260 + std::ios::trunc);
1.1261 +
1.1262 + // output the example sentence into the file
1.1263 +
1.1264 + // seek to the beginning of the file
1.1265 + out.seekp (0);
1.1266 + cout<<"";
1.1267 +#if STDCPP_OOM
1.1268 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1269 + #endif
1.1270 + // construct an istreambuf_iterator pointing to
1.1271 + // the ofstream object underlying streambuffer
1.1272 + std::istreambuf_iterator<char, std::char_traits<char> >iter (out.rdbuf ());
1.1273 +
1.1274 + // construct an end of stream iterator
1.1275 + const std::istreambuf_iterator<char,std::char_traits<char> > end;
1.1276 +#if STDCPP_OOM
1.1277 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1278 + #endif
1.1279 + std::cout << std::endl;
1.1280 +
1.1281 + // output the content of the file
1.1282 + while (!iter.equal (end)) {
1.1283 +
1.1284 + // use both operator++ and operator*
1.1285 + std::cout << *iter++;
1.1286 + }
1.1287 +
1.1288 + std::cout << std::endl;
1.1289 +
1.1290 + // remove temporary file
1.1291 + remove (fname);
1.1292 +//__UHEAP_MARKEND;
1.1293 +
1.1294 + //#if STDCPP_OOM
1.1295 +//failures++;
1.1296 +// #endif
1.1297 +
1.1298 + }
1.1299 +
1.1300 +catch(bad_alloc&)
1.1301 + {
1.1302 + //do nothing
1.1303 + }
1.1304 + catch(...)
1.1305 + {
1.1306 + failures++;
1.1307 +
1.1308 + }
1.1309 +
1.1310 + if( failures == 0 )
1.1311 + return KErrNone;
1.1312 + else
1.1313 + return KErrGeneral;
1.1314 + }
1.1315 +
1.1316 +
1.1317 +
1.1318 + TInt Ctiostreams::strstreambufL(CStifItemParser& aItem )
1.1319 +
1.1320 +
1.1321 + {
1.1322 +// __UHEAP_MARK;
1.1323 +
1.1324 + int failures =0;
1.1325 + try
1.1326 + {
1.1327 +
1.1328 + cout<<"";
1.1329 +
1.1330 + #if STDCPP_OOM
1.1331 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1332 + #endif
1.1333 +
1.1334 + signed char* get;
1.1335 + streamsize n=10;
1.1336 + signed char* put;
1.1337 + unsigned char* uget;
1.1338 + unsigned char* uput;
1.1339 + const char* cget;
1.1340 + const signed char* csget;
1.1341 +
1.1342 + const unsigned char* cucget;
1.1343 +
1.1344 +
1.1345 + typedef void* (*__alloc_fn)(size_t);
1.1346 + typedef void (*__free_fn)(void*);
1.1347 +
1.1348 + __alloc_fn alloc_f;
1.1349 +
1.1350 + __free_fn free_f;
1.1351 +
1.1352 + //overloaded
1.1353 + strstreambuf buf1(get, n,put);
1.1354 +
1.1355 + //overloaded
1.1356 +
1.1357 + strstreambuf buf2(uget,n,uput);
1.1358 +
1.1359 + //overloaded
1.1360 + strstreambuf buf3(cget,n);
1.1361 + //onverloaded
1.1362 + strstreambuf buf4(csget,n);
1.1363 + //overloaded
1.1364 + strstreambuf buf5(cucget,n);
1.1365 +
1.1366 +
1.1367 +// strstreambuf buf6( alloc_f, free_f);
1.1368 + strstreambuf buf7(n);
1.1369 +
1.1370 + strstreambuf buf;
1.1371 + string str;
1.1372 + int i = buf.sputn("strstreambuf testcase", sizeof("strstreambuf testcase")-1);
1.1373 +
1.1374 +if((buf.pcount())!= i)
1.1375 +failures++;
1.1376 +
1.1377 + buf.freeze();
1.1378 +//if(buf.str() != "strstreambuf testcase") //fails
1.1379 +//failures++;
1.1380 +
1.1381 +#if STDCPP_OOM
1.1382 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1383 + #endif
1.1384 +
1.1385 +//__UHEAP_MARKEND;
1.1386 +/*if(failures)
1.1387 +return KErrGeneral;
1.1388 +else
1.1389 + return KErrNone;
1.1390 + */
1.1391 +
1.1392 + //#if STDCPP_OOM
1.1393 +//failures++;
1.1394 +// #endif
1.1395 +
1.1396 + }
1.1397 + catch(bad_alloc&)
1.1398 + {
1.1399 + //do nothing
1.1400 + }
1.1401 + catch(...)
1.1402 + {
1.1403 + failures++;
1.1404 +
1.1405 + }
1.1406 +
1.1407 + if( failures == 0 )
1.1408 + return KErrNone;
1.1409 + else
1.1410 + return KErrGeneral;
1.1411 + }
1.1412 +
1.1413 +
1.1414 +
1.1415 +
1.1416 + TInt Ctiostreams::freezeL(CStifItemParser& aItem )
1.1417 + {
1.1418 +
1.1419 + int failures=0;
1.1420 + try
1.1421 + {
1.1422 +
1.1423 + strstream x;
1.1424 +int failures =0;
1.1425 + x << "test1";
1.1426 +
1.1427 +if(!x.good())
1.1428 +failures++;
1.1429 +cout<<"";
1.1430 +
1.1431 + #if STDCPP_OOM
1.1432 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1433 + #endif
1.1434 +
1.1435 + x.rdbuf()->freeze();
1.1436 + #if STDCPP_OOM
1.1437 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1438 + #endif
1.1439 +if(!x.good())
1.1440 +failures++;
1.1441 +
1.1442 + // Stream is bad now, wrote on frozen stream
1.1443 + x << "test1.5";
1.1444 +
1.1445 +// report(x);
1.1446 +if(!x.good())
1.1447 +failures++;
1.1448 + // Unfreeze stream, but it is still bad
1.1449 + x.rdbuf()->freeze(false);
1.1450 + if(!x.good())
1.1451 +failures++;
1.1452 +
1.1453 + // Clear stream
1.1454 + x.clear();
1.1455 +
1.1456 +if(!x.good())
1.1457 +failures++;
1.1458 +
1.1459 +
1.1460 + x << "test3";
1.1461 +
1.1462 +
1.1463 +
1.1464 +
1.1465 + // Clean up. Failure to unfreeze stream will cause a
1.1466 + // memory leak.
1.1467 + x.rdbuf()->freeze(false);
1.1468 + /*
1.1469 +if(failures)
1.1470 +return KErrGeneral;
1.1471 +else
1.1472 +return KErrNone;
1.1473 +
1.1474 +*/
1.1475 +
1.1476 + //#if STDCPP_OOM
1.1477 +//failures++;
1.1478 +// #endif
1.1479 + }
1.1480 +
1.1481 +
1.1482 +
1.1483 + catch(bad_alloc&)
1.1484 + {
1.1485 + //do nothing
1.1486 + }
1.1487 + catch(...)
1.1488 + {
1.1489 + failures++;
1.1490 +
1.1491 + }
1.1492 +
1.1493 + if( failures == 0 )
1.1494 + return KErrNone;
1.1495 + else
1.1496 + return KErrGeneral;
1.1497 + }
1.1498 +
1.1499 +
1.1500 + TInt Ctiostreams::fposL(CStifItemParser& aItem )
1.1501 + {
1.1502 + int failures=0;
1.1503 + try
1.1504 + {
1.1505 +
1.1506 +
1.1507 + streamoff s;
1.1508 + ifstream file( "c:\\TestFramework\\docs\\fpos_state.txt" );
1.1509 + cout<<"";
1.1510 + #if STDCPP_OOM
1.1511 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1512 + #endif
1.1513 + fpos<mbstate_t> f = file.tellg( );
1.1514 + char ch;
1.1515 + while ( !file.eof( ) )
1.1516 + file.get( ch );
1.1517 +
1.1518 + f.state();
1.1519 + cout<<"";
1.1520 + #if STDCPP_OOM
1.1521 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1522 + #endif
1.1523 + //s = f;
1.1524 + // if(f.state( ))
1.1525 + // failures++;
1.1526 + // f.state( 9 );
1.1527 + // if( f.state( ))
1.1528 + // failures++;
1.1529 + /*if(failures)
1.1530 + return KErrGeneral;
1.1531 + return KErrNone;*/
1.1532 +
1.1533 + //#if STDCPP_OOM
1.1534 +//failures++;
1.1535 +// #endif
1.1536 + }
1.1537 +
1.1538 + catch(bad_alloc&)
1.1539 + {
1.1540 + //do nothing
1.1541 + }
1.1542 + catch(...)
1.1543 + {
1.1544 + failures++;
1.1545 +
1.1546 + }
1.1547 +
1.1548 + if( failures == 0 )
1.1549 + return KErrNone;
1.1550 + else
1.1551 + return KErrGeneral;
1.1552 + }
1.1553 +
1.1554 +
1.1555 +
1.1556 +
1.1557 +// -----------------------------------------------------------------------------
1.1558 +// Cstdcpp_filebuf::filebufL
1.1559 +// Example test method function.
1.1560 +// (other items were commented in a header).
1.1561 +// -----------------------------------------------------------------------------
1.1562 +//
1.1563 +TInt Ctiostreams::filebufL( CStifItemParser& aItem )
1.1564 + {
1.1565 + int failures=0;
1.1566 +try
1.1567 +{
1.1568 +
1.1569 +
1.1570 +
1.1571 + ifstream is;
1.1572 + cout<<"";
1.1573 + #if STDCPP_OOM
1.1574 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1575 + #endif
1.1576 + filebuf * fb;
1.1577 +
1.1578 + fb = is.rdbuf();
1.1579 + fb->open ("c:\\TestFramework\\docs\\filebuf.txt",ios::in);
1.1580 +
1.1581 + if(!fb->is_open())
1.1582 + failures++;
1.1583 +
1.1584 +
1.1585 + fb->close();
1.1586 +if(fb->is_open())
1.1587 +failures++;
1.1588 +
1.1589 +
1.1590 +#if STDCPP_OOM
1.1591 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1592 + #endif
1.1593 +/*
1.1594 +if(failures)
1.1595 +return KErrGeneral;
1.1596 +return KErrNone;
1.1597 + */
1.1598 +
1.1599 + //#if STDCPP_OOM
1.1600 +//failures++;
1.1601 +// #endif
1.1602 +
1.1603 + }
1.1604 +
1.1605 + catch(bad_alloc&)
1.1606 + {
1.1607 + //do nothing
1.1608 + }
1.1609 + catch(...)
1.1610 + {
1.1611 + failures++;
1.1612 +
1.1613 + }
1.1614 +
1.1615 + if( failures == 0 )
1.1616 + return KErrNone;
1.1617 + else
1.1618 + return KErrGeneral;
1.1619 + }
1.1620 +
1.1621 +
1.1622 +
1.1623 +TInt Ctiostreams::basicstring( CStifItemParser& aItem )
1.1624 + {
1.1625 + int failures =0;
1.1626 +
1.1627 + try
1.1628 + {
1.1629 +
1.1630 +
1.1631 + const char *cstr1a = "Hello Out There.";
1.1632 + cout<<"";
1.1633 + #if STDCPP_OOM
1.1634 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1635 + #endif
1.1636 + basic_string<char> str1a(cstr1a ,5);
1.1637 +
1.1638 + if(str1a.compare("Hello")!=0)
1.1639 + failures++;
1.1640 +
1.1641 + str1a.append("Out There");
1.1642 + if(!str1a.compare("Hello Out There"))
1.1643 + failures++;
1.1644 +
1.1645 +
1.1646 + string str2a ( "How Do You Do?" );
1.1647 + basic_string <char> str2b ( str2a , 7 , 7 );
1.1648 +
1.1649 + if(str2b.compare("You Do?")!=0)
1.1650 + failures++;
1.1651 +
1.1652 +
1.1653 +
1.1654 + basic_string <char> str3a ( 5, '9' );
1.1655 + if(str3a.compare("99999")!=0)
1.1656 + failures++;
1.1657 +
1.1658 +
1.1659 +
1.1660 + basic_string <char> str4a;
1.1661 + string str4b;
1.1662 + basic_string <char> str4c ( str4b.get_allocator( ) );
1.1663 + if (!str4c.empty ())
1.1664 + failures++;
1.1665 +
1.1666 +
1.1667 +
1.1668 + string str5a ( "Hello World");
1.1669 + basic_string <char>::iterator strp_Iter, str1_Iter, str2_Iter;
1.1670 +
1.1671 +
1.1672 +
1.1673 + strp_Iter = str5a.begin();
1.1674 + if(*strp_Iter != 'H' )
1.1675 + failures++;
1.1676 +
1.1677 +
1.1678 +
1.1679 +
1.1680 + basic_string <char>::reference refStr2 = str5a.at ( 3 );
1.1681 +
1.1682 + if(refStr2 != 'l')
1.1683 + failures++;
1.1684 +
1.1685 +
1.1686 + if(str5a.size()!=11)
1.1687 + failures++;
1.1688 + if(str5a.length()!=11)
1.1689 + failures++;
1.1690 + if(str5a.capacity()!=11)
1.1691 + failures++;
1.1692 +
1.1693 +
1.1694 +
1.1695 + #if STDCPP_OOM
1.1696 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1697 + #endif
1.1698 + /* if(failures)
1.1699 + return KErrGeneral;
1.1700 + return KErrNone;
1.1701 + */
1.1702 +
1.1703 + }
1.1704 +
1.1705 + catch(bad_alloc&)
1.1706 + {
1.1707 + //do nothing
1.1708 + }
1.1709 + catch(...)
1.1710 + {
1.1711 + failures++;
1.1712 +
1.1713 + }
1.1714 +
1.1715 + if( failures == 0 )
1.1716 + return KErrNone;
1.1717 + else
1.1718 + return KErrGeneral;
1.1719 + }
1.1720 +
1.1721 +// -----------------------------------------------------------------------------
1.1722 +// Ctwiostreams::basic_filebuf
1.1723 +// Example test method function.
1.1724 +//
1.1725 +// -----------------------------------------------------------------------------
1.1726 +//
1.1727 +
1.1728 + TInt Ctiostreams::basicfilebufL( CStifItemParser& aItem )
1.1729 + {
1.1730 +
1.1731 + int failures=0;
1.1732 + try
1.1733 + {
1.1734 +
1.1735 +
1.1736 + char* wszHello = "Hello World";
1.1737 + char wBuffer[128];
1.1738 + cout<<"";
1.1739 + #if STDCPP_OOM
1.1740 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1741 + #endif
1.1742 +
1.1743 + basic_filebuf<char> wOutFile;
1.1744 +
1.1745 +
1.1746 + // Open a file, wcHello.txt, then write to it, then dump the
1.1747 + // file's contents in hex
1.1748 + wOutFile.open("c:\\TestFramework\\docs\\basicfilebuf.txt",ios_base::out | ios_base::trunc | ios_base::binary);
1.1749 + if(!wOutFile.is_open())
1.1750 + failures++;
1.1751 +
1.1752 + wOutFile.sputn(wszHello, 11);
1.1753 + wOutFile.close();
1.1754 + if(wOutFile.is_open())
1.1755 + failures++;
1.1756 + #if STDCPP_OOM
1.1757 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1758 + #endif
1.1759 + /* if(failures)
1.1760 + return KErrGeneral;
1.1761 + else
1.1762 + return KErrNone;
1.1763 +
1.1764 + */
1.1765 +
1.1766 +
1.1767 +
1.1768 +
1.1769 + }
1.1770 +
1.1771 + catch(bad_alloc&)
1.1772 + {
1.1773 + //do nothing
1.1774 + }
1.1775 + catch(...)
1.1776 + {
1.1777 + failures++;
1.1778 +
1.1779 + }
1.1780 +
1.1781 + if( failures == 0 )
1.1782 + return KErrNone;
1.1783 + else
1.1784 + return KErrGeneral;
1.1785 + }
1.1786 +
1.1787 +// -----------------------------------------------------------------------------
1.1788 +// Ctwiostreams::basic_istream
1.1789 +// Example test method function.
1.1790 +//
1.1791 +// -----------------------------------------------------------------------------
1.1792 +//
1.1793 +
1.1794 + TInt Ctiostreams::basicistreamL( CStifItemParser& aItem )
1.1795 + {
1.1796 +
1.1797 +
1.1798 + int failures = 0;
1.1799 + try
1.1800 + {
1.1801 + cout<<"";
1.1802 + #if STDCPP_OOM
1.1803 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1804 + #endif
1.1805 +
1.1806 +
1.1807 + typedef std::basic_istream<char, std::char_traits<char> > Input;
1.1808 + typedef std::basic_ofstream<Input::char_type, Input::traits_type> Output;
1.1809 +
1.1810 +
1.1811 + Input::char_type s [200];
1.1812 +
1.1813 + Output out ("c:\\TestFramework\\docs\\basicistream.txt", std::ios::in | std::ios::out | std::ios::trunc);
1.1814 +
1.1815 + Input in (out.rdbuf ());
1.1816 +
1.1817 + float f = 3.14159;
1.1818 + int i = 3;
1.1819 +
1.1820 + // output to the file
1.1821 + out << "He lifted his head and pondered.\n"
1.1822 + << f << std::endl << i << std::endl;
1.1823 +
1.1824 + // seek to the beginning of the file
1.1825 + in.seekg (0);
1.1826 +
1.1827 + if(!out.is_open())
1.1828 + failures++;
1.1829 +
1.1830 + out.close();
1.1831 +
1.1832 + if(out.is_open())
1.1833 + failures++;
1.1834 + #if STDCPP_OOM
1.1835 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1836 + #endif
1.1837 + /*if(failures)
1.1838 + return KErrGeneral;
1.1839 + else
1.1840 + return KErrNone;
1.1841 +
1.1842 + */
1.1843 +
1.1844 +
1.1845 + }
1.1846 +
1.1847 + catch(bad_alloc&)
1.1848 + {
1.1849 + //do nothing
1.1850 + }
1.1851 + catch(...)
1.1852 + {
1.1853 + failures++;
1.1854 +
1.1855 + }
1.1856 +
1.1857 + if( failures == 0 )
1.1858 + return KErrNone;
1.1859 + else
1.1860 + return KErrGeneral;
1.1861 + }
1.1862 +// -----------------------------------------------------------------------------
1.1863 +// Ctwiostreams::wfstream
1.1864 +// Example test method function.
1.1865 +//
1.1866 +// -----------------------------------------------------------------------------
1.1867 +//
1.1868 + TInt Ctiostreams::wfstreamL( CStifItemParser& aItem )
1.1869 +
1.1870 + {
1.1871 +
1.1872 + int failures=0;
1.1873 +
1.1874 + try
1.1875 + {
1.1876 + cout<<"";
1.1877 + #if STDCPP_OOM
1.1878 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1879 + #endif
1.1880 +
1.1881 + wfstream file;
1.1882 +
1.1883 +
1.1884 + file.open("c:\\TestFramework\\docs\\wfstream.txt");
1.1885 + file.rdbuf();
1.1886 + if(!file.is_open())
1.1887 + failures++;
1.1888 +
1.1889 + file.close();
1.1890 +
1.1891 + if(file.is_open())
1.1892 + failures++;
1.1893 + #if STDCPP_OOM
1.1894 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1895 + #endif
1.1896 +/* if(failures)
1.1897 + return KErrGeneral;
1.1898 + return KErrNone;
1.1899 +
1.1900 + */
1.1901 +
1.1902 + }
1.1903 +
1.1904 + catch(bad_alloc&)
1.1905 + {
1.1906 + //do nothing
1.1907 + }
1.1908 + catch(...)
1.1909 + {
1.1910 + failures++;
1.1911 +
1.1912 + }
1.1913 +
1.1914 + if( failures == 0 )
1.1915 + return KErrNone;
1.1916 + else
1.1917 + return KErrGeneral;
1.1918 + }
1.1919 +
1.1920 +
1.1921 +// -----------------------------------------------------------------------------
1.1922 +// Ctwiostreams::wifstream
1.1923 +// Example test method function.
1.1924 +//
1.1925 +// -----------------------------------------------------------------------------
1.1926 +//
1.1927 + TInt Ctiostreams::wifstreamL( CStifItemParser& aItem )
1.1928 +
1.1929 + {
1.1930 + int failures =0;
1.1931 +
1.1932 + try
1.1933 + {
1.1934 + cout<<"";
1.1935 + #if STDCPP_OOM
1.1936 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.1937 + #endif
1.1938 +
1.1939 + wifstream file;
1.1940 +
1.1941 +
1.1942 + file.open("c:\\TestFramework\\docs\\wifstream.txt");
1.1943 +
1.1944 +
1.1945 + file.rdbuf();
1.1946 + if(!file.is_open())
1.1947 + failures++;
1.1948 +
1.1949 + file.close();
1.1950 +
1.1951 + if(file.is_open())
1.1952 + failures++;
1.1953 + #if STDCPP_OOM
1.1954 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.1955 + #endif
1.1956 +/* if(failures)
1.1957 + return KErrGeneral;
1.1958 + return KErrNone;
1.1959 +
1.1960 + */
1.1961 +
1.1962 + }
1.1963 + catch(bad_alloc&)
1.1964 + {
1.1965 + //do nothing
1.1966 + }
1.1967 + catch(...)
1.1968 + {
1.1969 + failures++;
1.1970 +
1.1971 + }
1.1972 +
1.1973 + if( failures == 0 )
1.1974 + return KErrNone;
1.1975 + else
1.1976 + return KErrGeneral;
1.1977 + }
1.1978 +
1.1979 +
1.1980 +// -----------------------------------------------------------------------------
1.1981 +// Ctwiostreams::wfilebuf,wistream
1.1982 +// Example test method function.
1.1983 +//
1.1984 +// -----------------------------------------------------------------------------
1.1985 +//
1.1986 + TInt Ctiostreams::wistreamL( CStifItemParser& aItem )
1.1987 +
1.1988 + {
1.1989 + int failures=0;
1.1990 + try
1.1991 + {
1.1992 +
1.1993 +
1.1994 + int length;
1.1995 +wchar_t * buffer;
1.1996 +wchar_t getl[16] ;
1.1997 +
1.1998 + wfilebuf fb;
1.1999 + fb.open ("c:\\TestFramework\\docs\\wistream.txt",ios::in);
1.2000 + cout<<"";
1.2001 + #if STDCPP_OOM
1.2002 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.2003 + #endif
1.2004 + wistream is(&fb);
1.2005 +
1.2006 + if(!fb.is_open())
1.2007 + failures++;
1.2008 +
1.2009 + //if( char(is.get())!= 'S')
1.2010 + // failures++;
1.2011 +
1.2012 +//if(sizeof(fb)!=140)
1.2013 +//failures++;
1.2014 +
1.2015 +
1.2016 +
1.2017 +
1.2018 + // get length of file:
1.2019 + is.seekg (0, ios::end);
1.2020 + length = is.tellg();
1.2021 + is.seekg (0, ios::beg);
1.2022 +
1.2023 +
1.2024 +
1.2025 +
1.2026 +
1.2027 +if(length != 15)
1.2028 +failures++;
1.2029 +
1.2030 + wchar_t ch = is.get();
1.2031 +
1.2032 +
1.2033 + if(is.gcount() != 1)
1.2034 + failures++;
1.2035 +
1.2036 +
1.2037 + if( ch != L'S')
1.2038 + failures++;
1.2039 +
1.2040 +
1.2041 +
1.2042 +
1.2043 +
1.2044 +
1.2045 +
1.2046 + wchar_t pk1 = is.peek();
1.2047 +
1.2048 + if(pk1!= 'a')
1.2049 + failures++;
1.2050 +
1.2051 +
1.2052 + is.unget();
1.2053 +
1.2054 + wchar_t pk2 = is.peek();
1.2055 + if(pk2!= 'S')
1.2056 + failures++;
1.2057 +
1.2058 + is.get();
1.2059 + is.putback('K');
1.2060 +
1.2061 + is.getline(getl,16,'\0');
1.2062 +
1.2063 + if(getl == L"Kample sentence")
1.2064 + failures++;
1.2065 +
1.2066 +
1.2067 +
1.2068 +fb.close();
1.2069 +
1.2070 +if(fb.is_open())
1.2071 +failures++;
1.2072 + #if STDCPP_OOM
1.2073 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.2074 + #endif
1.2075 +/*
1.2076 + if(failures)
1.2077 +
1.2078 + return sizeof(fb);
1.2079 + return KErrNone;
1.2080 +
1.2081 + */
1.2082 +
1.2083 +
1.2084 +
1.2085 +
1.2086 + }
1.2087 +
1.2088 + catch(bad_alloc&)
1.2089 + {
1.2090 + //do nothing
1.2091 + }
1.2092 + catch(...)
1.2093 + {
1.2094 + failures++;
1.2095 +
1.2096 + }
1.2097 +
1.2098 + if( failures == 0 )
1.2099 + return KErrNone;
1.2100 + else
1.2101 + return KErrGeneral;
1.2102 + }
1.2103 +
1.2104 +// -----------------------------------------------------------------------------
1.2105 +// Ctwiostreams::wofstream
1.2106 +// Example test method function.
1.2107 +//
1.2108 +// -----------------------------------------------------------------------------
1.2109 +//
1.2110 +
1.2111 + TInt Ctiostreams::wofstreamL( CStifItemParser& aItem )
1.2112 + {
1.2113 +
1.2114 + int failures=0;
1.2115 + try
1.2116 + {
1.2117 + cout<<"";
1.2118 + #if STDCPP_OOM
1.2119 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.2120 + #endif
1.2121 +
1.2122 + wofstream outfile;
1.2123 +
1.2124 + outfile.open("c:\\TestFramework\\docs\\wostream.txt");
1.2125 + outfile.write(L"This is an ostreamfile",22);
1.2126 +
1.2127 + outfile.rdbuf();
1.2128 + if(!outfile.is_open())
1.2129 + failures++;
1.2130 +
1.2131 + outfile.close();
1.2132 +
1.2133 +
1.2134 + if(outfile.is_open())
1.2135 + failures++;
1.2136 + #if STDCPP_OOM
1.2137 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.2138 + #endif
1.2139 + /* if(failures)
1.2140 + return KErrGeneral;
1.2141 + else
1.2142 + return KErrNone;
1.2143 +
1.2144 + */
1.2145 +
1.2146 +
1.2147 + }
1.2148 +
1.2149 + catch(bad_alloc&)
1.2150 + {
1.2151 + //do nothing
1.2152 + }
1.2153 + catch(...)
1.2154 + {
1.2155 + failures++;
1.2156 +
1.2157 + }
1.2158 +
1.2159 + if( failures == 0 )
1.2160 + return KErrNone;
1.2161 + else
1.2162 + return KErrGeneral;
1.2163 + }
1.2164 +
1.2165 +// -----------------------------------------------------------------------------
1.2166 +// Ctwiostreams::wistringstream
1.2167 +// Example test method function.
1.2168 +//
1.2169 +// -----------------------------------------------------------------------------
1.2170 +//
1.2171 + TInt Ctiostreams::wistringstreamL( CStifItemParser& aItem )
1.2172 + {
1.2173 + int failures=0;
1.2174 + try
1.2175 + {
1.2176 +
1.2177 +
1.2178 + int output[5];
1.2179 + int n,val;
1.2180 + wstring strvalues ;
1.2181 +
1.2182 + strvalues = L"1 2 3 4 5";
1.2183 + cout<<"";
1.2184 + #if STDCPP_OOM
1.2185 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.2186 + #endif
1.2187 + wistringstream iss(strvalues,wistringstream::in);
1.2188 + #if STDCPP_OOM
1.2189 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.2190 + #endif
1.2191 +
1.2192 + for(n=0;n<5;n++)
1.2193 + {
1.2194 +
1.2195 + static int j;
1.2196 +
1.2197 + iss>>val;
1.2198 +
1.2199 + output[j]=val;
1.2200 +
1.2201 + j++;
1.2202 +
1.2203 +
1.2204 + }
1.2205 +
1.2206 + if(iss.str()!=L"1 2 3 4 5")
1.2207 + failures++;
1.2208 +/*
1.2209 + if(output[0]== 1)
1.2210 + if(output[1]== 2)
1.2211 + if(output[2]== 3)
1.2212 + if(output[3]== 4 )
1.2213 + if(output[4]== 5)
1.2214 +
1.2215 + return KErrNone;
1.2216 + else
1.2217 + return KErrGeneral;
1.2218 + */
1.2219 +
1.2220 + if(output[0]!= 1)
1.2221 + failures++;
1.2222 + if(output[1]!= 2)
1.2223 + failures++;
1.2224 + if(output[2]!= 3)
1.2225 + failures++;
1.2226 + if(output[3]!= 4 )
1.2227 + failures++;
1.2228 + if(output[4]!= 5)
1.2229 + failures++;
1.2230 + }
1.2231 +
1.2232 + catch(bad_alloc&)
1.2233 + {
1.2234 + //do nothing
1.2235 + }
1.2236 + catch(...)
1.2237 + {
1.2238 + failures++;
1.2239 +
1.2240 + }
1.2241 +
1.2242 + if( failures == 0 )
1.2243 + return KErrNone;
1.2244 + else
1.2245 + return KErrGeneral;
1.2246 + }
1.2247 +// -----------------------------------------------------------------------------
1.2248 +// Ctwiostreams::wostringstream,wstring
1.2249 +// Example test method function.
1.2250 +//
1.2251 +// -----------------------------------------------------------------------------
1.2252 +//
1.2253 + TInt Ctiostreams::wostringstreamL( CStifItemParser& aItem )
1.2254 + {
1.2255 + int failures=0;
1.2256 + try
1.2257 + { cout<<"";
1.2258 + #if STDCPP_OOM
1.2259 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.2260 + #endif
1.2261 +
1.2262 +
1.2263 +wostringstream oss;
1.2264 +wstring mystr;
1.2265 +
1.2266 +oss << L"wostringstream testcase";
1.2267 +oss.rdbuf();
1.2268 +mystr=oss.str();
1.2269 + #if STDCPP_OOM
1.2270 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.2271 + #endif
1.2272 +/*if(mystr.compare(L"wostringstream testcase")==0)
1.2273 +return KErrNone;
1.2274 +return KErrGeneral;
1.2275 +*/
1.2276 +if(mystr.compare(L"wostringstream testcase")!=0)
1.2277 +failures++;
1.2278 +
1.2279 + }
1.2280 +
1.2281 +
1.2282 + catch(bad_alloc&)
1.2283 + {
1.2284 + //do nothing
1.2285 + }
1.2286 + catch(...)
1.2287 + {
1.2288 + failures++;
1.2289 +
1.2290 + }
1.2291 +
1.2292 + if( failures == 0 )
1.2293 + return KErrNone;
1.2294 + else
1.2295 + return KErrGeneral;
1.2296 + }
1.2297 +// -----------------------------------------------------------------------------
1.2298 +// Ctwiostreams::wstreambuf,wofstreams
1.2299 +// Example test method function.
1.2300 +//
1.2301 +// -----------------------------------------------------------------------------
1.2302 +//
1.2303 +
1.2304 + TInt Ctiostreams::wstreambufL( CStifItemParser& aItem )
1.2305 + {
1.2306 +
1.2307 +
1.2308 +//locale loc ("en_GB.UTF-8");
1.2309 +
1.2310 +
1.2311 +
1.2312 + int failures = 0;
1.2313 + try
1.2314 + {
1.2315 +
1.2316 +
1.2317 + wchar_t a[4]=
1.2318 + {
1.2319 + 0
1.2320 + };
1.2321 +
1.2322 + wchar_t sentence[]= L"Sample sentence"; cout<<"";
1.2323 + #if STDCPP_OOM
1.2324 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.2325 + #endif
1.2326 + wstreambuf * pbuf;
1.2327 + wofstream ostr ("c:\\TestFramework\\docs\\wstreambuf.txt");
1.2328 +
1.2329 +
1.2330 +
1.2331 +// if(cout.rdbuf( )->getloc( ).name( ).c_str( ) != "C") //failing
1.2332 + //failures++;
1.2333 +
1.2334 + wchar_t ch[28];
1.2335 + //rdbuf()s
1.2336 + pbuf = ostr.rdbuf();
1.2337 +
1.2338 +
1.2339 +//sputn()
1.2340 +
1.2341 +
1.2342 +
1.2343 +
1.2344 + pbuf->sputn (sentence,sizeof(sentence)-1);
1.2345 +
1.2346 +
1.2347 + ostr.open("c:\\TestFramework\\docs\\wstreambuf.txt");
1.2348 +
1.2349 + if(!ostr.is_open())
1.2350 + failures++;
1.2351 +
1.2352 +
1.2353 + long size1 = pbuf->pubseekoff(0,ios_base::end);
1.2354 + if(size1!=31)
1.2355 + failures++;
1.2356 +
1.2357 +
1.2358 + pbuf->sputc('a');
1.2359 +
1.2360 +
1.2361 + long size2 = pbuf->pubseekoff(0,ios_base::end);
1.2362 + if(size2!=32)
1.2363 + failures++;
1.2364 +
1.2365 + wifstream istr("c:\\TestFramework\\docs\\wstreambuf.txt");
1.2366 + pbuf = istr.rdbuf();
1.2367 +
1.2368 +streamsize i = istr.rdbuf()->sgetn(&a[0], 3);
1.2369 + //a[i] = istr.widen('\0');
1.2370 +
1.2371 + // Display the size and contents of the buffer passed to sgetn.
1.2372 + if(i!=3)
1.2373 + failures++;
1.2374 +
1.2375 +
1.2376 + int k = pbuf->snextc();
1.2377 +
1.2378 +
1.2379 + //sgetc()
1.2380 + while (pbuf->sgetc()!=EOF)
1.2381 + {
1.2382 + static int i;
1.2383 + //sbumpc()
1.2384 + ch[i] = pbuf->sbumpc();
1.2385 + i++;
1.2386 + }
1.2387 +
1.2388 +
1.2389 + if(ch[0]!='l' )
1.2390 + failures++;
1.2391 +
1.2392 +
1.2393 +
1.2394 +
1.2395 +
1.2396 +
1.2397 + istr.close();
1.2398 + ostr.close();
1.2399 + #if STDCPP_OOM
1.2400 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.2401 + #endif
1.2402 + /* if(failures)
1.2403 + return KErrGeneral;
1.2404 + else
1.2405 + return KErrNone;
1.2406 + */
1.2407 +
1.2408 +
1.2409 +
1.2410 + }
1.2411 +
1.2412 + catch(bad_alloc&)
1.2413 + {
1.2414 + //do nothing
1.2415 + }
1.2416 + catch(...)
1.2417 + {
1.2418 + failures++;
1.2419 +
1.2420 + }
1.2421 +
1.2422 + if( failures == 0 )
1.2423 + return KErrNone;
1.2424 + else
1.2425 + return KErrGeneral;
1.2426 + }
1.2427 +
1.2428 +// -----------------------------------------------------------------------------
1.2429 +// Ctwiostreams::wostream
1.2430 +// Example test method function.
1.2431 +//
1.2432 +// -----------------------------------------------------------------------------
1.2433 +//
1.2434 +
1.2435 + TInt Ctiostreams::wostreamL( CStifItemParser& aItem )
1.2436 + {
1.2437 +
1.2438 +
1.2439 +
1.2440 + int failures = 0;
1.2441 + try
1.2442 + {
1.2443 +
1.2444 +
1.2445 + wfilebuf fb;
1.2446 +wchar_t input[18] = L"wostream testcase";
1.2447 +streamsize size = 5;
1.2448 + fb.open ("c:\\TestFramework\\docs\\wostream.txt",ios::out); cout<<"";
1.2449 + #if STDCPP_OOM
1.2450 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.2451 + #endif
1.2452 + wostream os(&fb);
1.2453 +
1.2454 + os.write(input,size);
1.2455 + streamoff i = os.tellp();
1.2456 + if(i!= 5)
1.2457 + failures++;
1.2458 +
1.2459 + os.put('K');
1.2460 + streamoff j = os.tellp();
1.2461 + if(j!=6)
1.2462 + failures++;
1.2463 +
1.2464 + os.seekp(2);
1.2465 + os<<"i";
1.2466 + streamoff k = os.tellp();
1.2467 +
1.2468 + if(k!=3)
1.2469 + failures++;
1.2470 +
1.2471 + os.flush();
1.2472 +
1.2473 + #if STDCPP_OOM
1.2474 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.2475 + #endif
1.2476 +
1.2477 +
1.2478 + /*
1.2479 +if(failures)
1.2480 +return KErrGeneral;
1.2481 +return KErrNone;
1.2482 +*/
1.2483 +
1.2484 +
1.2485 + }
1.2486 +
1.2487 + catch(bad_alloc&)
1.2488 + {
1.2489 + //do nothing
1.2490 + }
1.2491 + catch(...)
1.2492 + {
1.2493 + failures++;
1.2494 +
1.2495 + }
1.2496 +
1.2497 + if( failures == 0 )
1.2498 + return KErrNone;
1.2499 + else
1.2500 + return KErrGeneral;
1.2501 + }
1.2502 +
1.2503 +// -----------------------------------------------------------------------------
1.2504 +// Ctwiostreams::wstringbuf
1.2505 +// Example test method function.
1.2506 +//
1.2507 +// -----------------------------------------------------------------------------
1.2508 +//
1.2509 +
1.2510 + TInt Ctiostreams::wstringbufL( CStifItemParser& aItem )
1.2511 + {
1.2512 + int failures=0;
1.2513 + try
1.2514 + {
1.2515 + cout<<"";
1.2516 + #if STDCPP_OOM
1.2517 +User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1);
1.2518 + #endif
1.2519 +wstringbuf sb;
1.2520 +wstring mystr;
1.2521 +
1.2522 +
1.2523 +sb.sputn (L"Sample string",13);
1.2524 +mystr=sb.str();
1.2525 +
1.2526 +/*if(mystr.compare(L"Sample string") == 0)
1.2527 +return KErrNone;
1.2528 +else
1.2529 +return KErrGeneral;
1.2530 + */
1.2531 + #if STDCPP_OOM
1.2532 +User::__DbgSetAllocFail(FALSE,RHeap::ENone,1);
1.2533 + #endif
1.2534 + if(mystr.compare(L"Sample string") != 0)
1.2535 + failures++;
1.2536 +
1.2537 + }
1.2538 +
1.2539 + catch(bad_alloc&)
1.2540 + {
1.2541 + //do nothing
1.2542 + }
1.2543 + catch(...)
1.2544 + {
1.2545 + failures++;
1.2546 +
1.2547 + }
1.2548 +
1.2549 + if( failures == 0 )
1.2550 + return KErrNone;
1.2551 + else
1.2552 + return KErrGeneral;
1.2553 + }
1.2554 +
1.2555 +// End of File
1.2556 +
1.2557 +// End of File
1.2558 +
1.2559 +
1.2560 +
1.2561 +// End of File