OSDN Git Service

2002-04-17 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 27_io / fpos.cc
1 // 1999-09-20 bkoz
2
3 // Copyright (C) 1999, 2001 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 <testsuite_hooks.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   std::streampos pos05 = pos03;
111   std::streampos pos06 = pos03 + off02;
112   VERIFY ( pos05 == pos03 );
113
114   // q = p - o
115   // p -= o
116   pos03 = pos03 - off02;
117   pos04 -= off02;
118   VERIFY( pos03 == pos04 );
119   std::streampos pos07 = pos03;
120   std::streampos pos08 = pos03 - off02;
121   VERIFY ( pos07 == pos03 );
122
123   // o = p - q
124   VERIFY( 0 == pos03 - pos04 );
125
126   // streamsize -> streamoff
127   // streamoff -> streamsize 
128   off01 = off02;
129   std::streamsize size01(off02);
130   std::streamoff off04(size01);
131   VERIFY( off01 == off04 );
132
133 #ifdef DEBUG_ASSERT
134   assert(test);
135 #endif
136
137
138 void test03()
139 {
140   bool test = true;
141
142   typedef std::mbstate_t state_type;
143   state_type state01;
144   state_type state02;
145
146   std::streamoff off01;
147   std::streamoff off02 = 997;
148   
149   int i01 = 0;
150   int i02 = 999;
151
152   // casts to const streamoff
153   // (yes, I know this is weak code)
154   const std::streampos pos01 = 0;
155   off01 = pos01;
156
157   // equality/inequality with const args
158   const std::streampos pos02(54);
159   std::streampos pos03(44);
160   VERIFY( !(pos03 == pos02) );
161   VERIFY( pos03 != pos02 );
162   VERIFY( !(pos02 == pos03) );
163   VERIFY( pos02 != pos03 );
164
165   // default values
166   std::streampos pos04;
167   VERIFY( (std::streamoff)pos04 == 0 ); 
168
169 #ifdef DEBUG_ASSERT
170   assert(test);
171 #endif
172
173
174 int main() {
175   test01();
176   test02();
177   test03();
178   return 0;
179 }