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