2 #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
12 # include "full_streambuf.h"
13 # include "cppunit/cppunit_proxy.h"
15 # if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
19 //The macro value gives approximately the generated file
21 //#define CHECK_BIG_FILE 4
23 # if (!defined(STLPORT) && (defined (__GNUC__) && (__GNUC__ > 3))) || \
24 (defined (STLPORT) && !defined (_STLP_NO_CUSTOM_IO) && !defined (_STLP_NO_MEMBER_TEMPLATES) && \
25 !((defined (_STLP_MSVC) && (_STLP_MSVC < 1300)) || \
26 (defined (__GNUC__) && (__GNUC__ < 3)) || \
27 (defined (__SUNPRO_CC)) || \
28 (defined (__DMC__) && defined (_DLL))))
29 # define DO_CUSTOM_FACET_TEST
35 class FstreamTest : public CPPUNIT_NS::TestCase
37 CPPUNIT_TEST_SUITE(FstreamTest);
40 CPPUNIT_TEST(input_char);
48 CPPUNIT_TEST(streambuf_output);
49 CPPUNIT_TEST(win32_file_format);
50 CPPUNIT_TEST(null_stream);
51 # if defined (STLPORT) && (defined (_STLP_NO_WCHAR_T) || !defined (_STLP_USE_EXCEPTIONS))
54 CPPUNIT_TEST(null_buf);
55 # if !defined (STLPORT) || !defined (_STLP_WIN32)
58 # if defined (CHECK_BIG_FILE)
59 CPPUNIT_TEST(big_file);
61 # if !defined (DO_CUSTOM_FACET_TEST)
64 CPPUNIT_TEST(custom_facet);
65 CPPUNIT_TEST_SUITE_END();
78 void streambuf_output();
79 void win32_file_format();
82 # if !defined (STLPORT) || !defined (_STLP_WIN32)
86 # if defined (CHECK_BIG_FILE)
91 CPPUNIT_TEST_SUITE_REGISTRATION(FstreamTest);
94 // tests implementation
96 void FstreamTest::output()
98 ofstream f( "test_file.txt" );
101 CPPUNIT_ASSERT (f.good());
103 CPPUNIT_ASSERT (f.good());
105 CPPUNIT_ASSERT (f.good());
107 CPPUNIT_ASSERT (f.good());
109 CPPUNIT_ASSERT (f.good());
111 CPPUNIT_ASSERT (f.good());
113 CPPUNIT_ASSERT (f.good());
115 CPPUNIT_ASSERT (f.good());
117 f << 1 << '\n' << 2.0 << '\n' << "abcd\n" << "ghk lm\n" << "abcd ef";
118 CPPUNIT_ASSERT (f.good());
120 // CPPUNIT_ASSERT( s.str() == "1\n2\nabcd\nghk lm\nabcd ef" );
123 void FstreamTest::input()
126 ifstream f( "test_file.txt" );
129 CPPUNIT_ASSERT( f.good() );
130 CPPUNIT_ASSERT( i == 1 );
133 CPPUNIT_ASSERT( f.good() );
134 CPPUNIT_ASSERT( d == 2.0 );
137 CPPUNIT_ASSERT( f.good() );
138 CPPUNIT_ASSERT( str == "abcd" );
140 f.get(c); // extract newline, that not extracted by operator >>
141 CPPUNIT_ASSERT( f.good() );
142 CPPUNIT_ASSERT( c == '\n' );
144 CPPUNIT_ASSERT( f.good() );
145 CPPUNIT_ASSERT( str == "ghk lm" );
147 CPPUNIT_ASSERT( f.eof() );
148 CPPUNIT_ASSERT( str == "abcd ef" );
150 #if defined (STLPORT) && !defined (_STLP_USE_WIN32_IO)
156 CPPUNIT_ASSERT( in.fail() );
162 void FstreamTest::input_char()
164 char buf[16] = { 0, '1', '2', '3' };
165 ifstream s( "test_file.txt" );
168 CPPUNIT_ASSERT( buf[0] == '1' );
169 CPPUNIT_ASSERT( buf[1] == 0 );
170 CPPUNIT_ASSERT( buf[2] == '2' );
173 void FstreamTest::io()
175 basic_fstream<char,char_traits<char> > f( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc );
177 CPPUNIT_ASSERT( f.is_open() );
179 f << 1 << '\n' << 2.0 << '\n' << "abcd\n" << "ghk lm\n" << "abcd ef";
182 f.seekg( 0, ios_base::beg );
186 CPPUNIT_ASSERT( f.good() );
187 CPPUNIT_ASSERT( i == 1 );
190 CPPUNIT_ASSERT( d == 2.0 );
193 CPPUNIT_ASSERT( f.good() );
194 CPPUNIT_ASSERT( s == "abcd" );
196 f.get(c); // extract newline, that not extracted by operator >>
197 CPPUNIT_ASSERT( f.good() );
198 CPPUNIT_ASSERT( c == '\n' );
200 CPPUNIT_ASSERT( f.good() );
201 CPPUNIT_ASSERT( s == "ghk lm" );
203 CPPUNIT_ASSERT( !f.fail() );
204 CPPUNIT_ASSERT( s == "abcd ef" );
205 CPPUNIT_ASSERT( f.eof() );
208 void FstreamTest::err()
210 basic_fstream<char,char_traits<char> > f( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc );
212 CPPUNIT_ASSERT( f.is_open() );
216 CPPUNIT_ASSERT( f.good() );
218 f.seekg( 0, ios_base::beg );
220 CPPUNIT_ASSERT( !f.fail() );
221 CPPUNIT_ASSERT( i == 9 );
223 CPPUNIT_ASSERT( f.fail() );
224 CPPUNIT_ASSERT( f.eof() );
225 CPPUNIT_ASSERT( i == 9 );
228 void FstreamTest::tellg()
231 // bogus ios_base::binary is for Wins
232 ofstream of("test_file.txt", ios_base::out | ios_base::binary | ios_base::trunc);
233 CPPUNIT_ASSERT( of.is_open() );
235 for (int i = 0; i < 50; ++i) {
236 of << "line " << setiosflags(ios_base::right) << setfill('0') << setw(2) << i << "\n";
237 CPPUNIT_ASSERT( !of.fail() );
243 // bogus ios_base::binary is for Wins
244 ifstream is("test_file.txt", ios_base::in | ios_base::binary);
245 CPPUNIT_ASSERT( is.is_open() );
248 // CPPUNIT_ASSERT( is.tellg() == 0 );
250 for (int i = 0; i < 50; ++i) {
252 CPPUNIT_ASSERT( is.gcount() == 0 );
253 CPPUNIT_ASSERT( is.tellg() == p );
255 CPPUNIT_ASSERT( !is.fail() );
256 CPPUNIT_ASSERT( is.gcount() == 8 );
262 // bogus ios_base::binary is for Wins
263 ifstream is("test_file.txt", ios_base::in | ios_base::binary);
264 CPPUNIT_ASSERT( is.is_open() );
267 for (int i = 0; i < 50; ++i) {
268 CPPUNIT_ASSERT( !is.fail() );
270 CPPUNIT_ASSERT( is.tellg() == p );
272 is.seekg( p, ios_base::beg );
273 CPPUNIT_ASSERT( !is.fail() );
278 // bogus ios_base::binary is for Wins
279 ifstream is("test_file.txt", ios_base::in | ios_base::binary);
280 CPPUNIT_ASSERT( is.is_open() );
283 for (int i = 0; i < 50; ++i) {
284 CPPUNIT_ASSERT( is.tellg() == p );
286 is.seekg( 8, ios_base::cur );
287 CPPUNIT_ASSERT( !is.fail() );
292 void FstreamTest::tellp()
295 ofstream o( "test_file.txt" );
299 CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(6) );
300 CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(6) );
303 ofstream o( "test_file.txt" );
307 CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(9) );
308 CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(9) );
310 /* According to the standard
311 ofstream o( "test_file.txt", ios_base::app | ios_base::out )
312 should give the same effect as fopen( "test_file.txt", "a" ).
313 Problem is fopen( "test_file.txt", "a" ) has a bit different behaviour
314 on different platforms, and this difference is not covered by specification.
315 After fopen( "test_file.txt", "a" ) in this context ftell( f ) == 9 for
316 Linux and Mac OS X (I expect the same for others POSIX-like platforms too);
317 on Windows (independently from version?) ftell( f ) == 0, i.e. write pointer not
318 shifted to EOF (but shifted to EOF just before write, as described in the specs).
320 It isn't specifications violation, neither for Linux and Mac OS X nor for Windows.
322 The code below is intended to demonstrate ambiguity (dependance from fopen implementation).
326 //In Windows, stlport and fopen use kernel32.CreateFile for open.
327 //File position is at BOF after open, unless we open with ios_base::ate
328 long expected_pos = 0;
330 //On UNIX flavours, stlport and fopen use unix's open
331 //File position is at EOF after open
333 //3rd possible scenario, "other platforms" - _STLP_USE_STDIO_IO
334 //stlport uses fopen here. This case may fail this test, since the file position after
335 //fopen is implementation-dependent
336 long expected_pos = 9;
338 ofstream o( "test_file.txt", ios_base::app | ios_base::out );
339 CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(expected_pos) );
340 CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(expected_pos) );
342 { // for reference, to test fopen/ftell behaviour in append mode:
344 long expected_pos = 0;
346 long expected_pos = 9;
348 FILE* f = fopen( "test_file.txt", "a" );
349 CPPUNIT_CHECK( ftell( f ) == expected_pos );
353 //In append mode, file is positioned at EOF just before a write.
354 // After a write, file is at EOF. This is implementation-independent.
355 ofstream o( "test_file.txt", ios_base::app | ios_base::out );
357 CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(10) );
358 CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(10) );
362 void FstreamTest::buf()
364 fstream ss( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc );
366 ss << "1234567\n89\n";
367 ss.seekg( 0, ios_base::beg );
371 CPPUNIT_ASSERT( !ss.fail() );
372 CPPUNIT_ASSERT( buf[0] == '1' );
373 CPPUNIT_ASSERT( buf[1] == '2' );
374 CPPUNIT_ASSERT( buf[2] == '3' );
375 CPPUNIT_ASSERT( buf[3] == '4' );
376 CPPUNIT_ASSERT( buf[4] == '5' );
377 CPPUNIT_ASSERT( buf[5] == '6' );
378 CPPUNIT_ASSERT( buf[6] == '7' ); // 27.6.1.3 paragraph 10, paragraph 7
379 CPPUNIT_ASSERT( buf[7] == 0 ); // 27.6.1.3 paragraph 8
382 CPPUNIT_ASSERT( !ss.fail() );
383 CPPUNIT_ASSERT( c == '\n' ); // 27.6.1.3 paragraph 10, paragraph 7
385 CPPUNIT_ASSERT( !ss.fail() );
386 CPPUNIT_ASSERT( c == '8' );
389 void FstreamTest::seek()
392 // Test in binary mode:
394 fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc );
401 char b1[] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' };
402 fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary );
405 int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) );
406 CPPUNIT_CHECK( chars_read == 11 );
407 CPPUNIT_CHECK( b1[9] == '0' );
408 CPPUNIT_ASSERT( s.rdbuf()->pubseekoff( 0, ios_base::cur ) == fstream::pos_type(chars_read) );
409 CPPUNIT_ASSERT( s.rdbuf()->pubseekoff( -chars_read, ios_base::cur ) == fstream::pos_type(0) );
411 char b2[10] = { 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y' };
413 CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 10 ) == 10 );
414 CPPUNIT_CHECK( b2[9] == '0' );
418 // Test in text mode:
420 fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc );
427 char b1[] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' };
428 fstream s( "test_file.txt", ios_base::in | ios_base::out );
431 int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) );
432 CPPUNIT_CHECK( chars_read == 11 );
433 CPPUNIT_CHECK( b1[9] == '0' );
435 fstream::pos_type pos = s.rdbuf()->pubseekoff(0, ios_base::cur);
436 // Depending on how '\n' is written in file, file position can be greater or equal to the number of chars_read read.
437 streamoff offset = pos;
438 CPPUNIT_ASSERT( offset >= chars_read );
439 offset = s.rdbuf()->pubseekoff( -offset, ios_base::cur );
440 CPPUNIT_ASSERT( offset == 0 );
442 char b2[10] = { 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y' };
444 CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 5 ) == 5 );
445 CPPUNIT_CHECK( b2[4] == '5' );
447 pos = s.rdbuf()->pubseekoff(0, ios_base::cur);
448 CPPUNIT_ASSERT( pos == fstream::pos_type(5) );
449 CPPUNIT_ASSERT( s.rdbuf()->pubseekoff(-5, ios_base::cur) == fstream::pos_type(0) );
452 #if !defined (STLPORT) || \
453 (!defined (_STLP_NO_WCHAR_T) && defined (_STLP_USE_EXCEPTIONS))
455 // Test with a wariable encoding:
459 locale tmp(locale::classic(), new codecvt_byname<wchar_t, char, mbstate_t>(".UTF8"));
462 catch (const runtime_error&)
464 // Localization no supported so no test:
469 wfstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc );
474 s << L"1234567890\n";
478 wchar_t b1[] = { L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x' };
479 wfstream s( "test_file.txt", ios_base::in | ios_base::out );
484 int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) / sizeof(wchar_t) );
485 CPPUNIT_CHECK( chars_read == 11 );
486 CPPUNIT_CHECK( b1[9] == L'0' );
488 fstream::pos_type pos = s.rdbuf()->pubseekoff(0, ios_base::cur);
489 // Depending on how '\n' is written in file, file position can be greater or equal to the number of chars_read read.
491 CPPUNIT_ASSERT( off >= chars_read );
492 off = s.rdbuf()->pubseekoff(-off, ios_base::cur);
493 CPPUNIT_ASSERT( off == -1 );
494 off = s.rdbuf()->pubseekoff(0, ios_base::beg);
495 CPPUNIT_ASSERT( off == 0 );
497 wchar_t b2[10] = { L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y' };
499 CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 5 ) == 5 );
500 CPPUNIT_CHECK( b2[4] == L'5' );
502 pos = s.rdbuf()->pubseekoff(0, ios_base::cur);
503 CPPUNIT_ASSERT( pos == fstream::pos_type(5) );
504 //CPPUNIT_ASSERT( s.rdbuf()->pubseekoff(-5, ios_base::cur) == fstream::pos_type(0) );
509 void FstreamTest::rdbuf()
511 fstream ss( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc );
513 ss << "1234567\n89\n";
514 ss.seekg( 0, ios_base::beg );
517 ss.get( *os.rdbuf(), '\n' );
518 CPPUNIT_ASSERT( !ss.fail() );
521 CPPUNIT_ASSERT( !ss.fail() );
522 CPPUNIT_ASSERT( c == '\n' ); // 27.6.1.3 paragraph 12
523 CPPUNIT_ASSERT( os.str() == "1234567" );
526 void FstreamTest::streambuf_output()
529 ofstream ofstr("test_file.txt", ios_base::binary);
531 //No test if we cannot create the file
533 ofstr << "01234567890123456789";
534 CPPUNIT_ASSERT( ofstr );
538 ifstream in("test_file.txt", ios_base::binary);
539 CPPUNIT_ASSERT( in );
541 full_streambuf full_buf(10);
542 ostream out(&full_buf);
543 CPPUNIT_ASSERT( out );
546 CPPUNIT_ASSERT( out );
547 CPPUNIT_ASSERT( in );
548 CPPUNIT_ASSERT( full_buf.str() == "0123456789" );
551 CPPUNIT_ASSERT( out.fail() );
552 CPPUNIT_ASSERT( in );
556 CPPUNIT_ASSERT( ostr );
557 CPPUNIT_ASSERT( in );
558 CPPUNIT_ASSERT( ostr.str() == "0123456789" );
561 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
563 //If the output stream buffer throws:
564 ifstream in("test_file.txt", ios_base::binary);
565 CPPUNIT_ASSERT( in );
567 full_streambuf full_buf(10, true);
568 ostream out(&full_buf);
569 CPPUNIT_ASSERT( out );
572 CPPUNIT_ASSERT( out.bad() );
573 CPPUNIT_ASSERT( in );
574 //out is bad we have no guaranty on what has been extracted:
575 //CPPUNIT_ASSERT( full_buf.str() == "0123456789" );
579 CPPUNIT_ASSERT( out.fail() && out.bad() );
580 CPPUNIT_ASSERT( in );
584 CPPUNIT_ASSERT( ostr );
585 CPPUNIT_ASSERT( in );
586 CPPUNIT_ASSERT( ostr.str() == "0123456789" );
591 void FstreamTest::win32_file_format()
593 const char* file_name = "win32_file_format.tmp";
594 const size_t nb_lines = 2049;
596 ofstream out(file_name);
597 CPPUNIT_ASSERT( out.good() );
599 for (size_t i = 0; i < nb_lines - 1; ++i) {
603 CPPUNIT_ASSERT( out.good() );
606 ifstream in(file_name);
607 CPPUNIT_ASSERT( in.good() );
608 string line, last_line;
609 size_t nb_read_lines = 0;
610 while (getline(in, line)) {
614 CPPUNIT_ASSERT( in.eof() );
615 CPPUNIT_ASSERT( nb_read_lines == nb_lines );
616 CPPUNIT_ASSERT( !last_line.empty() && (last_line[0] == '\r') );
620 #if defined (DO_CUSTOM_FACET_TEST)
625 struct my_traits : public char_traits<char> {
626 typedef my_state state_type;
627 typedef fpos<state_type> pos_type;
630 #if !defined (STLPORT)
631 //STLport grant a default implementation, other Standard libs implementation
632 //do not necessarily do the same:
635 class codecvt<char, char, my_state>
636 : public locale::facet, public codecvt_base {
638 typedef char intern_type;
639 typedef char extern_type;
640 typedef my_state state_type;
642 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
643 result out(state_type&,
644 const intern_type* __from,
646 const intern_type*& __from_next,
649 extern_type*& __to_next) const
650 { __from_next = __from; __to_next = __to; return noconv; }
652 result in (state_type&,
653 const extern_type* __from,
655 const extern_type*& __from_next,
658 intern_type*& __to_next) const
659 { __from_next = __from; __to_next = __to; return noconv; }
661 result unshift(state_type&,
664 extern_type*& __to_next) const
665 { __to_next = __to; return noconv; }
667 int encoding() const throw()
670 bool always_noconv() const throw()
673 int length(const state_type&,
674 const extern_type* __from,
675 const extern_type* __end,
677 { return (int)min(static_cast<size_t>(__end - __from), __max); }
679 int max_length() const throw()
682 static locale::id id;
685 locale::id codecvt<char, char, my_state>::id;
688 # if defined (__BORLANDC__) && (__BORLANDC__ < 0x590)
690 locale::id codecvt<char, char, my_state>::id;
695 void FstreamTest::custom_facet()
697 #if defined (DO_CUSTOM_FACET_TEST)
698 const char* fileName = "test_file.txt";
701 ofstream ofstr(fileName, ios_base::binary);
702 ofstr << "0123456789";
703 CPPUNIT_ASSERT( ofstr );
707 typedef basic_ifstream<char, my_traits> my_ifstream;
708 typedef basic_string<char, my_traits> my_string;
710 my_ifstream ifstr(fileName);
711 CPPUNIT_ASSERT( ifstr );
713 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
714 ifstr.imbue(locale::classic());
715 CPPUNIT_ASSERT( ifstr.fail() && !ifstr.bad() );
718 typedef codecvt<char, char, my_state> my_codecvt;
719 locale my_loc(locale::classic(), new my_codecvt());
720 // Check that my_codecvt has not replace default codecvt:
721 CPPUNIT_ASSERT( (has_facet<my_codecvt>(my_loc)) );
722 CPPUNIT_ASSERT( (has_facet<codecvt<char, char, mbstate_t> >(my_loc)) );
723 # if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
724 CPPUNIT_ASSERT( (has_facet<codecvt<wchar_t, char, mbstate_t> >(my_loc)) );
727 CPPUNIT_ASSERT( ifstr.good() );
731 CPPUNIT_ASSERT( !ifstr.fail() );
732 CPPUNIT_ASSERT( !ifstr.bad() );
733 CPPUNIT_ASSERT( ifstr.eof() );
734 CPPUNIT_ASSERT( res == "0123456789" );
740 # if defined (CHECK_BIG_FILE)
741 void FstreamTest::big_file()
743 vector<pair<streamsize, streamoff> > file_pos;
747 ofstream out("big_file.txt");
748 CPPUNIT_ASSERT( out );
750 //We are going to generate a file with the following schema for the content:
751 //0(1019 times)0000 //1023 characters + 1 charater for \n (for some platforms it will be a 1 ko line)
757 //Generation of the number of loop:
759 for (int i = 0; i < 20; ++i) {
760 //This assertion check that the streamoff can at least represent the necessary integers values
762 CPPUNIT_ASSERT( (nb << 1) > nb );
765 CPPUNIT_ASSERT( nb * CHECK_BIG_FILE >= nb );
766 nb *= CHECK_BIG_FILE;
768 //Preparation of the ouput stream state:
769 out << setiosflags(ios_base::right) << setfill('*');
770 for (streamoff index = 0; index < nb; ++index) {
771 if (index % 1024 == 0) {
772 file_pos.push_back(make_pair(out.tellp(), index));
773 CPPUNIT_ASSERT( file_pos.back().first != streamsize(-1) );
774 if (file_pos.size() > 1) {
775 CPPUNIT_ASSERT( file_pos[file_pos.size() - 1].first > file_pos[file_pos.size() - 2].first );
778 out << setw(1023) << index << '\n';
783 ifstream in("big_file.txt");
784 CPPUNIT_ASSERT( in );
787 vector<pair<streamsize, streamsize> >::const_iterator pit(file_pos.begin()),
788 pitEnd(file_pos.end());
789 for (; pit != pitEnd; ++pit) {
790 in.seekg((*pit).first);
791 CPPUNIT_ASSERT( in );
793 size_t lastStarPos = line.rfind('*');
794 CPPUNIT_ASSERT( atoi(line.substr(lastStarPos + 1).c_str()) == (*pit).second );
799 The following test has been used to check that STLport do not generate
800 an infinite loop when the file size is larger than the streamsize and
801 streamoff representation (32 bits or 64 bits).
803 ifstream in("big_file.txt");
804 CPPUNIT_ASSERT( in );
806 streamsize nb_reads = 0;
807 while ((!in.eof()) && in.good()){
809 nb_reads += in.gcount();
816 void FstreamTest::null_stream()
818 # if (defined (STLPORT) && defined (_STLP_USE_WIN32_IO)) || \
819 (!defined (STLPORT) && (defined (WIN32) || defined (_WIN32)))
820 const char* nullStreamName = "NUL";
822 const char* nullStreamName = "/dev/null";
825 ofstream nullStream(nullStreamName);
826 CPPUNIT_CHECK( nullStream );
830 ofstream nullStream(nullStreamName, ios_base::ate);
831 CPPUNIT_CHECK( nullStream );
835 ofstream nullStream(nullStreamName, ios_base::trunc);
836 CPPUNIT_CHECK( nullStream );
840 ofstream nullStream(nullStreamName, ios_base::app);
841 CPPUNIT_CHECK( nullStream );
845 ifstream nullStream(nullStreamName);
846 CPPUNIT_CHECK( nullStream );
850 ifstream nullStream(nullStreamName, ios_base::ate);
851 CPPUNIT_CHECK( nullStream );
855 fstream nullStream(nullStreamName);
856 CPPUNIT_CHECK( nullStream );
860 fstream nullStream(nullStreamName, ios_base::in | ios_base::out | ios_base::ate);
861 CPPUNIT_CHECK( nullStream );
865 fstream nullStream(nullStreamName, ios_base::in | ios_base::out | ios_base::trunc);
866 CPPUNIT_CHECK( nullStream );
870 void FstreamTest::null_buf()
872 /* **********************************************************************************
874 testcase for bug #1830513:
877 template < class _CharT, class _Traits, class _Is_Delim>
878 streamsize _STLP_CALL __read_unbuffered(basic_istream<_CharT, _Traits>* __that,
879 basic_streambuf<_CharT, _Traits>* __buf,
880 streamsize _Num, _CharT* __s,
881 _Is_Delim __is_delim,
882 bool __extract_delim, bool __append_null,
885 can't accept _Num == 0; this is legal case, and may happen from
887 template <class _CharT, class _Traits>
888 basic_istream<_CharT, _Traits>&
889 basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n, _CharT __delim)
891 *********************************************************************************** */
893 fstream f( "test.txt", ios_base::in | ios_base::out | ios_base::trunc );
896 for ( int i = 0; i < 0x200; ++i ) {
900 // const streambuf *b = f.rdbuf();
909 // cerr << f.good() << endl;
910 f.seekg( 0, ios_base::beg );
911 // f.seekg( 0, ios_base::end );
914 // cerr << (void *)(b->_M_gptr()) << " " << (void *)(b->_M_egptr()) << endl;
915 // cerr << f.good() << endl;
917 f.getline( buf, 1 ); // <-- key line
918 CPPUNIT_CHECK( buf[0] == 0 );
919 CPPUNIT_CHECK( f.fail() ); // due to delimiter not found while buffer was exhausted
922 # if !defined (STLPORT) || !defined (_STLP_WIN32)
923 void FstreamTest::offset()
925 # if (defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE)) && !defined(_STLP_USE_DEFAULT_FILE_OFFSET)
926 CPPUNIT_CHECK( sizeof(streamoff) == 8 );
928 CPPUNIT_CHECK( sizeof(streamoff) == sizeof(off_t) );