OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [22_locale/] [locale/] [global_locale_objects/] [3.cc] - Blame information for rev 742

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
2
 
3
// Copyright (C) 2000, 2002, 2003, 2009 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 3, 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 COPYING3.  If not see
18
// <http://www.gnu.org/licenses/>.
19
 
20
// 22.1.1.5 locale static members [lib.locale.statics]
21
 
22
#include <cwchar> // for mbstate_t
23
#include <locale>
24
#include <testsuite_hooks.h>
25
 
26
// Static counter for use in checking ctors/dtors.
27
static std::size_t counter;
28
 
29
class surf : public std::locale::facet
30
{
31
public:
32
  static std::locale::id                id;
33
  surf(size_t refs = 0): std::locale::facet(refs) { ++counter; }
34
  ~surf() { --counter; }
35
};
36
 
37
std::locale::id surf::id;
38
 
39
typedef surf facet_type;
40
 
41
// Verify lifetimes of global objects.
42
void test03()
43
{
44
  using namespace std;
45
  bool test __attribute__((unused)) = true;
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);
106
}
107
 
108
int main ()
109
{
110
  test03();
111
  return 0;
112
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.