ReactOS 0.4.15-dev-7924-g5949c20
FstreamTest Class Reference
Inheritance diagram for FstreamTest:
Collaboration diagram for FstreamTest:

Protected Member Functions

void output ()
 
void input ()
 
void input_char ()
 
void io ()
 
void err ()
 
void tellg ()
 
void tellp ()
 
void seek ()
 
void buf ()
 
void rdbuf ()
 
void streambuf_output ()
 
void win32_file_format ()
 
void null_stream ()
 
void null_buf ()
 
void offset ()
 
void custom_facet ()
 

Private Member Functions

 CPPUNIT_TEST_SUITE (FstreamTest)
 
 CPPUNIT_TEST (output)
 
 CPPUNIT_TEST (input)
 
 CPPUNIT_TEST (input_char)
 
 CPPUNIT_TEST (io)
 
 CPPUNIT_TEST (err)
 
 CPPUNIT_TEST (tellg)
 
 CPPUNIT_TEST (tellp)
 
 CPPUNIT_TEST (seek)
 
 CPPUNIT_TEST (buf)
 
 CPPUNIT_TEST (rdbuf)
 
 CPPUNIT_TEST (streambuf_output)
 
 CPPUNIT_TEST (win32_file_format)
 
 CPPUNIT_TEST (null_stream)
 
 CPPUNIT_TEST (null_buf)
 
 CPPUNIT_TEST (offset)
 
 CPPUNIT_TEST (custom_facet)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Attributes

 CPPUNIT_IGNORE
 

Detailed Description

Definition at line 35 of file fstream_test.cpp.

Member Function Documentation

◆ buf()

void FstreamTest::buf ( )
protected

Definition at line 344 of file fstream_test.cpp.

345{
346 fstream ss( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc );
347
348 ss << "1234567\n89\n";
349 ss.seekg( 0, ios_base::beg );
350 char buf[10];
351 buf[7] = 'x';
352 ss.get( buf, 10 );
353 CPPUNIT_ASSERT( !ss.fail() );
354 CPPUNIT_ASSERT( buf[0] == '1' );
355 CPPUNIT_ASSERT( buf[1] == '2' );
356 CPPUNIT_ASSERT( buf[2] == '3' );
357 CPPUNIT_ASSERT( buf[3] == '4' );
358 CPPUNIT_ASSERT( buf[4] == '5' );
359 CPPUNIT_ASSERT( buf[5] == '6' );
360 CPPUNIT_ASSERT( buf[6] == '7' ); // 27.6.1.3 paragraph 10, paragraph 7
361 CPPUNIT_ASSERT( buf[7] == 0 ); // 27.6.1.3 paragraph 8
362 char c;
363 ss.get(c);
364 CPPUNIT_ASSERT( !ss.fail() );
365 CPPUNIT_ASSERT( c == '\n' ); // 27.6.1.3 paragraph 10, paragraph 7
366 ss.get(c);
367 CPPUNIT_ASSERT( !ss.fail() );
368 CPPUNIT_ASSERT( c == '8' );
369}
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
const GLubyte * c
Definition: glext.h:8905
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define ss
Definition: i386-dis.c:441
#define c
Definition: ke_i.h:80

Referenced by input_char().

◆ CPPUNIT_TEST() [1/16]

FstreamTest::CPPUNIT_TEST ( buf  )
private

◆ CPPUNIT_TEST() [2/16]

FstreamTest::CPPUNIT_TEST ( custom_facet  )
private

◆ CPPUNIT_TEST() [3/16]

FstreamTest::CPPUNIT_TEST ( err  )
private

◆ CPPUNIT_TEST() [4/16]

FstreamTest::CPPUNIT_TEST ( input  )
private

◆ CPPUNIT_TEST() [5/16]

FstreamTest::CPPUNIT_TEST ( input_char  )
private

◆ CPPUNIT_TEST() [6/16]

FstreamTest::CPPUNIT_TEST ( io  )
private

◆ CPPUNIT_TEST() [7/16]

FstreamTest::CPPUNIT_TEST ( null_buf  )
private

◆ CPPUNIT_TEST() [8/16]

FstreamTest::CPPUNIT_TEST ( null_stream  )
private

◆ CPPUNIT_TEST() [9/16]

FstreamTest::CPPUNIT_TEST ( offset  )
private

◆ CPPUNIT_TEST() [10/16]

FstreamTest::CPPUNIT_TEST ( output  )
private

