]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc
1 // 981208 bkoz test functionality of basic_stringbuf for char_type == char
3 // Copyright (C) 1997-2019 Free Software Foundation, Inc.
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)
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.
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/>.
21 #include <testsuite_hooks.h>
23 std::string
str_01("mykonos. . . or what?");
24 std::string
str_02("paris, or sainte-maxime?");
26 std::stringbuf
strb_01(str_01
);
27 std::stringbuf
strb_02(str_02
, std::ios_base::in
);
28 std::stringbuf
strb_03(str_03
, std::ios_base::out
);
30 // test overloaded virtual functions
34 typedef std::stringbuf::int_type int_type
;
35 typedef std::stringbuf::traits_type traits_type
;
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();
43 strb_03
.str(str_01
); //reset
44 strb_03
.str().length();
45 strb_03
.str().length();
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();
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();
56 str_tmp
= strb_02
.str();
57 strb_02
.sputn("racadabra", 10);
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()
65 str_tmp
= strb_01
.str();
66 c1
= strb_01
.sgetc(); //"mykonos. . . 'o'r what?"
67 c2
= strb_01
.sputbackc('z');//"mykonos. . .zor what?"
69 //test for _in_cur == _in_beg
72 c1
= strb_01
.sgetc(); //"'m'ykonos. . . or what?"
73 c2
= strb_01
.sputbackc('z');//"mykonos. . . or what?"
75 // test for replacing char with identical one
76 strb_01
.str(str_01
); //reset
80 c1
= strb_01
.sgetc(); //"my'k'onos. . . or what?"
81 c2
= strb_01
.sputbackc('y');//"mykonos. . . or what?"
83 //test for ios_base::out
85 c4
= strb_03
.sputbackc('x');
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
)
93 str_tmp
= strb_01
.str();
94 c1
= strb_01
.sgetc(); //"mykonos. . . 'o'r what?"
95 c2
= strb_01
.sungetc();//"mykonos. . . or what?"
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
);
106 c1
= strb_01
.sgetc(); //"'m'ykonos. . . or what?"
107 c2
= strb_01
.sungetc();//"mykonos. . . or what?"
108 c3
= strb_01
.sgetc();
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
120 c1
= strb_01
.sgetc(); //"my'k'onos. . . or what?"
121 c2
= strb_01
.sungetc();//"mykonos. . . or what?"
122 c3
= strb_01
.sgetc();
126 VERIFY( strb_01
.str() == str_01
);
127 VERIFY( str_01
.size() == strb_01
.str().size() );
128 //test for ios_base::out
130 c4
= strb_03
.sungetc();
131 VERIFY( c4
== traits_type::eof() );