]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_stringbuf / sungetc / wchar_t / 1.cc
CommitLineData
1bf4ab23
PC
1// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t
2
8d9254fc 3// Copyright (C) 1997-2020 Free Software Foundation, Inc.
1bf4ab23
PC
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
1bf4ab23
PC
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
1bf4ab23
PC
19
20#include <sstream>
21#include <testsuite_hooks.h>
22
23std::wstring str_01(L"mykonos. . . or what?");
24std::wstring str_02(L"paris, or sainte-maxime?");
25std::wstring str_03;
26std::wstringbuf strb_01(str_01);
27std::wstringbuf strb_02(str_02, std::ios_base::in);
28std::wstringbuf strb_03(str_03, std::ios_base::out);
29
30// test overloaded virtual functions
31void test04()
32{
1bf4ab23 33 std::wstring str_tmp;
1bf4ab23
PC
34 typedef std::wstringbuf::int_type int_type;
35 typedef std::wstringbuf::traits_type traits_type;
1bf4ab23
PC
36
37 int_type c1 = strb_01.sbumpc();
38 int_type c2 = strb_02.sbumpc();
39 int_type c3 = strb_01.sbumpc();
40 int_type c4 = strb_02.sbumpc();
41
42 // PUT
43 strb_03.str(str_01); //reset
567d4027
PC
44 strb_03.str().length();
45 strb_03.str().length();
1bf4ab23
PC
46
47 // streamsize sputn(const char_typs* s, streamsize n)
48 // write up to n chars to out_cur from s, returning number assigned
49 // NB *sputn will happily put '\0' into your stream if you give it a chance*
50 str_tmp = strb_03.str();
567d4027
PC
51 str_tmp.length();
52 strb_03.sputn(L"racadabras", 10);//"abracadabras or what?"
53 strb_03.str().length();
54 strb_03.sputn(L", i wanna reach out and", 10);
55 strb_03.str().length();
1bf4ab23 56 str_tmp = strb_02.str();
567d4027 57 strb_02.sputn(L"racadabra", 10);
1bf4ab23
PC
58
59 // PUTBACK
60
61 // int_type sputbackc(char_type c)
62 // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
63 // otherwise decrements in_cur and returns *gptr()
567d4027 64 strb_01.in_avail();
1bf4ab23
PC
65 str_tmp = strb_01.str();
66 c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
67 c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?"
68 c3 = strb_01.sgetc();
69 //test for _in_cur == _in_beg
70 strb_01.str(str_tmp);
567d4027 71 strb_01.in_avail();
1bf4ab23
PC
72 c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
73 c2 = strb_01.sputbackc(L'z');//"mykonos. . . or what?"
74 c3 = strb_01.sgetc();
75 // test for replacing char with identical one
76 strb_01.str(str_01); //reset
567d4027 77 strb_01.in_avail();
1bf4ab23
PC
78 strb_01.sbumpc();
79 strb_01.sbumpc();
80 c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
81 c2 = strb_01.sputbackc(L'y');//"mykonos. . . or what?"
82 c3 = strb_01.sgetc();
83 //test for ios_base::out
567d4027 84 strb_03.in_avail();
1bf4ab23
PC
85 c4 = strb_03.sputbackc(L'x');
86
87 // int_type sungetc()
88 // if in_cur not avail, return pbackfail(), else decrement and
89 // return to_int_type(*gptr())
90 for (int i = 0; i<12; ++i)
91 strb_01.sbumpc();
567d4027 92 strb_01.in_avail();
1bf4ab23
PC
93 str_tmp = strb_01.str();
94 c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
95 c2 = strb_01.sungetc();//"mykonos. . . or what?"
96 c3 = strb_01.sgetc();
97 VERIFY( c1 != c2 );
98 VERIFY( c3 == c2 );
99 VERIFY( c1 != c3 );
100 VERIFY( c2 == L' ' );
101 VERIFY( strb_01.str() == str_01 );
102 VERIFY( str_01.size() == strb_01.str().size() );
103 //test for _in_cur == _in_beg
104 strb_01.str(str_tmp);
567d4027 105 strb_01.in_avail();
1bf4ab23
PC
106 c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
107 c2 = strb_01.sungetc();//"mykonos. . . or what?"
108 c3 = strb_01.sgetc();
109 VERIFY( c1 != c2 );
110 VERIFY( c3 != c2 );
111 VERIFY( c1 == c3 );
112 VERIFY( c2 == traits_type::eof() );
113 VERIFY( strb_01.str() == str_01 );
114 VERIFY( str_01.size() == strb_01.str().size() );
115 // test for replacing char with identical one
116 strb_01.str(str_01); //reset
567d4027 117 strb_01.in_avail();
1bf4ab23
PC
118 strb_01.sbumpc();
119 strb_01.sbumpc();
120 c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
121 c2 = strb_01.sungetc();//"mykonos. . . or what?"
122 c3 = strb_01.sgetc();
123 VERIFY( c1 != c2 );
124 VERIFY( c3 == c2 );
125 VERIFY( c1 != c3 );
126 VERIFY( strb_01.str() == str_01 );
127 VERIFY( str_01.size() == strb_01.str().size() );
128 //test for ios_base::out
567d4027 129 strb_03.in_avail();
1bf4ab23
PC
130 c4 = strb_03.sungetc();
131 VERIFY( c4 == traits_type::eof() );
132}
133
134int main()
135{
136 test04();
137 return 0;
138}
139
140
141
142// more candy!!!