os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/iostream_test.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <string>
    17 #include <e32std.h>
    18 
    19 #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
    20 #  include <sstream>
    21 #  include <fstream>
    22 #  include <iostream>
    23 #  include <cassert>
    24 #  include "cppunit/cppunit_proxy.h"
    25 
    26 #  if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
    27 using namespace std;
    28 #  endif
    29 
    30 //
    31 // TestCase class
    32 //
    33 class IOStreamTest : public CPPUNIT_NS::TestCase
    34 {
    35   CPPUNIT_TEST_SUITE(IOStreamTest);
    36   CPPUNIT_TEST(manipulators);
    37   CPPUNIT_TEST(stringstream_cov);
    38 //  CPPUNIT_TEST(iostream_cov1);
    39   CPPUNIT_TEST(iostream_cov2);
    40   CPPUNIT_TEST_SUITE_END();
    41 
    42 private:
    43   void manipulators();
    44   void stringstream_cov();
    45 //  void iostream_cov1();
    46   void iostream_cov2();
    47 };
    48 
    49 CPPUNIT_TEST_SUITE_REGISTRATION(IOStreamTest);
    50 void testfn (ios_base::event ev, ios_base& /*iosobj*/, int /*index*/)
    51 	{
    52 	static int i =0;
    53 	  switch (ev)
    54 	  {
    55 	    case ios_base::copyfmt_event:
    56 	    	assert(0);
    57 	    case ios_base::imbue_event:
    58     	assert(i==0);
    59 	    i++;
    60 	    break;
    61 	    case ios_base::erase_event:
    62     	assert(i==1);
    63 	    break;
    64 	  }
    65 	}
    66 
    67 //
    68 // tests implementation
    69 //
    70 void IOStreamTest::manipulators()
    71 {
    72   {
    73     istringstream istr;
    74     istr.str("bar");
    75 
    76     istr >> ws;
    77     CPPUNIT_ASSERT( istr.good() );
    78 
    79     string foo;
    80     istr >> foo;
    81     CPPUNIT_ASSERT( istr.eof() );
    82     CPPUNIT_ASSERT( !istr.fail() );
    83     CPPUNIT_ASSERT( foo == "bar" );
    84 
    85     istr >> ws;
    86     CPPUNIT_ASSERT( istr.eof() );
    87     CPPUNIT_ASSERT( !istr.fail() );
    88     istr.clear();
    89   }
    90 
    91   {
    92     istringstream istr;
    93     istr.str("  bar  ");
    94 
    95     istr >> ws;
    96     CPPUNIT_ASSERT( istr.good() );
    97 
    98     string foo;
    99     istr >> foo;
   100     CPPUNIT_ASSERT( !istr.eof() );
   101     CPPUNIT_ASSERT( !istr.fail() );
   102     CPPUNIT_ASSERT( foo == "bar" );
   103 
   104     istr >> ws;
   105     CPPUNIT_ASSERT( istr.eof() );
   106     CPPUNIT_ASSERT( !istr.fail() );
   107     istr.clear();
   108   }
   109 }
   110 
   111 void IOStreamTest::stringstream_cov()
   112 	{
   113 	__UHEAP_MARK;
   114 	basic_string<char> i( "stdcpp" );
   115 	stringstream ss1,ss2,ss3;
   116 	ss1.rdbuf( )->str( i );
   117 	string foo1,foo2,foo3;
   118     ss1 >> foo1;
   119     CPPUNIT_ASSERT(foo1 == "stdcpp");
   120     ss2 << "pips";
   121     ss2 >> foo2;
   122     CPPUNIT_ASSERT(foo2 == "pips");
   123     ss3.rdbuf( )->str( "stdcppwithpips" );
   124     ss3 >> foo3;
   125     CPPUNIT_ASSERT(foo3 == "stdcppwithpips");
   126     __UHEAP_MARKEND;
   127 	}
   128 #if 0 
   129 void IOStreamTest::iostream_cov1()
   130 	{
   131 //	__UHEAP_MARK;
   132 		{
   133 		static const int i = ios_base::xalloc();
   134 		cout.iword( i ) = 11;
   135 		cin.iword( i ) = 13;
   136 		CPPUNIT_ASSERT(cout.iword( i ) == 11);
   137 		CPPUNIT_ASSERT(cin.iword( i ) == 13);
   138 		}
   139 	//__UHEAP_MARKEND;
   140 	}
   141 #endif
   142 void IOStreamTest::iostream_cov2()
   143 	{
   144 	//__UHEAP_MARK;
   145 	ofstream filestr;
   146     filestr.register_callback (testfn,0);
   147 	bool x = filestr.sync_with_stdio();
   148 	CPPUNIT_ASSERT(x);
   149 	filestr.imbue (cout.getloc());
   150 	  
   151     //__UHEAP_MARKEND;
   152 	}
   153 #endif