1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/ffilestream.cpp
3 // Purpose: Test wxFFileInputStream/wxFFileOutputStream
4 // Author: Hans Van Leemputten
6 // Copyright: (c) 2004 Hans Van Leemputten
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx/wx.h".
18 // for all others, include the necessary headers
23 #include "wx/wfstream.h"
27 #define DATABUFFER_SIZE 1024
29 static const wxString FILENAME_FFILEINSTREAM
= wxT("ffileinstream.test");
30 static const wxString FILENAME_FFILEOUTSTREAM
= wxT("ffileoutstream.test");
32 ///////////////////////////////////////////////////////////////////////////////
35 // Try to fully test wxFFileInputStream and wxFFileOutputStream
37 class ffileStream
: public BaseStreamTestCase
<wxFFileInputStream
, wxFFileOutputStream
>
41 virtual ~ffileStream();
43 CPPUNIT_TEST_SUITE(ffileStream
);
44 // Base class stream tests the ffileStream supports.
45 CPPUNIT_TEST(Input_GetSize
);
46 CPPUNIT_TEST(Input_GetC
);
47 CPPUNIT_TEST(Input_Read
);
48 CPPUNIT_TEST(Input_Eof
);
49 CPPUNIT_TEST(Input_LastRead
);
50 CPPUNIT_TEST(Input_CanRead
);
51 CPPUNIT_TEST(Input_SeekI
);
52 CPPUNIT_TEST(Input_TellI
);
53 CPPUNIT_TEST(Input_Peek
);
54 CPPUNIT_TEST(Input_Ungetch
);
56 CPPUNIT_TEST(Output_PutC
);
57 CPPUNIT_TEST(Output_Write
);
58 CPPUNIT_TEST(Output_LastWrite
);
59 CPPUNIT_TEST(Output_SeekO
);
60 CPPUNIT_TEST(Output_TellO
);
62 // Other test specific for File stream test case.
63 CPPUNIT_TEST_SUITE_END();
69 // Implement base class functions.
70 virtual wxFFileInputStream
*DoCreateInStream();
71 virtual wxFFileOutputStream
*DoCreateOutStream();
72 virtual void DoDeleteOutStream();
75 wxString
GetInFileName() const;
78 ffileStream::ffileStream()
80 m_bSeekInvalidBeyondEnd
= false;
81 m_bEofAtLastRead
= false;
84 ffileStream::~ffileStream()
86 // Remove the temp test file...
87 ::wxRemoveFile(FILENAME_FFILEINSTREAM
);
88 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM
);
91 wxFFileInputStream
*ffileStream::DoCreateInStream()
93 wxFFileInputStream
*pFileInStream
= new wxFFileInputStream(GetInFileName());
94 CPPUNIT_ASSERT(pFileInStream
->IsOk());
97 wxFFileOutputStream
*ffileStream::DoCreateOutStream()
99 wxFFileOutputStream
*pFileOutStream
= new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM
);
100 CPPUNIT_ASSERT(pFileOutStream
->IsOk());
101 return pFileOutStream
;
104 void ffileStream::DoDeleteOutStream()
106 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM
);
109 wxString
ffileStream::GetInFileName() const
111 static bool bFileCreated
= false;
114 // Create the file only once
117 // Make sure we have a input file...
118 char buf
[DATABUFFER_SIZE
];
119 wxFFileOutputStream
out(FILENAME_FFILEINSTREAM
);
121 // Init the data buffer.
122 for (size_t i
= 0; i
< DATABUFFER_SIZE
; i
++)
126 out
.Write(buf
, DATABUFFER_SIZE
);
129 return FILENAME_FFILEINSTREAM
;
132 // Register the stream sub suite, by using some stream helper macro.
133 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
134 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(ffileStream
)