1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/filestream.cpp
3 // Purpose: Test wxFileInputStream/wxFileOutputStream
4 // Author: Hans Van Leemputten
6 // Copyright: (c) 2004 Hans Van Leemputten
7 // Licence: wxWidgets licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(__APPLE__)
11 #pragma implementation
15 // For compilers that support precompilation, includes "wx/wx.h".
16 #include "wx/wxprec.h"
22 // for all others, include the necessary headers
27 #include "wx/cppunit.h"
28 #include "wx/wfstream.h"
32 #define DATABUFFER_SIZE 1024
34 static const wxString FILENAME_FILEINSTREAM
= _T("fileinstream.test");
35 static const wxString FILENAME_FILEOUTSTREAM
= _T("fileoutstream.test");
37 ///////////////////////////////////////////////////////////////////////////////
40 // Try to fully test wxFileInputStream and wxFileOutputStream
42 class fileStream
: public BaseStreamTestCase
<wxFileInputStream
, wxFileOutputStream
>
46 virtual ~fileStream();
48 CPPUNIT_TEST_SUITE(fileStream
);
49 // Base class stream tests the fileStream supports.
50 CPPUNIT_TEST(Input_GetSize
);
51 CPPUNIT_TEST(Input_GetC
);
52 CPPUNIT_TEST(Input_Read
);
53 CPPUNIT_TEST(Input_Eof
);
54 CPPUNIT_TEST(Input_LastRead
);
55 CPPUNIT_TEST(Input_SeekI
);
56 CPPUNIT_TEST(Input_TellI
);
57 CPPUNIT_TEST(Input_Peek
);
58 CPPUNIT_TEST(Input_Ungetch
);
60 CPPUNIT_TEST(Output_PutC
);
61 CPPUNIT_TEST(Output_Write
);
62 CPPUNIT_TEST(Output_LastWrite
);
63 CPPUNIT_TEST(Output_SeekO
);
64 CPPUNIT_TEST(Output_TellO
);
66 // Other test specific for File stream test case.
67 CPPUNIT_TEST_SUITE_END();
73 // Implement base class functions.
74 virtual wxFileInputStream
*DoCreateInStream();
75 virtual wxFileOutputStream
*DoCreateOutStream();
76 virtual void DoDeleteOutStream();
79 wxString
GetInFileName() const;
82 fileStream::fileStream()
84 m_bSeekInvalidBeyondEnd
= false;
87 fileStream::~fileStream()
89 // Remove the temp test file...
90 ::wxRemoveFile(FILENAME_FILEINSTREAM
);
91 ::wxRemoveFile(FILENAME_FILEOUTSTREAM
);
94 wxFileInputStream
*fileStream::DoCreateInStream()
96 wxFileInputStream
*pFileInStream
= new wxFileInputStream(GetInFileName());
97 CPPUNIT_ASSERT(pFileInStream
->IsOk());
100 wxFileOutputStream
*fileStream::DoCreateOutStream()
102 wxFileOutputStream
*pFileOutStream
= new wxFileOutputStream(FILENAME_FILEOUTSTREAM
);
103 CPPUNIT_ASSERT(pFileOutStream
->IsOk());
104 return pFileOutStream
;
107 void fileStream::DoDeleteOutStream()
109 ::wxRemoveFile(FILENAME_FILEOUTSTREAM
);
112 wxString
fileStream::GetInFileName() const
114 static bool bFileCreated
= false;
117 // Create the file only once
120 // Make sure we have a input file...
121 char buf
[DATABUFFER_SIZE
];
122 wxFileOutputStream
out(FILENAME_FILEINSTREAM
);
124 // Init the data buffer.
125 for (size_t i
= 0; i
< DATABUFFER_SIZE
; i
++)
129 out
.Write(buf
, DATABUFFER_SIZE
);
132 return FILENAME_FILEINSTREAM
;
135 // Register the stream sub suite, by using some stream helper macro.
136 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
137 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(fileStream
)