1 // Copyright (C) 2007, 2008 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 2, 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 COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 #include <testsuite_hooks.h>
23 // Based on Langer Kreft "Standard C++ IOStreams and Locales" p 316-318
24 struct base_facet
: public std::locale::facet
26 virtual std::string
msg() const
27 { return "base class"; }
29 static std::locale::id id
;
32 std::locale::id
base_facet::id
;
35 struct derived_facet
: public base_facet
37 virtual std::string
msg() const
38 { return "derived class"; }
40 virtual std::string
msg_repeater() const
41 { return "derived class derived class"; }
49 bool test
__attribute__((unused
)) = true;
55 locale loc_c
= locale::classic();
56 locale
loc_base(loc_c
, new base_facet
);
57 locale
loc_derived(loc_c
, new derived_facet
);
60 VERIFY( has_facet
<std::ctype
<char> >(loc_c
) );
61 VERIFY( has_facet
<std::ctype
<char> >(loc_base
) );
62 VERIFY( has_facet
<std::ctype
<char> >(loc_derived
) );
64 // User defined base facet.
65 VERIFY( !has_facet
<base_facet
>(loc_c
) );
66 VERIFY( has_facet
<base_facet
>(loc_base
) );
67 VERIFY( has_facet
<base_facet
>(loc_derived
) );
69 // User defined derived facet.
70 VERIFY( !has_facet
<derived_facet
>(loc_c
) );
71 VERIFY( !has_facet
<derived_facet
>(loc_base
) );
72 VERIFY( has_facet
<derived_facet
>(loc_derived
) );
78 if (has_facet
<derived_facet
>(loc_base
))
80 use_facet
<derived_facet
>(loc_base
).msg_repeater();
86 // Expect no exception.
93 if (has_facet
<base_facet
>(loc_derived
))
94 use_facet
<base_facet
>(loc_derived
).msg();
100 // Expect no exception.