1 // 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010
4 // Free Software Foundation, Inc.
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)
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 COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #include <testsuite_hooks.h>
24 std::wstring str_01(L"mykonos. . . or what?");
25 std::wstringbuf strb_01(str_01);
27 // test overloaded virtual functions
30 bool test __attribute__((unused)) = true;
32 std::streamsize strmsz_1, strmsz_2;
33 typedef std::wstringbuf::int_type int_type;
34 typedef std::wstringbuf::traits_type traits_type;
35 typedef std::wstringbuf::pos_type pos_type;
36 typedef std::wstringbuf::off_type off_type;
38 int_type c1 = strb_01.sbumpc();
41 // BUFFER MANAGEMENT & POSITIONING
44 // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
45 // alters the stream position to off
46 pos_type pt_1(off_type(-1));
47 pos_type pt_2(off_type(0));
50 strb_01.str(str_01); //in|out ("mykonos. . . or what?");
54 pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
55 off_1 = off_type(pt_1);
57 c1 = strb_01.snextc(); //current in pointer +1
59 c2 = strb_01.sputc(L'x'); //test current out pointer
60 str_tmp = std::wstring(L"myxonos. . . or what?");
61 VERIFY( strb_01.str() == str_tmp );
63 pt_1 = strb_01.pubseekoff(2, std::ios_base::cur);
64 off_1 = off_type(pt_1);
65 VERIFY( off_1 == -1 ); // can't seekoff for in and out + cur in sstreams
66 pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
67 off_1 = off_type(pt_1);
68 pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
69 off_2 = off_type(pt_2);
70 VERIFY( off_2 == off_1 + 2 );
71 c1 = strb_01.snextc(); //current in pointer + 1
73 c2 = strb_01.sputc(L'x'); //test current out pointer
74 str_tmp = std::wstring(L"myxxnos. . . or what?");
75 VERIFY( strb_01.str() == str_tmp );
77 pt_2 = strb_01.pubseekoff(2, std::ios_base::end);
78 off_1 = off_type(pt_2);
79 VERIFY( off_1 == -1 ); // not a valid position
80 VERIFY( strb_01.str() == str_tmp );
81 // end part two (from the filebuf tests)
82 strb_01.pubseekoff(0, std::ios_base::end);
83 strmsz_1 = strb_01.in_avail(); // 0 cuz at the end
85 c2 = strb_01.sungetc();
86 strmsz_2 = strb_01.in_avail(); // 1
89 VERIFY( strmsz_2 != strmsz_1 );
90 VERIFY( strmsz_2 == 1 );
92 strmsz_1 = strb_01.str().size();
93 strmsz_2 = strb_01.sputn(L" ravi shankar meets carlos santana in LoHa", 90);
94 strb_01.pubseekoff(0, std::ios_base::end);
96 str_tmp = strb_01.str();
97 VERIFY(static_cast<std::streamsize>(str_tmp.size()) == strmsz_1 + strmsz_2 + 1);