1 #include <string> 2 3 #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) 4 # include <sstream> 5 //# include <locale> 6 # include <iostream> 7 //# include <stdexcept> 8 9 # include "cppunit/cppunit_proxy.h" 10 11 # if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 12 using namespace std; 13 # endif 14 15 // 16 // TestCase class 17 // 18 class IOStreamTest : public CPPUNIT_NS::TestCase 19 { 20 CPPUNIT_TEST_SUITE(IOStreamTest); 21 CPPUNIT_TEST(manipulators); 22 CPPUNIT_TEST(in_avail); 23 //#if defined (STLPORT) && defined (_STLP_NO_WCHAR_T) 24 //CPPUNIT_IGNORE; 25 //#endif 26 //CPPUNIT_TEST(wimbue); 27 CPPUNIT_TEST_SUITE_END(); 28 29 private: 30 void manipulators(); 31 void in_avail(); 32 //void wimbue(); 33 }; 34 35 CPPUNIT_TEST_SUITE_REGISTRATION(IOStreamTest); 36 37 // 38 // tests implementation 39 // 40 void IOStreamTest::manipulators() 41 { 42 { 43 istringstream istr; 44 istr.str("bar"); 45 46 istr >> ws; 47 CPPUNIT_ASSERT( istr.good() ); 48 49 string foo; 50 istr >> foo; 51 CPPUNIT_ASSERT( istr.eof() ); 52 CPPUNIT_ASSERT( !istr.fail() ); 53 CPPUNIT_ASSERT( foo == "bar" ); 54 55 istr >> ws; 56 CPPUNIT_ASSERT( istr.eof() ); 57 CPPUNIT_ASSERT( !istr.fail() ); 58 istr.clear(); 59 } 60 61 { 62 istringstream istr; 63 istr.str(" bar "); 64 65 istr >> ws; 66 CPPUNIT_ASSERT( istr.good() ); 67 68 string foo; 69 istr >> foo; 70 CPPUNIT_ASSERT( !istr.eof() ); 71 CPPUNIT_ASSERT( !istr.fail() ); 72 CPPUNIT_ASSERT( foo == "bar" ); 73 74 istr >> ws; 75 CPPUNIT_ASSERT( istr.eof() ); 76 CPPUNIT_ASSERT( !istr.fail() ); 77 istr.clear(); 78 } 79 } 80 81 82 void IOStreamTest::in_avail() 83 { 84 CPPUNIT_CHECK( cin.rdbuf()->in_avail() == 0 ); 85 CPPUNIT_CHECK( cout.rdbuf()->in_avail() == -1 ); 86 CPPUNIT_CHECK( clog.rdbuf()->in_avail() == -1 ); 87 CPPUNIT_CHECK( cerr.rdbuf()->in_avail() == -1 ); 88 89 #if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) 90 CPPUNIT_CHECK( wcin.rdbuf()->in_avail() == 0 ); 91 CPPUNIT_CHECK( wcout.rdbuf()->in_avail() == 0 ); 92 CPPUNIT_CHECK( wclog.rdbuf()->in_avail() == 0 ); 93 CPPUNIT_CHECK( wcerr.rdbuf()->in_avail() == 0 ); 94 #endif 95 } 96 97 //void IOStreamTest::wimbue() 98 //{ 99 //#if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) 100 // locale loc; 101 // try { 102 // locale tmp(".866"); 103 // loc = tmp; 104 // } 105 // catch (const runtime_error&) { 106 // return; 107 // } 108 // 109 // wcout.imbue(loc); 110 // wcout << L"Hello world" << endl; 111 // wcout.imbue(loc); 112 // wcout << L"Hello world" << endl; 113 //#endif 114 //} 115 116 #endif 117