2010-06-03 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / libstdc++-v3 / testsuite / 27_io / basic_streambuf / sgetn / wchar_t / 1.cc
blob66b4af5d3e663de47d03163d7d2e6080a994af86
1 // 1999-10-11 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009, 2010
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.
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.
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/>.
22 // 27.5.2 template class basic_streambuf
24 #include <streambuf>
25 #include <cwchar>
26 #include <testsuite_hooks.h>
28 class testbuf : public std::wstreambuf
30 public:
32 // Typedefs:
33 typedef std::wstreambuf::traits_type traits_type;
34 typedef std::wstreambuf::char_type char_type;
36 testbuf(): std::wstreambuf()
37 { }
39 bool
40 check_pointers()
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;
52 int_type
53 pub_uflow()
54 { return (this->uflow()); }
56 int_type
57 pub_overflow(int_type __c = traits_type::eof())
58 { return (this->overflow(__c)); }
60 int_type
61 pub_pbackfail(int_type __c)
62 { return (this->pbackfail(__c)); }
64 void
65 pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end)
66 { this->setg(beg, cur, end); }
68 void
69 pub_setp(wchar_t* beg, wchar_t* end)
70 { this->setp(beg, end); }
72 protected:
73 int_type
74 underflow()
76 int_type __retval = traits_type::eof();
77 if (this->gptr() < this->egptr())
78 __retval = traits_type::not_eof(0);
79 return __retval;
83 void test02()
85 typedef testbuf::traits_type traits_type;
86 typedef testbuf::int_type int_type;
88 bool test __attribute__((unused)) = true;
90 wchar_t lit01[] = L"chicago underground trio/possible cube on delmark";
91 size_t i01 = traits_type::length(lit01);
93 testbuf buf01;
95 // 27.5.2.1 basic_streambuf ctors
96 // default ctor initializes
97 // - all pointer members to null pointers
98 // - locale to current global locale
99 VERIFY( buf01.check_pointers() );
100 VERIFY( buf01.getloc() == std::locale() );
102 // 27.5.2.2.5 Put area
104 wchar_t carray01[i01];
105 std::wmemset(carray01, 0, i01);
107 buf01.pub_setg(lit01, lit01, lit01 + i01);
108 buf01.sgetn(carray01, 0);
109 VERIFY( carray01[0] == 0 );
110 buf01.sgetn(carray01, 1);
111 VERIFY( carray01[0] == L'c' );
112 buf01.sgetn(carray01 + 1, i01 - 1);
113 VERIFY( carray01[0] == L'c' );
114 VERIFY( carray01[1] == L'h' );
115 VERIFY( carray01[i01 - 1] == L'k' );
118 int main()
120 test02();
121 return 0;