]>
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 | ||
10 | #if defined(__GNUG__) && !defined(__APPLE__) | |
11 | #pragma implementation | |
12 | #pragma interface | |
13 | #endif | |
14 | ||
15 | // For compilers that support precompilation, includes "wx/wx.h". | |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | // for all others, include the necessary headers | |
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/cppunit.h" | |
28 | #include "wx/wfstream.h" | |
29 | ||
30 | #include "bstream.h" | |
31 | ||
32 | using namespace std; | |
33 | using namespace CppUnit; | |
34 | ||
35 | #define DATABUFFER_SIZE 1024 | |
36 | ||
37 | static const wxString FILENAME_FFILEINSTREAM = _T("ffileinstream.test"); | |
38 | static const wxString FILENAME_FFILEOUTSTREAM = _T("ffileoutstream.test"); | |
39 | ||
40 | /////////////////////////////////////////////////////////////////////////////// | |
41 | // The test case | |
42 | // | |
43 | // Try to fully test wxFFileInputStream and wxFFileOutputStream | |
44 | ||
45 | class ffileStream : public BaseStreamTestCase<wxFFileInputStream, wxFFileOutputStream> | |
46 | { | |
47 | public: | |
48 | ffileStream(); | |
49 | virtual ~ffileStream(); | |
50 | ||
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); | |
62 | ||
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); | |
68 | ||
69 | // Other test specific for File stream test case. | |
70 | CPPUNIT_TEST_SUITE_END(); | |
71 | ||
72 | protected: | |
73 | // Add own test here. | |
74 | ||
75 | private: | |
76 | // Implement base class functions. | |
77 | virtual wxFFileInputStream *DoCreateInStream(); | |
78 | virtual wxFFileOutputStream *DoCreateOutStream(); | |
79 | virtual void DoDeleteOutStream(); | |
80 | ||
81 | private: | |
82 | wxString GetInFileName() const; | |
83 | }; | |
84 | ||
85 | ffileStream::ffileStream() | |
86 | { | |
87 | /* Nothing extra */ | |
88 | } | |
89 | ||
90 | ffileStream::~ffileStream() | |
91 | { | |
92 | // Remove the temp test file... | |
93 | ::wxRemoveFile(FILENAME_FFILEINSTREAM); | |
94 | ::wxRemoveFile(FILENAME_FFILEOUTSTREAM); | |
95 | } | |
96 | ||
97 | wxFFileInputStream *ffileStream::DoCreateInStream() | |
98 | { | |
99 | wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName()); | |
100 | CPPUNIT_ASSERT(pFileInStream->IsOk()); | |
101 | return pFileInStream; | |
102 | } | |
103 | wxFFileOutputStream *ffileStream::DoCreateOutStream() | |
104 | { | |
105 | wxFFileOutputStream *pFileOutStream = new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM); | |
106 | CPPUNIT_ASSERT(pFileOutStream->IsOk()); | |
107 | return pFileOutStream; | |
108 | } | |
109 | ||
110 | void ffileStream::DoDeleteOutStream() | |
111 | { | |
112 | ::wxRemoveFile(FILENAME_FFILEOUTSTREAM); | |
113 | } | |
114 | ||
115 | wxString ffileStream::GetInFileName() const | |
116 | { | |
117 | static bool bFileCreated = false; | |
118 | if (!bFileCreated) | |
119 | { | |
120 | // Create the file only once | |
121 | bFileCreated = true; | |
122 | ||
123 | // Make sure we have a input file... | |
124 | char buf[DATABUFFER_SIZE]; | |
125 | wxFFileOutputStream out(FILENAME_FFILEINSTREAM); | |
126 | ||
127 | // Init the data buffer. | |
128 | for (size_t i = 0; i < DATABUFFER_SIZE; i++) | |
129 | buf[i] = (i % 0xFF); | |
130 | ||
131 | // Save the data | |
132 | out.Write(buf, DATABUFFER_SIZE); | |
133 | } | |
134 | ||
135 | return FILENAME_FFILEINSTREAM; | |
136 | } | |
137 | ||
138 | // Register the stream sub suite, by using some stream helper macro. | |
139 | // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite()) | |
140 | STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(ffileStream) |