2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_stringbuf / str / char / 1.cc
blob2f9a5cf176f1c6459642ebbca776d375f5e8ef07
1 // 981208 bkoz test functionality of basic_stringbuf for char_type == char
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
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 2, or (at your option)
10 // any later version.
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.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
22 #include <sstream>
23 #include <testsuite_hooks.h>
25 std::string str_01("mykonos. . . or what?");
26 std::string str_02("paris, or sainte-maxime?");
27 std::string str_03;
28 std::stringbuf strb_01(str_01);
29 std::stringbuf strb_02(str_02, std::ios_base::in);
30 std::stringbuf strb_03(str_03, std::ios_base::out);
32 // test member functions
33 void test03()
35 bool test __attribute__((unused)) = true;
37 //stringbuf::str()
38 VERIFY( strb_01.str() == str_01 );
39 VERIFY( strb_02.str() == str_02 );
40 VERIFY( strb_03.str() == str_03 );
42 //stringbuf::str(string&)
43 strb_03.str("none of the above, go to the oberoi in cairo, egypt.");
44 strb_03.str(str_01);
45 std::streamsize d1 = strb_01.in_avail();
46 std::streamsize d2 = strb_03.in_avail();
47 VERIFY( d1 ); // non-zero
48 VERIFY( !d2 ); // zero, cuz ios_base::out
49 VERIFY( d1 != d2 ); //these should be the same
50 VERIFY( static_cast<std::streamsize>(str_01.length()) == d1 );
51 VERIFY( strb_01.str() == strb_03.str() ); //ditto
53 // stringbuf::str(string&) and stringbuf::stringbuf(string&), where the
54 // string in question contains embedded NUL characters. Note that in this
55 // embedded-NUL situation, the size must be passed to the string ctor.
56 std::string str_nulls ("eschew \0 obfuscation", 20); // tested in 21_strings
57 std::stringbuf strb_normal (str_01);
58 std::stringbuf strb_nulls (str_nulls);
59 strb_normal.str(str_nulls); // tried using 'strb_01' rather than declaring
60 // another variable, but then test04 broke!
61 VERIFY( strb_nulls.in_avail() == static_cast<std::streamsize>(str_nulls.size()) );
62 VERIFY( strb_nulls.str().size() == 20 );
63 VERIFY( strb_normal.in_avail() == static_cast<std::streamsize>(str_nulls.size()) );
66 int main()
68 test03();
69 return 0;
74 // more candy!!!