OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_streambuf/] [sgetn/] [char/] [1.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 1999-10-11 bkoz
2
 
3
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
// USA.
21
 
22
// As a special exception, you may use this file as part of a free software
23
// library without restriction.  Specifically, if other files instantiate
24
// templates or use macros or inline functions from this file, or you compile
25
// this file and link it with other files to produce an executable, this
26
// file does not by itself cause the resulting executable to be covered by
27
// the GNU General Public License.  This exception does not however
28
// invalidate any other reasons why the executable file might be covered by
29
// the GNU General Public License.
30
 
31
// 27.5.2 template class basic_streambuf
32
 
33
#include <streambuf>
34
#include <testsuite_hooks.h>
35
 
36
class testbuf : public std::streambuf
37
{
38
public:
39
 
40
  // Typedefs:
41
  typedef std::streambuf::traits_type traits_type;
42
  typedef std::streambuf::char_type char_type;
43
 
44
  testbuf(): std::streambuf()
45
  { }
46
 
47
  bool
48
  check_pointers()
49
  {
50
    bool test __attribute__((unused)) = true;
51
    VERIFY( this->eback() == NULL );
52
    VERIFY( this->gptr() == NULL );
53
    VERIFY( this->egptr() == NULL );
54
    VERIFY( this->pbase() == NULL );
55
    VERIFY( this->pptr() == NULL );
56
    VERIFY( this->epptr() == NULL );
57
    return test;
58
  }
59
 
60
  int_type
61
  pub_uflow()
62
  { return (this->uflow()); }
63
 
64
  int_type
65
  pub_overflow(int_type __c = traits_type::eof())
66
  { return (this->overflow(__c)); }
67
 
68
  int_type
69
  pub_pbackfail(int_type __c)
70
  { return (this->pbackfail(__c)); }
71
 
72
  void
73
  pub_setg(char* beg, char* cur, char *end)
74
  { this->setg(beg, cur, end); }
75
 
76
  void
77
  pub_setp(char* beg, char* end)
78
  { this->setp(beg, end); }
79
 
80
protected:
81
  int_type
82
  underflow()
83
  {
84
    int_type __retval = traits_type::eof();
85
    if (this->gptr() < this->egptr())
86
      __retval = traits_type::not_eof(0);
87
    return __retval;
88
  }
89
};
90
 
91
void test02()
92
{
93
  typedef testbuf::traits_type traits_type;
94
  typedef testbuf::int_type int_type;
95
 
96
  bool test __attribute__((unused)) = true;
97
 
98
  char lit01[] = "chicago underground trio/possible cube on delmark";
99
  size_t i01 = traits_type::length(lit01);
100
 
101
  testbuf buf01;
102
 
103
  // 27.5.2.1 basic_streambuf ctors
104
  // default ctor initializes 
105
  // - all pointer members to null pointers
106
  // - locale to current global locale
107
  VERIFY( buf01.check_pointers() );
108
  VERIFY( buf01.getloc() == std::locale() );
109
 
110
  // 27.5.2.2.5 Put area
111
 
112
  char carray01[i01];
113
  std::memset(carray01, 0, i01);
114
 
115
  buf01.pub_setg(lit01, lit01, lit01 + i01);
116
  buf01.sgetn(carray01, 0);
117
  VERIFY( carray01[0] == 0 );
118
  buf01.sgetn(carray01, 1);
119
  VERIFY( carray01[0] == 'c' );
120
  buf01.sgetn(carray01 + 1, i01 - 1);
121
  VERIFY( carray01[0] == 'c' );
122
  VERIFY( carray01[1] == 'h' );
123
  VERIFY( carray01[i01 - 1] == 'k' );
124
}
125
 
126
int main()
127
{
128
  test02();
129
  return 0;
130
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.