Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / testsuite / 22_locale / numpunct / members / char / cache_1.cc
blobfe69bcc21bbfd96c091d564af80187709edb089d
1 // 2003-07-06 Benjamin Kosnik <bkoz@redhat.com>
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.
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.
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 #include <locale>
22 #include <sstream>
23 #include <ostream>
24 #include <testsuite_hooks.h>
26 class numpunct_checked : public std::numpunct<char>
28 typedef std::numpunct<char> base;
30 public:
31 explicit
32 numpunct_checked(std::size_t refs = 0): base(refs) { }
34 string_type
35 base_truename() const
36 { return base::do_truename(); }
38 protected:
39 virtual string_type
40 do_truename() const
41 { return base::do_truename() + "st"; }
44 // Thwart locale caching strategies that incorrectly overwrite base
45 // class data.
46 void test01()
48 using namespace std;
50 bool test __attribute__((unused)) = true;
51 const string basestr("true");
52 const string derivedstr("truest");
54 const locale loc(locale::classic(), new numpunct_checked);
55 stringbuf sbuf;
56 ostream os(&sbuf);
57 os.setf(ios_base::boolalpha);
59 // Pre-cache sanity check.
60 const numpunct<char>& np = use_facet<numpunct<char> >(loc);
61 VERIFY( np.truename() == derivedstr );
63 // Cache.
64 os.imbue(loc);
65 os << true;
66 VERIFY( sbuf.str() == derivedstr );
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 );
74 int main()
76 test01();
77 return 0;