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: 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"
33 using namespace CppUnit
;
35 #define DATABUFFER_SIZE 1024
37 static const wxString FILENAME_FFILEINSTREAM
= _T("ffileinstream.test");
38 static const wxString FILENAME_FFILEOUTSTREAM
= _T("ffileoutstream.test");
40 ///////////////////////////////////////////////////////////////////////////////
43 // Try to fully test wxFFileInputStream and wxFFileOutputStream
45 class ffileStream
: public BaseStreamTestCase
<wxFFileInputStream
, wxFFileOutputStream
>
49 virtual ~ffileStream();
51 CPPUNIT_TEST_SUITE(ffileStream
);
52 // Base class stream tests the ffileStream supports.
53 CPPUNIT_TEST(Input_GetSize
);
54 CPPUNIT_TEST(Input_GetC
);
55 CPPUNIT_TEST(Input_Read
);
56 CPPUNIT_TEST(Input_Eof
);
57 CPPUNIT_TEST(Input_LastRead
);
58 CPPUNIT_TEST(Input_SeekI
);
59 CPPUNIT_TEST(Input_TellI
);
60 CPPUNIT_TEST(Input_Peek
);
61 CPPUNIT_TEST(Input_Ungetch
);
63 CPPUNIT_TEST(Output_PutC
);
64 CPPUNIT_TEST(Output_Write
);
65 CPPUNIT_TEST(Output_LastWrite
);
66 CPPUNIT_TEST(Output_SeekO
);
67 CPPUNIT_TEST(Output_TellO
);
69 // Other test specific for File stream test case.
70 CPPUNIT_TEST_SUITE_END();
76 // Implement base class functions.
77 virtual wxFFileInputStream
*DoCreateInStream();
78 virtual wxFFileOutputStream
*DoCreateOutStream();
79 virtual void DoDeleteOutStream();
82 wxString
GetInFileName() const;
85 ffileStream::ffileStream()
87 m_bSeekInvalidBeyondEnd
= false;
88 m_bEofAtLastRead
= false;
91 ffileStream::~ffileStream()
93 // Remove the temp test file...
94 ::wxRemoveFile(FILENAME_FFILEINSTREAM
);
95 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM
);
98 wxFFileInputStream
*ffileStream::DoCreateInStream()
100 wxFFileInputStream
*pFileInStream
= new wxFFileInputStream(GetInFileName());
101 CPPUNIT_ASSERT(pFileInStream
->IsOk());
102 return pFileInStream
;
104 wxFFileOutputStream
*ffileStream::DoCreateOutStream()
106 wxFFileOutputStream
*pFileOutStream
= new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM
);
107 CPPUNIT_ASSERT(pFileOutStream
->IsOk());
108 return pFileOutStream
;
111 void ffileStream::DoDeleteOutStream()
113 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM
);
116 wxString
ffileStream::GetInFileName() const
118 static bool bFileCreated
= false;
121 // Create the file only once
124 // Make sure we have a input file...
125 char buf
[DATABUFFER_SIZE
];
126 wxFFileOutputStream
out(FILENAME_FFILEINSTREAM
);
128 // Init the data buffer.
129 for (size_t i
= 0; i
< DATABUFFER_SIZE
; i
++)
133 out
.Write(buf
, DATABUFFER_SIZE
);
136 return FILENAME_FFILEINSTREAM
;
139 // Register the stream sub suite, by using some stream helper macro.
140 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
141 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(ffileStream
)