13631.cc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // { dg-require-namedlocale "fr_FR.ISO8859-15" }
  2. // Copyright (C) 2014-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License along
  14. // with this library; see the file COPYING3. If not see
  15. // <http://www.gnu.org/licenses/>.
  16. #include <locale>
  17. #include <testsuite_hooks.h>
  18. void test01()
  19. {
  20. // This is defined through CXXFLAGS in scripts/testsuite_flags[.in].
  21. const char* dir = LOCALEDIR;
  22. std::locale l(ISO_8859(15,fr_FR));
  23. typedef std::messages<char> messages;
  24. const messages &msgs_facet = std::use_facet<messages>(l);
  25. messages::catalog msgs = msgs_facet.open("libstdc++", l, dir);
  26. VERIFY( msgs >= 0 );
  27. const char msgid[] = "please";
  28. std::string translation1 = msgs_facet.get(msgs, 0, 0, msgid);
  29. // Without a real translation this test doesn't mean anything:
  30. VERIFY( translation1 != msgid );
  31. // Opening another catalog was enough to show the problem, even a fake
  32. // catalog.
  33. messages::catalog fake_msgs = msgs_facet.open("fake", l);
  34. std::string translation2 = msgs_facet.get(msgs, 0, 0, msgid);
  35. // Close catalogs before doing the check to avoid leaks.
  36. msgs_facet.close(fake_msgs);
  37. msgs_facet.close(msgs);
  38. VERIFY( translation1 == translation2 );
  39. }
  40. void test02()
  41. {
  42. #ifdef _GLIBCXX_USE_WCHAR_T
  43. // This is defined through CXXFLAGS in scripts/testsuite_flags[.in].
  44. const char* dir = LOCALEDIR;
  45. std::locale l(ISO_8859(15,fr_FR));
  46. typedef std::messages<wchar_t> messages;
  47. const messages &msgs_facet = std::use_facet<messages>(l);
  48. messages::catalog msgs = msgs_facet.open("libstdc++", l, dir);
  49. VERIFY( msgs >= 0 );
  50. const wchar_t msgid[] = L"please";
  51. std::wstring translation1 = msgs_facet.get(msgs, 0, 0, msgid);
  52. // Without a real translation this test doesn't mean anything:
  53. VERIFY( !translation1.empty() );
  54. VERIFY( translation1 != msgid );
  55. // Opening another catalog was enough to show the problem, even a fake
  56. // catalog.
  57. messages::catalog fake_msgs = msgs_facet.open("fake", l);
  58. std::wstring translation2 = msgs_facet.get(msgs, 0, 0, msgid);
  59. // Close catalogs before doing the check to avoid leaks.
  60. msgs_facet.close(fake_msgs);
  61. msgs_facet.close(msgs);
  62. VERIFY( translation1 == translation2 );
  63. #endif
  64. }
  65. int main()
  66. {
  67. test01();
  68. test02();
  69. return 0;
  70. }