]>
Commit | Line | Data |
---|---|---|
a2febbfb | 1 | // 981208 bkoz test functionality of basic_stringbuf for char_type == char |
2 | ||
f1717362 | 3 | // Copyright (C) 1997-2016 Free Software Foundation, Inc. |
a2febbfb | 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 | |
6bc9506f | 8 | // Free Software Foundation; either version 3, or (at your option) |
a2febbfb | 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 | |
6bc9506f | 17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
a2febbfb | 19 | |
20 | #include <sstream> | |
21 | #include <testsuite_hooks.h> | |
22 | ||
23 | std::string str_01("mykonos. . . or what?"); | |
24 | std::string str_02("paris, or sainte-maxime?"); | |
25 | std::string str_03; | |
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); | |
29 | ||
30 | // test overloaded virtual functions | |
31 | void test04() | |
32 | { | |
f8ef786c | 33 | bool test __attribute__((unused)) = true; |
a2febbfb | 34 | std::string str_tmp; |
a2febbfb | 35 | typedef std::stringbuf::int_type int_type; |
36 | typedef std::stringbuf::traits_type traits_type; | |
a2febbfb | 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(); | |
a2febbfb | 42 | |
43 | // PUT | |
44 | strb_03.str(str_01); //reset | |
1c78c762 | 45 | strb_03.str().length(); |
46 | strb_03.str().length(); | |
a2febbfb | 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(); | |
1c78c762 | 52 | str_tmp.length(); |
53 | strb_03.sputn("racadabras", 10);//"abracadabras or what?" | |
54 | strb_03.str().length(); | |
55 | strb_03.sputn(", i wanna reach out and", 10); | |
56 | strb_03.str().length(); | |
a2febbfb | 57 | str_tmp = strb_02.str(); |
1c78c762 | 58 | strb_02.sputn("racadabra", 10); |
a2febbfb | 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() | |
1c78c762 | 65 | strb_01.in_avail(); |
a2febbfb | 66 | str_tmp = strb_01.str(); |
67 | c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" | |
68 | c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?" | |
69 | c3 = strb_01.sgetc(); | |
70 | //test for _in_cur == _in_beg | |
71 | strb_01.str(str_tmp); | |
1c78c762 | 72 | strb_01.in_avail(); |
a2febbfb | 73 | c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" |
74 | c2 = strb_01.sputbackc('z');//"mykonos. . . or what?" | |
75 | c3 = strb_01.sgetc(); | |
76 | // test for replacing char with identical one | |
77 | strb_01.str(str_01); //reset | |
1c78c762 | 78 | strb_01.in_avail(); |
a2febbfb | 79 | strb_01.sbumpc(); |
80 | strb_01.sbumpc(); | |
81 | c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" | |
82 | c2 = strb_01.sputbackc('y');//"mykonos. . . or what?" | |
83 | c3 = strb_01.sgetc(); | |
84 | //test for ios_base::out | |
1c78c762 | 85 | strb_03.in_avail(); |
a2febbfb | 86 | c4 = strb_03.sputbackc('x'); |
87 | ||
88 | // int_type sungetc() | |
89 | // if in_cur not avail, return pbackfail(), else decrement and | |
90 | // return to_int_type(*gptr()) | |
91 | for (int i = 0; i<12; ++i) | |
92 | strb_01.sbumpc(); | |
1c78c762 | 93 | strb_01.in_avail(); |
a2febbfb | 94 | str_tmp = strb_01.str(); |
95 | c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" | |
96 | c2 = strb_01.sungetc();//"mykonos. . . or what?" | |
97 | c3 = strb_01.sgetc(); | |
98 | VERIFY( c1 != c2 ); | |
99 | VERIFY( c3 == c2 ); | |
100 | VERIFY( c1 != c3 ); | |
101 | VERIFY( c2 == ' ' ); | |
102 | VERIFY( strb_01.str() == str_01 ); | |
103 | VERIFY( str_01.size() == strb_01.str().size() ); | |
104 | //test for _in_cur == _in_beg | |
105 | strb_01.str(str_tmp); | |
1c78c762 | 106 | strb_01.in_avail(); |
a2febbfb | 107 | c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" |
108 | c2 = strb_01.sungetc();//"mykonos. . . or what?" | |
109 | c3 = strb_01.sgetc(); | |
110 | VERIFY( c1 != c2 ); | |
111 | VERIFY( c3 != c2 ); | |
112 | VERIFY( c1 == c3 ); | |
113 | VERIFY( c2 == traits_type::eof() ); | |
114 | VERIFY( strb_01.str() == str_01 ); | |
115 | VERIFY( str_01.size() == strb_01.str().size() ); | |
116 | // test for replacing char with identical one | |
117 | strb_01.str(str_01); //reset | |
1c78c762 | 118 | strb_01.in_avail(); |
a2febbfb | 119 | strb_01.sbumpc(); |
120 | strb_01.sbumpc(); | |
121 | c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" | |
122 | c2 = strb_01.sungetc();//"mykonos. . . or what?" | |
123 | c3 = strb_01.sgetc(); | |
124 | VERIFY( c1 != c2 ); | |
125 | VERIFY( c3 == c2 ); | |
126 | VERIFY( c1 != c3 ); | |
127 | VERIFY( strb_01.str() == str_01 ); | |
128 | VERIFY( str_01.size() == strb_01.str().size() ); | |
129 | //test for ios_base::out | |
1c78c762 | 130 | strb_03.in_avail(); |
a2febbfb | 131 | c4 = strb_03.sungetc(); |
132 | VERIFY( c4 == traits_type::eof() ); | |
133 | } | |
134 | ||
135 | int main() | |
136 | { | |
137 | test04(); | |
138 | return 0; | |
139 | } | |
140 | ||
141 | ||
142 | ||
143 | // more candy!!! |