OSDN Git Service

Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 27_io / basic_stringstream / str / char / 1.cc
1 // 2001-05-24 Benjamin Kosnik  <bkoz@redhat.com>
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3.  If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // 27.7.6 member functions (stringstream_members)
22
23 #include <sstream>
24 #include <testsuite_hooks.h>
25
26 void test01()
27 {
28   bool test __attribute__((unused)) = true;
29   std::stringstream is01;
30   const std::string str00; 
31   const std::string str01 = "123";
32   std::string str02;
33   const int i01 = 123;
34   int a = 0, b = 0;
35
36   std::ios_base::iostate state1, state2, stateeof;
37   stateeof = std::ios_base::eofbit;
38
39   // string str() const
40   str02 = is01.str();
41   VERIFY( str00 == str02 );
42
43   // void str(const basic_string&)
44   is01.str(str01);
45   str02 = is01.str();
46   VERIFY( str01 == str02 );
47   state1 = is01.rdstate();
48   is01 >> a;
49   state2 = is01.rdstate();
50   VERIFY( a == i01 );
51   // 22.2.2.1.2 num_get virtual functions
52   // p 13
53   // in any case, if stage 2 processing was terminated by the test for
54   // in == end then err != ios_base::eofbit is performed.
55   VERIFY( state1 != state2 );
56   VERIFY( state2 == stateeof ); 
57
58   is01.str(str01);
59   is01 >> b;
60   VERIFY( b != a ); 
61   // as is01.good() is false, istream::sentry blocks extraction.
62
63   is01.clear();
64   state1 = is01.rdstate();
65   is01 >> b;
66   state2 = is01.rdstate();
67   VERIFY( b == a ); 
68   VERIFY( state1 != state2 );
69   VERIFY( state2 == stateeof ); 
70 }
71
72 int main()
73 {
74   test01();
75   return 0;
76 }