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"
32 #define DATABUFFER_SIZE 1024
34 static const wxString FILENAME_FFILEINSTREAM
= _T("ffileinstream.test");
35 static const wxString FILENAME_FFILEOUTSTREAM
= _T("ffileoutstream.test");
37 ///////////////////////////////////////////////////////////////////////////////
40 // Try to fully test wxFFileInputStream and wxFFileOutputStream
42 class ffileStream
: public BaseStreamTestCase
<wxFFileInputStream
, wxFFileOutputStream
>
46 virtual ~ffileStream();
48 CPPUNIT_TEST_SUITE(ffileStream
);
49 // Base class stream tests the ffileStream 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 wxFFileInputStream
*DoCreateInStream();
75 virtual wxFFileOutputStream
*DoCreateOutStream();
76 virtual void DoDeleteOutStream();
79 wxString
GetInFileName() const;
82 ffileStream::ffileStream()
84 m_bSeekInvalidBeyondEnd
= false;
85 m_bEofAtLastRead
= false;
88 ffileStream::~ffileStream()
90 // Remove the temp test file...
91 ::wxRemoveFile(FILENAME_FFILEINSTREAM
);
92 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM
);
95 wxFFileInputStream
*ffileStream::DoCreateInStream()
97 wxFFileInputStream
*pFileInStream
= new wxFFileInputStream(GetInFileName());
98 CPPUNIT_ASSERT(pFileInStream
->IsOk());
101 wxFFileOutputStream
*ffileStream::DoCreateOutStream()
103 wxFFileOutputStream
*pFileOutStream
= new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM
);
104 CPPUNIT_ASSERT(pFileOutStream
->IsOk());
105 return pFileOutStream
;
108 void ffileStream::DoDeleteOutStream()
110 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM
);
113 wxString
ffileStream::GetInFileName() const
115 static bool bFileCreated
= false;
118 // Create the file only once
121 // Make sure we have a input file...
122 char buf
[DATABUFFER_SIZE
];
123 wxFFileOutputStream
out(FILENAME_FFILEINSTREAM
);
125 // Init the data buffer.
126 for (size_t i
= 0; i
< DATABUFFER_SIZE
; i
++)
130 out
.Write(buf
, DATABUFFER_SIZE
);
133 return FILENAME_FFILEINSTREAM
;
136 // Register the stream sub suite, by using some stream helper macro.
137 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
138 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(ffileStream
)