]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc
1 // Copyright (C) 2007, 2008, 2009 Free Software Foundation
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
20 #include <testsuite_hooks.h>
22 // Based on Langer Kreft "Standard C++ IOStreams and Locales" p 316-318
23 struct base_facet
: public std::locale::facet
25 virtual std::string
msg() const
26 { return "base class"; }
28 static std::locale::id id
;
31 std::locale::id
base_facet::id
;
34 struct derived_facet
: public base_facet
36 virtual std::string
msg() const
37 { return "derived class"; }
39 virtual std::string
msg_repeater() const
40 { return "derived class derived class"; }
48 bool test
__attribute__((unused
)) = true;
54 locale loc_c
= locale::classic();
55 locale
loc_base(loc_c
, new base_facet
);
56 locale
loc_derived(loc_c
, new derived_facet
);
59 VERIFY( has_facet
<std::ctype
<char> >(loc_c
) );
60 VERIFY( has_facet
<std::ctype
<char> >(loc_base
) );
61 VERIFY( has_facet
<std::ctype
<char> >(loc_derived
) );
63 // User defined base facet.
64 VERIFY( !has_facet
<base_facet
>(loc_c
) );
65 VERIFY( has_facet
<base_facet
>(loc_base
) );
66 VERIFY( has_facet
<base_facet
>(loc_derived
) );
68 // User defined derived facet.
69 VERIFY( !has_facet
<derived_facet
>(loc_c
) );
70 VERIFY( !has_facet
<derived_facet
>(loc_base
) );
71 VERIFY( has_facet
<derived_facet
>(loc_derived
) );
77 if (has_facet
<derived_facet
>(loc_base
))
79 use_facet
<derived_facet
>(loc_base
).msg_repeater();
85 // Expect no exception.
92 if (has_facet
<base_facet
>(loc_derived
))
93 use_facet
<base_facet
>(loc_derived
).msg();
99 // Expect no exception.