2010-06-03 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / libstdc++-v3 / testsuite / 27_io / basic_streambuf / sgetn / char / 1.cc
blobd1530b18f3fbca464979cd80034cc4f9ebe222d9
1 // 1999-10-11 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 // 2007, 2009, 2010
5 // Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
23 // 27.5.2 template class basic_streambuf
25 #include <streambuf>
26 #include <cstring>
27 #include <testsuite_hooks.h>
29 class testbuf : public std::streambuf
31 public:
33 // Typedefs:
34 typedef std::streambuf::traits_type traits_type;
35 typedef std::streambuf::char_type char_type;
37 testbuf(): std::streambuf()
38 { }
40 bool
41 check_pointers()
43 bool test __attribute__((unused)) = true;
44 VERIFY( !this->eback() );
45 VERIFY( !this->gptr() );
46 VERIFY( !this->egptr() );
47 VERIFY( !this->pbase() );
48 VERIFY( !this->pptr() );
49 VERIFY( !this->epptr() );
50 return test;
53 int_type
54 pub_uflow()
55 { return (this->uflow()); }
57 int_type
58 pub_overflow(int_type __c = traits_type::eof())
59 { return (this->overflow(__c)); }
61 int_type
62 pub_pbackfail(int_type __c)
63 { return (this->pbackfail(__c)); }
65 void
66 pub_setg(char* beg, char* cur, char *end)
67 { this->setg(beg, cur, end); }
69 void
70 pub_setp(char* beg, char* end)
71 { this->setp(beg, end); }
73 protected:
74 int_type
75 underflow()
77 int_type __retval = traits_type::eof();
78 if (this->gptr() < this->egptr())
79 __retval = traits_type::not_eof(0);
80 return __retval;
84 void test02()
86 typedef testbuf::traits_type traits_type;
87 typedef testbuf::int_type int_type;
89 bool test __attribute__((unused)) = true;
91 char lit01[] = "chicago underground trio/possible cube on delmark";
92 size_t i01 = traits_type::length(lit01);
94 testbuf buf01;
96 // 27.5.2.1 basic_streambuf ctors
97 // default ctor initializes
98 // - all pointer members to null pointers
99 // - locale to current global locale
100 VERIFY( buf01.check_pointers() );
101 VERIFY( buf01.getloc() == std::locale() );
103 // 27.5.2.2.5 Put area
105 char carray01[i01];
106 std::memset(carray01, 0, i01);
108 buf01.pub_setg(lit01, lit01, lit01 + i01);
109 buf01.sgetn(carray01, 0);
110 VERIFY( carray01[0] == 0 );
111 buf01.sgetn(carray01, 1);
112 VERIFY( carray01[0] == 'c' );
113 buf01.sgetn(carray01 + 1, i01 - 1);
114 VERIFY( carray01[0] == 'c' );
115 VERIFY( carray01[1] == 'h' );
116 VERIFY( carray01[i01 - 1] == 'k' );
119 int main()
121 test02();
122 return 0;