]> git.saurik.com Git - wxWidgets.git/blame_incremental - tests/streams/filestream.cpp
wxTextOutputStream::PutChar and text stream test
[wxWidgets.git] / tests / streams / filestream.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/streams/filestream.cpp
3// Purpose: Test wxFileInputStream/wxFileOutputStream
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#define DATABUFFER_SIZE 1024
33
34static const wxString FILENAME_FILEINSTREAM = _T("fileinstream.test");
35static const wxString FILENAME_FILEOUTSTREAM = _T("fileoutstream.test");
36
37///////////////////////////////////////////////////////////////////////////////
38// The test case
39//
40// Try to fully test wxFileInputStream and wxFileOutputStream
41
42class fileStream : public BaseStreamTestCase<wxFileInputStream, wxFileOutputStream>
43{
44public:
45 fileStream();
46 virtual ~fileStream();
47
48 CPPUNIT_TEST_SUITE(fileStream);
49 // Base class stream tests the fileStream 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.
74 virtual wxFileInputStream *DoCreateInStream();
75 virtual wxFileOutputStream *DoCreateOutStream();
76 virtual void DoDeleteOutStream();
77
78private:
79 wxString GetInFileName() const;
80};
81
82fileStream::fileStream()
83{
84 m_bSeekInvalidBeyondEnd = false;
85}
86
87fileStream::~fileStream()
88{
89 // Remove the temp test file...
90 ::wxRemoveFile(FILENAME_FILEINSTREAM);
91 ::wxRemoveFile(FILENAME_FILEOUTSTREAM);
92}
93
94wxFileInputStream *fileStream::DoCreateInStream()
95{
96 wxFileInputStream *pFileInStream = new wxFileInputStream(GetInFileName());
97 CPPUNIT_ASSERT(pFileInStream->IsOk());
98 return pFileInStream;
99}
100wxFileOutputStream *fileStream::DoCreateOutStream()
101{
102 wxFileOutputStream *pFileOutStream = new wxFileOutputStream(FILENAME_FILEOUTSTREAM);
103 CPPUNIT_ASSERT(pFileOutStream->IsOk());
104 return pFileOutStream;
105}
106
107void fileStream::DoDeleteOutStream()
108{
109 ::wxRemoveFile(FILENAME_FILEOUTSTREAM);
110}
111
112wxString fileStream::GetInFileName() const
113{
114 static bool bFileCreated = false;
115 if (!bFileCreated)
116 {
117 // Create the file only once
118 bFileCreated = true;
119
120 // Make sure we have a input file...
121 char buf[DATABUFFER_SIZE];
122 wxFileOutputStream out(FILENAME_FILEINSTREAM);
123
124 // Init the data buffer.
125 for (size_t i = 0; i < DATABUFFER_SIZE; i++)
126 buf[i] = (i % 0xFF);
127
128 // Save the data
129 out.Write(buf, DATABUFFER_SIZE);
130 }
131
132 return FILENAME_FILEINSTREAM;
133}
134
135// Register the stream sub suite, by using some stream helper macro.
136// Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
137STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(fileStream)