]>
Commit | Line | Data |
---|---|---|
5f8d36fe BK |
1 | // 2000-08-31 Benjamin Kosnik <bkoz@redhat.com> |
2 | ||
3 | // Copyright (C) 2000, 2002, 2003 Free Software Foundation | |
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 2, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING. If not, write to the Free | |
18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | ||
21 | // 22.1.1.1.2 - class locale::facet [lib.locale.facet] | |
22 | ||
23 | #include <cwchar> // for mbstate_t | |
24 | #include <locale> | |
25 | #include <stdexcept> | |
26 | #include <string> | |
27 | #include <iterator> | |
28 | #include <limits> | |
29 | #include <testsuite_hooks.h> | |
30 | ||
31 | // Static counter for use in checking ctors/dtors. | |
32 | static std::size_t counter; | |
33 | ||
34 | class surf : public std::locale::facet | |
35 | { | |
36 | public: | |
37 | static std::locale::id id; | |
38 | surf(size_t refs = 0): std::locale::facet(refs) { ++counter; } | |
39 | ~surf() { --counter; } | |
40 | }; | |
41 | ||
42 | std::locale::id surf::id; | |
43 | ||
44 | typedef surf facet_type; | |
45 | ||
46 | void test02() | |
47 | { | |
48 | using namespace std; | |
11f10e6b | 49 | bool test __attribute__((unused)) = true; |
5f8d36fe BK |
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 | { | |
aecf642c | 86 | locale loc03 = __gnu_test::try_named_locale("es_MX"); |
5f8d36fe BK |
87 | } |
88 | } | |
89 | ||
90 | int main () | |
91 | { | |
3d838e28 | 92 | test02(); |
5f8d36fe BK |
93 | return 0; |
94 | } |