OSDN Git Service

2003-01-21 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 22_locale / money_get / get / char / 6.cc
1 // 2001-09-12 Benjamin Kosnik  <bkoz@redhat.com>
2
3 // Copyright (C) 2001, 2002, 2003 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 2, 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 COPYING.  If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // 22.2.6.1.1 money_get members
22
23 #include <locale>
24 #include <sstream>
25 #include <testsuite_hooks.h>
26
27 struct My_money_io : public std::moneypunct<char,false>
28 {
29   char_type do_decimal_point() const { return '.'; }
30   std::string do_grouping() const { return "\004"; }
31   
32   std::string do_curr_symbol() const { return "$"; }
33   std::string do_positive_sign() const { return ""; }
34   std::string do_negative_sign() const { return "-"; }
35   
36   int do_frac_digits() const { return 2; }
37
38   pattern do_pos_format() const
39   {
40     pattern pat = { { symbol, none, sign, value } };
41     return pat;
42   }
43
44   pattern do_neg_format() const
45   {
46     pattern pat = { { symbol, none, sign, value } };
47     return pat;
48   }
49 };
50
51 // libstdc++/5579
52 void test06()
53 {
54   using namespace std;
55   typedef istreambuf_iterator<char> InIt;
56
57   bool test = true;
58
59   locale loc(locale::classic(), new My_money_io);
60
61   string bufferp("$1234.56");
62   string buffern("$-1234.56");
63   string bufferp_ns("1234.56");
64   string buffern_ns("-1234.56");
65
66   bool intl = false;
67
68   InIt iendp, iendn, iendp_ns, iendn_ns;
69   ios_base::iostate err;
70   string valp, valn, valp_ns, valn_ns;
71
72   const money_get<char,InIt>& mg  =
73     use_facet<money_get<char, InIt> >(loc);
74
75   istringstream fmtp(bufferp);
76   fmtp.imbue(loc);
77   InIt ibegp(fmtp);
78   mg.get(ibegp,iendp,intl,fmtp,err,valp);
79   VERIFY( valp == "123456" );
80
81   istringstream fmtn(buffern);
82   fmtn.imbue(loc);
83   InIt ibegn(fmtn);
84   mg.get(ibegn,iendn,intl,fmtn,err,valn);
85   VERIFY( valn == "-123456" );
86
87   istringstream fmtp_ns(bufferp_ns);
88   fmtp_ns.imbue(loc);
89   InIt ibegp_ns(fmtp_ns);
90   mg.get(ibegp_ns,iendp_ns,intl,fmtp_ns,err,valp_ns);
91   VERIFY( valp_ns == "123456" );
92
93   istringstream fmtn_ns(buffern_ns);
94   fmtn_ns.imbue(loc);
95   InIt ibegn_ns(fmtn_ns);
96   mg.get(ibegn_ns,iendn_ns,intl,fmtn_ns,err,valn_ns);
97   VERIFY( valn_ns == "-123456" );
98 }
99
100 int main()
101 {
102   test06();
103   return 0;
104 }