1 // 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t
2 
3 // Copyright (C) 1997-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19 
20 #include <sstream>
21 #include <testsuite_hooks.h>
22 
23 std::wstring str_01(L"mykonos. . . or what?");
24 std::wstring str_02(L"paris, or sainte-maxime?");
25 std::wstring str_03;
26 std::wstringbuf strb_01(str_01);
27 std::wstringbuf strb_02(str_02, std::ios_base::in);
28 std::wstringbuf strb_03(str_03, std::ios_base::out);
29 
30 // test overloaded virtual functions
test04()31 void test04()
32 {
33   bool test __attribute__((unused)) = true;
34   std::wstring 		str_tmp, str_tmp2;
35   typedef std::wstringbuf::int_type int_type;
36   typedef std::wstringbuf::traits_type traits_type;
37 
38   int_type c1 = strb_01.sbumpc();
39   int_type c2 = strb_02.sbumpc();
40   int_type c3 = strb_01.sbumpc();
41   int_type c4 = strb_02.sbumpc();
42 
43   // PUT
44   strb_03.str(str_01); //reset
45   strb_03.str().length();
46   strb_03.str().length();
47 
48   // streamsize sputn(const char_typs* s, streamsize n)
49   // write up to n chars to out_cur from s, returning number assigned
50   // NB *sputn will happily put '\0' into your stream if you give it a chance*
51   str_tmp = strb_03.str();
52   str_tmp.length();
53   strb_03.sputn(L"racadabras", 10);//"abracadabras or what?"
54   strb_03.str().length();
55   strb_03.sputn(L", i wanna reach out and", 10);
56   strb_03.str().length();
57   str_tmp = strb_02.str();
58   strb_02.sputn(L"racadabra", 10);
59 
60   // PUTBACK
61 
62   // int_type sputbackc(char_type c)
63   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
64   // otherwise decrements in_cur and returns *gptr()
65   strb_01.in_avail();
66   str_tmp = strb_01.str();
67   c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
68   c2 = strb_01.sputbackc(L'z');//"mykonos. . .zor what?"
69   c3 = strb_01.sgetc();
70   str_tmp2 = strb_01.str();
71   VERIFY( c1 != c2 );
72   VERIFY( c3 == c2 );
73   VERIFY( str_tmp2 == std::wstring(L"mzkonos. . . or what?") );
74   VERIFY( str_tmp.size() == str_tmp2.size() );
75   //test for _in_cur == _in_beg
76   strb_01.str(str_tmp);
77   strb_01.in_avail();
78   c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
79   c2 = strb_01.sputbackc(L'z');//"mykonos. . . or what?"
80   c3 = strb_01.sgetc();
81   VERIFY( c1 != c2 );
82   VERIFY( c3 != c2 );
83   VERIFY( c1 == c3 );
84   VERIFY( c2 == traits_type::eof() );
85   VERIFY( strb_01.str() == str_tmp );
86   VERIFY( str_tmp.size() == strb_01.str().size() );
87   // test for replacing char with identical one
88   strb_01.str(str_01); //reset
89   strb_01.in_avail();
90   strb_01.sbumpc();
91   strb_01.sbumpc();
92   c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
93   c2 = strb_01.sputbackc(L'y');//"mykonos. . . or what?"
94   c3 = strb_01.sgetc();
95   VERIFY( c1 != c2 );
96   VERIFY( c3 == c2 );
97   VERIFY( c1 != c3 );
98   VERIFY( strb_01.str() == str_01 );
99   VERIFY( str_01.size() == strb_01.str().size() );
100   //test for ios_base::out
101   strb_03.in_avail();
102   c4 = strb_03.sputbackc(L'x');
103   VERIFY( c4 == traits_type::eof() );
104 }
105 
main()106 int main()
107 {
108   test04();
109   return 0;
110 }
111 
112 
113 
114 // more candy!!!
115