| 1 |
// 1999-10-14 bkoz |
| 2 |
|
| 3 |
// Copyright (C) 1999-2025 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 3, 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 COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
|
| 21 |
// 27.6.1.1.2 class basic_istream::sentry |
| 22 |
|
| 23 |
#include <ostream> |
| 24 |
#include <sstream> |
| 25 |
#include <typeinfo> |
| 26 |
#include <ext/pod_char_traits.h> |
| 27 |
#include <testsuite_hooks.h> |
| 28 |
#include <testsuite_character.h> |
| 29 |
|
| 30 |
void test01() |
| 31 |
{ |
| 32 |
using namespace std; |
| 33 |
using __gnu_test::pod_ushort; |
| 34 |
typedef basic_string<pod_ushort> string_type; |
| 35 |
typedef basic_stringbuf<pod_ushort> stringbuf_type; |
| 36 |
typedef basic_ostream<pod_ushort> ostream_type; |
| 37 |
|
| 38 |
const string_type str01; |
| 39 |
stringbuf_type* strbuf01 = 0; |
| 40 |
stringbuf_type strbuf02(str01); |
| 41 |
ostream_type ostr01(strbuf01); |
| 42 |
ostream_type ostr02(&strbuf02); |
| 43 |
|
| 44 |
// test negatives |
| 45 |
try |
| 46 |
{ |
| 47 |
ostream_type::sentry sentry01(ostr01); |
| 48 |
} |
| 49 |
catch (std::bad_cast& obj) |
| 50 |
{ |
| 51 |
// Not ok, throws bad_cast because locale has no ctype facet, |
| 52 |
// but none is needed for ostream::sentry. |
| 53 |
VERIFY( false ); |
| 54 |
} |
| 55 |
catch (...) |
| 56 |
{ |
| 57 |
VERIFY( false ); |
| 58 |
} |
| 59 |
|
| 60 |
// imbued. |
| 61 |
const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>); |
| 62 |
ostr01.imbue(loc); |
| 63 |
try |
| 64 |
{ |
| 65 |
ostream_type::sentry sentry01(ostr01); |
| 66 |
VERIFY( bool(sentry01) == false ); |
| 67 |
} |
| 68 |
catch (...) |
| 69 |
{ |
| 70 |
VERIFY( false ); |
| 71 |
} |
| 72 |
|
| 73 |
// test positive |
| 74 |
try |
| 75 |
{ |
| 76 |
ostream_type::sentry sentry03(ostr02); |
| 77 |
} |
| 78 |
catch (std::bad_cast& obj) |
| 79 |
{ |
| 80 |
// Not ok, throws bad_cast because locale has no ctype facet, |
| 81 |
// but none is needed for ostream::sentry. |
| 82 |
VERIFY( false ); |
| 83 |
} |
| 84 |
catch (...) |
| 85 |
{ |
| 86 |
VERIFY( false ); |
| 87 |
} |
| 88 |
|
| 89 |
// imbued. |
| 90 |
ostr02.clear(); |
| 91 |
ostr02.imbue(loc); |
| 92 |
try |
| 93 |
{ |
| 94 |
ostream_type::sentry sentry03(ostr02); |
| 95 |
VERIFY( bool(sentry03) == true ); |
| 96 |
} |
| 97 |
catch (...) |
| 98 |
{ |
| 99 |
VERIFY( false ); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
#if !__GXX_WEAK__ |
| 104 |
// Explicitly instantiate for systems with no COMDAT or weak support. |
| 105 |
template |
| 106 |
const std::basic_string<__gnu_test::pod_ushort>::size_type |
| 107 |
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; |
| 108 |
|
| 109 |
template |
| 110 |
const __gnu_test::pod_ushort |
| 111 |
std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; |
| 112 |
#endif |
| 113 |
|
| 114 |
int main() |
| 115 |
{ |
| 116 |
test01(); |
| 117 |
return 0; |
| 118 |
} |