]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / getline / wchar_t / 1.cc
1 // Copyright (C) 2004, 2009 Free Software Foundation
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 27.6.1.3 unformatted input functions
19
20 #include <istream>
21 #include <sstream>
22 #include <testsuite_hooks.h>
23
24 void
25 test02()
26 {
27 typedef std::char_traits<wchar_t> traits_type;
28
29 bool test __attribute__((unused)) = true;
30 const wchar_t str_lit01[] = L"\t\t\t sun*ra \n"
31 L" "
32 L"and his myth science arkestra present\n"
33 L" "
34 L"angles and demons @ play\n"
35 L" "
36 L"the nubians of plutonia";
37 std::wstring str01(str_lit01);
38 std::wstring strtmp;
39
40 std::wstringbuf sbuf_04(str01, std::ios_base::in);
41
42 std::wistream is_00(NULL);
43 std::wistream is_04(&sbuf_04);
44 std::ios_base::iostate state1, state2, statefail, stateeof;
45 statefail = std::ios_base::failbit;
46 stateeof = std::ios_base::eofbit;
47 wchar_t carray1[400] = L"";
48
49 // istream& getline(wchar_t* s, streamsize n, wchar_t delim)
50 // istream& getline(wchar_t* s, streamsize n)
51 state1 = is_00.rdstate();
52 is_00.getline(carray1, 20, L'*');
53 state2 = is_00.rdstate();
54 // make sure failbit was set, since we couldn't extract
55 // from the NULL streambuf...
56 VERIFY( state1 != state2 );
57 VERIFY( static_cast<bool>(state2 & statefail) );
58
59 VERIFY( is_04.gcount() == 0 );
60 state1 = is_04.rdstate();
61 is_04.getline(carray1, 1, L'\t'); // extracts, throws away
62 state2 = is_04.rdstate();
63 VERIFY( is_04.gcount() == 1 );
64 VERIFY( state1 == state2 );
65 VERIFY( state1 == 0 );
66 VERIFY( !traits_type::compare(L"", carray1, 1) );
67
68 state1 = is_04.rdstate();
69 is_04.getline(carray1, 20, L'*');
70 state2 = is_04.rdstate();
71 VERIFY( is_04.gcount() == 10 );
72 VERIFY( state1 == state2 );
73 VERIFY( state1 == 0 );
74 VERIFY( !traits_type::compare(L"\t\t sun", carray1, 10) );
75
76 state1 = is_04.rdstate();
77 is_04.getline(carray1, 20);
78 state2 = is_04.rdstate();
79 VERIFY( is_04.gcount() == 4 );
80 VERIFY( state1 == state2 );
81 VERIFY( state1 == 0 );
82 VERIFY( !traits_type::compare(L"ra ", carray1, 4) );
83
84 state1 = is_04.rdstate();
85 is_04.getline(carray1, 65);
86 state2 = is_04.rdstate();
87 VERIFY( is_04.gcount() == 64 );
88 VERIFY( state1 != state2 );
89 VERIFY( state2 == statefail );
90 VERIFY( !traits_type::compare(
91 L" and his myth science arkestra presen",
92 carray1, 65) );
93
94 is_04.clear();
95 state1 = is_04.rdstate();
96 is_04.getline(carray1, 120, L'|');
97 state2 = is_04.rdstate();
98 VERIFY( is_04.gcount() == 106 );
99 VERIFY( state1 != state2 );
100 VERIFY( state2 == stateeof );
101
102 is_04.clear();
103 state1 = is_04.rdstate();
104 is_04.getline(carray1, 100, L'|');
105 state2 = is_04.rdstate();
106 VERIFY( is_04.gcount() == 0 );
107 VERIFY( state1 != state2 );
108 VERIFY( static_cast<bool>(state2 & stateeof) );
109 VERIFY( static_cast<bool>(state2 & statefail) );
110 }
111
112 int
113 main()
114 {
115 test02();
116 return 0;
117 }