]>
git.saurik.com Git - wxWidgets.git/blob - tests/streams/memstream.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/memstream.cpp
3 // Purpose: Test wxMemoryInputStream/wxMemoryOutputStream
4 // Author: Hans Van Leemputten
6 // Copyright: (c) 2004 Hans Van Leemputten
7 // Licence: wxWidgets licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx/wx.h".
18 // for all others, include the necessary headers
23 #include "wx/mstream.h"
27 #define DATABUFFER_SIZE 256
29 ///////////////////////////////////////////////////////////////////////////////
32 // Try to fully test wxMemoryInputStream and wxMemoryOutputStream
34 class memStream
: public BaseStreamTestCase
<wxMemoryInputStream
, wxMemoryOutputStream
>
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
);
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
);
58 // Other test specific for Memory stream test case.
59 CPPUNIT_TEST(Ctor_InFromOut
);
60 CPPUNIT_TEST_SUITE_END();
64 void Ctor_InFromOut();
67 const char *GetDataBuffer();
70 // Implement base class functions.
71 virtual wxMemoryInputStream
*DoCreateInStream();
72 virtual wxMemoryOutputStream
*DoCreateOutStream();
75 char m_DataBuffer
[DATABUFFER_SIZE
];
78 memStream::memStream()
80 // Init the data buffer.
81 for (size_t i
= 0; i
< DATABUFFER_SIZE
; i
++)
82 m_DataBuffer
[i
] = (i
% 0xFF);
85 memStream::~memStream()
87 /* Nothing extra for now. */
90 const char *memStream::GetDataBuffer()
95 wxMemoryInputStream
*memStream::DoCreateInStream()
97 wxMemoryInputStream
*pMemInStream
= new wxMemoryInputStream(GetDataBuffer(), DATABUFFER_SIZE
);
98 CPPUNIT_ASSERT(pMemInStream
->IsOk());
101 wxMemoryOutputStream
*memStream::DoCreateOutStream()
103 wxMemoryOutputStream
*pMemOutStream
= new wxMemoryOutputStream();
104 CPPUNIT_ASSERT(pMemOutStream
->IsOk());
105 return pMemOutStream
;
108 void memStream::Ctor_InFromOut()
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);
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
)