2.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // { dg-require-namedlocale "es_MX.ISO8859-1" }
  2. // 2000-08-31 Benjamin Kosnik <bkoz@redhat.com>
  3. // Copyright (C) 2000-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.1.2 - class locale::facet [lib.locale.facet]
  18. #include <cwchar> // for mbstate_t
  19. #include <locale>
  20. #include <stdexcept>
  21. #include <string>
  22. #include <iterator>
  23. #include <limits>
  24. #include <testsuite_hooks.h>
  25. // Static counter for use in checking ctors/dtors.
  26. static std::size_t counter;
  27. class surf : public std::locale::facet
  28. {
  29. public:
  30. static std::locale::id id;
  31. surf(size_t refs = 0): std::locale::facet(refs) { ++counter; }
  32. ~surf() { --counter; }
  33. };
  34. std::locale::id surf::id;
  35. typedef surf facet_type;
  36. void test02()
  37. {
  38. using namespace std;
  39. // 1: Destroyed when out of scope.
  40. VERIFY( counter == 0 );
  41. {
  42. locale loc01(locale::classic(), new facet_type);
  43. VERIFY( counter == 1 );
  44. }
  45. VERIFY( counter == 0 );
  46. // 2: Not destroyed when out of scope, deliberately leaked.
  47. VERIFY( counter == 0 );
  48. {
  49. // Default refs argument is zero.
  50. locale loc02(locale::classic(), new facet_type(1));
  51. VERIFY( counter == 1 );
  52. }
  53. VERIFY( counter == 1 );
  54. // 3: Pathological.
  55. counter = 0;
  56. {
  57. // Test bounds.
  58. facet_type* f = new facet_type(numeric_limits<size_t>::max());
  59. VERIFY( counter == 1 );
  60. // Add a reference.
  61. locale loc01(locale::classic(), f);
  62. {
  63. // Add another reference...
  64. locale loc02(locale::classic(), f);
  65. }
  66. VERIFY( counter == 1 );
  67. }
  68. // 4: Named locale should destroy facets when it goes out of scope.
  69. // Not quite sure how to test for this w/o valgrind at the moment.
  70. {
  71. locale loc03 = locale(ISO_8859(1,es_MX));
  72. }
  73. }
  74. int main ()
  75. {
  76. test02();
  77. return 0;
  78. }