OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [22_locale/] [money_get/] [get/] [wchar_t/] [19.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 2004-03-15  Paolo Carlini  <pcarlini@suse.de>
2
 
3
// Copyright (C) 2004 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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_01 : public std::moneypunct<wchar_t, false>
28
{
29
  std::wstring do_curr_symbol() const { return L"$"; }
30
  std::wstring do_positive_sign() const { return L""; }
31
  std::wstring do_negative_sign() const { return L""; }
32
 
33
  pattern do_neg_format() const
34
  {
35
    pattern pat = { { value, symbol, none, sign } };
36
    return pat;
37
  }
38
};
39
 
40
struct My_money_io_02 : public std::moneypunct<wchar_t, false>
41
{
42
  std::wstring do_curr_symbol() const { return L"%"; }
43
  std::wstring do_positive_sign() const { return L""; }
44
  std::wstring do_negative_sign() const { return L"-"; }
45
 
46
  pattern do_neg_format() const
47
  {
48
    pattern pat = { { value, symbol, sign, none } };
49
    return pat;
50
  }
51
};
52
 
53
struct My_money_io_03 : public std::moneypunct<wchar_t, false>
54
{
55
  std::wstring do_curr_symbol() const { return L"&"; }
56
  std::wstring do_positive_sign() const { return L""; }
57
  std::wstring do_negative_sign() const { return L""; }
58
 
59
  pattern do_neg_format() const
60
  {
61
    pattern pat = { { value, space, symbol, sign } };
62
    return pat;
63
  }
64
};
65
 
66
// When both do_positive_sign and do_negative_sign return an empty
67
// string, patterns of the forms { value, symbol, none, sign },
68
// { value, symbol, sign, none } and { X, Y, symbol, sign } imply
69
// that the symbol is not consumed since no other characters are
70
// needed to complete the format.
71
void test01()
72
{
73
  using namespace std;
74
  typedef istreambuf_iterator<wchar_t> iterator_type;
75
 
76
  bool test __attribute__((unused)) = true;
77
 
78
  // basic construction
79
  locale loc_01(locale::classic(), new My_money_io_01);
80
  locale loc_02(locale::classic(), new My_money_io_02);
81
  locale loc_03(locale::classic(), new My_money_io_03);
82
 
83
  iterator_type end, end01, end02, end03;
84
  wistringstream iss_01, iss_02, iss_03;
85
  iss_01.imbue(loc_01);
86
  iss_02.imbue(loc_02);
87
  iss_03.imbue(loc_03);
88
  // cache the money_get facet
89
  const money_get<wchar_t>& mon_get_01 =
90
    use_facet<money_get<wchar_t> >(iss_01.getloc());
91
  const money_get<wchar_t>& mon_get_02 =
92
    use_facet<money_get<wchar_t> >(iss_02.getloc());
93
  const money_get<wchar_t>& mon_get_03 =
94
    use_facet<money_get<wchar_t> >(iss_03.getloc());
95
 
96
  iss_01.str(L"10$");
97
  iterator_type is_it01(iss_01);
98
  wstring result01;
99
  ios_base::iostate err01 = ios_base::goodbit;
100
  end01 = mon_get_01.get(is_it01, end, false, iss_01, err01, result01);
101
  VERIFY( err01 == ios_base::goodbit );
102
  VERIFY( *end01 == L'$' );
103
 
104
  iss_02.str(L"50%");
105
  iterator_type is_it02(iss_02);
106
  wstring result02;
107
  ios_base::iostate err02 = ios_base::goodbit;
108
  end02 = mon_get_02.get(is_it02, end, false, iss_02, err02, result02);
109
  VERIFY( err02 == ios_base::goodbit );
110
  VERIFY( *end02 == L'%' );
111
 
112
  iss_03.str(L"7 &");
113
  iterator_type is_it03(iss_03);
114
  wstring result03;
115
  ios_base::iostate err03 = ios_base::goodbit;
116
  end03 = mon_get_03.get(is_it03, end, false, iss_03, err03, result03);
117
  VERIFY( err03 == ios_base::goodbit );
118
  VERIFY( *end03 == L'&' );
119
}
120
 
121
int main()
122
{
123
  test01();
124
  return 0;
125
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.