X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f4bebe8ff6cd3a19a186a423cd671f72951cb73..8d1517cef26509f5b2fca218145af4e4db7a4be2:/tests/streams/datastreamtest.cpp?ds=sidebyside diff --git a/tests/streams/datastreamtest.cpp b/tests/streams/datastreamtest.cpp index 2085c9d7de..efe700336c 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) @@ -59,6 +72,7 @@ DataStreamTestCase::DataStreamTestCase() { } +static wxFloat64 TestFloatRW(wxFloat64 fValue) { wxFileOutputStream* pFileOutput = new wxFileOutputStream( _T("mytext.dat") ); @@ -82,6 +96,91 @@ 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( _T("mytext.dat") ); + wxDataOutputStream DataOutput( FileOutput ); + + (DataOutput.*pfnWriter)(Values, Size); + } + + { + wxFileInputStream FileInput( _T("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 Ok(void) const { + return m_ok; + } +}; + +template +static +T TestRW(const T &Value) +{ + T InValue; + + { + wxFileOutputStream FileOutput( _T("mytext.dat") ); + wxDataOutputStream DataOutput( FileOutput ); + + DataOutput << Value; + } + + { + wxFileInputStream FileInput( _T("mytext.dat") ); + wxDataInputStream DataInput( FileInput ); + + DataInput >> InValue; + } + + return InValue; +} + void DataStreamTestCase::FloatRW() { CPPUNIT_ASSERT( TestFloatRW(5.5) == 5.5 ); @@ -96,6 +195,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).Ok() ); + CPPUNIT_ASSERT( TestMultiRW(ValuesULL, &wxDataOutputStream::WriteLL, &wxDataInputStream::ReadLL).Ok() ); +} +#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).Ok() ); + CPPUNIT_ASSERT( TestMultiRW(ValuesUI64, &wxDataOutputStream::Write64, &wxDataInputStream::Read64).Ok() ); +} +#endif + void DataStreamTestCase::NaNRW() { //TODO?