]>
git.saurik.com Git - wxWidgets.git/blob - tests/streams/textstreamtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/uris/uris.cpp
3 // Purpose: wxTextXXXStream unit test
7 // Copyright: (c) 2004 Ryan Norton
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/txtstrm.h"
25 #include "wx/wfstream.h"
28 #include "wx/longlong.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 class TextStreamTestCase
: public CppUnit::TestCase
41 CPPUNIT_TEST_SUITE( TextStreamTestCase
);
42 CPPUNIT_TEST( Endline
);
44 CPPUNIT_TEST( TestLongLong
);
45 CPPUNIT_TEST( TestLongLong
);
47 CPPUNIT_TEST_SUITE_END();
53 #endif // wxUSE_LONGLONG
56 DECLARE_NO_COPY_CLASS(TextStreamTestCase
)
59 // register in the unnamed registry so that these tests are run by default
60 CPPUNIT_TEST_SUITE_REGISTRATION( TextStreamTestCase
);
62 // also include in it's own registry so that these tests can be run alone
63 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TextStreamTestCase
, "TextStreamTestCase" );
65 TextStreamTestCase::TextStreamTestCase()
69 #if defined(__WXMSW__) || defined(__WXPM__)
70 # define NEWLINE "\r\n"
72 #elif defined(__WXMAC__) && !defined(__DARWIN__)
80 void TextStreamTestCase::Endline()
82 wxFileOutputStream
* pOutFile
= new wxFileOutputStream(_T("test.txt"));
83 wxTextOutputStream
* pOutText
= new wxTextOutputStream(*pOutFile
);
84 *pOutText
<< _T("Test text") << endl
85 << _T("More Testing Text (There should be newline before this)");
90 wxFileInputStream
* pInFile
= new wxFileInputStream(_T("test.txt"));
92 char szIn
[9 + NEWLINELEN
];
94 pInFile
->Read(szIn
, 9 + NEWLINELEN
);
96 CPPUNIT_ASSERT( memcmp(&szIn
[9], NEWLINE
, NEWLINELEN
) == 0 );
103 template <typename T
>
104 static void DoTestRoundTrip(const T
*values
, size_t numValues
)
107 wxFileOutputStream
fileOut(_T("test.txt"));
108 wxTextOutputStream
textOut(fileOut
);
110 for ( size_t n
= 0; n
< numValues
; n
++ )
112 textOut
<< values
[n
] << endl
;
117 wxFileInputStream
fileIn(_T("test.txt"));
118 wxTextInputStream
textIn(fileIn
);
121 for ( size_t n
= 0; n
< numValues
; n
++ )
125 CPPUNIT_ASSERT( value
== values
[n
] );
130 void TextStreamTestCase::TestLongLong()
132 static const wxLongLong llvalues
[] =
139 wxLL(0x123456789abcdef0),
140 wxLL(-0x123456789abcdef0),
143 DoTestRoundTrip(llvalues
, WXSIZEOF(llvalues
));
146 void TextStreamTestCase::TestULongLong()
148 static const wxULongLong ullvalues
[] =
153 wxULL(0x123456789abcdef0),
156 DoTestRoundTrip(ullvalues
, WXSIZEOF(ullvalues
));
159 #endif // wxUSE_LONGLONG