◆ CPPUNIT_TEST() [11/16]

FstreamTest::CPPUNIT_TEST ( rdbuf  )
private

◆ CPPUNIT_TEST() [12/16]

FstreamTest::CPPUNIT_TEST ( seek  )
private

◆ CPPUNIT_TEST() [13/16]

FstreamTest::CPPUNIT_TEST ( streambuf_output  )
private

◆ CPPUNIT_TEST() [14/16]

FstreamTest::CPPUNIT_TEST ( tellg  )
private

◆ CPPUNIT_TEST() [15/16]

FstreamTest::CPPUNIT_TEST ( tellp  )
private

◆ CPPUNIT_TEST() [16/16]

FstreamTest::CPPUNIT_TEST ( win32_file_format  )
private

◆ CPPUNIT_TEST_SUITE()

FstreamTest::CPPUNIT_TEST_SUITE ( FstreamTest  )
private

◆ CPPUNIT_TEST_SUITE_END()

FstreamTest::CPPUNIT_TEST_SUITE_END ( )
private

◆ custom_facet()

void FstreamTest::custom_facet ( )
protected

Definition at line 677 of file fstream_test.cpp.

678{
679#if defined (DO_CUSTOM_FACET_TEST)
680 const char* fileName = "test_file.txt";
681 //File preparation:
682 {
683 ofstream ofstr(fileName, ios_base::binary);
684 ofstr << "0123456789";
685 CPPUNIT_ASSERT( ofstr );
686 }
687
688 {
689 typedef basic_ifstream<char, my_traits> my_ifstream;
690 typedef basic_string<char, my_traits> my_string;
691
692 my_ifstream ifstr(fileName);
693 CPPUNIT_ASSERT( ifstr );
694
695# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
696 ifstr.imbue(locale::classic());
697 CPPUNIT_ASSERT( ifstr.fail() && !ifstr.bad() );
698 ifstr.clear();
699# endif
701 locale my_loc(locale::classic(), new my_codecvt());
702 // Check that my_codecvt has not replace default codecvt:
703 CPPUNIT_ASSERT( (has_facet<my_codecvt>(my_loc)) );
705# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
707# endif
708 ifstr.imbue(my_loc);
709 CPPUNIT_ASSERT( ifstr.good() );
710 /*
711 my_string res;
712 ifstr >> res;
713 CPPUNIT_ASSERT( !ifstr.fail() );
714 CPPUNIT_ASSERT( !ifstr.bad() );
715 CPPUNIT_ASSERT( ifstr.eof() );
716 CPPUNIT_ASSERT( res == "0123456789" );
717 */
718 }
719#endif
720}
bool has_facet(const locale &__loc) _STLP_NOTHROW
Definition: _locale.h:304
Definition: _locale.h:75
static const locale &_STLP_CALL classic()
Definition: locale.cpp:404

◆ err()

void FstreamTest::err ( )
protected

Definition at line 190 of file fstream_test.cpp.

191{
192 basic_fstream<char,char_traits<char> > f( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc );
193
194 CPPUNIT_ASSERT( f.is_open() );
195
196 int i = 9;
197 f << i;
198 CPPUNIT_ASSERT( f.good() );
199 i = 0;
200 f.seekg( 0, ios_base::beg );
201 f >> i;
202 CPPUNIT_ASSERT( !f.fail() );
203 CPPUNIT_ASSERT( i == 9 );
204 f >> i;
205 CPPUNIT_ASSERT( f.fail() );
206 CPPUNIT_ASSERT( f.eof() );
207 CPPUNIT_ASSERT( i == 9 );
208}
GLfloat f
Definition: glext.h:7540
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define f
Definition: ke_i.h:83

◆ input()

void FstreamTest::input ( )
protected

Definition at line 105 of file fstream_test.cpp.

