Remove test input file in file stream unit tests only once
Don't remove the files in the test cases classes dtors, this was inconsistent with how they were created: we either need to create the file in the ctor and destroy it in the dtor or do both only once globally. Implement the second solution using the helper AutoRemoveFile instead of a simple static bool in GetInFileName() implementations.
This commit is contained in:
@@ -37,7 +37,6 @@ class ffileStream : public BaseStreamTestCase<wxFFileInputStream, wxFFileOutputS
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ffileStream();
|
ffileStream();
|
||||||
virtual ~ffileStream();
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(ffileStream);
|
CPPUNIT_TEST_SUITE(ffileStream);
|
||||||
// Base class stream tests the ffileStream supports.
|
// Base class stream tests the ffileStream supports.
|
||||||
@@ -80,13 +79,6 @@ ffileStream::ffileStream()
|
|||||||
m_bEofAtLastRead = false;
|
m_bEofAtLastRead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ffileStream::~ffileStream()
|
|
||||||
{
|
|
||||||
// Remove the temp test file...
|
|
||||||
::wxRemoveFile(FILENAME_FFILEINSTREAM);
|
|
||||||
::wxRemoveFile(FILENAME_FFILEOUTSTREAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFFileInputStream *ffileStream::DoCreateInStream()
|
wxFFileInputStream *ffileStream::DoCreateInStream()
|
||||||
{
|
{
|
||||||
wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName());
|
wxFFileInputStream *pFileInStream = new wxFFileInputStream(GetInFileName());
|
||||||
@@ -107,12 +99,37 @@ void ffileStream::DoDeleteOutStream()
|
|||||||
|
|
||||||
wxString ffileStream::GetInFileName() const
|
wxString ffileStream::GetInFileName() const
|
||||||
{
|
{
|
||||||
static bool bFileCreated = false;
|
class AutoRemoveFile
|
||||||
if (!bFileCreated)
|
|
||||||
{
|
{
|
||||||
// Create the file only once
|
public:
|
||||||
bFileCreated = true;
|
AutoRemoveFile()
|
||||||
|
{
|
||||||
|
m_created = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
~AutoRemoveFile()
|
||||||
|
{
|
||||||
|
if ( m_created )
|
||||||
|
wxRemoveFile(FILENAME_FFILEINSTREAM);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShouldCreate()
|
||||||
|
{
|
||||||
|
if ( m_created )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_created = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_created;
|
||||||
|
};
|
||||||
|
|
||||||
|
static AutoRemoveFile autoFile;
|
||||||
|
if ( autoFile.ShouldCreate() )
|
||||||
|
{
|
||||||
// Make sure we have a input file...
|
// Make sure we have a input file...
|
||||||
char buf[DATABUFFER_SIZE];
|
char buf[DATABUFFER_SIZE];
|
||||||
wxFFileOutputStream out(FILENAME_FFILEINSTREAM);
|
wxFFileOutputStream out(FILENAME_FFILEINSTREAM);
|
||||||
|
@@ -37,7 +37,6 @@ class fileStream : public BaseStreamTestCase<wxFileInputStream, wxFileOutputStre
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
fileStream();
|
fileStream();
|
||||||
virtual ~fileStream();
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(fileStream);
|
CPPUNIT_TEST_SUITE(fileStream);
|
||||||
// Base class stream tests the fileStream supports.
|
// Base class stream tests the fileStream supports.
|
||||||
@@ -79,13 +78,6 @@ fileStream::fileStream()
|
|||||||
m_bSeekInvalidBeyondEnd = false;
|
m_bSeekInvalidBeyondEnd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStream::~fileStream()
|
|
||||||
{
|
|
||||||
// Remove the temp test file...
|
|
||||||
::wxRemoveFile(FILENAME_FILEINSTREAM);
|
|
||||||
::wxRemoveFile(FILENAME_FILEOUTSTREAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFileInputStream *fileStream::DoCreateInStream()
|
wxFileInputStream *fileStream::DoCreateInStream()
|
||||||
{
|
{
|
||||||
wxFileInputStream *pFileInStream = new wxFileInputStream(GetInFileName());
|
wxFileInputStream *pFileInStream = new wxFileInputStream(GetInFileName());
|
||||||
@@ -106,12 +98,37 @@ void fileStream::DoDeleteOutStream()
|
|||||||
|
|
||||||
wxString fileStream::GetInFileName() const
|
wxString fileStream::GetInFileName() const
|
||||||
{
|
{
|
||||||
static bool bFileCreated = false;
|
class AutoRemoveFile
|
||||||
if (!bFileCreated)
|
|
||||||
{
|
{
|
||||||
// Create the file only once
|
public:
|
||||||
bFileCreated = true;
|
AutoRemoveFile()
|
||||||
|
{
|
||||||
|
m_created = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
~AutoRemoveFile()
|
||||||
|
{
|
||||||
|
if ( m_created )
|
||||||
|
wxRemoveFile(FILENAME_FILEINSTREAM);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShouldCreate()
|
||||||
|
{
|
||||||
|
if ( m_created )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_created = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_created;
|
||||||
|
};
|
||||||
|
|
||||||
|
static AutoRemoveFile autoFile;
|
||||||
|
if ( autoFile.ShouldCreate() )
|
||||||
|
{
|
||||||
// Make sure we have a input file...
|
// Make sure we have a input file...
|
||||||
char buf[DATABUFFER_SIZE];
|
char buf[DATABUFFER_SIZE];
|
||||||
wxFileOutputStream out(FILENAME_FILEINSTREAM);
|
wxFileOutputStream out(FILENAME_FILEINSTREAM);
|
||||||
|
Reference in New Issue
Block a user