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