1// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t
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
24std::wstring str_01(L"mykonos. . . or what?");
25std::wstringbuf strb_01(str_01);
26
27// test overloaded virtual functions
28void test04()
29{
30  bool test __attribute__((unused)) = true;
31  std::wstring 		str_tmp;
32  std::streamsize 		strmsz_1, strmsz_2;
33  typedef std::wstringbuf::int_type int_type;
34  typedef std::wstringbuf::traits_type traits_type;
35  typedef std::wstringbuf::pos_type pos_type;
36  typedef std::wstringbuf::off_type off_type;
37
38  int_type c1 = strb_01.sbumpc();
39  int_type c2, c3;
40
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?");
51
52  //IN|OUT
53  //beg
54  pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
55  off_1 = off_type(pt_1);
56  VERIFY( off_1 >= 0 );
57  c1 = strb_01.snextc(); //current in pointer +1
58  VERIFY( c1 == L'o' );
59  c2 = strb_01.sputc(L'x');  //test current out pointer
60  str_tmp = std::wstring(L"myxonos. . . or what?");
61  VERIFY( strb_01.str() == str_tmp );
62  //cur
63  pt_1 = strb_01.pubseekoff(2, std::ios_base::cur);
64  off_1 = off_type(pt_1);
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);
67  off_1 = off_type(pt_1);
68  pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
69  off_2 = off_type(pt_2);
70  VERIFY( off_2 == off_1 + 2 );
71  c1 = strb_01.snextc(); //current in pointer + 1
72  VERIFY( c1 == L' ' );
73  c2 = strb_01.sputc(L'x');  //test current out pointer
74  str_tmp = std::wstring(L"myxxnos. . . or what?");
75  VERIFY( strb_01.str() == str_tmp );
76  //end
77  pt_2 = strb_01.pubseekoff(2, std::ios_base::end);
78  off_1 = off_type(pt_2);
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(L" ravi shankar meets carlos santana in LoHa", 90);
94  strb_01.pubseekoff(0, std::ios_base::end);
95  strb_01.sputc(L'<');
96  str_tmp = strb_01.str();
97  VERIFY(static_cast<std::streamsize>(str_tmp.size()) == strmsz_1 + strmsz_2 + 1);
98  // IN
99  // OUT
100}
101
102int main()
103{
104  test04();
105  return 0;
106}
107
108
109
110// more candy!!!
111