Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / 22_locale / facet / 2.cc
blob2368849a91fd00bf0abd0354879fcf931c5dadee
1 // { dg-require-namedlocale "" }
3 // 2000-08-31 Benjamin Kosnik <bkoz@redhat.com>
5 // Copyright (C) 2000, 2002, 2003, 2005 Free Software Foundation
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 2, or (at your option)
11 // any later version.
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 COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // USA.
23 // 22.1.1.1.2 - class locale::facet [lib.locale.facet]
25 #include <cwchar> // for mbstate_t
26 #include <locale>
27 #include <stdexcept>
28 #include <string>
29 #include <iterator>
30 #include <limits>
31 #include <testsuite_hooks.h>
33 // Static counter for use in checking ctors/dtors.
34 static std::size_t counter;
36 class surf : public std::locale::facet
38 public:
39 static std::locale::id id;
40 surf(size_t refs = 0): std::locale::facet(refs) { ++counter; }
41 ~surf() { --counter; }
44 std::locale::id surf::id;
46 typedef surf facet_type;
48 void test02()
50 using namespace std;
51 bool test __attribute__((unused)) = true;
53 // 1: Destroyed when out of scope.
54 VERIFY( counter == 0 );
56 locale loc01(locale::classic(), new facet_type);
57 VERIFY( counter == 1 );
59 VERIFY( counter == 0 );
61 // 2: Not destroyed when out of scope, deliberately leaked.
62 VERIFY( counter == 0 );
64 // Default refs argument is zero.
65 locale loc02(locale::classic(), new facet_type(1));
66 VERIFY( counter == 1 );
68 VERIFY( counter == 1 );
70 // 3: Pathological.
71 counter = 0;
73 // Test bounds.
74 facet_type* f = new facet_type(numeric_limits<size_t>::max());
75 VERIFY( counter == 1 );
76 // Add a reference.
77 locale loc01(locale::classic(), f);
79 // Add another reference...
80 locale loc02(locale::classic(), f);
82 VERIFY( counter == 1 );
85 // 4: Named locale should destroy facets when it goes out of scope.
86 // Not quite sure how to test for this w/o valgrind at the moment.
88 locale loc03 = locale("es_MX");
92 int main ()
94 test02();
95 return 0;