]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / getline / wchar_t / 2.cc
CommitLineData
a945c346 1// Copyright (C) 2004-2024 Free Software Foundation, Inc.
75a25e3f
PC
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
748086b7 6// Free Software Foundation; either version 3, or (at your option)
75a25e3f
PC
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
748086b7
JJ
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
75a25e3f
PC
17
18// 27.6.1.3 unformatted input functions
19
20#include <cwchar> // for wcslen
21#include <istream>
22#include <sstream>
23#include <testsuite_hooks.h>
24
25// [patch] bits/istream.tcc - getline(char_type*,streamsize,char_type)
26// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00003.html
27void
28test05()
29{
30 const wchar_t* charray = L"\n"
31L"a\n"
32L"aa\n"
33L"aaa\n"
34L"aaaa\n"
35L"aaaaa\n"
36L"aaaaaa\n"
37L"aaaaaaa\n"
38L"aaaaaaaa\n"
39L"aaaaaaaaa\n"
40L"aaaaaaaaaa\n"
41L"aaaaaaaaaaa\n"
42L"aaaaaaaaaaaa\n"
43L"aaaaaaaaaaaaa\n"
44L"aaaaaaaaaaaaaa\n";
45
75a25e3f
PC
46 const std::streamsize it = 5;
47 std::streamsize br = 0;
48 wchar_t tmp[it];
49 std::wstringbuf sb(charray, std::ios_base::in);
50 std::wistream ifs(&sb);
51 std::streamsize blen = std::wcslen(charray);
52 VERIFY(!(!ifs));
53 while(ifs.getline(tmp, it) || ifs.gcount())
54 {
55 br += ifs.gcount();
56 if(ifs.eof())
57 {
58 // Just sanity checks to make sure we've extracted the same
59 // number of chars that were in the streambuf
60 VERIFY( br == blen );
61 // Also, we should only set the failbit if we could
62 // _extract_ no chars from the stream, i.e. the first read
63 // returned EOF.
64 VERIFY( ifs.fail() && ifs.gcount() == 0 );
65 }
66 else if(ifs.fail())
67 {
68 // delimiter not read
69 //
70 // either
71 // -> extracted no characters
72 // or
73 // -> n - 1 characters are stored
74 ifs.clear(ifs.rdstate() & ~std::ios::failbit);
75 VERIFY( (ifs.gcount() == 0) || (std::wcslen(tmp) == it - 1) );
76 VERIFY( !(!ifs) );
77 continue;
78 }
79 else
80 {
81 // delimiter was read.
82 //
83 // -> wcslen(__s) < n - 1
fcfbdb74 84 // -> delimiter was seen -> gcount() > wcslen(__s)
75a25e3f
PC
85 VERIFY( ifs.gcount() == static_cast<std::streamsize>(std::wcslen(tmp)
86 + 1) );
87 continue;
88 }
89 }
90}
91
92int
93main()
94{
95 test05();
96 return 0;
97}