1 // 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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 2, 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 COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
23 #include <testsuite_hooks.h>
25 std::wstring str_01(L"mykonos. . . or what?");
26 std::wstring str_02(L"paris, or sainte-maxime?");
28 std::wstringbuf strb_01(str_01);
29 std::wstringbuf strb_02(str_02, std::ios_base::in);
30 std::wstringbuf strb_03(str_03, std::ios_base::out);
32 // test overloaded virtual functions
35 bool test __attribute__((unused)) = true;
37 std::wstringbuf strb_tmp;
38 std::streamsize strmsz_1, strmsz_2;
39 typedef std::wstringbuf::int_type int_type;
40 typedef std::wstringbuf::traits_type traits_type;
41 typedef std::wstringbuf::pos_type pos_type;
42 typedef std::wstringbuf::off_type off_type;
44 int_type c1 = strb_01.sbumpc();
45 int_type c2 = strb_02.sbumpc();
46 int_type c3 = strb_01.sbumpc();
47 int_type c4 = strb_02.sbumpc();
50 strb_03.str(str_01); //reset
51 std::wstring::size_type sz1 = strb_03.str().length();
52 std::wstring::size_type sz2 = strb_03.str().length();
54 // streamsize sputn(const char_typs* s, streamsize n)
55 // write up to n chars to out_cur from s, returning number assigned
56 // NB *sputn will happily put '\0' into your stream if you give it a chance*
57 str_tmp = strb_03.str();
58 sz1 = str_tmp.length();
59 strmsz_1 = strb_03.sputn(L"racadabras", 10);//"abracadabras or what?"
60 sz2 = strb_03.str().length();
61 strmsz_2 = strb_03.sputn(L", i wanna reach out and", 10);
62 sz2 = strb_03.str().length();
63 str_tmp = strb_02.str();
64 strmsz_1 = strb_02.sputn(L"racadabra", 10);
68 // int_type sputbackc(char_type c)
69 // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
70 // otherwise decrements in_cur and returns *gptr()
71 strmsz_1 = strb_01.in_avail();
72 str_tmp = strb_01.str();
73 c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
74 c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?"
76 //test for _in_cur == _in_beg
78 strmsz_1 = strb_01.in_avail();
79 c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
80 c2 = strb_01.sputbackc(L'z');//"mykonos. . . or what?"
82 // test for replacing char with identical one
83 strb_01.str(str_01); //reset
84 strmsz_1 = strb_01.in_avail();
87 c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
88 c2 = strb_01.sputbackc(L'y');//"mykonos. . . or what?"
90 //test for ios_base::out
91 strmsz_2 = strb_03.in_avail();
92 c4 = strb_03.sputbackc(L'x');
95 // if in_cur not avail, return pbackfail(), else decrement and
96 // return to_int_type(*gptr())
97 for (int i = 0; i<12; ++i)
99 strmsz_1 = strb_01.in_avail();
100 str_tmp = strb_01.str();
101 c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
102 c2 = strb_01.sungetc();//"mykonos. . . or what?"
103 c3 = strb_01.sgetc();
107 VERIFY( c2 == L' ' );
108 VERIFY( strb_01.str() == str_01 );
109 VERIFY( str_01.size() == strb_01.str().size() );
110 //test for _in_cur == _in_beg
111 strb_01.str(str_tmp);
112 strmsz_1 = strb_01.in_avail();
113 c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
114 c2 = strb_01.sungetc();//"mykonos. . . or what?"
115 c3 = strb_01.sgetc();
119 VERIFY( c2 == traits_type::eof() );
120 VERIFY( strb_01.str() == str_01 );
121 VERIFY( str_01.size() == strb_01.str().size() );
122 // test for replacing char with identical one
123 strb_01.str(str_01); //reset
124 strmsz_1 = strb_01.in_avail();
127 c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
128 c2 = strb_01.sungetc();//"mykonos. . . or what?"
129 c3 = strb_01.sgetc();
133 VERIFY( strb_01.str() == str_01 );
134 VERIFY( str_01.size() == strb_01.str().size() );
135 //test for ios_base::out
136 strmsz_2 = strb_03.in_avail();
137 c4 = strb_03.sungetc();
138 VERIFY( c4 == traits_type::eof() );