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