OSDN Git Service

2004-07-09 Paolo Carlini <pcarlini@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 27_io / basic_stringbuf / sungetc / wchar_t / 1.cc
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
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 2, 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 COPYING.  If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21
22 #include <sstream>
23 #include <testsuite_hooks.h>
24
25 std::wstring str_01(L"mykonos. . . or what?");
26 std::wstring str_02(L"paris, or sainte-maxime?");
27 std::wstring str_03;
28 std::wstringbuf strb_01(str_01);
29 std::wstringbuf strb_02(str_02, std::ios_base::in);
30 std::wstringbuf strb_03(str_03, std::ios_base::out);
31
32 // test overloaded virtual functions
33 void test04() 
34 {
35   bool test __attribute__((unused)) = true;
36   std::wstring          str_tmp;
37   std::wstringbuf               strb_tmp;
38   std::streamsize               strmsz_1, strmsz_2;
39   typedef std::wstringbuf::int_type int_type;
40   typedef std::wstringbuf::traits_type traits_type;
41   typedef std::wstringbuf::pos_type pos_type;
42   typedef std::wstringbuf::off_type off_type;
43
44   int_type c1 = strb_01.sbumpc();
45   int_type c2 = strb_02.sbumpc();
46   int_type c3 = strb_01.sbumpc();
47   int_type c4 = strb_02.sbumpc();
48
49   // PUT
50   strb_03.str(str_01); //reset
51   std::wstring::size_type sz1 = strb_03.str().length();
52   std::wstring::size_type sz2 = strb_03.str().length();
53   
54   // streamsize sputn(const char_typs* s, streamsize n)
55   // write up to n chars to out_cur from s, returning number assigned
56   // NB *sputn will happily put '\0' into your stream if you give it a chance*
57   str_tmp = strb_03.str();
58   sz1 = str_tmp.length();
59   strmsz_1 = strb_03.sputn(L"racadabras", 10);//"abracadabras or what?"
60   sz2 = strb_03.str().length();
61   strmsz_2 = strb_03.sputn(L", i wanna reach out and", 10);
62   sz2 = strb_03.str().length();
63   str_tmp = strb_02.str();
64   strmsz_1 = strb_02.sputn(L"racadabra", 10);
65
66   // PUTBACK
67
68   // int_type sputbackc(char_type c)
69   // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
70   // otherwise decrements in_cur and returns *gptr()
71   strmsz_1 = strb_01.in_avail();
72   str_tmp = strb_01.str();
73   c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
74   c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?"
75   c3 = strb_01.sgetc();
76   //test for _in_cur == _in_beg
77   strb_01.str(str_tmp);
78   strmsz_1 = strb_01.in_avail();
79   c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
80   c2 = strb_01.sputbackc(L'z');//"mykonos. . . or what?"
81   c3 = strb_01.sgetc();
82   // test for replacing char with identical one
83   strb_01.str(str_01); //reset
84   strmsz_1 = strb_01.in_avail();
85   strb_01.sbumpc();
86   strb_01.sbumpc();
87   c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
88   c2 = strb_01.sputbackc(L'y');//"mykonos. . . or what?"
89   c3 = strb_01.sgetc();
90   //test for ios_base::out
91   strmsz_2 = strb_03.in_avail();
92   c4 = strb_03.sputbackc(L'x');
93
94   // int_type sungetc()
95   // if in_cur not avail, return pbackfail(), else decrement and
96   // return to_int_type(*gptr())
97   for (int i = 0; i<12; ++i)
98     strb_01.sbumpc();
99   strmsz_1 = strb_01.in_avail();
100   str_tmp = strb_01.str();
101   c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
102   c2 = strb_01.sungetc();//"mykonos. . . or what?"
103   c3 = strb_01.sgetc();
104   VERIFY( c1 != c2 );
105   VERIFY( c3 == c2 );
106   VERIFY( c1 != c3 );
107   VERIFY( c2 == L' ' );
108   VERIFY( strb_01.str() == str_01 );
109   VERIFY( str_01.size() == strb_01.str().size() );
110   //test for _in_cur == _in_beg
111   strb_01.str(str_tmp);
112   strmsz_1 = strb_01.in_avail();
113   c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
114   c2 = strb_01.sungetc();//"mykonos. . . or what?"
115   c3 = strb_01.sgetc();
116   VERIFY( c1 != c2 );
117   VERIFY( c3 != c2 );
118   VERIFY( c1 == c3 );
119   VERIFY( c2 == traits_type::eof() );
120   VERIFY( strb_01.str() == str_01 );
121   VERIFY( str_01.size() == strb_01.str().size() );
122   // test for replacing char with identical one
123   strb_01.str(str_01); //reset
124   strmsz_1 = strb_01.in_avail();
125   strb_01.sbumpc();
126   strb_01.sbumpc();
127   c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
128   c2 = strb_01.sungetc();//"mykonos. . . or what?"
129   c3 = strb_01.sgetc();
130   VERIFY( c1 != c2 );
131   VERIFY( c3 == c2 );
132   VERIFY( c1 != c3 );
133   VERIFY( strb_01.str() == str_01 );
134   VERIFY( str_01.size() == strb_01.str().size() );
135   //test for ios_base::out
136   strmsz_2 = strb_03.in_avail();
137   c4 = strb_03.sungetc();
138   VERIFY( c4 == traits_type::eof() );
139 }
140
141 int main()
142 {
143   test04();
144   return 0;
145 }
146
147
148
149 // more candy!!!