106{
107 {
108 ifstream f( "test_file.txt" );
109 int i = 0;
110 f >> i;
111 CPPUNIT_ASSERT( f.good() );
112 CPPUNIT_ASSERT( i == 1 );
113 double d = 0.0;
114 f >> d;
115 CPPUNIT_ASSERT( f.good() );
116 CPPUNIT_ASSERT( d == 2.0 );
117 string str;
118 f >> str;
119 CPPUNIT_ASSERT( f.good() );
120 CPPUNIT_ASSERT( str == "abcd" );
121 char c;
122 f.get(c); // extract newline, that not extracted by operator >>
123 CPPUNIT_ASSERT( f.good() );
124 CPPUNIT_ASSERT( c == '\n' );
125 getline( f, str );
126 CPPUNIT_ASSERT( f.good() );
127 CPPUNIT_ASSERT( str == "ghk lm" );
128 getline( f, str );
129 CPPUNIT_ASSERT( f.eof() );
130 CPPUNIT_ASSERT( str == "abcd ef" );
131 }
132#if defined (STLPORT) && !defined (_STLP_USE_WIN32_IO)
133 {
134 ifstream in("/tmp");
135 if (in.good()) {
136 string s;
137 getline(in, s);
138 CPPUNIT_ASSERT( in.fail() );
139 }
140 }
141#endif
142}
GLdouble s
Definition: gl.h:2039
GLuint in
Definition: glext.h:9616
#define d
Definition: ke_i.h:81
const WCHAR * str
#define getline
Definition: schily.h:567

◆ input_char()

void FstreamTest::input_char ( )
protected

Definition at line 144 of file fstream_test.cpp.

145{
146 char buf[16] = { 0, '1', '2', '3' };
147 ifstream s( "test_file.txt" );
148 s >> buf;
149
150 CPPUNIT_ASSERT( buf[0] == '1' );
151 CPPUNIT_ASSERT( buf[1] == 0 );
152 CPPUNIT_ASSERT( buf[2] == '2' );
153}

◆ io()

void FstreamTest::io ( )
protected

Definition at line 155 of file fstream_test.cpp.

156{
157 basic_fstream<char,char_traits<char> > f( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc );
158
159 CPPUNIT_ASSERT( f.is_open() );
160
161 f << 1 << '\n' << 2.0 << '\n' << "abcd\n" << "ghk lm\n" << "abcd ef";
162
163 // f.flush();
164 f.seekg( 0, ios_base::beg );
165
166 int i = 0;
167 f >> i;
168 CPPUNIT_ASSERT( f.good() );
169 CPPUNIT_ASSERT( i == 1 );
170 double d = 0.0;
171 f >> d;
172 CPPUNIT_ASSERT( d == 2.0 );
173 string s;
174 f >> s;
175 CPPUNIT_ASSERT( f.good() );
176 CPPUNIT_ASSERT( s == "abcd" );
177 char c;
178 f.get(c); // extract newline, that not extracted by operator >>
179 CPPUNIT_ASSERT( f.good() );
180 CPPUNIT_ASSERT( c == '\n' );
181 getline( f, s );
182 CPPUNIT_ASSERT( f.good() );
183 CPPUNIT_ASSERT( s == "ghk lm" );
184 getline( f, s );
185 CPPUNIT_ASSERT( !f.fail() );
186 CPPUNIT_ASSERT( s == "abcd ef" );
187 CPPUNIT_ASSERT( f.eof() );
188}

◆ null_buf()

void FstreamTest::null_buf ( )
protected

Definition at line 852 of file fstream_test.cpp.

853{
854 /* **********************************************************************************
855
856 testcase for bug #1830513:
857 in _istream.c
858
859 template < class _CharT, class _Traits, class _Is_Delim>
860 streamsize _STLP_CALL __read_unbuffered(basic_istream<_CharT, _Traits>* __that,
861 basic_streambuf<_CharT, _Traits>* __buf,
862 streamsize _Num, _CharT* __s,
863 _Is_Delim __is_delim,
864 bool __extract_delim, bool __append_null,
865 bool __is_getline)
866
867 can't accept _Num == 0; this is legal case, and may happen from
868
869 template <class _CharT, class _Traits>
870 basic_istream<_CharT, _Traits>&
871 basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n, _CharT __delim)
872
873 *********************************************************************************** */
874
875 fstream f( "test.txt", ios_base::in | ios_base::out | ios_base::trunc );
876 // string line;
877
878 for ( int i = 0; i < 0x200; ++i ) {
879 f.put( ' ' );
880 }
881
882 // const streambuf *b = f.rdbuf();
883
884 // string s;
885 char buf[1024];
886 buf[0] = 'a';
887 buf[1] = 'b';
888 buf[2] = 'c';
889
890 // getline( f, s );
891 // cerr << f.good() << endl;
892 f.seekg( 0, ios_base::beg );
893 // f.seekg( 0, ios_base::end );
894 // buf[0] = f.get();
895
896 // cerr << (void *)(b->_M_gptr()) << " " << (void *)(b->_M_egptr()) << endl;
897 // cerr << f.good() << endl;
898 // getline( f, s );
899 f.getline( buf, 1 ); // <-- key line
900 CPPUNIT_CHECK( buf[0] == 0 );
901 CPPUNIT_CHECK( f.fail() ); // due to delimiter not found while buffer was exhausted
902}
#define CPPUNIT_CHECK(X)
Definition: cppunit_mini.h:195

