Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
27.basic.ios.cpp
Go to the documentation of this file.
1
29// prevent the inclusion of non-essential public headers; only headers
30// necessary to compile each header #included here are #included
31// will produce errors if any templates defined in the header are
32// instantiated without the names they use having been completely defined
33#if !defined (_MSC_VER) || _MSC_VER > 1300
34# define _RWSTD_NO_REDUNDANT_DEFINITIONS
35#endif
36
37// prevent out-of-line template definitions in .cc files from being explicitly
38// #included during the processing of library headers (faster compilation)
39// assumes that the test doesn't instantiate those templates on types other
40// than those they were explcitly instantiated on (will have no effect if
41// explicit instantiation is disabled or unsupported)
42#define _RWSTD_NO_TEMPLATE_DEFINITIONS
43
44#include <ios>
45
46// IMPORTANT: do not #include any other header before the declarations
47// below in order not to accidentally bring in any missing
48// definitions from the #included header
49
50#ifndef _RWSTD_NO_NAMESPACE
51# define std std
52#else
53# define std
54#endif // _RWSTD_NO_NAMESPACE
55
56
58// compilation tests
59
60// use defs from <iosfwd> to verify that it is #included
61
62struct S { /* empty */ };
63
64typedef std::char_traits<S> Traits;
65typedef std::char_traits<char> char_Traits;
66
67#ifndef _RWSTD_NO_WCHAR_T
68
69typedef std::char_traits<wchar_t> wchar_t_Traits;
70
71#endif // _RWSTD_NO_WCHAR_T
72
73typedef std::allocator<S> Alloc;
74
75#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
76
77// make sure that default template arguments are specified
78
79typedef std::basic_ios<S> S_basic_ios;
80typedef std::basic_streambuf<S> S_basic_streambuf;
81typedef std::basic_istream<S> S_basic_istream;
82typedef std::basic_ostream<S> S_basic_ostream;
83typedef std::basic_iostream<S> S_basic_iostream;
84typedef std::basic_stringbuf<S> S_basic_stringbuf;
85typedef std::basic_istringstream<S> S_basic_istringstream;
86typedef std::basic_ostringstream<S> S_basic_ostringstream;
87typedef std::basic_stringstream<S> S_basic_stringstream;
88
89typedef std::basic_filebuf<S> S_basic_filebuf;
90typedef std::basic_ifstream<S> S_basic_ifstream;
91typedef std::basic_ofstream<S> S_basic_ofstream;
92typedef std::basic_fstream<S> S_basic_fstream;
93
94typedef std::istreambuf_iterator<S> S_istreambuf_iterator;
95typedef std::ostreambuf_iterator<S> S_ostreambuf_iterator;
96
97#else // if defined _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
98
99// specify default template argument for broken compilers
100
101typedef std::basic_ios<S, Traits> S_basic_ios;
102typedef std::basic_streambuf<S, Traits> S_basic_streambuf;
103typedef std::basic_istream<S, Traits> S_basic_istream;
104typedef std::basic_ostream<S, Traits> S_basic_ostream;
105typedef std::basic_iostream<S, Traits> S_basic_iostream;
106typedef std::basic_stringbuf<S, Traits, Alloc> S_basic_stringbuf;
107typedef std::basic_istringstream<S, Traits, Alloc> S_basic_istringstream;
108typedef std::basic_ostringstream<S, Traits, Alloc> S_basic_ostringstream;
109typedef std::basic_stringstream<S, Traits, Alloc> S_basic_stringstream;
110
111typedef std::basic_filebuf<S, Traits> S_basic_filebuf;
112typedef std::basic_ifstream<S, Traits> S_basic_ifstream;
113typedef std::basic_ofstream<S, Traits> S_basic_ofstream;
114typedef std::basic_fstream<S, Traits> S_basic_fstream;
115
116typedef std::istreambuf_iterator<S, Traits> S_istreambuf_iterator;
117typedef std::ostreambuf_iterator<S, Traits> S_ostreambuf_iterator;
118
119#endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
120
121typedef std::fpos<S> S_fpos;
122
123// test whether all required typedefs are defined
124
125typedef std::ios X_ios;
126typedef std::streambuf X_streambuf;
127typedef std::istream X_istream;
128typedef std::ostream X_ostream;
129typedef std::iostream X_iostream;
130typedef std::stringbuf X_stringbuf;
131typedef std::istringstream X_istringstream;
132typedef std::ostringstream X_ostringstream;
133typedef std::stringstream X_stringstream;
134typedef std::filebuf X_filebuf;
135typedef std::ifstream X_ifstream;
136typedef std::ofstream X_ofstream;
137typedef std::fstream X_fstream;
138
139typedef std::streampos X_streampos;
140
141#ifndef _RWSTD_NO_WCHAR_T
142
143typedef std::wios X_wios;
144typedef std::wstreambuf X_wstreambuf;
145typedef std::wistream X_wistream;
146typedef std::wostream X_wostream;
147typedef std::wiostream X_wiostream;
148typedef std::wstringbuf X_wstringbuf;
149typedef std::wistringstream X_wistringstream;
150typedef std::wostringstream X_wostringstream;
151typedef std::wstringstream X_wstringstream;
152typedef std::wfilebuf X_wfilebuf;
153typedef std::wifstream X_wifstream;
154typedef std::wofstream X_wofstream;
155typedef std::wfstream X_wfstream;
156
157typedef std::wstreampos X_wstreampos;
158
159#endif // _RWSTD_NO_WCHAR_T
160
161
163// additional compilation tests
164
165#include <rw_driver.h>
166
167static void
168test_synopsis ()
169{
170 rw_info (0, 0, __LINE__, "27.4.4 Class template basic_ios");
171
172 // exercise types
173 std::streamoff off = 0;
175
176 std::streamsize size = 0;
178
179 std::fpos<int> fpi;
180 _RWSTD_UNUSED (fpi);
181
182 std::ios_base *iob = 0;
183 _RWSTD_UNUSED (iob);
184
185 // exercise a default argument
186 std::basic_ios<char, std::char_traits<char> > *bios_2 = 0;
187 std::basic_ios<char /*, char_traits<char> */> *bios_1 = bios_2;
188
189 _RWSTD_UNUSED (bios_2);
190 _RWSTD_UNUSED (bios_1);
191
192#ifndef _RWSTD_NO_WCHAR_T
193
194 // exercise a default argument
195 std::basic_ios<wchar_t, std::char_traits<wchar_t> > *wbios_2 = 0;
196 std::basic_ios<wchar_t /*, char_traits<wchar_t> */> *wbios_1 = wbios_2;
197
198 _RWSTD_UNUSED (wbios_2);
199 _RWSTD_UNUSED (wbios_1);
200
201#endif // _RWSTD_NO_WCHAR_T
202
203#define TEST_MANIP(name) { \
204 std::ios_base& (*pf)(std::ios_base&) = &name; \
205 _RWSTD_UNUSED (pf); \
206 }
207
208 // 27.4.5, manipulators:
209 TEST_MANIP (std::boolalpha);
210 TEST_MANIP (std::noboolalpha);
211 TEST_MANIP (std::noshowbase);
212 TEST_MANIP (std::showpoint);
213 TEST_MANIP (std::noshowpoint);
214 TEST_MANIP (std::noshowpos);
215 TEST_MANIP (std::skipws);
216 TEST_MANIP (std::noskipws);
217 TEST_MANIP (std::uppercase);
218 TEST_MANIP (std::nouppercase);
219 TEST_MANIP (std::internal);
220 TEST_MANIP (std::left);
221 TEST_MANIP (std::right);
222 TEST_MANIP (std::dec);
223 TEST_MANIP (std::hex);
224 TEST_MANIP (std::oct);
225 TEST_MANIP (std::fixed);
226 TEST_MANIP (std::scientific);
227}
228
229
231// invariant tests
232
233template <class charT>
234static void
235test_ctors (charT /* unused */, const char* cname)
236{
237 rw_info (0, 0, __LINE__, "27.4.4.1 basic_ios<%s> constructors", cname);
238
239 // 27.4.4.1, p1
240 std::basic_ios<charT, std::char_traits<charT> > io0 (0);
241
242 rw_assert (0 == io0.rdbuf (), __FILE__, __LINE__,
243 "basic_ios<%s>::rdbuf () == 0", cname);
244
245 rw_assert (0 == io0.tie (), __FILE__, __LINE__,
246 "basic_ios<%s>::tie () == 0", cname);
247
248 rw_assert (io0.badbit == io0.rdstate (), __FILE__, __LINE__,
249 "basic_ios<%s>::rdstate () == %{If}, got %{If}",
250 cname, io0.badbit, io0.flags ());
251
252 rw_assert ((io0.skipws | io0.dec) == io0.flags (),
253 __FILE__, __LINE__,
254 "basic_ios<%s>::flags () == %{If}, got %{If}",
255 cname, io0.skipws | io0.dec, io0.flags ());
256
257 rw_assert (0 == io0.width (), __FILE__, __LINE__,
258 "basic_ios<%s>::width () == 0, got %l",
259 cname, io0.width ());
260
261 rw_assert (6 == io0.precision (), __FILE__, __LINE__,
262 "basic_ios<%s>::precision () == 6, got %l",
263 cname, io0.precision ());
264
265 rw_assert (io0.widen (' ') == io0.fill (), __FILE__, __LINE__,
266 "basic_ios<%s>::fill ()", cname);
267}
268
269
271// command-line options
272static int opt_no_basic_ios_ctors = 0;
273
274static int
275run_test (int /* unused */, char* /* unused */ [])
276{
277 test_synopsis ();
278
279 if (opt_no_basic_ios_ctors) {
280 rw_note (0, 0, 0, "basic_ios<T> ctors disabled");
281 }
282 else {
283 test_ctors (char (), "char");
284 }
285
286 return 0;
287}
288
289/* extern */ int
290main (int argc, char* argv [])
291{
292 return rw_test (argc, argv, __FILE__,
293 "lib.iostream.basic_ios",
294 0, // no comment
295 run_test,
296 "|-no-basic_ios-ctors# ",
297 &opt_no_basic_ios_ctors);
298}
299
#define off
Definition 17.names.cpp:507
#define charT
Definition 17.names.cpp:456
void test_ctors()
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
std::basic_filebuf< S > S_basic_filebuf
std::wifstream X_wifstream
std::filebuf X_filebuf
std::basic_stringbuf< S > S_basic_stringbuf
std::basic_istream< S > S_basic_istream
std::wiostream X_wiostream
std::wistream X_wistream
std::ostringstream X_ostringstream
std::wfstream X_wfstream
std::wstringbuf X_wstringbuf
std::basic_ostream< S > S_basic_ostream
std::char_traits< S > Traits
std::wstreambuf X_wstreambuf
std::stringbuf X_stringbuf
std::ios X_ios
std::wfilebuf X_wfilebuf
std::streambuf X_streambuf
std::istream X_istream
std::ostreambuf_iterator< S > S_ostreambuf_iterator
std::ifstream X_ifstream
std::fstream X_fstream
std::wostream X_wostream
std::istringstream X_istringstream
std::ofstream X_ofstream
std::iostream X_iostream
std::fpos< S > S_fpos
std::streampos X_streampos
std::wstringstream X_wstringstream
std::wstreampos X_wstreampos
std::basic_stringstream< S > S_basic_stringstream
std::istreambuf_iterator< S > S_istreambuf_iterator
std::char_traits< char > char_Traits
std::basic_fstream< S > S_basic_fstream
std::wios X_wios
std::basic_streambuf< S > S_basic_streambuf
std::stringstream X_stringstream
std::wofstream X_wofstream
std::basic_ios< S > S_basic_ios
std::wostringstream X_wostringstream
std::basic_iostream< S > S_basic_iostream
std::ostream X_ostream
#define TEST_MANIP(name)
std::char_traits< wchar_t > wchar_t_Traits
std::allocator< S > Alloc
std::basic_ifstream< S > S_basic_ifstream
std::basic_istringstream< S > S_basic_istringstream
std::basic_ostringstream< S > S_basic_ostringstream
std::basic_ofstream< S > S_basic_ofstream
std::wistringstream X_wistringstream
#define main
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
Definition driver.cpp:1664
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630