Factor out TempFile class and reuse it in other tests
Ensure we don't leave "mytext.dat" and "test.txt" lying around in any directory the tests are run from by ensuring that these files are destroyed by the test code using them.
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/math.h"
|
||||
|
||||
#include "testfile.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -107,8 +109,10 @@ DataStreamTestCase::DataStreamTestCase()
|
||||
|
||||
wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue)
|
||||
{
|
||||
TempFile f("mytext.dat");
|
||||
|
||||
{
|
||||
wxFileOutputStream pFileOutput( wxT("mytext.dat") );
|
||||
wxFileOutputStream pFileOutput( f.GetName() );
|
||||
wxDataOutputStream pDataOutput( pFileOutput );
|
||||
if ( ms_useBigEndianFormat )
|
||||
pDataOutput.BigEndianOrdered(true);
|
||||
@@ -121,7 +125,7 @@ wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue)
|
||||
pDataOutput << fValue;
|
||||
}
|
||||
|
||||
wxFileInputStream pFileInput( wxT("mytext.dat") );
|
||||
wxFileInputStream pFileInput( f.GetName() );
|
||||
wxDataInputStream pDataInput( pFileInput );
|
||||
if ( ms_useBigEndianFormat )
|
||||
pDataInput.BigEndianOrdered(true);
|
||||
@@ -156,15 +160,17 @@ private:
|
||||
{
|
||||
ValueArray InValues(Size);
|
||||
|
||||
TempFile f("mytext.dat");
|
||||
|
||||
{
|
||||
wxFileOutputStream FileOutput( wxT("mytext.dat") );
|
||||
wxFileOutputStream FileOutput( f.GetName() );
|
||||
wxDataOutputStream DataOutput( FileOutput );
|
||||
|
||||
(DataOutput.*pfnWriter)(Values, Size);
|
||||
}
|
||||
|
||||
{
|
||||
wxFileInputStream FileInput( wxT("mytext.dat") );
|
||||
wxFileInputStream FileInput( f.GetName() );
|
||||
wxDataInputStream DataInput( FileInput );
|
||||
|
||||
(DataInput.*pfnReader)(&*InValues.begin(), InValues.size());
|
||||
@@ -207,15 +213,17 @@ T TestRW(const T &Value)
|
||||
{
|
||||
T InValue;
|
||||
|
||||
TempFile f("mytext.dat");
|
||||
|
||||
{
|
||||
wxFileOutputStream FileOutput( wxT("mytext.dat") );
|
||||
wxFileOutputStream FileOutput( f.GetName() );
|
||||
wxDataOutputStream DataOutput( FileOutput );
|
||||
|
||||
DataOutput << Value;
|
||||
}
|
||||
|
||||
{
|
||||
wxFileInputStream FileInput( wxT("mytext.dat") );
|
||||
wxFileInputStream FileInput( f.GetName() );
|
||||
wxDataInputStream DataInput( FileInput );
|
||||
|
||||
DataInput >> InValue;
|
||||
|
@@ -31,6 +31,8 @@
|
||||
#include "wx/mstream.h"
|
||||
#endif // wxUSE_UNICODE
|
||||
|
||||
#include "testfile.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -105,7 +107,9 @@ TextStreamTestCase::TextStreamTestCase()
|
||||
|
||||
void TextStreamTestCase::Endline()
|
||||
{
|
||||
wxFileOutputStream* pOutFile = new wxFileOutputStream(wxT("test.txt"));
|
||||
TempFile f("test.txt");
|
||||
|
||||
wxFileOutputStream* pOutFile = new wxFileOutputStream(f.GetName());
|
||||
wxTextOutputStream* pOutText = new wxTextOutputStream(*pOutFile);
|
||||
*pOutText << wxT("Test text") << endl
|
||||
<< wxT("More Testing Text (There should be newline before this)");
|
||||
@@ -113,7 +117,7 @@ void TextStreamTestCase::Endline()
|
||||
delete pOutText;
|
||||
delete pOutFile;
|
||||
|
||||
wxFileInputStream* pInFile = new wxFileInputStream(wxT("test.txt"));
|
||||
wxFileInputStream* pInFile = new wxFileInputStream(f.GetName());
|
||||
|
||||
char szIn[9 + NEWLINELEN];
|
||||
|
||||
@@ -147,8 +151,10 @@ void TextStreamTestCase::MiscTests()
|
||||
template <typename T>
|
||||
static void DoTestRoundTrip(const T *values, size_t numValues)
|
||||
{
|
||||
TempFile f("test.txt");
|
||||
|
||||
{
|
||||
wxFileOutputStream fileOut(wxT("test.txt"));
|
||||
wxFileOutputStream fileOut(f.GetName());
|
||||
wxTextOutputStream textOut(fileOut);
|
||||
|
||||
for ( size_t n = 0; n < numValues; n++ )
|
||||
@@ -158,7 +164,7 @@ static void DoTestRoundTrip(const T *values, size_t numValues)
|
||||
}
|
||||
|
||||
{
|
||||
wxFileInputStream fileIn(wxT("test.txt"));
|
||||
wxFileInputStream fileIn(f.GetName());
|
||||
wxTextInputStream textIn(fileIn);
|
||||
|
||||
T value;
|
||||
|
Reference in New Issue
Block a user