◆ null_stream()

void FstreamTest::null_stream ( )
protected

Definition at line 798 of file fstream_test.cpp.

799{
800# if (defined (STLPORT) && defined (_STLP_USE_WIN32_IO)) || \
801 (!defined (STLPORT) && (defined (WIN32) || defined (_WIN32)))
802 const char* nullStreamName = "NUL";
803# else
804 const char* nullStreamName = "/dev/null";
805# endif
806 {
807 ofstream nullStream(nullStreamName);
808 CPPUNIT_CHECK( nullStream );
809 }
810
811 {
812 ofstream nullStream(nullStreamName, ios_base::ate);
813 CPPUNIT_CHECK( nullStream );
814 }
815
816 {
817 ofstream nullStream(nullStreamName, ios_base::trunc);
818 CPPUNIT_CHECK( nullStream );
819 }
820
821 {
822 ofstream nullStream(nullStreamName, ios_base::app);
823 CPPUNIT_CHECK( nullStream );
824 }
825
826 {
827 ifstream nullStream(nullStreamName);
828 CPPUNIT_CHECK( nullStream );
829 }
830
831 {
832 ifstream nullStream(nullStreamName, ios_base::ate);
833 CPPUNIT_CHECK( nullStream );
834 }
835
836 {
837 fstream nullStream(nullStreamName);
838 CPPUNIT_CHECK( nullStream );
839 }
840
841 {
842 fstream nullStream(nullStreamName, ios_base::in | ios_base::out | ios_base::ate);
843 CPPUNIT_CHECK( nullStream );
844 }
845
846 {
847 fstream nullStream(nullStreamName, ios_base::in | ios_base::out | ios_base::trunc);
848 CPPUNIT_CHECK( nullStream );
849 }
850}

◆ offset()

void FstreamTest::offset ( )
protected

Definition at line 905 of file fstream_test.cpp.

906{
907# if (defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE)) && !defined(_STLP_USE_DEFAULT_FILE_OFFSET)
908 CPPUNIT_CHECK( sizeof(streamoff) == 8 );
909# else
910 CPPUNIT_CHECK( sizeof(streamoff) == sizeof(off_t) );
911# endif
912}
off_t streamoff
Definition: char_traits.h:74
__kernel_off_t off_t
Definition: linux.h:201

◆ output()

void FstreamTest::output ( )
protected

Definition at line 96 of file fstream_test.cpp.

97{
98 ofstream f( "test_file.txt" );
99
100 f << 1 << '\n' << 2.0 << '\n' << "abcd\n" << "ghk lm\n" << "abcd ef";
101 CPPUNIT_ASSERT (f.good());
102 // CPPUNIT_ASSERT( s.str() == "1\n2\nabcd\nghk lm\nabcd ef" );
103}

◆ rdbuf()

void FstreamTest::rdbuf ( )
protected

Definition at line 491 of file fstream_test.cpp.

492{
493 fstream ss( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc );
494
495 ss << "1234567\n89\n";
496 ss.seekg( 0, ios_base::beg );
497
498 ostringstream os;
499 ss.get( *os.rdbuf(), '\n' );
500 CPPUNIT_ASSERT( !ss.fail() );
501 char c;
502 ss.get(c);
503 CPPUNIT_ASSERT( !ss.fail() );
504 CPPUNIT_ASSERT( c == '\n' ); // 27.6.1.3 paragraph 12
505 CPPUNIT_ASSERT( os.str() == "1234567" );
506}
_String str() const
Definition: _sstream.h:184
basic_stringbuf< _CharT, _Traits, _Alloc > * rdbuf() const
Definition: _sstream.h:181

◆ seek()

void FstreamTest::seek ( )
protected

Definition at line 371 of file fstream_test.cpp.

