OSDN Git Service

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