]>
Commit | Line | Data |
---|---|---|
23cac885 BK |
1 | // 981208 bkoz test functionality of basic_stringbuf for char_type == char |
2 | ||
748086b7 | 3 | // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 |
23cac885 BK |
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 | |
748086b7 | 9 | // Free Software Foundation; either version 3, or (at your option) |
23cac885 BK |
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 | |
748086b7 JJ |
18 | // with this library; see the file COPYING3. If not see |
19 | // <http://www.gnu.org/licenses/>. | |
23cac885 BK |
20 | |
21 | #include <sstream> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | std::string str_01("mykonos. . . or what?"); | |
23cac885 | 25 | std::stringbuf strb_01(str_01); |
23cac885 BK |
26 | |
27 | // test overloaded virtual functions | |
28 | void test04() | |
29 | { | |
11f10e6b | 30 | bool test __attribute__((unused)) = true; |
23cac885 | 31 | std::string str_tmp; |
23cac885 | 32 | std::streamsize strmsz_1, strmsz_2; |
23cac885 BK |
33 | typedef std::stringbuf::int_type int_type; |
34 | typedef std::stringbuf::traits_type traits_type; | |
35 | typedef std::stringbuf::pos_type pos_type; | |
36 | typedef std::stringbuf::off_type off_type; | |
37 | ||
38 | int_type c1 = strb_01.sbumpc(); | |
0a162bde | 39 | int_type c2, c3; |
23cac885 | 40 | |
23cac885 BK |
41 | // BUFFER MANAGEMENT & POSITIONING |
42 | ||
43 | // seekoff | |
44 | // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) | |
45 | // alters the stream position to off | |
46 | pos_type pt_1(off_type(-1)); | |
47 | pos_type pt_2(off_type(0)); | |
48 | off_type off_1 = 0; | |
49 | off_type off_2 = 0; | |
50 | strb_01.str(str_01); //in|out ("mykonos. . . or what?"); | |
0a162bde | 51 | |
23cac885 BK |
52 | //IN|OUT |
53 | //beg | |
54 | pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); | |
4c4809c1 | 55 | off_1 = off_type(pt_1); |
23cac885 BK |
56 | VERIFY( off_1 >= 0 ); |
57 | c1 = strb_01.snextc(); //current in pointer +1 | |
58 | VERIFY( c1 == 'o' ); | |
59 | c2 = strb_01.sputc('x'); //test current out pointer | |
60 | str_tmp = std::string("myxonos. . . or what?"); | |
61 | VERIFY( strb_01.str() == str_tmp ); | |
62 | //cur | |
63 | pt_1 = strb_01.pubseekoff(2, std::ios_base::cur); | |
4c4809c1 | 64 | off_1 = off_type(pt_1); |
23cac885 BK |
65 | VERIFY( off_1 == -1 ); // can't seekoff for in and out + cur in sstreams |
66 | pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); | |
4c4809c1 | 67 | off_1 = off_type(pt_1); |
23cac885 | 68 | pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); |
4c4809c1 | 69 | off_2 = off_type(pt_2); |
23cac885 BK |
70 | VERIFY( off_2 == off_1 + 2 ); |
71 | c1 = strb_01.snextc(); //current in pointer + 1 | |
72 | VERIFY( c1 == ' ' ); | |
73 | c2 = strb_01.sputc('x'); //test current out pointer | |
74 | str_tmp = std::string("myxxnos. . . or what?"); | |
75 | VERIFY( strb_01.str() == str_tmp ); | |
76 | //end | |
77 | pt_2 = strb_01.pubseekoff(2, std::ios_base::end); | |
4c4809c1 | 78 | off_1 = off_type(pt_2); |
23cac885 BK |
79 | VERIFY( off_1 == -1 ); // not a valid position |
80 | VERIFY( strb_01.str() == str_tmp ); | |
81 | // end part two (from the filebuf tests) | |
82 | strb_01.pubseekoff(0, std::ios_base::end); | |
83 | strmsz_1 = strb_01.in_avail(); // 0 cuz at the end | |
84 | c1 = strb_01.sgetc(); | |
85 | c2 = strb_01.sungetc(); | |
86 | strmsz_2 = strb_01.in_avail(); // 1 | |
87 | c3 = strb_01.sgetc(); | |
88 | VERIFY( c1 != c2 ); | |
89 | VERIFY( strmsz_2 != strmsz_1 ); | |
90 | VERIFY( strmsz_2 == 1 ); | |
91 | // end part three | |
92 | strmsz_1 = strb_01.str().size(); | |
93 | strmsz_2 = strb_01.sputn(" ravi shankar meets carlos santana in LoHa", 90); | |
94 | strb_01.pubseekoff(0, std::ios_base::end); | |
95 | strb_01.sputc('<'); | |
96 | str_tmp = strb_01.str(); | |
11f10e6b | 97 | VERIFY(static_cast<std::streamsize>(str_tmp.size()) == strmsz_1 + strmsz_2 + 1); |
23cac885 BK |
98 | // IN |
99 | // OUT | |
100 | } | |
101 | ||
102 | int main() | |
103 | { | |
104 | test04(); | |
105 | return 0; | |
106 | } | |
107 | ||
108 | ||
109 | ||
110 | // more candy!!! |