372{
373 {
374 // Test in binary mode:
375 {
376 fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc );
377 CPPUNIT_ASSERT( s );
378
379 s << "1234567890\n";
380 CPPUNIT_ASSERT( s );
381 }
382
383 char b1[] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' };
384 fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary );
385 CPPUNIT_ASSERT( s );
386
387 int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) );
388 CPPUNIT_CHECK( chars_read == 11 );
389 CPPUNIT_CHECK( b1[9] == '0' );
390 CPPUNIT_ASSERT( s.rdbuf()->pubseekoff( 0, ios_base::cur ) == fstream::pos_type(chars_read) );
391 CPPUNIT_ASSERT( s.rdbuf()->pubseekoff( -chars_read, ios_base::cur ) == fstream::pos_type(0) );
392
393 char b2[10] = { 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y' };
394
395 CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 10 ) == 10 );
396 CPPUNIT_CHECK( b2[9] == '0' );
397 }
398
399 {
400 // Test in text mode:
401 {
402 fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc );
403 CPPUNIT_ASSERT( s );
404
405 s << "1234567890\n";
406 CPPUNIT_ASSERT( s );
407 }
408
409 char b1[] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' };
410 fstream s( "test_file.txt", ios_base::in | ios_base::out );
411 CPPUNIT_ASSERT( s );
412
413 int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) );
414 CPPUNIT_CHECK( chars_read == 11 );
415 CPPUNIT_CHECK( b1[9] == '0' );
416
417 fstream::pos_type pos = s.rdbuf()->pubseekoff(0, ios_base::cur);
418 // Depending on how '\n' is written in file, file position can be greater or equal to the number of chars_read read.
420 CPPUNIT_ASSERT( offset >= chars_read );
421 offset = s.rdbuf()->pubseekoff( -offset, ios_base::cur );
422 CPPUNIT_ASSERT( offset == 0 );
423
424 char b2[10] = { 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y' };
425
426 CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 5 ) == 5 );
427 CPPUNIT_CHECK( b2[4] == '5' );
428
429 pos = s.rdbuf()->pubseekoff(0, ios_base::cur);
431 CPPUNIT_ASSERT( s.rdbuf()->pubseekoff(-5, ios_base::cur) == fstream::pos_type(0) );
432 }
433
434#if !defined (STLPORT) || \
435 (!defined (_STLP_NO_WCHAR_T) && defined (_STLP_USE_EXCEPTIONS))
436 {
437 // Test with a wariable encoding:
438 locale loc;
439 try
440 {
442 loc = tmp;
443 }
444 catch (const runtime_error&)
445 {
446 // Localization no supported so no test:
447 return;
448 }
449
450 {
451 wfstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc );
452 CPPUNIT_ASSERT( s );
453 s.imbue(loc);
454 CPPUNIT_ASSERT( s );
455
456 s << L"1234567890\n";
457 CPPUNIT_ASSERT( s );
458 }
459
460 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' };
461 wfstream s( "test_file.txt", ios_base::in | ios_base::out );
462 CPPUNIT_ASSERT( s );
463 s.imbue(loc);
464 CPPUNIT_ASSERT( s );
465
466 int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) / sizeof(wchar_t) );
467 CPPUNIT_CHECK( chars_read == 11 );
468 CPPUNIT_CHECK( b1[9] == L'0' );
469
470 fstream::pos_type pos = s.rdbuf()->pubseekoff(0, ios_base::cur);
471 // Depending on how '\n' is written in file, file position can be greater or equal to the number of chars_read read.
472 streamoff off = pos;
473 CPPUNIT_ASSERT( off >= chars_read );
474 off = s.rdbuf()->pubseekoff(-off, ios_base::cur);
475 CPPUNIT_ASSERT( off == -1 );
476 off = s.rdbuf()->pubseekoff(0, ios_base::beg);
477 CPPUNIT_ASSERT( off == 0 );
478
479 wchar_t b2[10] = { L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y' };
480
481 CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 5 ) == 5 );
482 CPPUNIT_CHECK( b2[4] == L'5' );
483
484 pos = s.rdbuf()->pubseekoff(0, ios_base::cur);
486 //CPPUNIT_ASSERT( s.rdbuf()->pubseekoff(-5, ios_base::cur) == fstream::pos_type(0) );
487 }
488#endif
489}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLintptr offset
Definition: glext.h:5920
static CRYPT_DATA_BLOB b2[]
Definition: msg.c:582
static CRYPT_DATA_BLOB b1[]
Definition: msg.c:573
#define L(x)
Definition: ntvdm.h:50
#define wchar_t
Definition: wchar.h:102

◆ streambuf_output()

