2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / inserters_character / wchar_t / 7.cc
blob722ec06e8ae65acbd4fe3e858fc70c05312e7299
1 // 1999-08-16 bkoz
3 // Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 27.6.2.5.4 basic_ostream character inserters
23 #include <string>
24 #include <ostream>
25 #include <sstream>
26 #include <fstream>
27 #include <testsuite_hooks.h>
29 // Global counter, needs to be reset after use.
30 bool used;
32 class gnu_ctype : public std::ctype<wchar_t>
34 protected:
35 char_type
36 do_widen(char c) const
38 used = true;
39 return std::ctype<wchar_t>::do_widen(c);
42 const char*
43 do_widen(const char* low, const char* high, char_type* dest) const
45 used = true;
46 return std::ctype<wchar_t>::do_widen(low, high, dest);
50 // 27.6.2.5.4 - Character inserter template functions
51 // [lib.ostream.inserters.character]
52 void test07()
54 using namespace std;
55 bool test __attribute__((unused)) = true;
57 const char* buffer = "SFPL 5th floor, outside carrol, the Asian side";
59 wostringstream oss;
60 oss.imbue(locale(locale::classic(), new gnu_ctype));
62 // 1
63 // template<class charT, class traits>
64 // basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
65 // const char* s);
66 used = false;
67 oss << buffer;
68 VERIFY( used ); // Only required for char_type != char
69 wstring str = oss.str();
70 wchar_t c1 = oss.widen(buffer[0]);
71 VERIFY( str[0] == c1 );
72 wchar_t c2 = oss.widen(buffer[1]);
73 VERIFY( str[1] == c2 );
75 // 2
76 // template<class charT, class traits>
77 // basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out,
78 // char c);
79 used = false;
80 oss.str(wstring());
81 oss << 'b';
82 VERIFY( used ); // Only required for char_type != char
83 str = oss.str();
84 wchar_t c3 = oss.widen('b');
85 VERIFY( str[0] == c3 );
88 int main()
90 test07();
91 return 0;