OSDN Git Service

ef290bc5d8ad80d56ffbcc84ea5741bcae383e47
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 27_io / fpos.cc
1 // 1999-09-20 bkoz
2
3 // Copyright (C) 1999 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 // 27.4.3 template class fpos
31
32 #include <cwchar> // for mbstate_t
33 #include <ios>
34 #include <debug_assert.h>
35
36 void test01()
37 {
38   bool test = true;
39
40   typedef std::mbstate_t state_type;
41   state_type state01;
42   state_type state02;
43
44   std::streampos pos01;
45   std::streampos pos02;
46
47   std::streamoff off01;
48   std::streamoff off02;
49   
50   std::streamsize size01;
51   std::streamsize size02;
52
53   // 27.4.3.1 fpos members
54   // void state(state_type s);
55   // state_type state();
56 #if 0
57 // XXX Need to have some sanity checking for the mbstate_t type, or
58 // whatever the insantiating type for class fpos happens to be for
59 // streampos, as things like equality operators and assignment
60 // operators, increment and deincrement operators need to be in place.
61   pos01.state(state02);
62   state01 = pos01.state();
63   VERIFY( state01 == state02 );
64 #endif
65   
66 #ifdef DEBUG_ASSERT
67   assert(test);
68 #endif
69 }
70
71 // 27.4.3.2 fpos requirements/invariants
72 void test02()
73 {
74   bool test = true;
75
76   typedef std::mbstate_t state_type;
77   state_type state01;
78   state_type state02;
79
80   std::streamoff off01;
81   std::streamoff off02 = 997;
82   
83   int i01 = 0;
84   int i02 = 999;
85
86   // p(i), p = i
87   std::streampos pos01(i02);
88   std::streampos pos02 = i02;
89   VERIFY( pos01 == pos02 );
90   
91   // p(o), p = o 
92   // NB: P(o) is only required.
93   std::streampos pos03(off02);
94   std::streampos pos04 = off02;
95   VERIFY( pos03 == pos04 );
96   
97   // O(p)
98   std::streamoff off03(pos04);
99   VERIFY( off03 == off02 );
100
101   // p == q, p!= q
102   VERIFY( pos01 == pos02 );
103   VERIFY( pos02 != pos03 );
104
105   // q = p + o
106   // p += o
107   pos03 = pos03 + off02;
108   pos04 += off02;
109   VERIFY( pos03 == pos04 );
110
111   // q = p - o
112   // p -= o
113   pos03 = pos03 - off02;
114   pos04 -= off02;
115   VERIFY( pos03 == pos04 );
116
117   // o = p - q
118   VERIFY( 0 == pos03 - pos04 );
119
120   // streamsize -> streamoff
121   // streamoff -> streamsize 
122   off01 = off02;
123   std::streamsize size01(off02);
124   std::streamoff off04(size01);
125   VERIFY( off01 == off04 );
126
127 #ifdef DEBUG_ASSERT
128   assert(test);
129 #endif
130
131
132 void test03()
133 {
134   bool test = true;
135
136   typedef std::mbstate_t state_type;
137   state_type state01;
138   state_type state02;
139
140   std::streamoff off01;
141   std::streamoff off02 = 997;
142   
143   int i01 = 0;
144   int i02 = 999;
145
146   // casts to const streamoff
147   // (yes, I know this is weak code)
148   const std::streampos pos01 = 0;
149   off01 = pos01;
150
151   // equality/inequality with const args
152   const std::streampos pos02(54);
153   std::streampos pos03(44);
154   VERIFY( !(pos03 == pos02) );
155   VERIFY( pos03 != pos02 );
156   VERIFY( !(pos02 == pos03) );
157   VERIFY( pos02 != pos03 );
158
159   // default values
160   std::streampos pos04;
161   VERIFY( (std::streamoff)pos04 == 0 ); 
162
163 #ifdef DEBUG_ASSERT
164   assert(test);
165 #endif
166
167
168 int main() {
169   test01();
170   test02();
171   test03();
172   return 0;
173 }
174
175
176
177