]>
git.saurik.com Git - wxWidgets.git/blob - tests/streams/datastreamtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/datastreamtest.cpp
3 // Purpose: wxDataXXXStream Unit Test
7 // Copyright: (c) 2004 Ryan Norton
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/datstrm.h"
25 #include "wx/wfstream.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class DataStreamTestCase
: public CppUnit::TestCase
38 CPPUNIT_TEST_SUITE( DataStreamTestCase
);
39 CPPUNIT_TEST( FloatRW
);
40 CPPUNIT_TEST( DoubleRW
);
41 CPPUNIT_TEST( NaNRW
);
42 CPPUNIT_TEST_SUITE_END();
48 DECLARE_NO_COPY_CLASS(DataStreamTestCase
)
51 // register in the unnamed registry so that these tests are run by default
52 CPPUNIT_TEST_SUITE_REGISTRATION( DataStreamTestCase
);
54 // also include in it's own registry so that these tests can be run alone
55 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataStreamTestCase
, "DataStreamTestCase" );
57 DataStreamTestCase::DataStreamTestCase()
61 wxFloat64
TestFloatRW(wxFloat64 fValue
)
63 wxFileOutputStream
* pFileOutput
= new wxFileOutputStream( _T("mytext.dat") );
64 wxDataOutputStream
* pDataOutput
= new wxDataOutputStream( *pFileOutput
);
66 *pDataOutput
<< fValue
;
71 wxFileInputStream
* pFileInput
= new wxFileInputStream( _T("mytext.dat") );
72 wxDataInputStream
* pDataInput
= new wxDataInputStream( *pFileInput
);
76 *pDataInput
>> fInFloat
;
84 void DataStreamTestCase::FloatRW()
86 CPPUNIT_ASSERT( TestFloatRW(5.5) == 5.5 );
87 CPPUNIT_ASSERT( TestFloatRW(5) == 5 );
88 CPPUNIT_ASSERT( TestFloatRW(5.55) == 5.55 );
89 CPPUNIT_ASSERT( TestFloatRW(55555.555555) == 55555.555555 );
92 void DataStreamTestCase::DoubleRW()
94 CPPUNIT_ASSERT( TestFloatRW(2132131.1232132) == 2132131.1232132 );
95 CPPUNIT_ASSERT( TestFloatRW(21321343431.1232143432) == 21321343431.1232143432 );
98 void DataStreamTestCase::NaNRW()