]> git.saurik.com Git - wxWidgets.git/blob - tests/streams/filestream.cpp
Fix install_name_tool calls in OS X "make install".
[wxWidgets.git] / tests / streams / filestream.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/filestream.cpp
3 // Purpose: Test wxFileInputStream/wxFileOutputStream
4 // Author: Hans Van Leemputten
5 // Copyright: (c) 2004 Hans Van Leemputten
6 // Licence: wxWindows licence
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // For compilers that support precompilation, includes "wx/wx.h".
10 // and "wx/cppunit.h"
11 #include "testprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 // for all others, include the necessary headers
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21
22 #include "wx/wfstream.h"
23
24 #include "bstream.h"
25
26 #define DATABUFFER_SIZE 1024
27
28 static const wxString FILENAME_FILEINSTREAM = wxT("fileinstream.test");
29 static const wxString FILENAME_FILEOUTSTREAM = wxT("fileoutstream.test");
30
31 ///////////////////////////////////////////////////////////////////////////////
32 // The test case
33 //
34 // Try to fully test wxFileInputStream and wxFileOutputStream
35
36 class fileStream : public BaseStreamTestCase<wxFileInputStream, wxFileOutputStream>
37 {
38 public:
39 fileStream();
40 virtual ~fileStream();
41
42 CPPUNIT_TEST_SUITE(fileStream);
43 // Base class stream tests the fileStream supports.
44 CPPUNIT_TEST(Input_GetSize);
45 CPPUNIT_TEST(Input_GetC);
46 CPPUNIT_TEST(Input_Read);
47 CPPUNIT_TEST(Input_Eof);
48 CPPUNIT_TEST(Input_LastRead);
49 CPPUNIT_TEST(Input_CanRead);
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
64 protected:
65 // Add own test here.
66
67 private:
68 // Implement base class functions.
69 virtual wxFileInputStream *DoCreateInStream();
70 virtual wxFileOutputStream *DoCreateOutStream();
71 virtual void DoDeleteOutStream();
72
73 private:
74 wxString GetInFileName() const;
75 };
76
77 fileStream::fileStream()
78 {
79 m_bSeekInvalidBeyondEnd = false;
80 }
81
82 fileStream::~fileStream()
83 {
84 // Remove the temp test file...
85 ::wxRemoveFile(FILENAME_FILEINSTREAM);
86 ::wxRemoveFile(FILENAME_FILEOUTSTREAM);
87 }
88
89 wxFileInputStream *fileStream::DoCreateInStream()
90 {
91 wxFileInputStream *pFileInStream = new wxFileInputStream(GetInFileName());
92 CPPUNIT_ASSERT(pFileInStream->IsOk());
93 return pFileInStream;
94 }
95 wxFileOutputStream *fileStream::DoCreateOutStream()
96 {
97 wxFileOutputStream *pFileOutStream = new wxFileOutputStream(FILENAME_FILEOUTSTREAM);
98 CPPUNIT_ASSERT(pFileOutStream->IsOk());
99 return pFileOutStream;
100 }
101
102 void fileStream::DoDeleteOutStream()
103 {
104 ::wxRemoveFile(FILENAME_FILEOUTSTREAM);
105 }
106
107 wxString fileStream::GetInFileName() const
108 {
109 static bool bFileCreated = false;
110 if (!bFileCreated)
111 {
112 // Create the file only once
113 bFileCreated = true;
114
115 // Make sure we have a input file...
116 char buf[DATABUFFER_SIZE];
117 wxFileOutputStream out(FILENAME_FILEINSTREAM);
118
119 // Init the data buffer.
120 for (size_t i = 0; i < DATABUFFER_SIZE; i++)
121 buf[i] = (i % 0xFF);
122
123 // Save the data
124 out.Write(buf, DATABUFFER_SIZE);
125 }
126
127 return FILENAME_FILEINSTREAM;
128 }
129
130 // Register the stream sub suite, by using some stream helper macro.
131 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
132 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(fileStream)