]> git.saurik.com Git - wxWidgets.git/blame - tests/streams/ffilestream.cpp
wxTextOutputStream::PutChar and text stream test
[wxWidgets.git] / tests / streams / ffilestream.cpp
CommitLineData
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
340da6ae
VS
32#define DATABUFFER_SIZE 1024
33
34static const wxString FILENAME_FFILEINSTREAM = _T("ffileinstream.test");
35static const wxString FILENAME_FFILEOUTSTREAM = _T("ffileoutstream.test");
36
37///////////////////////////////////////////////////////////////////////////////
38// The test case
39//
40// Try to fully test wxFFileInputStream and wxFFileOutputStream
41
42class ffileStream : public BaseStreamTestCase<wxFFileInputStream, wxFFileOutputStream>
43{
44public:
45 ffileStream();
46 virtual ~ffileStream();
47
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);
59
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);
65
66 // Other test specific for File stream test case.
67 CPPUNIT_TEST_SUITE_END();
68
69protected:
70 // Add own test here.
71
72private:
73 // Implement base class functions.
3e5f6c1c 74 virtual wxFFileInputStream *DoCreateInStream();
340da6ae
VS
75 virtual wxFFileOutputStream *DoCreateOutStream();
76 virtual void DoDeleteOutStream();
77
78private:
79 wxString GetInFileName() const;
80};
81
82ffileStream::ffileStream()
83{
08776b09 84 m_bSeekInvalidBeyondEnd = false;
7735998c 85 m_bEofAtLastRead = false;
340da6ae
VS
86}
87
88ffileStream::~ffileStream()
89{
90 // Remove the temp test file...
91 ::wxRemoveFile(FILENAME_FFILEINSTREAM);
92 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM);
93}
94
3e5f6c1c
WS
95wxFFileInputStream *ffileStream::DoCreateInStream()
96{
340da6ae
VS
97 wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName());
98 CPPUNIT_ASSERT(pFileInStream->IsOk());
99 return pFileInStream;
100}
101wxFFileOutputStream *ffileStream::DoCreateOutStream()
3e5f6c1c 102{
340da6ae
VS
103 wxFFileOutputStream *pFileOutStream = new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM);
104 CPPUNIT_ASSERT(pFileOutStream->IsOk());
105 return pFileOutStream;
106}
107
108void ffileStream::DoDeleteOutStream()
109{
110 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM);
111}
112
113wxString ffileStream::GetInFileName() const
114{
115 static bool bFileCreated = false;
116 if (!bFileCreated)
117 {
118 // Create the file only once
119 bFileCreated = true;
120
121 // Make sure we have a input file...
122 char buf[DATABUFFER_SIZE];
123 wxFFileOutputStream out(FILENAME_FFILEINSTREAM);
3e5f6c1c 124
340da6ae
VS
125 // Init the data buffer.
126 for (size_t i = 0; i < DATABUFFER_SIZE; i++)
127 buf[i] = (i % 0xFF);
128
129 // Save the data
130 out.Write(buf, DATABUFFER_SIZE);
131 }
132
133 return FILENAME_FFILEINSTREAM;
134}
135
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())
138STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(ffileStream)