]> git.saurik.com Git - wxWidgets.git/blame_incremental - tests/streams/ffilestream.cpp
removed a couple of useless #if wxUSE_UNICODE tests
[wxWidgets.git] / tests / streams / ffilestream.cpp
... / ...
CommitLineData
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// 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
29static const wxString FILENAME_FFILEINSTREAM = _T("ffileinstream.test");
30static const wxString FILENAME_FFILEOUTSTREAM = _T("ffileoutstream.test");
31
32///////////////////////////////////////////////////////////////////////////////
33// The test case
34//
35// Try to fully test wxFFileInputStream and wxFFileOutputStream
36
37class ffileStream : public BaseStreamTestCase<wxFFileInputStream, wxFFileOutputStream>
38{
39public:
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_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
64protected:
65 // Add own test here.
66
67private:
68 // Implement base class functions.
69 virtual wxFFileInputStream *DoCreateInStream();
70 virtual wxFFileOutputStream *DoCreateOutStream();
71 virtual void DoDeleteOutStream();
72
73private:
74 wxString GetInFileName() const;
75};
76
77ffileStream::ffileStream()
78{
79 m_bSeekInvalidBeyondEnd = false;
80 m_bEofAtLastRead = false;
81}
82
83ffileStream::~ffileStream()
84{
85 // Remove the temp test file...
86 ::wxRemoveFile(FILENAME_FFILEINSTREAM);
87 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM);
88}
89
90wxFFileInputStream *ffileStream::DoCreateInStream()
91{
92 wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName());
93 CPPUNIT_ASSERT(pFileInStream->IsOk());
94 return pFileInStream;
95}
96wxFFileOutputStream *ffileStream::DoCreateOutStream()
97{
98 wxFFileOutputStream *pFileOutStream = new wxFFileOutputStream(FILENAME_FFILEOUTSTREAM);
99 CPPUNIT_ASSERT(pFileOutStream->IsOk());
100 return pFileOutStream;
101}
102
103void ffileStream::DoDeleteOutStream()
104{
105 ::wxRemoveFile(FILENAME_FFILEOUTSTREAM);
106}
107
108wxString 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);
119
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())
133STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(ffileStream)