sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include <string> sl@0: #include <e32std.h> sl@0: sl@0: #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) sl@0: # include <sstream> sl@0: # include <fstream> sl@0: # include <iostream> sl@0: # include <cassert> sl@0: # include "cppunit/cppunit_proxy.h" sl@0: sl@0: # if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) sl@0: using namespace std; sl@0: # endif sl@0: sl@0: // sl@0: // TestCase class sl@0: // sl@0: class IOStreamTest : public CPPUNIT_NS::TestCase sl@0: { sl@0: CPPUNIT_TEST_SUITE(IOStreamTest); sl@0: CPPUNIT_TEST(manipulators); sl@0: CPPUNIT_TEST(stringstream_cov); sl@0: // CPPUNIT_TEST(iostream_cov1); sl@0: CPPUNIT_TEST(iostream_cov2); sl@0: CPPUNIT_TEST_SUITE_END(); sl@0: sl@0: private: sl@0: void manipulators(); sl@0: void stringstream_cov(); sl@0: // void iostream_cov1(); sl@0: void iostream_cov2(); sl@0: }; sl@0: sl@0: CPPUNIT_TEST_SUITE_REGISTRATION(IOStreamTest); sl@0: void testfn (ios_base::event ev, ios_base& /*iosobj*/, int /*index*/) sl@0: { sl@0: static int i =0; sl@0: switch (ev) sl@0: { sl@0: case ios_base::copyfmt_event: sl@0: assert(0); sl@0: case ios_base::imbue_event: sl@0: assert(i==0); sl@0: i++; sl@0: break; sl@0: case ios_base::erase_event: sl@0: assert(i==1); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: // sl@0: // tests implementation sl@0: // sl@0: void IOStreamTest::manipulators() sl@0: { sl@0: { sl@0: istringstream istr; sl@0: istr.str("bar"); sl@0: sl@0: istr >> ws; sl@0: CPPUNIT_ASSERT( istr.good() ); sl@0: sl@0: string foo; sl@0: istr >> foo; sl@0: CPPUNIT_ASSERT( istr.eof() ); sl@0: CPPUNIT_ASSERT( !istr.fail() ); sl@0: CPPUNIT_ASSERT( foo == "bar" ); sl@0: sl@0: istr >> ws; sl@0: CPPUNIT_ASSERT( istr.eof() ); sl@0: CPPUNIT_ASSERT( !istr.fail() ); sl@0: istr.clear(); sl@0: } sl@0: sl@0: { sl@0: istringstream istr; sl@0: istr.str(" bar "); sl@0: sl@0: istr >> ws; sl@0: CPPUNIT_ASSERT( istr.good() ); sl@0: sl@0: string foo; sl@0: istr >> foo; sl@0: CPPUNIT_ASSERT( !istr.eof() ); sl@0: CPPUNIT_ASSERT( !istr.fail() ); sl@0: CPPUNIT_ASSERT( foo == "bar" ); sl@0: sl@0: istr >> ws; sl@0: CPPUNIT_ASSERT( istr.eof() ); sl@0: CPPUNIT_ASSERT( !istr.fail() ); sl@0: istr.clear(); sl@0: } sl@0: } sl@0: sl@0: void IOStreamTest::stringstream_cov() sl@0: { sl@0: __UHEAP_MARK; sl@0: basic_string<char> i( "stdcpp" ); sl@0: stringstream ss1,ss2,ss3; sl@0: ss1.rdbuf( )->str( i ); sl@0: string foo1,foo2,foo3; sl@0: ss1 >> foo1; sl@0: CPPUNIT_ASSERT(foo1 == "stdcpp"); sl@0: ss2 << "pips"; sl@0: ss2 >> foo2; sl@0: CPPUNIT_ASSERT(foo2 == "pips"); sl@0: ss3.rdbuf( )->str( "stdcppwithpips" ); sl@0: ss3 >> foo3; sl@0: CPPUNIT_ASSERT(foo3 == "stdcppwithpips"); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: #if 0 sl@0: void IOStreamTest::iostream_cov1() sl@0: { sl@0: // __UHEAP_MARK; sl@0: { sl@0: static const int i = ios_base::xalloc(); sl@0: cout.iword( i ) = 11; sl@0: cin.iword( i ) = 13; sl@0: CPPUNIT_ASSERT(cout.iword( i ) == 11); sl@0: CPPUNIT_ASSERT(cin.iword( i ) == 13); sl@0: } sl@0: //__UHEAP_MARKEND; sl@0: } sl@0: #endif sl@0: void IOStreamTest::iostream_cov2() sl@0: { sl@0: //__UHEAP_MARK; sl@0: ofstream filestr; sl@0: filestr.register_callback (testfn,0); sl@0: bool x = filestr.sync_with_stdio(); sl@0: CPPUNIT_ASSERT(x); sl@0: filestr.imbue (cout.getloc()); sl@0: sl@0: //__UHEAP_MARKEND; sl@0: } sl@0: #endif