]>
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"
27 #include <math.h> //HUGE
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class DataStreamTestCase
: public CppUnit::TestCase
39 CPPUNIT_TEST_SUITE( DataStreamTestCase
);
40 CPPUNIT_TEST( FloatRW
);
41 CPPUNIT_TEST( DoubleRW
);
42 CPPUNIT_TEST( NaNRW
);
43 CPPUNIT_TEST_SUITE_END();
49 DECLARE_NO_COPY_CLASS(DataStreamTestCase
)
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( DataStreamTestCase
);
55 // also include in it's own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataStreamTestCase
, "DataStreamTestCase" );
58 DataStreamTestCase::DataStreamTestCase()
62 wxFloat64
TestFloatRW(wxFloat64 fValue
)
64 wxFileOutputStream
* pFileOutput
= new wxFileOutputStream( _T("mytext.dat") );
65 wxDataOutputStream
* pDataOutput
= new wxDataOutputStream( *pFileOutput
);
67 *pDataOutput
<< fValue
;
72 wxFileInputStream
* pFileInput
= new wxFileInputStream( _T("mytext.dat") );
73 wxDataInputStream
* pDataInput
= new wxDataInputStream( *pFileInput
);
77 *pDataInput
>> fInFloat
;
85 void DataStreamTestCase::FloatRW()
87 CPPUNIT_ASSERT( TestFloatRW(5.5) == 5.5 );
88 CPPUNIT_ASSERT( TestFloatRW(5) == 5 );
89 CPPUNIT_ASSERT( TestFloatRW(5.55) == 5.55 );
90 CPPUNIT_ASSERT( TestFloatRW(55555.555555) == 55555.555555 );
93 void DataStreamTestCase::DoubleRW()
95 CPPUNIT_ASSERT( TestFloatRW(2132131.1232132) == 2132131.1232132 );
96 CPPUNIT_ASSERT( TestFloatRW(21321343431.1232143432) == 21321343431.1232143432 );
99 void DataStreamTestCase::NaNRW()