40#ifndef _RWSTD_NO_LONG_DOUBLE
41# define LongDouble long double
43# define LongDouble double
44# define rw_ldblcmp rw_dblcmp
51static int no_basic_string;
58struct Ctype: std::ctype<charT>
60 typedef std::ctype<charT>
Base;
72 case '0':
c =
'9';
break;
73 case '1':
c =
'8';
break;
74 case '2':
c =
'7';
break;
75 case '3':
c =
'6';
break;
76 case '4':
c =
'5';
break;
77 case '5':
c =
'4';
break;
78 case '6':
c =
'3';
break;
79 case '7':
c =
'2';
break;
80 case '8':
c =
'1';
break;
81 case '9':
c =
'0';
break;
90 return Base::do_widen (lo, hi, dst);
106template <
class charT>
115 static std::money_base::pattern
format_ [2][2];
120template <
class charT>
124template <
class charT>
128template <
class charT>
132template <
class charT>
136template <
class charT>
140template <
class charT>
144template <
class charT>
148 std::money_base::symbol, std::money_base::sign,
149 std::money_base::none, std::money_base::value
152 std::money_base::symbol, std::money_base::sign,
153 std::money_base::none, std::money_base::value
159 std::money_base::symbol, std::money_base::sign,
160 std::money_base::none, std::money_base::value
163 std::money_base::symbol, std::money_base::sign,
164 std::money_base::none, std::money_base::value
169template <
class charT>
173template <
class charT,
bool Intl>
176 typedef std::moneypunct<charT, Intl>
Base;
218 return this->
format_ [Intl][0];
222 return this->
format_ [Intl][1];
226template <
class charT,
bool Intl>
232template <
class charT>
233struct Ios: std::basic_ios<charT>
239template <
class charT>
240struct MoneyGet: std::money_get<charT, const charT*> { };
244std::money_base::pattern
247 std::money_base::pattern pat;
249 for (
unsigned i = 0;
i !=
sizeof pat.field /
sizeof *pat.field; ++
i) {
250 switch (format [
i]) {
251 case '\0':
case '@': pat.field [
i] = std::money_base::none;
break;
252 case '\1':
case ' ': pat.field [
i] = std::money_base::space;
break;
253 case '\2':
case '$': pat.field [
i] = std::money_base::symbol;
break;
254 case '\3':
case '-': pat.field [
i] = std::money_base::sign;
break;
255 case '\4':
case '1': pat.field [
i] = std::money_base::value;
break;
265template <
class charT>
277 const char *fmat = 0,
278 const char *cursym = 0,
279 const char *grouping =
"")
282 rw_note (0, __FILE__, __LINE__,
"test on line %d disabled",
lineno);
288 static const std::money_base::pattern pat = { {
289 std::money_base::symbol, std::money_base::sign,
290 std::money_base::none, std::money_base::value
299 const bool locl = !intl;
336 io.imbue (std::locale (io.getloc (),
pf));
340 io.imbue (std::locale (io.getloc (),
pf));
343 io.flags (std::ios_base::fmtflags (
flags));
348 std::ios_base::iostate err = std::ios_base::goodbit;
354 last = next + std::char_traits<charT>::length (next);
358 last = mg.get (next,
last, intl, io, err,
x);
360 if (-1 == err_expect)
364 !((-1 != consumed &&
last - next != consumed) || err != err_expect);
367 "money_get<%s>::get (%{*Ac}, ..., %b, ..., %s&), "
368 "ate %d, expected %d, frac_digits = %d, "
369 "flags = %{If}, grouping = %#s, pattern = %{LM}, "
370 "state = %{Is}, expected %{Is}",
371 cname,
int (
sizeof *next), next, intl, tname,
372 last - next, consumed, frac_digits,
373 flags, grouping, fmat,
377 "money_get<%s>::get (%{*Ac}, ..., %b, ..., %s&), "
378 "got %Lg, expected %Lg, frac_digits = %d, "
379 "flags = %{If}s, grouping = %#s, pattern = %{LM}, "
380 "state = %{Is}, expected %{Is}",
381 cname,
int (
sizeof *next), next, intl, tname,
383 flags, grouping, fmat,
388 static const charT initial[] = {
'*',
'*',
'*',
'\0' };
389 typename std::money_get<charT, const charT*>::string_type bs (initial);
391 last = next + std::char_traits<charT>::length (next);
393 last = mg.get (next,
last, intl, io, err, bs);
396 !((-1 != consumed &&
last - next != consumed) || err != err_expect);
399 "money_get<%s>::get (%{*Ac}, ..., %b, ..., "
400 "basic_string<%s>&), ate %d, expected %d, "
401 "frac_digits = %d, flags = %{If}, grouping = %#s"
402 ", format = %{LM}, state = %{Is}, expected %{Is}",
403 cname,
int (
sizeof *next), next, intl,
404 cname,
last - next, consumed,
405 frac_digits,
flags, grouping,
406 fmat, err, err_expect);
410 char narrow_buf [4096];
418 int n = std::sscanf (narrow_buf, fmt, &
x);
421 !( ( err_expect & std::ios::failbit && !*grouping
422 && (1 ==
n || bs != initial))
423 || ( !(err_expect & std::ios::failbit)
427 "money_get<%s>::get (%{*Ac}, ..., %b, ..., "
428 "basic_string<%s>&), got %s, expected %Lg, "
429 "frac_digits = %d, flags = %{If}, grouping = %#s,"
430 " pattern = %{LM}, iostate = %{Is}, expected %{Is}",
431 cname,
int (
sizeof *next), next, intl,
432 cname, bs.c_str (),
val,
433 frac_digits,
flags, grouping,
434 fmat, err, err_expect);
445#define boolalpha std::ios_base::boolalpha
446#define dec std::ios_base::dec
447#define fixed std::ios_base::fixed
448#define hex std::ios_base::hex
449#define internal std::ios_base::internal
450#define left std::ios_base::left
451#define oct std::ios_base::oct
452#define right std::ios_base::right
453#define scientific std::ios_base::scientific
454#define showbase std::ios_base::showbase
455#define showpoint std::ios_base::showpoint
456#define showpos std::ios_base::showpos
457#define skipws std::ios_base::skipws
458#define unitbuf std::ios_base::unitbuf
459#define uppercase std::ios_base::uppercase
460#define bin std::ios_base::bin
461#define adjustfield std::ios_base::adjustfield
462#define basefield std::ios_base::basefield
463#define floatfield std::ios_base::floatfield
464#define nolock std::ios_base::nolock
465#define nolockbuf std::ios_base::nolockbuf
467#define badbit std::ios_base::badbit
468#define eofbit std::ios_base::eofbit
469#define failbit std::ios_base::failbit
470#define goodbit std::ios_base::goodbit
473template <
class charT>
476#define T intl, opt, cname, tname, __LINE__
479 const bool locl = !intl;
482 "money_get<%s, istreambuf_iterator<%s> >::get "
483 "(..., %s&) const", cname, cname, tname);
564 TEST (
T, 54321098.0,
"5432.1098", 9, 0,
eofbit, 4);
565 TEST (
T, 432109870.0,
"43210.987", 9, 0,
eofbit, 4);
572 TEST (
T, 0.0,
"0,0", 3, 0,
eofbit, 0, 0,
"",
"\1");
573 TEST (
T, 0.0,
"0,", 1, 0,
goodbit, 0, 0,
"",
"\0");
574 TEST (
T, 0.0,
"0,0,0", 5, 0,
eofbit, 0, 0,
"",
"\1");
575 TEST (
T, 1.0,
"0,0,1", 5, 0,
eofbit, 0, 0,
"",
"\1");
576 TEST (
T, 2.0,
"0,0,2.", 5, 0,
goodbit, 0, 0,
"",
"\1");
577 TEST (
T, 30.0,
"0,0,3.", 6, 0,
eofbit, 1, 0,
"",
"\1");
578 TEST (
T, 4.0,
"0,0.4", 5, 0,
eofbit, 1, 0,
"",
"\1");
579 TEST (
T, 5670.0,
"5,67.0", 6, 0,
eofbit, 1, 0,
"",
"\2");
580 TEST (
T, 6789.0,
"678.9", 5, 0,
eofbit, 1, 0,
"",
"\3");
581 TEST (
T, 789012.0,
"7,890.12", 8, 0,
eofbit, 2, 0,
"",
"\3");
584 TEST (
T, 890123.0,
"890.123", 7, 0,
eofbit, 3, 0,
"",
"\1");
585 TEST (
T, 901234.0,
"901.234", 7, 0,
eofbit, 3, 0,
"",
"\2");
586 TEST (
T, 123450.0,
"0123.45", 7, 0,
eofbit, 3, 0,
"",
"\3");
590 TEST (
T, 0.0,
",", 0, 0,
failbit, 0, 0,
"",
"\0");
591 TEST (
T, 0.0,
",0", 0, 0,
failbit, 0, 0,
"",
"\0");
594 TEST (
T, 1.0,
",1", 2, 0,
eofbit |
failbit, 0, 0,
"",
"\1");
595 TEST (
T, 2.0,
"2,", 2, 0,
eofbit |
failbit, 0, 0,
"",
"\1");
596 TEST (
T, 3.0,
",3,", 3, 0,
eofbit |
failbit, 0, 0,
"",
"\1");
597 TEST (
T, 4.0,
",,4", 3, 0,
eofbit |
failbit, 0, 0,
"",
"\1");
598 TEST (
T, 5.0,
"5,,", 3, 0,
eofbit |
failbit, 0, 0,
"",
"\1");
599 TEST (
T, 6.0,
",6,,", 4, 0,
eofbit |
failbit, 0, 0,
"",
"\2");
600 TEST (
T, 7.0,
",,7,", 4, 0,
eofbit |
failbit, 0, 0,
"",
"\2");
601 TEST (
T, 8.0,
"0,,8", 4, 0,
eofbit |
failbit, 0, 0,
"",
"\2");
602 TEST (
T, 9.0,
"0,0,9", 5, 0,
eofbit |
failbit, 0, 0,
"",
"\2");
603 TEST (
T, 10.0,
"0,10,", 5, 0,
eofbit |
failbit, 0, 0,
"",
"\2");
634 TEST (
T, 13.0,
"din13", 5, 0,
eofbit, 0, 0,
"din");
635 TEST (
T, 14.0,
"Esc 14", 6, 0,
eofbit, 0, 0,
"Esc");
639 static const charT plus[][2] = { {
'+',
'\0' }, {
'\0' } };
640 static const charT minus[][2] = { {
'-',
'\0' }, {
'\0' } };
672 static const charT plus_plus[][3] = { {
'+',
'+',
'\0' }, {
'\0' } };
673 static const charT minus_minus[][3] = { {
'-',
'-',
'\0' }, {
'\0' } };
683 TEST (
T, -30.0,
"- 3.09-", 7, 0,
eofbit, 1, 0,
"");
688 TEST (
T, -33.0,
"$-3.30-", 7, 0,
eofbit, 1, 0,
"$");
689 TEST (
T, -34.0,
"$- 3.41-", 8, 0,
eofbit, 1, 0,
"$");
692 TEST (
T, 35.0,
"USD+35+", 7, 0,
eofbit, 0, 0,
"USD");
693 TEST (
T, 36.0,
"USD+ 36+", 9, 0,
eofbit, 0, 0,
"USD");
694 TEST (
T, -37.0,
"USD-3.70-", 9, 0,
eofbit, 1, 0,
"USD");
695 TEST (
T, -38.0,
"USD- 3.81-", 10, 0,
eofbit, 1, 0,
"USD");
709 static const charT plus_minus[][3] = { {
'+',
'-',
'\0' }, {
'\0' } };
757 const charT parens[][3] = { {
'(',
')',
'\0' }, {
'\0' } };
781 TEST (
T, -104.0,
"(104 L)", 7, 0,
eofbit, 0,
"-1@$",
"L");
792 TEST (
T, -101.0,
"-101 $", 4, 0,
goodbit, 0,
"-1@$",
"$");
795 TEST (
T, -103.0,
"-103 $", 4, 0,
goodbit, 0,
"-1 $",
"$");
799 TEST (
T, -105.0,
"-105 $", 4, 0,
goodbit, 0,
"-1$@",
"$");
805 TEST (
T, 107.0,
"107 $", 4, 0,
goodbit, 0,
"1@-$",
"$");
807 TEST (
T, -108.0,
"108-$", 4, 0,
goodbit, 0,
"1@-$",
"$");
811 const charT minus_space[][3] = { {
'-',
' ',
'\0' }, {
'\0' } };
821 TEST (
T, -109.1,
"-109 ", 6, 0,
eofbit, 0,
"-1@$",
"");
866 TEST (
T, 110.0,
"110 $", 3, 0,
goodbit, 0,
"1@-$",
"$");
867 TEST (
T, 111.0,
"111 $", 3, 0,
goodbit, 0,
"1 -$",
"$");
872 TEST (
T, 115.0,
"115 $", 3, 0,
goodbit, 0,
"1@$-",
"$");
873 TEST (
T, 116.0,
"116 $", 3, 0,
goodbit, 0,
"1 $-",
"$");
887 TEST (
T, 0.0,
"$0", 2, 0,
eofbit, 0, 0,
"$",
"\1");
888 TEST (
T, 0.0,
"$0;0", 4, 0,
eofbit, 0, 0,
"$",
"\1");
889 TEST (
T, 0.0,
"$0;0;0", 6, 0,
eofbit, 0, 0,
"$",
"\1");
891 TEST (
T, 0.0,
"$+0", 3, 0,
eofbit, 0, 0,
"$",
"\1");
892 TEST (
T, 0.0,
"$+0;0", 5, 0,
eofbit, 0, 0,
"$",
"\1");
893 TEST (
T, 0.0,
"$+0;0;0", 7, 0,
eofbit, 0, 0,
"$",
"\1");
895 TEST (
T, 0.0,
"$-0.0", 5, 0,
eofbit, 1, 0,
"$",
"\1");
896 TEST (
T, 0.0,
"$-0;0.00", 8, 0,
eofbit, 2, 0,
"$",
"\1");
897 TEST (
T, 0.0,
"$-0;0;0.000", 11, 0,
eofbit, 3, 0,
"$",
"\1");
899 TEST (
T, -10.0,
"$-1.", 4, 0,
eofbit, 1, 0,
"$",
"\1");
900 TEST (
T, -2000.0,
"$-2;0.0000", 10, 0,
eofbit, 2, 0,
"$",
"\1");
901 TEST (
T, -300000.0,
"$-3;0;0.00000", 13, 0,
eofbit, 3, 0,
"$",
"\1");
902 TEST (
T, -300001.0,
"$-3;0;0.00123", 13, 0,
eofbit, 3, 0,
"$",
"\1");
917 TEST (
T, 0.0,
"$+;.0;", 5, 0,
failbit, 1, 0,
"$",
"\1");
919 TEST (
T, -40.0,
"$-4;. ", 5, 0,
failbit, 1, 0,
"$",
"\1");
920 TEST (
T, -5000.0,
"$-;5;0.0000 ", 11, 0,
failbit, 2, 0,
"$",
"\1");
921 TEST (
T, -600000.0,
"$-6;0;;0.00000 ", 14, 0,
failbit, 3, 0,
"$",
"\1");
922 TEST (
T, -700004.0,
"$-7;;0;0.00456 ", 14, 0,
failbit, 3, 0,
"$",
"\1");
924#ifndef _RWSTD_NO_LONG_DOUBLE
925# define LDBL(x) x ## L
930 "$1;2;3;4;5;6;7;8;9;0", 20, 0,
eofbit, 0, 0,
"$",
"\1");
933 "$0;1;2;3;4;5;6;7;8;9;0", 22, 0,
eofbit, 0, 0,
"$",
"\1");
936 "$0;0;1;2;3;4;5;6;7;8;9;0", 24, 0,
eofbit, 0, 0,
"$",
"\1");
939 "$+1;2;3;4;5;6;7;8;9;0", 21, 0,
eofbit, 0, 0,
"$",
"\1");
942 "$+0;1;2;3;4;5;6;7;8;9;0", 23, 0,
eofbit, 0, 0,
"$",
"\1");
945 "$+0;0;1;2;3;4;5;6;7;8;9;0", 25, 0,
eofbit, 0, 0,
"$",
"\1");
948 "$+0;1;2;3;4;5;6;7;8;9;0", 23, 0,
eofbit, 0, 0,
"$",
"\1");
951 "$-1;2;3;4;5;6;7;8;9;0", 21, 0,
eofbit, 0, 0,
"$",
"\1");
954 "$-0;1;2;3;4;5;6;7;8;9;0", 23, 0,
eofbit, 0, 0,
"$",
"\1");
957 "$-0;0;1;2;3;4;5;6;7;8;9;0", 25, 0,
eofbit, 0, 0,
"$",
"\1");
961 "$12;34;56;78;90", 15, 0,
eofbit, 0, 0,
"$",
"\2");
964 "$+12;34;56;78;90", 16, 0,
eofbit, 0, 0,
"$",
"\2");
967 "$-12;34;56;78;90", 16, 0,
eofbit, 0, 0,
"$",
"\2");
975template <
class charT>
980 test_get (opt, cname, tname,
false);
988template <
class charT>
994 cname,
"long double");
996 rw_note (0, __FILE__, __LINE__,
"long double test disabled");
1001template <
class charT>
1007 cname,
"basic_string");
1009 rw_note (0, __FILE__, __LINE__,
1010 "basic_string<%s> test disabled", cname);
1019 rw_fatal (
'\0' == std::money_base::none, 0, 0,
1020 "'\\0' == money_base::none, got %d", std::money_base::none);
1022 rw_fatal (
'\1' == std::money_base::space, 0, 0,
1023 "'\\1' == money_base::space, got %d", std::money_base::space);
1025 rw_fatal (
'\2' == std::money_base::symbol, 0, 0,
1026 "'\\2' == money_base::symbol, got %d", std::money_base::symbol);
1028 rw_fatal (
'\3' == std::money_base::sign, 0, 0,
1029 "'\\3' == money_base::sign, got %d", std::money_base::sign);
1031 rw_fatal (
'\4' == std::money_base::value, 0, 0,
1032 "'\\4' == money_base::value, got %d", std::money_base::value);
1039 rw_note (0, __FILE__, __LINE__,
"char test disabled");
1041#ifndef _RWSTD_NO_WCHAR_T
1048 rw_note (0, __FILE__, __LINE__,
"wchar_t test disabled");
1059 return rw_test (argc, argv, __FILE__,
1060 "lib.locale.money.get",
1062 "|-no-basic_string#",
void test_string(const char *charTname, const std::collate< charT > &co, const char *str1, const char *str2, int expected_val)
void test_long_double(charT, const char *cname)
std::money_base::pattern set_pattern(const char *format)
void test_get(charT opt, const char *cname, const char *tname, bool intl)
void do_test(int line, const char *src, std::size_t resoff, ForwardIterator dummy_iter, const T *, const char *predname)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define _RWSTD_LDBL_PRINTF_PREFIX
#define _RWSTD_ASSERT(ignore)
_TEST_EXPORT char * rw_expand(char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, _RWSTD_SIZE_T *=0)
_TEST_EXPORT char * rw_narrow(char *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX)
_TEST_EXPORT int rw_enabled(const char *name)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_fatal(int expr, const char *filename, int line, const char *fmtspec,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_ldblcmp(long double x, long double y)
Base::char_type char_type
virtual const char_type * do_widen(const char *lo, const char *hi, char_type *dst) const
virtual char_type do_widen(char c) const
static const charT * positive_sign_[2]
static charT decimal_point_[2]
static charT thousands_sep_[2]
static const charT * negative_sign_[2]
static int frac_digits_[2]
static const char * grouping_[2]
static std::money_base::pattern format_[2][2]
static const charT * curr_symbol_[2]
virtual string_type do_negative_sign() const
static char_type decimal_point_
static const char_type * negative_sign_
virtual std::money_base::pattern do_pos_format() const
static const char_type * positive_sign_
int do_frac_digits() const
static int n_thousands_sep_
static const char * grouping_
static const char_type * curr_symbol_
static char_type thousands_sep_
virtual string_type do_curr_symbol() const
char_type do_decimal_point() const
std::moneypunct< charT, Intl > Base
virtual string_type do_positive_sign() const
virtual std::string do_grouping() const
virtual char_type do_thousands_sep() const
Base::char_type char_type
Base::string_type string_type
virtual std::money_base::pattern do_neg_format() const