34#undef _RWSTD_NO_OPERATOR_NEW_ARRAY
35#undef _RWSTD_NO_OPERATOR_DELETE_ARRAY
38#if defined (__IBMCPP__) && !defined (_RWSTD_NO_IMPLICIT_INCLUSION)
42# define _RWSTD_NO_IMPLICIT_INCLUSION
45#if !defined (_MSC_VER) || _MSC_VER > 1300
51# define _RWSTD_NO_TEMPLATE_DEFINITIONS
84#ifndef _RWSTD_NO_WCHAR_T
117 rw_note (0, 0, __LINE__,
"test of global dtors disabled");
122 std::cout <<
"[output from the dtor of a global object]";
124 std::cout <<
"[cout]";
125 std::cerr <<
"[cerr]";
126 std::clog <<
"[clog]";
128#ifndef _RWSTD_NO_WCHAR_T
130 std::wcout <<
"[wcout]";
131 std::wcerr <<
"[wcerr]";
132 std::wclog <<
"[wclog]";
141template <
class charT>
144 rw_info (0, 0, 0,
"checking whether objects are initialized");
147 rw_assert ( 0 != &std::cin && 0 != &std::cout
148 && 0 != &std::cerr && 0 != &std::clog,
149 0, __LINE__,
"std::cin, cout, cerr, or clog address 0");
151 rw_info (0, 0, __LINE__,
"checking tied stream objects");
156 rw_assert (&std::cout == std::cin.
tie (&std::cout), 0, __LINE__,
157 "&std::cout == std::cin.tie (&std::cout)");
159 "0 == std::cout.tie ()");
161 "0 == std::cerr.tie ()");
163 "0 == std::clog.tie ()");
166 "unexpected dynamic memory allocation");
168 rw_info (0, 0, __LINE__,
"checking for std::ios_base::unitbuf in flags");
173 rw_assert (!(std::ios::unitbuf & std::cout.
flags ()), 0, __LINE__,
174 "std::ios::unitbuf & std::cout.flags ()");
177 rw_assert (!!(std::ios::unitbuf & std::cerr.
flags ()), 0, __LINE__,
178 "std::ios::unitbuf & std::cerr.flags ()");
181 rw_assert (!(std::ios::unitbuf & std::clog.
flags ()), 0, __LINE__,
182 "std::ios::unitbuf & std::clog.flags ()");
185 "unexpected dynamic memory allocation");
187#ifndef _RWSTD_NO_WCHAR_T
189 rw_assert ( 0 != &std::wcin && 0 != &std::wcout
190 && 0 != &std::wcerr && 0 != &std::wclog,
191 0, __LINE__,
"std::wcin, wcout, wcerr, or wclog address 0");
196 rw_assert (&std::wcout == std::wcin.
tie (&std::wcout), 0, __LINE__,
197 "&std::wcout == std::wcin.tie (&std::wcout)");
199 "0 == std::wcout.tie ()");
201 "0 == std::wcerr.tie ()");
203 "0 == std::wclog.tie ()");
206 "unexpected dynamic memory allocation");
211 rw_assert (!(std::wios::unitbuf & std::wcout.
flags ()), 0, __LINE__,
212 "std::wios::unitbuf & std::wcout.flags ()");
215 rw_assert (!!(std::wios::unitbuf & std::wcerr.
flags ()), 0, __LINE__,
216 "std::wios::unitbuf & std::wcerr.flags ()");
219 rw_assert (!(std::wios::unitbuf & std::wclog.
flags ()), 0, __LINE__,
220 "std::wios::unitbuf & std::wclog.flags ()");
223 "unexpected dynamic memory allocation");
231#ifndef _RWSTD_NO_WCHAR_T
239 std::cout << std::endl;
242 rw_info (0, 0, __LINE__,
"exercising the ability to tie each stream "
243 "to itself without causing a deadlock");
245 std::cout.tie (&std::cout);
246 std::cout << std::cout.tie () <<
' ';
248 std::cerr.tie (&std::cerr);
249 std::cerr << std::cerr.tie () <<
' ';
251 std::clog.tie (&std::clog);
252 std::clog << std::clog.tie () <<
' ';
254#ifndef _RWSTD_NO_WCHAR_T
256 std::wcout.tie (&std::wcout);
257 std::wcout << std::wcout.tie () <<
' ';
259 std::wcerr.tie (&std::wcerr);
260 std::wcerr << std::wcerr.tie () <<
' ';
262 std::wclog.tie (&std::wclog);
263 std::wclog << std::wclog.tie () <<
' ';
268 rw_info (0, 0, __LINE__,
"exercising the ability to tie stream objects "
269 "together without causing a deadlock");
271 std::cout.tie (&std::cerr);
272 std::cout << std::cout.tie () <<
' ';
274 std::cerr.tie (&std::cout);
275 std::cerr << std::cerr.tie () <<
' ';
277 std::clog.tie (&std::cout);
278 std::clog << std::clog.tie () <<
' ';
287#ifndef _RWSTD_NO_WCHAR_T
289 std::wcout.tie (&std::wcerr);
290 std::wcout << std::wcout.tie () <<
' ';
292 std::wcerr.tie (&std::wcout);
293 std::wcerr << std::wcerr.tie () <<
' ';
295 std::wclog.tie (&std::wcout);
296 std::wclog << std::wclog.tie () <<
' ';
307 std::cout << std::endl;
324 rw_assert (0 == new_1 - delete_1, 0, __LINE__,
325 "test leaked %d blocks of memory", new_1 - delete_1);
327 "iostream initialization called operator new() %d times, "
330#ifdef _RWSTD_NO_REPLACEABLE_NEW_DELETE
333 "replacement operators new and delete not tested: "
334 "_RWSTD_NO_REPLACEABLE_NEW_DELETE #defined");
343#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
347# ifndef _RWSTD_BAD_ALLOC
350# define _RWSTD_BAD_ALLOC _STD::bad_alloc
356 static int recursion;
364 "test of replacement operator new disabled");
366 else if (1 != recursion) {
372 rw_warn (1 == recursion, 0, __LINE__,
373 "recursive call to replacement operator new()");
378 static std::ios_base::Init io_initializer;
382 std::cout <<
"[replacement operator new (" <<
n <<
")]\n";
389 void*
const ptr = std::malloc (
n);
399 static int recursion;
407 "test of replacement operator delete disabled");
409 else if (
rw_warn (1 == recursion, 0, __LINE__,
410 "recursive call to replacement operator delete()")) {
411 std::cout <<
"[replacement operator delete (" <<
ptr <<
")]\n";
425 return operator new (
n);
438int main (
int argc,
char *argv[])
443 return rw_test (argc, argv, __FILE__,
444 "lib.iostream.objects",
447 "|-no-global-dtors# "
448 "|-no-replacement-new# "
449 "|-no-replacement-delete#",
void do_test(int line, const char *src, std::size_t resoff, ForwardIterator dummy_iter, const T *, const char *predname)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
void tie(std::ostringstream *ps, std::size_t n)
int rw_opt_no_replacement_new
int rw_opt_no_replacement_delete
struct LifetimeChecker lifetime_check
int rw_opt_no_global_dtors
_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 *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)