]> git.saurik.com Git - wxWidgets.git/blame - tests/streams/sstream.cpp
Removed dummy wxFont == operator implementation (IIRC was needed to compile with...
[wxWidgets.git] / tests / streams / sstream.cpp
CommitLineData
32d49041
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/streams/sstream.cpp
3// Purpose: Test wxStringInputStream/wxStringOutputStream
4// Author: Vadim Zeitlin
5// RCS-ID: $Id$
6// Copyright: (c) 2004 Vadim Zeitlin
7// Licence: wxWidgets licence
8///////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx/wx.h".
8899b155
RN
11// and "wx/cppunit.h"
12#include "testprec.h"
32d49041
VZ
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18// for all others, include the necessary headers
19#ifndef WX_PRECOMP
20#endif
21
32d49041
VZ
22#include "wx/sstream.h"
23
24#include "bstream.h"
25
32d49041
VZ
26///////////////////////////////////////////////////////////////////////////////
27// The test case
28//
29// Try to fully test wxStringInputStream and wxStringOutputStream
30
31class strStream :
32 public BaseStreamTestCase<wxStringInputStream, wxStringOutputStream>
33{
34public:
35 strStream();
36 virtual ~strStream();
37
38 CPPUNIT_TEST_SUITE(strStream);
39 // Base class stream tests the strStream supports.
40 CPPUNIT_TEST(Input_GetSize);
41 CPPUNIT_TEST(Input_GetC);
42 CPPUNIT_TEST(Input_Read);
43 CPPUNIT_TEST(Input_Eof);
44 CPPUNIT_TEST(Input_LastRead);
2d76b6d8 45 CPPUNIT_TEST(Input_CanRead);
32d49041
VZ
46 CPPUNIT_TEST(Input_SeekI);
47 CPPUNIT_TEST(Input_TellI);
48 CPPUNIT_TEST(Input_Peek);
49 CPPUNIT_TEST(Input_Ungetch);
50
51 CPPUNIT_TEST(Output_PutC);
52 CPPUNIT_TEST(Output_Write);
53 CPPUNIT_TEST(Output_LastWrite);
54 // seeking currently not supported by output string stream
55 //CPPUNIT_TEST(Output_SeekO);
56 //CPPUNIT_TEST(Output_TellO);
57
58 // Other test specific for String stream test case.
a7b9ab62 59 CPPUNIT_TEST(Output_Check);
32d49041
VZ
60 CPPUNIT_TEST_SUITE_END();
61
62protected:
a7b9ab62 63 void Output_Check();
32d49041
VZ
64
65private:
66 // Implement base class functions.
3e5f6c1c 67 virtual wxStringInputStream *DoCreateInStream();
32d49041
VZ
68 virtual wxStringOutputStream *DoCreateOutStream();
69
a7b9ab62
VZ
70 // output the given string to wxStringOutputStream and check that its
71 // contents is exactly the same string
72 void CheckString(const wxString& text);
73
32d49041
VZ
74 wxString m_str;
75};
76
77strStream::strStream()
78{
79 static const size_t LEN = 256;
80 m_str.reserve(LEN);
81 for ( size_t n = 0; n < LEN; n++ )
82 {
c9f78968 83 m_str += wxChar(_T('A') + n % (_T('Z') - _T('A') + 1));
32d49041
VZ
84 }
85}
86
87strStream::~strStream()
88{
89}
90
3e5f6c1c
WS
91wxStringInputStream *strStream::DoCreateInStream()
92{
32d49041
VZ
93 wxStringInputStream *pStrInStream = new wxStringInputStream(m_str);
94 CPPUNIT_ASSERT(pStrInStream->IsOk());
95 return pStrInStream;
96}
97
98wxStringOutputStream *strStream::DoCreateOutStream()
3e5f6c1c 99{
32d49041
VZ
100 wxStringOutputStream *pStrOutStream = new wxStringOutputStream();
101 CPPUNIT_ASSERT(pStrOutStream->IsOk());
102 return pStrOutStream;
103}
104
a7b9ab62
VZ
105void strStream::CheckString(const wxString& text)
106{
107 wxStringOutputStream sos;
108
109 size_t len = text.length();
110#if wxUSE_UNICODE
111 const wxCharBuffer textMB(wxConvLibc.cWC2MB(text.wc_str(), len + 1, &len));
112#else
113 const char *textMB = text.c_str();
114#endif
115
116 sos.Write(textMB, len);
117
118 CPPUNIT_ASSERT_EQUAL( text, sos.GetString() );
119}
120
121void strStream::Output_Check()
122{
123 CheckString("Hello world!");
124 CheckString(wxString("hi\0dden", 8));
125}
32d49041
VZ
126
127// Register the stream sub suite, by using some stream helper macro.
128STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(strStream)