]>
git.saurik.com Git - wxWidgets.git/blob - tests/streams/sstream.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/sstream.cpp
3 // Purpose: Test wxStringInputStream/wxStringOutputStream
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2004 Vadim Zeitlin
7 // Licence: wxWidgets licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx/wx.h".
18 // for all others, include the necessary headers
22 #include "wx/sstream.h"
26 ///////////////////////////////////////////////////////////////////////////////
29 // Try to fully test wxStringInputStream and wxStringOutputStream
32 public BaseStreamTestCase
<wxStringInputStream
, wxStringOutputStream
>
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
);
45 CPPUNIT_TEST(Input_CanRead
);
46 CPPUNIT_TEST(Input_SeekI
);
47 CPPUNIT_TEST(Input_TellI
);
48 CPPUNIT_TEST(Input_Peek
);
49 CPPUNIT_TEST(Input_Ungetch
);
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);
58 // Other test specific for String stream test case.
59 CPPUNIT_TEST(Output_Check
);
60 CPPUNIT_TEST_SUITE_END();
66 // Implement base class functions.
67 virtual wxStringInputStream
*DoCreateInStream();
68 virtual wxStringOutputStream
*DoCreateOutStream();
70 // output the given string to wxStringOutputStream and check that its
71 // contents is exactly the same string
72 void CheckString(const wxString
& text
);
77 strStream::strStream()
79 static const size_t LEN
= 256;
81 for ( size_t n
= 0; n
< LEN
; n
++ )
83 m_str
+= wxChar(_T('A') + n
% (_T('Z') - _T('A') + 1));
87 strStream::~strStream()
91 wxStringInputStream
*strStream::DoCreateInStream()
93 wxStringInputStream
*pStrInStream
= new wxStringInputStream(m_str
);
94 CPPUNIT_ASSERT(pStrInStream
->IsOk());
98 wxStringOutputStream
*strStream::DoCreateOutStream()
100 wxStringOutputStream
*pStrOutStream
= new wxStringOutputStream();
101 CPPUNIT_ASSERT(pStrOutStream
->IsOk());
102 return pStrOutStream
;
105 void strStream::CheckString(const wxString
& text
)
107 wxStringOutputStream sos
;
109 size_t len
= text
.length();
111 const wxCharBuffer
textMB(wxConvLibc
.cWC2MB(text
.wc_str(), len
+ 1, &len
));
113 const char *textMB
= text
.c_str();
116 sos
.Write(textMB
, len
);
118 CPPUNIT_ASSERT_EQUAL( text
, sos
.GetString() );
121 void strStream::Output_Check()
123 CheckString("Hello world!");
124 CheckString(wxString("hi\0dden", 8));
127 // Register the stream sub suite, by using some stream helper macro.
128 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(strStream
)