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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [22_locale/] [numpunct/] [members/] [char/] [cache_1.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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<char>
27
{
28
  typedef std::numpunct<char> 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() + "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 string  basestr("true");
52
  const string  derivedstr("truest");
53
 
54
  const locale  loc(locale::classic(), new numpunct_checked);
55
  stringbuf     sbuf;
56
  ostream       os(&sbuf);
57
  os.setf(ios_base::boolalpha);
58
 
59
  // Pre-cache sanity check.
60
  const numpunct<char>& np = use_facet<numpunct<char> >(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
}

powered by: WebSVN 2.1.0

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