]> git.saurik.com Git - wxWidgets.git/blob - tests/streams/ffilestream.cpp
compilation fix for case that wxHAS_RAW_BITMAP is NOT defined
[wxWidgets.git] / tests / streams / ffilestream.cpp
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: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx/wx.h".
11 // and "wx/cppunit.h"
12 #include "testprec.h"
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
23 #include "wx/wfstream.h"
24
25 #include "bstream.h"
26
27 #define DATABUFFER_SIZE 1024
28
29 static const wxString FILENAME_FFILEINSTREAM = wxT("ffileinstream.test");
30 static const wxString FILENAME_FFILEOUTSTREAM = wxT("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);
50 CPPUNIT_TEST(Input_CanRead);
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.
70 virtual wxFFileInputStream *DoCreateInStream();
71 virtual wxFFileOutputStream *DoCreateOutStream();
72 virtual void DoDeleteOutStream();
73
74 private:
75 wxString GetInFileName() const;
76 };
77
78 ffileStream::ffileStream()
79 {
80 m_bSeekInvalidBeyondEnd = false;
81 m_bEofAtLastRead = false;
82 }
83
84 ffileStream::~ffileStream()
85 {
86 // Remove the temp test file...
87 ::wxRemoveFile(FILENAME_FFILEINSTREAM);
88 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM);
89 }
90
91 wxFFileInputStream *ffileStream::DoCreateInStream()
92 {
93 wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName());
94 CPPUNIT_ASSERT(pFileInStream->IsOk());
95 return pFileInStream;
96 }
97 wxFFileOutputStream *ffileStream::DoCreateOutStream()
98 {
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);
120
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)