void FstreamTest::streambuf_output ( )
protected

Definition at line 508 of file fstream_test.cpp.

509{
510 {
511 ofstream ofstr("test_file.txt", ios_base::binary);
512 if (!ofstr)
513 //No test if we cannot create the file
514 return;
515 ofstr << "01234567890123456789";
516 CPPUNIT_ASSERT( ofstr );
517 }
518
519 {
520 ifstream in("test_file.txt", ios_base::binary);
522
523 full_streambuf full_buf(10);
524 ostream out(&full_buf);
526
527 out << in.rdbuf();
530 CPPUNIT_ASSERT( full_buf.str() == "0123456789" );
531
532 out << in.rdbuf();
533 CPPUNIT_ASSERT( out.fail() );
535
536 ostringstream ostr;
537 ostr << in.rdbuf();
538 CPPUNIT_ASSERT( ostr );
540 CPPUNIT_ASSERT( ostr.str() == "0123456789" );
541 }
542
543# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
544 {
545 //If the output stream buffer throws:
546 ifstream in("test_file.txt", ios_base::binary);
548
549 full_streambuf full_buf(10, true);
550 ostream out(&full_buf);
552
553 out << in.rdbuf();
554 CPPUNIT_ASSERT( out.bad() );
556 //out is bad we have no guaranty on what has been extracted:
557 //CPPUNIT_ASSERT( full_buf.str() == "0123456789" );
558
559 out.clear();
560 out << in.rdbuf();
561 CPPUNIT_ASSERT( out.fail() && out.bad() );
563
564 ostringstream ostr;
565 ostr << in.rdbuf();
566 CPPUNIT_ASSERT( ostr );
568 CPPUNIT_ASSERT( ostr.str() == "0123456789" );
569 }
570# endif
571}
static FILE * out
Definition: regtests2xml.c:44

◆ tellg()

void FstreamTest::tellg ( )
protected

Definition at line 210 of file fstream_test.cpp.

211{
212 {
213 // bogus ios_base::binary is for Wins
214 ofstream of("test_file.txt", ios_base::out | ios_base::binary | ios_base::trunc);
215 CPPUNIT_ASSERT( of.is_open() );
216
217 for (int i = 0; i < 50; ++i) {
218 of << "line " << setiosflags(ios_base::right) << setfill('0') << setw(2) << i << "\n";
219 CPPUNIT_ASSERT( !of.fail() );
220 }
221 of.close();
222 }
223
224 {
225 // bogus ios_base::binary is for Wins
226 ifstream is("test_file.txt", ios_base::in | ios_base::binary);
227 CPPUNIT_ASSERT( is.is_open() );
228 char buf[64];
229
230 // CPPUNIT_ASSERT( is.tellg() == 0 );
231 streampos p = 0;
232 for (int i = 0; i < 50; ++i) {
233 is.read(buf, 0);
234 CPPUNIT_ASSERT( is.gcount() == 0 );
235 CPPUNIT_ASSERT( is.tellg() == p );
236 is.read( buf, 8 );
237 CPPUNIT_ASSERT( !is.fail() );
238 CPPUNIT_ASSERT( is.gcount() == 8 );
239 p += 8;
240 }
241 }
242
243 {
244 // bogus ios_base::binary is for Wins
245 ifstream is("test_file.txt", ios_base::in | ios_base::binary);
246 CPPUNIT_ASSERT( is.is_open() );
247
248 streampos p = 0;
249 for (int i = 0; i < 50; ++i) {
250 CPPUNIT_ASSERT( !is.fail() );
251 is.tellg();
252 CPPUNIT_ASSERT( is.tellg() == p );
253 p += 8;
254 is.seekg( p, ios_base::beg );
255 CPPUNIT_ASSERT( !is.fail() );
256 }
257 }
258
259 {
260 // bogus ios_base::binary is for Wins
261 ifstream is("test_file.txt", ios_base::in | ios_base::binary);
262 CPPUNIT_ASSERT( is.is_open() );
263
264 streampos p = 0;
265 for (int i = 0; i < 50; ++i) {
266 CPPUNIT_ASSERT( is.tellg() == p );
267 p += 8;
268 is.seekg( 8, ios_base::cur );
269 CPPUNIT_ASSERT( !is.fail() );
270 }
271 }
272}
_STLP_PRIV _Ios_Manip_1< streamsize > _STLP_CALL setw(int __n)
Definition: _iomanip.h:125
_STLP_PRIV _Setfill_Manip< _CharT > _STLP_CALL setfill(_CharT __c)
Definition: _iomanip.h:160
_STLP_PRIV _Ios_Setf_Manip _STLP_CALL setiosflags(ios_base::fmtflags __flag)
Definition: _iomanip.h:107
GLfloat GLfloat p
Definition: glext.h:8902

