]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_stringbuf / sputbackc / char / 1.cc
CommitLineData
23cac885
BK
1// 981208 bkoz test functionality of basic_stringbuf for char_type == char
2
8d9254fc 3// Copyright (C) 1997-2020 Free Software Foundation, Inc.
23cac885
BK
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)
23cac885
BK
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/>.
23cac885
BK
19
20#include <sstream>
21#include <testsuite_hooks.h>
22
23std::string str_01("mykonos. . . or what?");
24std::string str_02("paris, or sainte-maxime?");
25std::string str_03;
26std::stringbuf strb_01(str_01);
27std::stringbuf strb_02(str_02, std::ios_base::in);
28std::stringbuf strb_03(str_03, std::ios_base::out);
29
30// test overloaded virtual functions
31void test04()
32{
23cac885 33 std::string str_tmp, str_tmp2;
23cac885
BK
34 typedef std::stringbuf::int_type int_type;
35 typedef std::stringbuf::traits_type traits_type;
23cac885
BK
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();
23cac885
BK
41
42 // PUT
43 strb_03.str(str_01); //reset
567d4027
PC
44 strb_03.str().length();
45 strb_03.str().length();
23cac885
BK
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("racadabras", 10);//"abracadabras or what?"
53 strb_03.str().length();
54 strb_03.sputn(", i wanna reach out and", 10);
55 strb_03.str().length();
23cac885 56 str_tmp = strb_02.str();
567d4027 57 strb_02.sputn("racadabra", 10);
23cac885
BK
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();
23cac885
BK
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 str_tmp2 = strb_01.str();
70 VERIFY( c1 != c2 );
71 VERIFY( c3 == c2 );
72 VERIFY( str_tmp2 == std::string("mzkonos. . . or what?") );
73 VERIFY( str_tmp.size() == str_tmp2.size() );
74 //test for _in_cur == _in_beg
75 strb_01.str(str_tmp);
567d4027 76 strb_01.in_avail();
23cac885
BK
77 c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
78 c2 = strb_01.sputbackc('z');//"mykonos. . . or what?"
79 c3 = strb_01.sgetc();
80 VERIFY( c1 != c2 );
81 VERIFY( c3 != c2 );
82 VERIFY( c1 == c3 );
83 VERIFY( c2 == traits_type::eof() );
84 VERIFY( strb_01.str() == str_tmp );
85 VERIFY( str_tmp.size() == strb_01.str().size() );
86 // test for replacing char with identical one
87 strb_01.str(str_01); //reset
567d4027 88 strb_01.in_avail();
23cac885
BK
89 strb_01.sbumpc();
90 strb_01.sbumpc();
91 c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
92 c2 = strb_01.sputbackc('y');//"mykonos. . . or what?"
93 c3 = strb_01.sgetc();
94 VERIFY( c1 != c2 );
95 VERIFY( c3 == c2 );
96 VERIFY( c1 != c3 );
97 VERIFY( strb_01.str() == str_01 );
98 VERIFY( str_01.size() == strb_01.str().size() );
99 //test for ios_base::out
567d4027 100 strb_03.in_avail();
23cac885
BK
101 c4 = strb_03.sputbackc('x');
102 VERIFY( c4 == traits_type::eof() );
103}
104
105int main()
106{
107 test04();
108 return 0;
109}
110
111
112
113// more candy!!!