1 /* Test locale support in C++ functions.
3 Copyright 2001, 2002, 2003, 2007 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
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 3 of the License, or (at your
10 option) any later version.
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.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
36 // Like std::numpunct, but with decimal_point coming from point_string[].
37 class my_numpunct : public numpunct<char> {
39 explicit my_numpunct (size_t r = 0) : numpunct<char>(r) { }
41 char do_decimal_point() const { return point_string[0]; }
51 locale loc (locale::classic(), new my_numpunct ());
79 static char point[] = {
86 for (size_t i = 0; i < numberof (point); i++)
90 for (int neg = 0; neg <= 1; neg++)
92 for (size_t j = 0; j < numberof (data); j++)
94 string str = string(data[j].str1)+point[i]+string(data[j].str2);
98 istringstream is (str.c_str());
100 mpf_set_ui (got, 123); // dummy initial value
104 cout << "istream mpf_t operator>> error\n";
105 cout << " point " << point[i] << "\n";
106 cout << " str \"" << str << "\"\n";
107 cout << " localeconv point \""
108 << localeconv()->decimal_point << "\"\n";
112 double want = data[j].want;
115 if (mpf_cmp_d (got, want) != 0)
117 cout << "istream mpf_t operator>> wrong\n";
118 cout << " point " << point[i] << "\n";
119 cout << " str \"" << str << "\"\n";
120 cout << " got " << got << "\n";
121 cout << " want " << want << "\n";
122 cout << " localeconv point \""
123 << localeconv()->decimal_point << "\"\n";
136 static char point[] = {
137 '.', ',', 'x', '\xFF'
140 for (size_t i = 0; i < numberof (point); i++)
142 set_point (point[i]);
151 string want = string("1") + point[i] + string("5");
153 if (want.compare (got.str()) != 0)
155 cout << "ostream mpf_t operator<< doesn't respect locale\n";
156 cout << " point " << point[i] << "\n";
157 cout << " got \"" << got.str() << "\"\n";
158 cout << " want \"" << want << "\"\n";
165 replacement_works (void)
175 return (s.str().compare("1x5") == 0);
183 if (replacement_works())
190 cout << "Replacing decimal point didn't work, tests skipped\n";