◆ tellp()

void FstreamTest::tellp ( )
protected

Definition at line 274 of file fstream_test.cpp.

275{
276 {
277 ofstream o( "test_file.txt" );
278
279 o << "123456";
280
281 CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(6) );
282 CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(6) );
283 }
284 {
285 ofstream o( "test_file.txt" );
286
287 o << "123456789";
288
289 CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(9) );
290 CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(9) );
291 }
292 /* According to the standard
293 ofstream o( "test_file.txt", ios_base::app | ios_base::out )
294 should give the same effect as fopen( "test_file.txt", "a" ).
295 Problem is fopen( "test_file.txt", "a" ) has a bit different behaviour
296 on different platforms, and this difference is not covered by specification.
297 After fopen( "test_file.txt", "a" ) in this context ftell( f ) == 9 for
298 Linux and Mac OS X (I expect the same for others POSIX-like platforms too);
299 on Windows (independently from version?) ftell( f ) == 0, i.e. write pointer not
300 shifted to EOF (but shifted to EOF just before write, as described in the specs).
301
302 It isn't specifications violation, neither for Linux and Mac OS X nor for Windows.
303
304 The code below is intended to demonstrate ambiguity (dependance from fopen implementation).
305 */
306 {
307 #ifdef WIN32
308 //In Windows, stlport and fopen use kernel32.CreateFile for open.
309 //File position is at BOF after open, unless we open with ios_base::ate
310 long expected_pos = 0;
311 #else
312 //On UNIX flavours, stlport and fopen use unix's open
313 //File position is at EOF after open
314 //
315 //3rd possible scenario, "other platforms" - _STLP_USE_STDIO_IO
316 //stlport uses fopen here. This case may fail this test, since the file position after
317 //fopen is implementation-dependent
318 long expected_pos = 9;
319 #endif
320 ofstream o( "test_file.txt", ios_base::app | ios_base::out );
321 CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(expected_pos) );
322 CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(expected_pos) );
323 }
324 { // for reference, to test fopen/ftell behaviour in append mode:
325 #ifdef WIN32
326 long expected_pos = 0;
327 #else
328 long expected_pos = 9;
329 #endif
330 FILE* f = fopen( "test_file.txt", "a" );
331 CPPUNIT_CHECK( ftell( f ) == expected_pos );
332 fclose( f );
333 }
334 {
335 //In append mode, file is positioned at EOF just before a write.
336 // After a write, file is at EOF. This is implementation-independent.
337 ofstream o( "test_file.txt", ios_base::app | ios_base::out );
338 o << "X";
339 CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(10) );
340 CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(10) );
341 }
342}
_Traits::pos_type pos_type
Definition: _fstream.h:537
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)

◆ win32_file_format()

void FstreamTest::win32_file_format ( )
protected

Definition at line 573 of file fstream_test.cpp.

574{
575 const char* file_name = "win32_file_format.tmp";
576 const size_t nb_lines = 2049;
577 {
579 CPPUNIT_ASSERT( out.good() );
580 out << 'a';
581 for (size_t i = 0; i < nb_lines - 1; ++i) {
582 out << '\n';
583 }
584 out << '\r';
585 CPPUNIT_ASSERT( out.good() );
586 }
587 {
589 CPPUNIT_ASSERT( in.good() );
590 string line, last_line;
591 size_t nb_read_lines = 0;
592 while (getline(in, line)) {
593 ++nb_read_lines;
594 last_line = line;
595 }
596 CPPUNIT_ASSERT( in.eof() );
597 CPPUNIT_ASSERT( nb_read_lines == nb_lines );
598 CPPUNIT_ASSERT( !last_line.empty() && (last_line[0] == '\r') );
599 }
600}
bool empty() const
Definition: _string.h:428
static LPCWSTR file_name
Definition: protocol.c:147
Definition: parser.c:49

Member Data Documentation

◆ CPPUNIT_IGNORE

FstreamTest::CPPUNIT_IGNORE
private

Definition at line 62 of file fstream_test.cpp.


The documentation for this class was generated from the following file: