Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libstdc++-v3 / testsuite / 27_io / basic_streambuf / sputn / wchar_t / 1.cc
1 // 1999-10-11 bkoz
2
3 // Copyright (C) 1999-2013 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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
17 // with this library; see the file COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19
20
21 // 27.5.2 template class basic_streambuf
22
23 #include <streambuf>
24 #include <cwchar>
25 #include <cstring>
26 #include <testsuite_hooks.h>
27
28 class testbuf : public std::wstreambuf
29 {
30 public:
31
32   // Typedefs:
33   typedef std::wstreambuf::traits_type traits_type;
34   typedef std::wstreambuf::char_type char_type;
35
36   testbuf(): std::wstreambuf() 
37   { }
38
39   bool
40   check_pointers()
41   { 
42     bool test __attribute__((unused)) = true;
43     VERIFY( !this->eback() );
44     VERIFY( !this->gptr() );
45     VERIFY( !this->egptr() );
46     VERIFY( !this->pbase() );
47     VERIFY( !this->pptr() );
48     VERIFY( !this->epptr() );
49     return test;
50   }
51
52   int_type 
53   pub_uflow() 
54   { return (this->uflow()); }
55
56   int_type 
57   pub_overflow(int_type __c = traits_type::eof()) 
58   { return (this->overflow(__c)); }
59
60   int_type 
61   pub_pbackfail(int_type __c) 
62   { return (this->pbackfail(__c)); }
63
64   void 
65   pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) 
66   { this->setg(beg, cur, end); }
67
68   void 
69   pub_setp(wchar_t* beg, wchar_t* end)
70   { this->setp(beg, end); }
71
72 protected:
73   int_type 
74   underflow() 
75   { 
76     int_type __retval = traits_type::eof();
77     if (this->gptr() < this->egptr())
78       __retval = traits_type::not_eof(0); 
79     return __retval;
80   }
81 };
82
83 void test01()
84 {
85   typedef testbuf::traits_type traits_type;
86   typedef testbuf::int_type int_type;
87
88   bool test __attribute__((unused)) = true;
89   testbuf buf01;
90
91   // sputn/xsputn
92   wchar_t lit02[] = L"isotope 217: the unstable molecule on thrill jockey";
93   const int i02 = std::wcslen(lit02);
94
95   wchar_t carray[i02 + 1];
96   std::wmemset(carray, 0, i02 + 1);
97
98   buf01.pub_setp(carray, (carray + i02));
99   buf01.sputn(lit02, 0);
100   VERIFY( carray[0] == 0 );
101   VERIFY( lit02[0] == L'i' );
102   buf01.sputn(lit02, 1);
103   VERIFY( lit02[0] == carray[0] );
104   VERIFY( lit02[1] == L's' );
105   VERIFY( carray[1] == 0 );
106   buf01.sputn(lit02 + 1, 10);
107   VERIFY( std::memcmp(lit02, carray, 10) == 0 );
108   buf01.sputn(lit02 + 11, 20);
109   VERIFY( std::memcmp(lit02, carray, 30) == 0 );
110 }
111
112 int main() 
113 {
114   test01();
115   return 0;
116 }