]>
Commit | Line | Data |
---|---|---|
340da6ae VS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/streams/ffilestream.cpp | |
3 | // Purpose: Test wxFFileInputStream/wxFFileOutputStream | |
4 | // Author: Hans Van Leemputten | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 2004 Hans Van Leemputten | |
7 | // Licence: wxWidgets licence | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
340da6ae | 10 | // For compilers that support precompilation, includes "wx/wx.h". |
8899b155 RN |
11 | // and "wx/cppunit.h" |
12 | #include "testprec.h" | |
340da6ae VS |
13 | |
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | // for all others, include the necessary headers | |
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/wx.h" | |
21 | #endif | |
22 | ||
340da6ae VS |
23 | #include "wx/wfstream.h" |
24 | ||
25 | #include "bstream.h" | |
26 | ||
340da6ae VS |
27 | #define DATABUFFER_SIZE 1024 |
28 | ||
29 | static const wxString FILENAME_FFILEINSTREAM = _T("ffileinstream.test"); | |
30 | static const wxString FILENAME_FFILEOUTSTREAM = _T("ffileoutstream.test"); | |
31 | ||
32 | /////////////////////////////////////////////////////////////////////////////// | |
33 | // The test case | |
34 | // | |
35 | // Try to fully test wxFFileInputStream and wxFFileOutputStream | |
36 | ||
37 | class ffileStream : public BaseStreamTestCase<wxFFileInputStream, wxFFileOutputStream> | |
38 | { | |
39 | public: | |
40 | ffileStream(); | |
41 | virtual ~ffileStream(); | |
42 | ||
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); | |
2d76b6d8 | 50 | CPPUNIT_TEST(Input_CanRead); |
340da6ae VS |
51 | CPPUNIT_TEST(Input_SeekI); |
52 | CPPUNIT_TEST(Input_TellI); | |
53 | CPPUNIT_TEST(Input_Peek); | |
54 | CPPUNIT_TEST(Input_Ungetch); | |
55 | ||
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); | |
61 | ||
62 | // Other test specific for File stream test case. | |
63 | CPPUNIT_TEST_SUITE_END(); | |
64 | ||
65 | protected: | |
66 | // Add own test here. | |
67 | ||
68 | private: | |
69 | // Implement base class functions. | |
3e5f6c1c | 70 | virtual wxFFileInputStream *DoCreateInStream(); |
340da6ae VS |
71 | virtual wxFFileOutputStream *DoCreateOutStream(); |
72 | virtual void DoDeleteOutStream(); | |
73 | ||
74 | private: | |
75 | wxString GetInFileName() const; | |
76 | }; | |
77 | ||
78 | ffileStream::ffileStream() | |
79 | { | |
08776b09 | 80 | m_bSeekInvalidBeyondEnd = false; |
7735998c | 81 | m_bEofAtLastRead = false; |
340da6ae VS |
82 | } |
83 | ||
84 | ffileStream::~ffileStream() | |
85 | { | |
86 | // Remove the temp test file... | |
87 | ::wxRemoveFile(FILENAME_FFILEINSTREAM); | |
88 | ::wxRemoveFile(FILENAME_FFILEOUTSTREAM); | |
89 | } | |
90 | ||
3e5f6c1c WS |
91 | wxFFileInputStream *ffileStream::DoCreateInStream() |
92 | { | |
340da6ae VS |
93 | wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName()); |
94 | CPPUNIT_ASSERT(pFileInStream->IsOk()); | |
95 | return pFileInStream; | |
96 | } | |
97 | wxFFileOutputStream *ffileStream::DoCreateOutStream() | |
3e5f6c1c | 98 | { |
340da6ae VS |
99 | wxFFileOutputStream *pFileOutStream = new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM); |
100 | CPPUNIT_ASSERT(pFileOutStream->IsOk()); | |
101 | return pFileOutStream; | |
102 | } | |
103 | ||
104 | void ffileStream::DoDeleteOutStream() | |
105 | { | |
106 | ::wxRemoveFile(FILENAME_FFILEOUTSTREAM); | |
107 | } | |
108 | ||
109 | wxString ffileStream::GetInFileName() const | |
110 | { | |
111 | static bool bFileCreated = false; | |
112 | if (!bFileCreated) | |
113 | { | |
114 | // Create the file only once | |
115 | bFileCreated = true; | |
116 | ||
117 | // Make sure we have a input file... | |
118 | char buf[DATABUFFER_SIZE]; | |
119 | wxFFileOutputStream out(FILENAME_FFILEINSTREAM); | |
3e5f6c1c | 120 | |
340da6ae VS |
121 | // Init the data buffer. |
122 | for (size_t i = 0; i < DATABUFFER_SIZE; i++) | |
123 | buf[i] = (i % 0xFF); | |
124 | ||
125 | // Save the data | |
126 | out.Write(buf, DATABUFFER_SIZE); | |
127 | } | |
128 | ||
129 | return FILENAME_FFILEINSTREAM; | |
130 | } | |
131 | ||
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) |