]>
Commit | Line | Data |
---|---|---|
062bf895 PC |
1 | // Copyright (C) 2004 Free Software Foundation, Inc. |
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 2, 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 COPYING. If not, write to the Free | |
16 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
17 | // USA. | |
18 | ||
19 | // As a special exception, you may use this file as part of a free software | |
20 | // library without restriction. Specifically, if other files instantiate | |
21 | // templates or use macros or inline functions from this file, or you compile | |
22 | // this file and link it with other files to produce an executable, this | |
23 | // file does not by itself cause the resulting executable to be covered by | |
24 | // the GNU General Public License. This exception does not however | |
25 | // invalidate any other reasons why the executable file might be covered by | |
26 | // the GNU General Public License. | |
27 | ||
28 | #include <cstring> // for strlen | |
29 | #include <istream> | |
30 | #include <testsuite_hooks.h> | |
31 | ||
32 | class Inbuf : public std::streambuf | |
33 | { | |
34 | static const char buf[]; | |
35 | const char* current; | |
36 | int size; | |
37 | ||
38 | public: | |
39 | Inbuf() | |
40 | { | |
41 | current = buf; | |
42 | size = std::strlen(buf); | |
43 | } | |
44 | ||
45 | int_type underflow() | |
46 | { | |
47 | if (current < buf + size) | |
48 | return traits_type::to_int_type(*current); | |
49 | return traits_type::eof(); | |
50 | } | |
51 | ||
52 | int_type uflow() | |
53 | { | |
54 | if (current < buf + size) | |
55 | return traits_type::to_int_type(*current++); | |
56 | return traits_type::eof(); | |
57 | } | |
58 | }; | |
59 | ||
60 | const char Inbuf::buf[] = "1234567890abcdefghij"; | |
61 | ||
62 | void test01() | |
63 | { | |
64 | using namespace std; | |
65 | bool test __attribute__((unused)) = true; | |
66 | ||
67 | typedef char_traits<char> traits_type; | |
68 | ||
69 | Inbuf inbuf1; | |
70 | istream is(&inbuf1); | |
71 | ||
72 | char buffer[10]; | |
73 | traits_type::assign(buffer, sizeof(buffer), 'X'); | |
74 | ||
75 | is.getline(buffer, sizeof(buffer), '0'); | |
76 | VERIFY( is.rdstate() == ios_base::goodbit ); | |
77 | VERIFY( !traits_type::compare(buffer, "123456789\0", sizeof(buffer)) ); | |
78 | VERIFY( is.gcount() == 10 ); | |
79 | ||
80 | is.clear(); | |
81 | traits_type::assign(buffer, sizeof(buffer), 'X'); | |
82 | is.getline(buffer, sizeof(buffer)); | |
83 | VERIFY( is.rdstate() == ios_base::failbit ); | |
84 | VERIFY( !traits_type::compare(buffer, "abcdefghi\0", sizeof(buffer)) ); | |
85 | VERIFY( is.gcount() == 9 ); | |
86 | ||
87 | is.clear(); | |
88 | traits_type::assign(buffer, sizeof(buffer), 'X'); | |
89 | is.getline(buffer, sizeof(buffer)); | |
90 | VERIFY( is.rdstate() == ios_base::eofbit ); | |
91 | VERIFY( !traits_type::compare(buffer, "j\0XXXXXXXX", sizeof(buffer)) ); | |
92 | VERIFY( is.gcount() == 1 ); | |
93 | ||
94 | is.clear(); | |
95 | traits_type::assign(buffer, sizeof(buffer), 'X'); | |
96 | is.getline(buffer, sizeof(buffer)); | |
97 | VERIFY( is.rdstate() == (ios_base::eofbit | ios_base::failbit) ); | |
98 | VERIFY( !traits_type::compare(buffer, "\0XXXXXXXXX", sizeof(buffer)) ); | |
99 | VERIFY( is.gcount() == 0 ); | |
100 | } | |
101 | ||
102 | int main() | |
103 | { | |
104 | test01(); | |
105 | return 0; | |
106 | } |