]> git.saurik.com Git - wxWidgets.git/blame - tests/streams/memstream.cpp
don't test for __WIN95__ which doesn't exist any more; don't do compiler checks here...
[wxWidgets.git] / tests / streams / memstream.cpp
CommitLineData
340da6ae
VS
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
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/mstream.h"
24
25#include "bstream.h"
26
340da6ae
VS
27#define DATABUFFER_SIZE 256
28
29///////////////////////////////////////////////////////////////////////////////
30// The test case
31//
32// Try to fully test wxMemoryInputStream and wxMemoryOutputStream
33
34class memStream : public BaseStreamTestCase<wxMemoryInputStream, wxMemoryOutputStream>
35{
36public:
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.
96461cc2 59 CPPUNIT_TEST(Ctor_InFromOut);
340da6ae
VS
60 CPPUNIT_TEST_SUITE_END();
61
62protected:
63 // Add own test here.
96461cc2 64 void Ctor_InFromOut();
340da6ae
VS
65
66private:
67 const char *GetDataBuffer();
68
69private:
70 // Implement base class functions.
3e5f6c1c 71 virtual wxMemoryInputStream *DoCreateInStream();
340da6ae
VS
72 virtual wxMemoryOutputStream *DoCreateOutStream();
73
74private:
75 char m_DataBuffer[DATABUFFER_SIZE];
76};
77
78memStream::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
85memStream::~memStream()
86{
87 /* Nothing extra for now. */
88}
89
90const char *memStream::GetDataBuffer()
91{
92 return m_DataBuffer;
93}
94
3e5f6c1c
WS
95wxMemoryInputStream *memStream::DoCreateInStream()
96{
340da6ae
VS
97 wxMemoryInputStream *pMemInStream = new wxMemoryInputStream(GetDataBuffer(), DATABUFFER_SIZE);
98 CPPUNIT_ASSERT(pMemInStream->IsOk());
99 return pMemInStream;
100}
101wxMemoryOutputStream *memStream::DoCreateOutStream()
3e5f6c1c 102{
340da6ae
VS
103 wxMemoryOutputStream *pMemOutStream = new wxMemoryOutputStream();
104 CPPUNIT_ASSERT(pMemOutStream->IsOk());
105 return pMemOutStream;
106}
107
96461cc2
VZ
108void 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}
340da6ae
VS
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())
126STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(memStream)