7.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // { dg-require-namedlocale "is_IS.ISO8859-1" }
  2. // 2001-01-19 Benjamin Kosnik <bkoz@redhat.com>
  3. // Copyright (C) 2001-2022 Free Software Foundation, Inc.
  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 3, or (at your option)
  9. // any later version.
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. // You should have received a copy of the GNU General Public License along
  15. // with this library; see the file COPYING3. If not see
  16. // <http://www.gnu.org/licenses/>.
  17. // 22.1.1 - Class locale [lib.locale]
  18. #include <locale>
  19. #include <string>
  20. #include <testsuite_hooks.h>
  21. void
  22. test02()
  23. {
  24. using namespace std;
  25. const string name_c("C");
  26. const string name_no("*");
  27. string str;
  28. // construct a locale object with the specialized facet.
  29. locale loc_c = locale::classic();
  30. locale loc_is = locale(ISO_8859(1,is_IS));
  31. locale loc_1(locale::classic(),
  32. new numpunct_byname<char>(ISO_8859(1,is_IS)));
  33. // check names
  34. VERIFY( loc_c.name() == name_c );
  35. VERIFY( loc_1.name() == name_no );
  36. // sanity check the constructed locale has the specialized facet.
  37. VERIFY( has_facet<numpunct<char> >(loc_1) );
  38. VERIFY( has_facet<numpunct<char> >(loc_c) );
  39. // attempt to re-synthesize classic locale
  40. locale loc_2 = loc_1.combine<numpunct<char> >(loc_c);
  41. VERIFY( loc_2.name() == name_no );
  42. VERIFY( loc_2 != loc_c );
  43. // extract facet
  44. const numpunct<char>& nump_1 = use_facet<numpunct<char> >(loc_1);
  45. const numpunct<char>& nump_2 = use_facet<numpunct<char> >(loc_2);
  46. const numpunct<char>& nump_c = use_facet<numpunct<char> >(loc_c);
  47. const numpunct<char>& nump_is = use_facet<numpunct<char> >(loc_is);
  48. // sanity check the data is correct.
  49. char dp1 = nump_c.decimal_point();
  50. char th1 = nump_c.thousands_sep();
  51. string g1 = nump_c.grouping();
  52. string t1 = nump_c.truename();
  53. string f1 = nump_c.falsename();
  54. char dp2 = nump_1.decimal_point();
  55. char th2 = nump_1.thousands_sep();
  56. string g2 = nump_1.grouping();
  57. string t2 = nump_1.truename();
  58. string f2 = nump_1.falsename();
  59. char dp3 = nump_2.decimal_point();
  60. char th3 = nump_2.thousands_sep();
  61. string g3 = nump_2.grouping();
  62. string t3 = nump_2.truename();
  63. string f3 = nump_2.falsename();
  64. char dp4 = nump_is.decimal_point();
  65. char th4 = nump_is.thousands_sep();
  66. string g4 = nump_is.grouping();
  67. string t4 = nump_is.truename();
  68. string f4 = nump_is.falsename();
  69. VERIFY( dp1 != dp2 );
  70. VERIFY( th1 != th2 );
  71. VERIFY( dp1 == dp3 );
  72. VERIFY( th1 == th3 );
  73. VERIFY( t1 == t3 );
  74. VERIFY( f1 == f3 );
  75. VERIFY( dp2 == dp4 );
  76. VERIFY( th2 == th4 );
  77. VERIFY( t2 == t4 );
  78. VERIFY( f2 == f4 );
  79. }
  80. int main()
  81. {
  82. test02();
  83. return 0;
  84. }