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/] [sputn/] [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 test01()
92
{
93
  typedef testbuf::traits_type traits_type;
94
  typedef testbuf::int_type int_type;
95
 
96
  bool test __attribute__((unused)) = true;
97
  testbuf buf01;
98
 
99
  // sputn/xsputn
100
  char lit02[] = "isotope 217: the unstable molecule on thrill jockey";
101
  const int i02 = std::strlen(lit02);
102
 
103
  char carray[i02 + 1];
104
  std::memset(carray, 0, i02 + 1);
105
 
106
  buf01.pub_setp(carray, (carray + i02));
107
  buf01.sputn(lit02, 0);
108
  VERIFY( carray[0] == 0 );
109
  VERIFY( lit02[0] == 'i' );
110
  buf01.sputn(lit02, 1);
111
  VERIFY( lit02[0] == carray[0] );
112
  VERIFY( lit02[1] == 's' );
113
  VERIFY( carray[1] == 0 );
114
  buf01.sputn(lit02 + 1, 10);
115
  VERIFY( std::memcmp(lit02, carray, 10) == 0 );
116
  buf01.sputn(lit02 + 11, 20);
117
  VERIFY( std::memcmp(lit02, carray, 30) == 0 );
118
}
119
 
120
int main()
121
{
122
  test01();
123
  return 0;
124
}

powered by: WebSVN 2.1.0

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