]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/facet/2.cc
1 // { dg-require-namedlocale "es_MX" }
3 // 2000-08-31 Benjamin Kosnik <bkoz@redhat.com>
5 // Copyright (C) 2000-2014 Free Software Foundation, Inc.
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)
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.
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/>.
22 // 22.1.1.1.2 - class locale::facet [lib.locale.facet]
24 #include <cwchar> // for mbstate_t
30 #include <testsuite_hooks.h>
32 // Static counter for use in checking ctors/dtors.
33 static std::size_t counter
;
35 class surf
: public std::locale::facet
38 static std::locale::id id
;
39 surf(size_t refs
= 0): std::locale::facet(refs
) { ++counter
; }
40 ~surf() { --counter
; }
43 std::locale::id
surf::id
;
45 typedef surf facet_type
;
50 bool test
__attribute__((unused
)) = true;
52 // 1: Destroyed when out of scope.
53 VERIFY( counter
== 0 );
55 locale
loc01(locale::classic(), new facet_type
);
56 VERIFY( counter
== 1 );
58 VERIFY( counter
== 0 );
60 // 2: Not destroyed when out of scope, deliberately leaked.
61 VERIFY( counter
== 0 );
63 // Default refs argument is zero.
64 locale
loc02(locale::classic(), new facet_type(1));
65 VERIFY( counter
== 1 );
67 VERIFY( counter
== 1 );
73 facet_type
* f
= new facet_type(numeric_limits
<size_t>::max());
74 VERIFY( counter
== 1 );
76 locale
loc01(locale::classic(), f
);
78 // Add another reference...
79 locale
loc02(locale::classic(), f
);
81 VERIFY( counter
== 1 );
84 // 4: Named locale should destroy facets when it goes out of scope.
85 // Not quite sure how to test for this w/o valgrind at the moment.
87 locale loc03
= locale("es_MX");