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_filebuf/] [seekoff/] [wchar_t/] [11543.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// Copyright (C) 2003
2
// Free Software Foundation, Inc.
3
//
4
// This file is part of the GNU ISO C++ Library.  This library is free
5
// software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the
7
// Free Software Foundation; either version 2, or (at your option)
8
// any later version.
9
 
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
 
15
// You should have received a copy of the GNU General Public License along
16
// with this library; see the file COPYING.  If not, write to the Free
17
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18
// USA.
19
 
20
// 27.8.1.4 Overridden virtual functions
21
 
22
#include <fstream>
23
#include <locale>
24
#include <testsuite_hooks.h>
25
 
26
struct MyState
27
{
28
};
29
 
30
struct MyCharTraits : std::char_traits<wchar_t>
31
{
32
  typedef std::fpos<MyState> pos_type;
33
  typedef MyState state_type;
34
};
35
 
36
namespace std
37
{
38
  template <>
39
    class codecvt<wchar_t, char, MyState> :
40
      public locale::facet, public codecvt_base
41
    {
42
    public:
43
      typedef wchar_t intern_type;
44
      typedef char extern_type;
45
      typedef MyState state_type;
46
 
47
      explicit codecvt(size_t refs = 0)
48
      : locale::facet(refs) { }
49
 
50
      result out(state_type& state, const intern_type* from,
51
                 const intern_type* from_end,  const intern_type*& from_next,
52
                 extern_type* to, extern_type* to_limit,
53
                 extern_type*& to_next) const
54
      { return do_out(state, from, from_end, from_next,
55
                      to, to_limit, to_next); }
56
 
57
      result unshift(state_type& state, extern_type* to, extern_type* to_limit,
58
                     extern_type*& to_next) const
59
      { return do_unshift(state, to, to_limit, to_next); }
60
 
61
      result in(state_type& state, const extern_type* from,
62
                const extern_type* from_end, const extern_type*& from_next,
63
                intern_type* to, intern_type* to_limit,
64
                intern_type*& to_next) const
65
      { return do_in(state, from, from_end, from_next,
66
                     to, to_limit, to_next); }
67
 
68
      int encoding() const throw()
69
      { return do_encoding(); }
70
 
71
      bool always_noconv() const throw()
72
      { return do_always_noconv(); }
73
 
74
      int length(state_type& state, const extern_type* from,
75
                 const extern_type* end, size_t max) const
76
      { return do_length(state, from, end, max); }
77
 
78
      int max_length() const throw()
79
      { return do_max_length(); }
80
 
81
      static locale::id id;
82
 
83
    protected:
84
      virtual ~codecvt();
85
 
86
      virtual result do_out(state_type&, const intern_type*,
87
                            const intern_type*, const intern_type*&,
88
                            extern_type*, extern_type*, extern_type*&) const
89
      { return error; }
90
 
91
      virtual result do_in(state_type&, const extern_type*, const extern_type*,
92
                           const extern_type*&, intern_type*, intern_type*,
93
                           intern_type*&) const
94
      { return error; }
95
 
96
      virtual result do_unshift(state_type&, extern_type*, extern_type*,
97
                                extern_type*&) const
98
      { return noconv; }
99
 
100
      virtual int do_encoding() const throw()
101
      { return 1; }
102
 
103
      virtual bool do_always_noconv() const throw()
104
      { return false; }
105
 
106
      virtual int do_length(state_type&, const extern_type* from,
107
                            const extern_type* end, size_t max) const
108
      {
109
        size_t len = end - from;
110
        return std::min(max, len);
111
      }
112
 
113
      virtual int do_max_length() const throw()
114
      { return 1; }
115
    };
116
 
117
  locale::id codecvt<wchar_t, char, MyState>::id;
118
 
119
  codecvt<wchar_t, char, MyState>::~codecvt()
120
  { }
121
}
122
 
123
void test01()
124
{
125
  bool test __attribute__((unused)) = true;
126
 
127
  std::locale loc(std::locale::classic(),
128
                  new std::codecvt<wchar_t, char, MyState>);
129
  std::basic_filebuf<wchar_t, MyCharTraits> fb;
130
  fb.pubimbue(loc);
131
  fb.open("tmp_11543", std::ios_base::out);
132
  VERIFY( fb.is_open() );
133
  MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
134
  VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );
135
  fb.close();
136
}
137
 
138
int main()
139
{
140
  test01();
141
  return 0;
142
}

powered by: WebSVN 2.1.0

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