Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / objects / char / 5.cc
blob6e449261fd083d35903b4b75325cee2adf0480ec
1 // 2003-04-26 Petur Runolfsson <peturr02@ru.is>
3 // Copyright (C) 2003-2013 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 3, or (at your option)
9 // any later version.
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 27.3 Standard iostream objects
22 // Check that standard streams can be used from constructors and
23 // destructors of static objects, provided that an instance of
24 // ios_base::Init has been constructed.
26 void init_standard_streams();
27 int use_standard_streams();
29 struct Strange
31 int i;
33 Strange()
35 init_standard_streams();
36 i = use_standard_streams();
39 ~Strange()
41 use_standard_streams();
42 init_standard_streams();
46 static Strange static_ob;
48 #include <testsuite_hooks.h>
49 #include <iostream>
51 void init_standard_streams()
53 std::ios_base::Init init;
56 int use_standard_streams()
58 std::cout << "Hello, world!" << std::endl;
59 std::cerr << "World, hello!" << std::endl;
61 int ret = std::ios_base::xalloc();
62 std::cin.iword(ret) = ret + 1;
63 std::cout.iword(ret) = ret + 2;
64 std::cerr.iword(ret) = ret + 3;
65 std::clog.iword(ret) = ret + 4;
66 return ret;
69 void test05()
71 bool test __attribute__((unused)) = true;
72 int i = static_ob.i;
74 VERIFY( std::cin.iword(i) == i + 1 );
75 VERIFY( std::cout.iword(i) == i + 2 );
76 VERIFY( std::cerr.iword(i) == i + 3 );
77 VERIFY( std::clog.iword(i) == i + 4 );
80 int main()
82 test05();
83 return 0;