]> git.saurik.com Git - wxWidgets.git/blame - tests/streams/sstream.cpp
Convert back to UNIX line endings (again)
[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".
11#include "wx/wxprec.h"
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
21#include "wx/cppunit.h"
22#include "wx/sstream.h"
23
24#include "bstream.h"
25
26using namespace std;
27using namespace CppUnit;
28
29///////////////////////////////////////////////////////////////////////////////
30// The test case
31//
32// Try to fully test wxStringInputStream and wxStringOutputStream
33
34class strStream :
35 public BaseStreamTestCase<wxStringInputStream, wxStringOutputStream>
36{
37public:
38 strStream();
39 virtual ~strStream();
40
41 CPPUNIT_TEST_SUITE(strStream);
42 // Base class stream tests the strStream supports.
43 CPPUNIT_TEST(Input_GetSize);
44 CPPUNIT_TEST(Input_GetC);
45 CPPUNIT_TEST(Input_Read);
46 CPPUNIT_TEST(Input_Eof);
47 CPPUNIT_TEST(Input_LastRead);
48 CPPUNIT_TEST(Input_SeekI);
49 CPPUNIT_TEST(Input_TellI);
50 CPPUNIT_TEST(Input_Peek);
51 CPPUNIT_TEST(Input_Ungetch);
52
53 CPPUNIT_TEST(Output_PutC);
54 CPPUNIT_TEST(Output_Write);
55 CPPUNIT_TEST(Output_LastWrite);
56 // seeking currently not supported by output string stream
57 //CPPUNIT_TEST(Output_SeekO);
58 //CPPUNIT_TEST(Output_TellO);
59
60 // Other test specific for String stream test case.
61 CPPUNIT_TEST_SUITE_END();
62
63protected:
64 // Add own test here.
65
66private:
67 // Implement base class functions.
68 virtual wxStringInputStream *DoCreateInStream();
69 virtual wxStringOutputStream *DoCreateOutStream();
70
71 wxString m_str;
72};
73
74strStream::strStream()
75{
76 static const size_t LEN = 256;
77 m_str.reserve(LEN);
78 for ( size_t n = 0; n < LEN; n++ )
79 {
80 m_str += _T('A') + n % (_T('Z') - _T('A') + 1);
81 }
82}
83
84strStream::~strStream()
85{
86}
87
88wxStringInputStream *strStream::DoCreateInStream()
89{
90 wxStringInputStream *pStrInStream = new wxStringInputStream(m_str);
91 CPPUNIT_ASSERT(pStrInStream->IsOk());
92 return pStrInStream;
93}
94
95wxStringOutputStream *strStream::DoCreateOutStream()
96{
97 wxStringOutputStream *pStrOutStream = new wxStringOutputStream();
98 CPPUNIT_ASSERT(pStrOutStream->IsOk());
99 return pStrOutStream;
100}
101
102
103// Register the stream sub suite, by using some stream helper macro.
104STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(strStream)