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