1// 981208 bkoz test functionality of basic_stringbuf for char_type == char 2 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2009 4// Free Software Foundation, Inc. 5// 6// This file is part of the GNU ISO C++ Library. This library is free 7// software; you can redistribute it and/or modify it under the 8// terms of the GNU General Public License as published by the 9// Free Software Foundation; either version 3, or (at your option) 10// any later version. 11 12// This library is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17// You should have received a copy of the GNU General Public License along 18// with this library; see the file COPYING3. If not see 19// <http://www.gnu.org/licenses/>. 20 21#include <sstream> 22#include <testsuite_hooks.h> 23 24std::string str_01("mykonos. . . or what?"); 25std::string str_02("paris, or sainte-maxime?"); 26std::string str_03; 27std::stringbuf strb_01(str_01); 28std::stringbuf strb_02(str_02, std::ios_base::in); 29std::stringbuf strb_03(str_03, std::ios_base::out); 30 31// test member functions 32void test03() 33{ 34 bool test __attribute__((unused)) = true; 35 36 //stringbuf::str() 37 VERIFY( strb_01.str() == str_01 ); 38 VERIFY( strb_02.str() == str_02 ); 39 VERIFY( strb_03.str() == str_03 ); 40 41 //stringbuf::str(string&) 42 strb_03.str("none of the above, go to the oberoi in cairo, egypt."); 43 strb_03.str(str_01); 44 std::streamsize d1 = strb_01.in_avail(); 45 std::streamsize d2 = strb_03.in_avail(); 46 VERIFY( d1 ); // non-zero 47 VERIFY( d2 == -1 ); // -1, cuz ios_base::out 48 VERIFY( d1 != d2 ); //these should be the same 49 VERIFY( static_cast<std::streamsize>(str_01.length()) == d1 ); 50 VERIFY( strb_01.str() == strb_03.str() ); //ditto 51 52 // stringbuf::str(string&) and stringbuf::stringbuf(string&), where the 53 // string in question contains embedded NUL characters. Note that in this 54 // embedded-NUL situation, the size must be passed to the string ctor. 55 std::string str_nulls ("eschew \0 obfuscation", 20); // tested in 21_strings 56 std::stringbuf strb_normal (str_01); 57 std::stringbuf strb_nulls (str_nulls); 58 strb_normal.str(str_nulls); // tried using 'strb_01' rather than declaring 59 // another variable, but then test04 broke! 60 VERIFY( strb_nulls.in_avail() == static_cast<std::streamsize>(str_nulls.size()) ); 61 VERIFY( strb_nulls.str().size() == 20 ); 62 VERIFY( strb_normal.in_avail() == static_cast<std::streamsize>(str_nulls.size()) ); 63} 64 65int main() 66{ 67 test03(); 68 return 0; 69} 70 71 72 73// more candy!!! 74