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