1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/filestream.cpp
3 // Purpose: Test wxFileInputStream/wxFileOutputStream
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_FILEINSTREAM
= wxT("fileinstream.test");
29 static const wxString FILENAME_FILEOUTSTREAM
= wxT("fileoutstream.test");
31 ///////////////////////////////////////////////////////////////////////////////
34 // Try to fully test wxFileInputStream and wxFileOutputStream
36 class fileStream
: public BaseStreamTestCase
<wxFileInputStream
, wxFileOutputStream
>
40 virtual ~fileStream();
42 CPPUNIT_TEST_SUITE(fileStream
);
43 // Base class stream tests the fileStream 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 wxFileInputStream
*DoCreateInStream();
70 virtual wxFileOutputStream
*DoCreateOutStream();
71 virtual void DoDeleteOutStream();
74 wxString
GetInFileName() const;
77 fileStream::fileStream()
79 m_bSeekInvalidBeyondEnd
= false;
82 fileStream::~fileStream()
84 // Remove the temp test file...
85 ::wxRemoveFile(FILENAME_FILEINSTREAM
);
86 ::wxRemoveFile(FILENAME_FILEOUTSTREAM
);
89 wxFileInputStream
*fileStream::DoCreateInStream()
91 wxFileInputStream
*pFileInStream
= new wxFileInputStream(GetInFileName());
92 CPPUNIT_ASSERT(pFileInStream
->IsOk());
95 wxFileOutputStream
*fileStream::DoCreateOutStream()
97 wxFileOutputStream
*pFileOutStream
= new wxFileOutputStream(FILENAME_FILEOUTSTREAM
);
98 CPPUNIT_ASSERT(pFileOutStream
->IsOk());
99 return pFileOutStream
;
102 void fileStream::DoDeleteOutStream()
104 ::wxRemoveFile(FILENAME_FILEOUTSTREAM
);
107 wxString
fileStream::GetInFileName() const
109 static bool bFileCreated
= false;
112 // Create the file only once
115 // Make sure we have a input file...
116 char buf
[DATABUFFER_SIZE
];
117 wxFileOutputStream
out(FILENAME_FILEINSTREAM
);
119 // Init the data buffer.
120 for (size_t i
= 0; i
< DATABUFFER_SIZE
; i
++)
124 out
.Write(buf
, DATABUFFER_SIZE
);
127 return FILENAME_FILEINSTREAM
;
130 // Register the stream sub suite, by using some stream helper macro.
131 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
132 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(fileStream
)