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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_istream/] [sentry/] [pod/] [1.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 1999-10-14 bkoz
2
 
3
// Copyright (C) 1999, 2001, 2003, 2005 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
// As a special exception, you may use this file as part of a free software
22
// library without restriction.  Specifically, if other files instantiate
23
// templates or use macros or inline functions from this file, or you compile
24
// this file and link it with other files to produce an executable, this
25
// file does not by itself cause the resulting executable to be covered by
26
// the GNU General Public License.  This exception does not however
27
// invalidate any other reasons why the executable file might be covered by
28
// the GNU General Public License.
29
 
30
// 27.6.1.1.2 class basic_istream::sentry
31
 
32
#include <istream>
33
#include <sstream>
34
#include <ext/pod_char_traits.h>
35
#include <testsuite_hooks.h>
36
#include <testsuite_character.h>
37
 
38
void test01()
39
{
40
  using namespace std;
41
  using __gnu_test::pod_ushort;
42
  typedef basic_string<pod_ushort>      string_type;
43
  typedef basic_stringbuf<pod_ushort>   stringbuf_type;
44
  typedef basic_istream<pod_ushort>     istream_type;
45
 
46
  bool test __attribute__((unused)) = true;
47
 
48
 
49
  const string_type str01;
50
  stringbuf_type strbuf01;
51
  stringbuf_type strbuf02(str01);
52
  istream_type istr01(&strbuf01);
53
  istream_type istr02(&strbuf02);
54
 
55
  // test negatives
56
  try
57
    {
58
      istream_type::sentry sentry01(istr01);
59
    }
60
  catch (std::bad_cast& obj)
61
    {
62
      // Ok, throws bad_cast because locale has no ctype facet.
63
    }
64
  catch (...)
65
    {
66
      VERIFY( false );
67
    }
68
 
69
  try
70
    {
71
      istream_type::sentry sentry02(istr01, true);
72
    }
73
  catch (std::bad_cast& obj)
74
    {
75
      // Ok, throws bad_cast because locale has no ctype facet.
76
    }
77
  catch (...)
78
    {
79
      VERIFY( false );
80
    }
81
 
82
  // imbued.
83
  const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
84
  istr01.imbue(loc);
85
  try
86
    {
87
      istream_type::sentry sentry01(istr01);
88
      VERIFY( bool(sentry01) == false );
89
    }
90
  catch (...)
91
    {
92
      VERIFY( false );
93
    }
94
 
95
  try
96
    {
97
      istream_type::sentry sentry02(istr01, true);
98
      VERIFY( bool(sentry02) == false );
99
    }
100
  catch (...)
101
    {
102
      VERIFY( false );
103
    }
104
 
105
  // test positive 
106
  try
107
    {
108
      istream_type::sentry sentry03(istr02);
109
    }
110
  catch (std::bad_cast& obj)
111
    {
112
      // Ok, throws bad_cast because locale has no ctype facet.
113
    }
114
  catch (...)
115
    {
116
      VERIFY( false );
117
    }
118
 
119
  try
120
    {
121
      istream_type::sentry sentry04(istr02, true);
122
    }
123
  catch (std::bad_cast& obj)
124
    {
125
      // Ok, throws bad_cast because locale has no ctype facet.
126
    }
127
  catch (...)
128
    {
129
      VERIFY( false );
130
    }
131
 
132
  // imbued.
133
  istr02.imbue(loc);
134
  try
135
    {
136
      istr02.clear();
137
      istream_type::sentry sentry03(istr02);
138
      // ... as eofbit set.
139
      VERIFY( bool(sentry03) == false );
140
    }
141
  catch (...)
142
    {
143
      VERIFY( false );
144
    }
145
 
146
  try
147
    {
148
      istr02.clear();
149
      istream_type::sentry sentry04(istr02, true);
150
      VERIFY( bool(sentry04) == true );
151
    }
152
  catch (...)
153
    {
154
      VERIFY( false );
155
    }
156
}
157
 
158
#if !__GXX_WEAK__
159
// Explicitly instantiate for systems with no COMDAT or weak support.
160
template
161
  std::basic_string<__gnu_test::pod_ushort>::size_type
162
  std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
163
 
164
template
165
  __gnu_test::pod_ushort
166
  std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
167
#endif
168
 
169
int main()
170
{
171
  test01();
172
  return 0;
173
}

powered by: WebSVN 2.1.0

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