OSDN Git Service

2011-12-15 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 22_locale / num_put / put / char / 10.cc
1 // 2005-07-11  Paolo Carlini  <pcarlini@suse.de>
2
3 // Copyright (C) 2005, 2009 Free Software Foundation
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.
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 COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 22.2.2.2.1  num_put members
21
22 #include <locale>
23 #include <sstream>
24 #include <testsuite_hooks.h>
25
26 void test01()
27 {
28   using namespace std;
29   bool test __attribute__((unused)) = true;
30
31   locale loc_c = locale::classic();
32
33   const string empty;
34
35   stringstream ss;
36   ss.imbue(loc_c);
37   const num_put<char>& np = use_facet<num_put<char> >(ss.getloc()); 
38
39   long l = -1;
40   unsigned long ul = 0;
41
42   ss.setf(ios::hex, ios::basefield);
43   np.put(ss.rdbuf(), ss, '+', l);
44   VERIFY( ss.str() != "1" );
45   ss >> ul;
46   VERIFY( ul == static_cast<unsigned long>(l) );
47
48 #ifdef _GLIBCXX_USE_LONG_LONG  
49   long long ll = -1LL;
50   unsigned long long ull = 0ULL;
51
52   ss.str(empty);
53   ss.clear();
54   np.put(ss.rdbuf(), ss, '+', ll);
55   VERIFY( ss.str() != "1" );
56   ss >> ull;
57   VERIFY( ull == static_cast<unsigned long long>(ll) );
58 #endif
59 }
60
61 int main()
62 {
63   test01();
64   return 0;
65 }
66
67