Annotation of OpenXM_contrib/gmp/tests/cxx/t-locale.cc, Revision 1.1.1.1
1.1 ohara 1: /* Test locale support in C++ functions, or attempt to do so.
2:
3: Copyright 2001 Free Software Foundation, Inc.
4:
5: This file is part of the GNU MP Library.
6:
7: The GNU MP Library is free software; you can redistribute it and/or modify
8: it under the terms of the GNU Lesser General Public License as published by
9: the Free Software Foundation; either version 2.1 of the License, or (at your
10: option) any later version.
11:
12: The GNU MP Library is distributed in the hope that it will be useful, but
13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15: License for more details.
16:
17: You should have received a copy of the GNU Lesser General Public License
18: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20: MA 02111-1307, USA. */
21:
22: #include "config.h"
23:
24: #include <strstream.h>
25:
26: #include <stdio.h>
27: #include <stdlib.h>
28: #include <string.h>
29:
30: #if HAVE_LOCALE_H
31: #include <locale.h> /* for lconv */
32: #endif
33:
34: #include "gmp.h"
35: #include "gmp-impl.h"
36: #include "tests.h"
37:
38:
39: #if HAVE_LOCALECONV
40:
41: char *decimal_point;
42:
43: /* Replace the libc localeconv with one we can manipulate. */
44: struct lconv *
45: localeconv (void)
46: {
47: static struct lconv l;
48: l.decimal_point = decimal_point;
49: return &l;
50: }
51:
52: void
53: check_input (void)
54: {
55: static char *point[] = {
56: ".", ",", "xy", "xyz", "xyz***"
57: };
58:
59: static const struct {
60: const char *str;
61: double d;
62: } data[] = {
63:
64: { "1%s", 1.0 },
65: { "1%s0", 1.0 },
66: { "1%s00", 1.0 },
67:
68: { "%s5", 0.5 },
69: { "0%s5", 0.5 },
70: { "00%s5", 0.5 },
71: { "00%s50", 0.5 },
72:
73: { "1%s5", 1.5 },
74: { "1%s5e1", 15.0 },
75: };
76:
77: mpf_t f;
78: double d;
79: mpf_init (f);
80:
81: for (size_t i = 0; i < numberof (point); i++)
82: {
83: decimal_point = point[i];
84:
85: for (int neg = 0; neg <= 1; neg++)
86: {
87: for (size_t j = 0; j < numberof (data); j++)
88: {
89: char str[128];
90: strcpy (str, neg ? "-" : "");
91: sprintf (str+strlen(str), data[j].str, decimal_point);
92:
93: mpf_set_d (f, 123.0);
94: istrstream i (str);
95: if (! (i >> f))
96: {
97: printf ("operator>> input error\n");
98: printf (" point %s\n", decimal_point);
99: printf (" str %s\n", str);
100: abort ();
101: }
102: d = data[j].d;
103: if (neg)
104: d = -d;
105: if (mpf_cmp_d (f, d) != 0)
106: {
107: printf ("operator>> wrong result\n");
108: printf (" point %s\n", decimal_point);
109: printf (" str %s\n", str);
110: mpf_trace (" f", f);
111: printf (" d=%g\n", d);
112: abort ();
113: }
114: }
115: }
116: }
117:
118: mpf_clear (f);
119: }
120:
121: int
122: main (void)
123: {
124: tests_start ();
125:
126: {
127: mpf_t f;
128: mpf_init (f);
129: decimal_point = ",";
130: mpf_set_d (f, 1.5);
131: ostrstream got;
132: got << f << '\0';
133: mpf_clear (f);
134: if (strcmp (got.str(), "1,5") != 0)
135: {
136: printf ("Test skipped, replacing localeconv doesn't work\n");
137: goto done;
138: }
139: }
140:
141: check_input ();
142:
143: done:
144: tests_end ();
145: exit (0);
146: }
147:
148:
149: #else
150:
151: int
152: main (void)
153: {
154: printf ("Test skipped, no locale support\n");
155: exit (0);
156: }
157:
158: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>