Patch 1053127 - Test fixes.
[wxWidgets.git] / tests / streams / memstream.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/memstream.cpp
3 // Purpose: Test wxMemoryInputStream/wxMemoryOutputStream
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/mstream.h"
29
30 #include "bstream.h"
31
32 #define DATABUFFER_SIZE 256
33
34 ///////////////////////////////////////////////////////////////////////////////
35 // The test case
36 //
37 // Try to fully test wxMemoryInputStream and wxMemoryOutputStream
38
39 class memStream : public BaseStreamTestCase<wxMemoryInputStream, wxMemoryOutputStream>
40 {
41 public:
42 memStream();
43 virtual ~memStream();
44
45 CPPUNIT_TEST_SUITE(memStream);
46 // Base class stream tests the memStream supports.
47 CPPUNIT_TEST(Input_GetSize);
48 CPPUNIT_TEST(Input_GetC);
49 CPPUNIT_TEST(Input_Read);
50 CPPUNIT_TEST(Input_Eof);
51 CPPUNIT_TEST(Input_LastRead);
52 CPPUNIT_TEST(Input_SeekI);
53 CPPUNIT_TEST(Input_TellI);
54 CPPUNIT_TEST(Input_Peek);
55 CPPUNIT_TEST(Input_Ungetch);
56
57 CPPUNIT_TEST(Output_PutC);
58 CPPUNIT_TEST(Output_Write);
59 CPPUNIT_TEST(Output_LastWrite);
60 CPPUNIT_TEST(Output_SeekO);
61 CPPUNIT_TEST(Output_TellO);
62
63 // Other test specific for Memory stream test case.
64 CPPUNIT_TEST_SUITE_END();
65
66 protected:
67 // Add own test here.
68
69 private:
70 const char *GetDataBuffer();
71
72 private:
73 // Implement base class functions.
74 virtual wxMemoryInputStream *DoCreateInStream();
75 virtual wxMemoryOutputStream *DoCreateOutStream();
76
77 private:
78 char m_DataBuffer[DATABUFFER_SIZE];
79 };
80
81 memStream::memStream()
82 {
83 // Init the data buffer.
84 for (size_t i = 0; i < DATABUFFER_SIZE; i++)
85 m_DataBuffer[i] = (i % 0xFF);
86 }
87
88 memStream::~memStream()
89 {
90 /* Nothing extra for now. */
91 }
92
93 const char *memStream::GetDataBuffer()
94 {
95 return m_DataBuffer;
96 }
97
98 wxMemoryInputStream *memStream::DoCreateInStream()
99 {
100 wxMemoryInputStream *pMemInStream = new wxMemoryInputStream(GetDataBuffer(), DATABUFFER_SIZE);
101 CPPUNIT_ASSERT(pMemInStream->IsOk());
102 return pMemInStream;
103 }
104 wxMemoryOutputStream *memStream::DoCreateOutStream()
105 {
106 wxMemoryOutputStream *pMemOutStream = new wxMemoryOutputStream();
107 CPPUNIT_ASSERT(pMemOutStream->IsOk());
108 return pMemOutStream;
109 }
110
111
112 // Register the stream sub suite, by using some stream helper macro.
113 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
114 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(memStream)