]> git.saurik.com Git - wxWidgets.git/blame - tests/streams/filestream.cpp
Fix warnings in the MSW IE backend.
[wxWidgets.git] / tests / streams / filestream.cpp
CommitLineData
340da6ae
VS
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
526954c5 7// Licence: wxWindows licence
340da6ae
VS
8///////////////////////////////////////////////////////////////////////////////
9
340da6ae 10// For compilers that support precompilation, includes "wx/wx.h".
8899b155
RN
11// and "wx/cppunit.h"
12#include "testprec.h"
340da6ae
VS
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
340da6ae
VS
23#include "wx/wfstream.h"
24
25#include "bstream.h"
26
340da6ae
VS
27#define DATABUFFER_SIZE 1024
28
9a83f860
VZ
29static const wxString FILENAME_FILEINSTREAM = wxT("fileinstream.test");
30static const wxString FILENAME_FILEOUTSTREAM = wxT("fileoutstream.test");
340da6ae
VS
31
32///////////////////////////////////////////////////////////////////////////////
33// The test case
34//
35// Try to fully test wxFileInputStream and wxFileOutputStream
36
37class fileStream : public BaseStreamTestCase<wxFileInputStream, wxFileOutputStream>
38{
39public:
40 fileStream();
41 virtual ~fileStream();
42
43 CPPUNIT_TEST_SUITE(fileStream);
44 // Base class stream tests the fileStream 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);
2d76b6d8 50 CPPUNIT_TEST(Input_CanRead);
340da6ae
VS
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
65protected:
66 // Add own test here.
67
68private:
69 // Implement base class functions.
3e5f6c1c 70 virtual wxFileInputStream *DoCreateInStream();
340da6ae
VS
71 virtual wxFileOutputStream *DoCreateOutStream();
72 virtual void DoDeleteOutStream();
73
74private:
75 wxString GetInFileName() const;
76};
77
78fileStream::fileStream()
79{
08776b09 80 m_bSeekInvalidBeyondEnd = false;
340da6ae
VS
81}
82
83fileStream::~fileStream()
84{
85 // Remove the temp test file...
86 ::wxRemoveFile(FILENAME_FILEINSTREAM);
87 ::wxRemoveFile(FILENAME_FILEOUTSTREAM);
88}
89
3e5f6c1c
WS
90wxFileInputStream *fileStream::DoCreateInStream()
91{
340da6ae
VS
92 wxFileInputStream *pFileInStream = new wxFileInputStream(GetInFileName());
93 CPPUNIT_ASSERT(pFileInStream->IsOk());
94 return pFileInStream;
95}
96wxFileOutputStream *fileStream::DoCreateOutStream()
3e5f6c1c 97{
340da6ae
VS
98 wxFileOutputStream *pFileOutStream = new wxFileOutputStream(FILENAME_FILEOUTSTREAM);
99 CPPUNIT_ASSERT(pFileOutStream->IsOk());
100 return pFileOutStream;
101}
102
103void fileStream::DoDeleteOutStream()
104{
105 ::wxRemoveFile(FILENAME_FILEOUTSTREAM);
106}
107
108wxString fileStream::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 wxFileOutputStream out(FILENAME_FILEINSTREAM);
3e5f6c1c 119
340da6ae
VS
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_FILEINSTREAM;
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(fileStream)