OSDN Git Service

* testsuite/lib/libstdc++.exp (check_v3_target_fileio,
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / seekoff / char / 11543.cc
1 // 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 // { dg-require-fileio "" }
23
24 #include <fstream>
25 #include <locale>
26 #include <testsuite_hooks.h>
27
28 struct MyState
29 {
30 };
31
32 struct MyCharTraits : std::char_traits<char>
33 {
34   typedef std::fpos<MyState> pos_type;
35   typedef MyState state_type;
36 };
37
38 namespace std
39 {
40   template <>
41     class codecvt<char, char, MyState> :
42       public locale::facet, public codecvt_base
43     {
44     public:
45       typedef char intern_type;
46       typedef char extern_type;
47       typedef MyState state_type;
48     
49       explicit codecvt(size_t refs = 0)
50       : locale::facet(refs) { }
51     
52       result out(state_type& state, const intern_type* from,
53                  const intern_type* from_end,  const intern_type*& from_next,
54                  extern_type* to, extern_type* to_limit,
55                  extern_type*& to_next) const
56       { return do_out(state, from, from_end, from_next,
57                       to, to_limit, to_next); }
58
59       result unshift(state_type& state, extern_type* to, extern_type* to_limit,
60                      extern_type*& to_next) const
61       { return do_unshift(state, to, to_limit, to_next); }
62
63       result in(state_type& state, const extern_type* from,
64                 const extern_type* from_end, const extern_type*& from_next,
65                 intern_type* to, intern_type* to_limit,
66                 intern_type*& to_next) const
67       { return do_in(state, from, from_end, from_next,
68                      to, to_limit, to_next); }
69
70       int encoding() const throw()
71       { return do_encoding(); }
72       
73       bool always_noconv() const throw()
74       { return do_always_noconv(); }
75
76       int length(state_type& state, const extern_type* from,
77                  const extern_type* end, size_t max) const
78       { return do_length(state, from, end, max); }
79
80       int max_length() const throw()
81       { return do_max_length(); }
82     
83       static locale::id id;
84     
85     protected:
86       virtual ~codecvt();
87
88       virtual result do_out(state_type&, const intern_type* from,
89                             const intern_type*, const intern_type*& from_next,
90                             extern_type* to, extern_type*,
91                             extern_type*& to_next) const
92       {
93         from_next = from;
94         to_next = to;
95         return noconv;
96       }
97
98       virtual result do_in(state_type&, const extern_type* from,
99                            const extern_type*, const extern_type*& from_next,
100                            intern_type* to, intern_type*,
101                            intern_type*& to_next) const
102       {
103         from_next = from;
104         to_next = to;
105         return noconv;
106       }
107
108       virtual result do_unshift(state_type&, extern_type*, extern_type*,
109                                 extern_type*&) const
110       { return noconv; }
111
112       virtual int do_encoding() const throw()
113       { return 1; }
114
115       virtual bool do_always_noconv() const throw()
116       { return true; }
117
118       virtual int do_length(state_type&, const extern_type* from,
119                             const extern_type* end, size_t max) const
120       {
121         size_t len = end - from;
122         return std::min(max, len);
123       }
124
125       virtual int do_max_length() const throw()
126       { return 1; }
127     };
128   
129   locale::id codecvt<char, char, MyState>::id;
130
131   codecvt<char, char, MyState>::~codecvt()
132   { }
133 }
134
135 void test01()
136 {
137   bool test __attribute__((unused)) = true;
138
139   std::locale loc(std::locale::classic(),
140                   new std::codecvt<char, char, MyState>);
141   std::basic_filebuf<char, MyCharTraits> fb;
142   fb.pubimbue(loc);
143   fb.open("tmp_11543", std::ios_base::out);
144   VERIFY( fb.is_open() );
145   MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
146   VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );
147   fb.close();
148 }
149
150 int main()
151 {
152   test01();
153   return 0;
154 }