]> git.saurik.com Git - wxWidgets.git/blob - tests/streams/textstreamtest.cpp
wxTextOutputStream::PutChar and text stream test
[wxWidgets.git] / tests / streams / textstreamtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/uris/uris.cpp
3 // Purpose: wxTextXXXStream unit test
4 // Author: Ryan Norton
5 // Created: 2004-08-14
6 // RCS-ID: $Id$
7 // Copyright: (c) 2004 Ryan Norton
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/wx.h"
22 #endif // WX_PRECOMP
23
24 #include "wx/txtstrm.h"
25 #include "wx/wfstream.h"
26
27 #include "wx/cppunit.h"
28
29 // ----------------------------------------------------------------------------
30 // test class
31 // ----------------------------------------------------------------------------
32
33 class TextStreamTestCase : public CppUnit::TestCase
34 {
35 public:
36 TextStreamTestCase();
37
38 private:
39 CPPUNIT_TEST_SUITE( TextStreamTestCase );
40 CPPUNIT_TEST( Endline );
41 CPPUNIT_TEST_SUITE_END();
42
43 void Endline();
44
45
46 DECLARE_NO_COPY_CLASS(TextStreamTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( TextStreamTestCase );
51
52 // also include in it's own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TextStreamTestCase, "TextStreamTestCase" );
54
55 TextStreamTestCase::TextStreamTestCase()
56 {
57 }
58
59 #if defined(__WXMSW__) || defined(__WXPM__)
60 # define NEWLINE "\r\n"
61 # define NEWLINELEN 2
62 #elif defined(__WXMAC__) && !defined(__DARWIN__)
63 # define NEWLINE "\r"
64 # define NEWLINELEN 1
65 #else
66 # define NEWLINE "\n"
67 # define NEWLINELEN 1
68 #endif
69
70 void TextStreamTestCase::Endline()
71 {
72 wxFileOutputStream* pOutFile = new wxFileOutputStream(_T("test.txt"));
73 wxTextOutputStream* pOutText = new wxTextOutputStream(*pOutFile);
74 *pOutText << _T("Test text") << endl
75 << _T("More Testing Text (There should be newline before this)");
76
77 delete pOutText;
78 delete pOutFile;
79
80 wxFileInputStream* pInFile = new wxFileInputStream(_T("test.txt"));
81
82 char szIn[9 + NEWLINELEN];
83
84 pInFile->Read(szIn, 9 + NEWLINELEN);
85
86 CPPUNIT_ASSERT( memcmp(&szIn[9], NEWLINE, NEWLINELEN) == 0 );
87
88 delete pInFile;
89 }