1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/ffilestream.cpp
3 // Purpose: Test wxFFileInputStream/wxFFileOutputStream
4 // Author: Hans Van Leemputten
5 // Copyright: (c) 2004 Hans Van Leemputten
6 // Licence: wxWindows licence
7 ///////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx/wx.h".
17 // for all others, include the necessary headers
22 #include "wx/wfstream.h"
26 #define DATABUFFER_SIZE 1024
28 static const wxString FILENAME_FFILEINSTREAM
= wxT("ffileinstream.test");
29 static const wxString FILENAME_FFILEOUTSTREAM
= wxT("ffileoutstream.test");
31 ///////////////////////////////////////////////////////////////////////////////
34 // Try to fully test wxFFileInputStream and wxFFileOutputStream
36 class ffileStream
: public BaseStreamTestCase
<wxFFileInputStream
, wxFFileOutputStream
>
40 virtual ~ffileStream();
42 CPPUNIT_TEST_SUITE(ffileStream
);
43 // Base class stream tests the ffileStream supports.
44 CPPUNIT_TEST(Input_GetSize
);
45 CPPUNIT_TEST(Input_GetC
);
46 CPPUNIT_TEST(Input_Read
);
47 CPPUNIT_TEST(Input_Eof
);
48 CPPUNIT_TEST(Input_LastRead
);
49 CPPUNIT_TEST(Input_CanRead
);
50 CPPUNIT_TEST(Input_SeekI
);
51 CPPUNIT_TEST(Input_TellI
);
52 CPPUNIT_TEST(Input_Peek
);
53 CPPUNIT_TEST(Input_Ungetch
);
55 CPPUNIT_TEST(Output_PutC
);
56 CPPUNIT_TEST(Output_Write
);
57 CPPUNIT_TEST(Output_LastWrite
);
58 CPPUNIT_TEST(Output_SeekO
);
59 CPPUNIT_TEST(Output_TellO
);
61 // Other test specific for File stream test case.
62 CPPUNIT_TEST_SUITE_END();
68 // Implement base class functions.
69 virtual wxFFileInputStream
*DoCreateInStream();
70 virtual wxFFileOutputStream
*DoCreateOutStream();
71 virtual void DoDeleteOutStream();
74 wxString
GetInFileName() const;
77 ffileStream::ffileStream()
79 m_bSeekInvalidBeyondEnd
= false;
80 m_bEofAtLastRead
= false;
83 ffileStream::~ffileStream()
85 // Remove the temp test file...
86 ::wxRemoveFile(FILENAME_FFILEINSTREAM
);
87 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM
);
90 wxFFileInputStream
*ffileStream::DoCreateInStream()
92 wxFFileInputStream
*pFileInStream
= new wxFFileInputStream(GetInFileName());
93 CPPUNIT_ASSERT(pFileInStream
->IsOk());
96 wxFFileOutputStream
*ffileStream::DoCreateOutStream()
98 wxFFileOutputStream
*pFileOutStream
= new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM
);
99 CPPUNIT_ASSERT(pFileOutStream
->IsOk());
100 return pFileOutStream
;
103 void ffileStream::DoDeleteOutStream()
105 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM
);
108 wxString
ffileStream::GetInFileName() const
110 static bool bFileCreated
= false;
113 // Create the file only once
116 // Make sure we have a input file...
117 char buf
[DATABUFFER_SIZE
];
118 wxFFileOutputStream
out(FILENAME_FFILEINSTREAM
);
120 // Init the data buffer.
121 for (size_t i
= 0; i
< DATABUFFER_SIZE
; i
++)
125 out
.Write(buf
, DATABUFFER_SIZE
);
128 return FILENAME_FFILEINSTREAM
;
131 // Register the stream sub suite, by using some stream helper macro.
132 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
133 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(ffileStream
)