]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / global_locale_objects / 3.cc
CommitLineData
8a17a7b4
BK
1// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
2
748086b7 3// Copyright (C) 2000, 2002, 2003, 2009 Free Software Foundation
8a17a7b4
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
8a17a7b4
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
8a17a7b4
BK
19
20// 22.1.1.5 locale static members [lib.locale.statics]
21
4bc95009 22#include <cwchar> // for mbstate_t
8a17a7b4 23#include <locale>
402a402c 24#include <testsuite_hooks.h>
8a17a7b4 25
402a402c
BK
26// Static counter for use in checking ctors/dtors.
27static std::size_t counter;
28
29class surf : public std::locale::facet
30{
31public:
32 static std::locale::id id;
33 surf(size_t refs = 0): std::locale::facet(refs) { ++counter; }
34 ~surf() { --counter; }
35};
36
37std::locale::id surf::id;
38
39typedef surf facet_type;
40
41// Verify lifetimes of global objects.
42void test03()
43{
44 using namespace std;
11f10e6b 45 bool test __attribute__((unused)) = true;
402a402c
BK
46
47 string name;
48 locale global_orig;
49 // 1: Destroyed when out of scope.
50 {
51 {
52 {
53 VERIFY( counter == 0 );
54 {
55 locale loc01(locale::classic(), new facet_type);
56 VERIFY( counter == 1 );
57 global_orig = locale::global(loc01);
58 name = loc01.name();
59 }
60 VERIFY( counter == 1 );
61 locale loc02 = locale();
62 // Weak, but it's something...
63 VERIFY( loc02.name() == name );
64 }
65 VERIFY( counter == 1 );
66 // NB: loc03 should be a copy of the previous global locale.
67 locale loc03 = locale::global(global_orig);
68 VERIFY( counter == 1 );
69 VERIFY( loc03.name() == name );
70 }
71 VERIFY( counter == 0 );
72 locale loc04 = locale();
73 VERIFY( loc04 == global_orig );
74 }
75
76 // 2: Not destroyed when out of scope, deliberately leaked.
77 {
78 {
79 {
80 VERIFY( counter == 0 );
81 {
82 locale loc01(locale::classic(), new facet_type(1));
83 VERIFY( counter == 1 );
84 global_orig = locale::global(loc01);
85 name = loc01.name();
86 }
87 VERIFY( counter == 1 );
88 locale loc02 = locale();
89 // Weak, but it's something...
90 VERIFY( loc02.name() == name );
91 }
92 VERIFY( counter == 1 );
93 // NB: loc03 should be a copy of the previous global locale.
94 locale loc03 = locale::global(global_orig);
95 VERIFY( counter == 1 );
96 VERIFY( loc03.name() == name );
97 }
98 VERIFY( counter == 1 );
99 locale loc04 = locale();
100 VERIFY( loc04 == global_orig );
101 }
102 VERIFY( counter == 1 );
103
104 // Restore global settings.
105 locale::global(global_orig);
8a17a7b4
BK
106}
107
108int main ()
109{
402a402c 110 test03();
8a17a7b4
BK
111 return 0;
112}