]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/facet/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / facet / 2.cc
1 // { dg-require-namedlocale "es_MX.ISO8859-1" }
2
3 // 2000-08-31 Benjamin Kosnik <bkoz@redhat.com>
4
5 // Copyright (C) 2000-2019 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 // 22.1.1.1.2 - class locale::facet [lib.locale.facet]
23
24 #include <cwchar> // for mbstate_t
25 #include <locale>
26 #include <stdexcept>
27 #include <string>
28 #include <iterator>
29 #include <limits>
30 #include <testsuite_hooks.h>
31
32 // Static counter for use in checking ctors/dtors.
33 static std::size_t counter;
34
35 class surf : public std::locale::facet
36 {
37 public:
38 static std::locale::id id;
39 surf(size_t refs = 0): std::locale::facet(refs) { ++counter; }
40 ~surf() { --counter; }
41 };
42
43 std::locale::id surf::id;
44
45 typedef surf facet_type;
46
47 void test02()
48 {
49 using namespace std;
50
51 // 1: Destroyed when out of scope.
52 VERIFY( counter == 0 );
53 {
54 locale loc01(locale::classic(), new facet_type);
55 VERIFY( counter == 1 );
56 }
57 VERIFY( counter == 0 );
58
59 // 2: Not destroyed when out of scope, deliberately leaked.
60 VERIFY( counter == 0 );
61 {
62 // Default refs argument is zero.
63 locale loc02(locale::classic(), new facet_type(1));
64 VERIFY( counter == 1 );
65 }
66 VERIFY( counter == 1 );
67
68 // 3: Pathological.
69 counter = 0;
70 {
71 // Test bounds.
72 facet_type* f = new facet_type(numeric_limits<size_t>::max());
73 VERIFY( counter == 1 );
74 // Add a reference.
75 locale loc01(locale::classic(), f);
76 {
77 // Add another reference...
78 locale loc02(locale::classic(), f);
79 }
80 VERIFY( counter == 1 );
81 }
82
83 // 4: Named locale should destroy facets when it goes out of scope.
84 // Not quite sure how to test for this w/o valgrind at the moment.
85 {
86 locale loc03 = locale(ISO_8859(1,es_MX));
87 }
88 }
89
90 int main ()
91 {
92 test02();
93 return 0;
94 }