]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc
1 // 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t
3 // Copyright (C) 1997-2014 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::wstring
str_01(L
"mykonos. . . or what?");
24 std::wstringbuf
strb_01(str_01
);
26 // test overloaded virtual functions
29 bool test
__attribute__((unused
)) = true;
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
;
37 int_type c1
= strb_01
.sbumpc();
40 // BUFFER MANAGEMENT & POSITIONING
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));
49 strb_01
.str(str_01
); //in|out ("mykonos. . . or what?");
53 pt_1
= strb_01
.pubseekoff(2, std::ios_base::beg
);
54 off_1
= off_type(pt_1
);
56 c1
= strb_01
.snextc(); //current in pointer +1
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
);
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
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
);
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
84 c2
= strb_01
.sungetc();
85 strmsz_2
= strb_01
.in_avail(); // 1
88 VERIFY( strmsz_2
!= strmsz_1
);
89 VERIFY( strmsz_2
== 1 );
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
);
95 str_tmp
= strb_01
.str();
96 VERIFY(static_cast<std::streamsize
>(str_tmp
.size()) == strmsz_1
+ strmsz_2
+ 1);