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