]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/numpunct/members/wchar_t/cache_1.cc
locale_facets.tcc: Tweak to avoid warnings.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / numpunct / members / wchar_t / cache_1.cc
1 // 2003-07-06 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2003 Free Software Foundation, Inc.
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 2, 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 COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 #include <locale>
22 #include <sstream>
23 #include <ostream>
24 #include <testsuite_hooks.h>
25
26 class numpunct_checked : public std::numpunct<wchar_t>
27 {
28 typedef std::numpunct<wchar_t> base;
29
30 public:
31 explicit
32 numpunct_checked(std::size_t refs = 0): base(refs) { }
33
34 string_type
35 base_truename() const
36 { return base::do_truename(); }
37
38 protected:
39 virtual string_type
40 do_truename() const
41 { return base::do_truename() + L"st"; }
42 };
43
44 // Thwart locale caching strategies that incorrectly overwrite base
45 // class data.
46 void test01()
47 {
48 using namespace std;
49
50 bool test __attribute__((unused)) = true;
51 const wstring basestr(L"true");
52 const wstring derivedstr(L"truest");
53
54 const locale loc(locale::classic(), new numpunct_checked);
55 wstringbuf sbuf;
56 wostream os(&sbuf);
57 os.setf(ios_base::boolalpha);
58
59 // Pre-cache sanity check.
60 const numpunct<wchar_t>& np = use_facet<numpunct<wchar_t> >(loc);
61 VERIFY( np.truename() == derivedstr );
62
63 // Cache.
64 os.imbue(loc);
65 os << true;
66 VERIFY( sbuf.str() == derivedstr );
67
68 // Post-cache sanity check, make sure that base class is still fine.
69 VERIFY( np.truename() == derivedstr );
70 const numpunct_checked& npd = static_cast<const numpunct_checked&>(np);
71 VERIFY( npd.base_truename() == basestr );
72 }
73
74 int main()
75 {
76 test01();
77 return 0;
78 }