X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f4bebe8ff6cd3a19a186a423cd671f72951cb73..5f519da23d582da30a0d7894d330198c673400d6:/tests/streams/datastreamtest.cpp diff --git a/tests/streams/datastreamtest.cpp b/tests/streams/datastreamtest.cpp index 2085c9d7de..d42dc381c9 100644 --- a/tests/streams/datastreamtest.cpp +++ b/tests/streams/datastreamtest.cpp @@ -21,10 +21,11 @@ #include "wx/wx.h" #endif // WX_PRECOMP +#include + #include "wx/datstrm.h" #include "wx/wfstream.h" - -#include //HUGE +#include "wx/math.h" // ---------------------------------------------------------------------------- // test class @@ -39,11 +40,23 @@ private: CPPUNIT_TEST_SUITE( DataStreamTestCase ); CPPUNIT_TEST( FloatRW ); CPPUNIT_TEST( DoubleRW ); +#if wxUSE_LONGLONG + CPPUNIT_TEST( LongLongRW ); +#endif +#if wxHAS_INT64 + CPPUNIT_TEST( Int64RW ); +#endif CPPUNIT_TEST( NaNRW ); CPPUNIT_TEST_SUITE_END(); void FloatRW(); void DoubleRW(); +#if wxUSE_LONGLONG + void LongLongRW(); +#endif +#if wxHAS_INT64 + void Int64RW(); +#endif void NaNRW(); DECLARE_NO_COPY_CLASS(DataStreamTestCase) @@ -52,16 +65,17 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( DataStreamTestCase ); -// also include in it's own registry so that these tests can be run alone +// also include in its own registry so that these tests can be run alone CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataStreamTestCase, "DataStreamTestCase" ); DataStreamTestCase::DataStreamTestCase() { } +static wxFloat64 TestFloatRW(wxFloat64 fValue) { - wxFileOutputStream* pFileOutput = new wxFileOutputStream( _T("mytext.dat") ); + wxFileOutputStream* pFileOutput = new wxFileOutputStream( wxT("mytext.dat") ); wxDataOutputStream* pDataOutput = new wxDataOutputStream( *pFileOutput ); *pDataOutput << fValue; @@ -69,7 +83,7 @@ wxFloat64 TestFloatRW(wxFloat64 fValue) delete pDataOutput; delete pFileOutput; - wxFileInputStream* pFileInput = new wxFileInputStream( _T("mytext.dat") ); + wxFileInputStream* pFileInput = new wxFileInputStream( wxT("mytext.dat") ); wxDataInputStream* pDataInput = new wxDataInputStream( *pFileInput ); wxFloat64 fInFloat; @@ -82,6 +96,92 @@ wxFloat64 TestFloatRW(wxFloat64 fValue) return fInFloat; } +template +class TestMultiRW { +public: + typedef std::vector ValueArray; + typedef void (wxDataOutputStream::*FnWriter)(const T *buffer, size_t size); + typedef void (wxDataInputStream::*FnReader)(T *buffer, size_t size); + +private: + bool m_ok; + +private: + void ProcessData(const T *Values, + typename ValueArray::size_type Size, + FnWriter pfnWriter, + FnReader pfnReader) + { + ValueArray InValues(Size); + + { + wxFileOutputStream FileOutput( wxT("mytext.dat") ); + wxDataOutputStream DataOutput( FileOutput ); + + (DataOutput.*pfnWriter)(Values, Size); + } + + { + wxFileInputStream FileInput( wxT("mytext.dat") ); + wxDataInputStream DataInput( FileInput ); + + (DataInput.*pfnReader)(&*InValues.begin(), InValues.size()); + } + + m_ok = true; + for (typename ValueArray::size_type idx=0; idx!=Size; ++idx) { + if (InValues[idx]!=Values[idx]) { + m_ok = false; + break; + } + } + } + + +public: + TestMultiRW(const T *Values, + size_t Size, + FnWriter pfnWriter, + FnReader pfnReader) + { + ProcessData(Values, (typename ValueArray::size_type) Size, pfnWriter, pfnReader); + } + TestMultiRW(const ValueArray &Values, + FnWriter pfnWriter, + FnReader pfnReader) + { + ProcessData(&*Values.begin(), Values.size(), pfnWriter, pfnReader); + } + + bool IsOk() const + { + return m_ok; + } +}; + +template +static +T TestRW(const T &Value) +{ + T InValue; + + { + wxFileOutputStream FileOutput( wxT("mytext.dat") ); + wxDataOutputStream DataOutput( FileOutput ); + + DataOutput << Value; + } + + { + wxFileInputStream FileInput( wxT("mytext.dat") ); + wxDataInputStream DataInput( FileInput ); + + DataInput >> InValue; + } + + return InValue; +} + void DataStreamTestCase::FloatRW() { CPPUNIT_ASSERT( TestFloatRW(5.5) == 5.5 ); @@ -96,6 +196,54 @@ void DataStreamTestCase::DoubleRW() CPPUNIT_ASSERT( TestFloatRW(21321343431.1232143432) == 21321343431.1232143432 ); } +#if wxUSE_LONGLONG +void DataStreamTestCase::LongLongRW() +{ + TestMultiRW::ValueArray ValuesLL; + TestMultiRW::ValueArray ValuesULL; + + ValuesLL.push_back(wxLongLong(0l)); + ValuesLL.push_back(wxLongLong(1l)); + ValuesLL.push_back(wxLongLong(-1l)); + ValuesLL.push_back(wxLongLong(0x12345678l)); + ValuesLL.push_back(wxLongLong(0x12345678l, 0xabcdef01l)); + + ValuesULL.push_back(wxULongLong(0l)); + ValuesULL.push_back(wxULongLong(1l)); + ValuesULL.push_back(wxULongLong(0x12345678l)); + ValuesULL.push_back(wxULongLong(0x12345678l, 0xabcdef01l)); + + CPPUNIT_ASSERT( TestRW(wxLongLong(0x12345678l)) == wxLongLong(0x12345678l) ); + CPPUNIT_ASSERT( TestRW(wxLongLong(0x12345678l, 0xabcdef01l)) == wxLongLong(0x12345678l, 0xabcdef01l) ); + CPPUNIT_ASSERT( TestMultiRW(ValuesLL, &wxDataOutputStream::WriteLL, &wxDataInputStream::ReadLL).IsOk() ); + CPPUNIT_ASSERT( TestMultiRW(ValuesULL, &wxDataOutputStream::WriteLL, &wxDataInputStream::ReadLL).IsOk() ); +} +#endif + +#if wxHAS_INT64 +void DataStreamTestCase::Int64RW() +{ + TestMultiRW::ValueArray ValuesI64; + TestMultiRW::ValueArray ValuesUI64; + + ValuesI64.push_back(wxInt64(0l)); + ValuesI64.push_back(wxInt64(1l)); + ValuesI64.push_back(wxInt64(-1l)); + ValuesI64.push_back(wxInt64(0x12345678l)); + ValuesI64.push_back((wxInt64(0x12345678l) << 32) + wxInt64(0xabcdef01l)); + + ValuesUI64.push_back(wxUint64(0l)); + ValuesUI64.push_back(wxUint64(1l)); + ValuesUI64.push_back(wxUint64(0x12345678l)); + ValuesUI64.push_back((wxUint64(0x12345678l) << 32) + wxUint64(0xabcdef01l)); + + CPPUNIT_ASSERT( TestRW(wxUint64(0x12345678l)) == wxUint64(0x12345678l) ); + CPPUNIT_ASSERT( TestRW((wxUint64(0x12345678l) << 32) + wxUint64(0xabcdef01l)) == (wxUint64(0x12345678l) << 32) + wxUint64(0xabcdef01l) ); + CPPUNIT_ASSERT( TestMultiRW(ValuesI64, &wxDataOutputStream::Write64, &wxDataInputStream::Read64).IsOk() ); + CPPUNIT_ASSERT( TestMultiRW(ValuesUI64, &wxDataOutputStream::Write64, &wxDataInputStream::Read64).IsOk() ); +} +#endif + void DataStreamTestCase::NaNRW() { //TODO?