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:
Vadim Zeitlin
2017-11-05 17:28:24 +01:00
parent 0425b8b7f0
commit 10b80a16f0
4 changed files with 53 additions and 18 deletions

View File

@@ -37,6 +37,8 @@
#define fileno _fileno
#endif
#include "testfile.h"
///////////////////////////////////////////////////////////////////////////////
// The test case
@@ -100,23 +102,17 @@ void FileKindTestCase::TestFd(wxFile& file, bool expected)
CPPUNIT_ASSERT(outStream.IsSeekable() == expected);
}
struct TempFile
{
~TempFile() { if (!m_name.IsEmpty()) wxRemoveFile(m_name); }
wxString m_name;
};
// test with an ordinary file
//
void FileKindTestCase::File()
{
TempFile tmp; // put first
wxFile file;
tmp.m_name = wxFileName::CreateTempFileName(wxT("wxft"), &file);
tmp.Assign(wxFileName::CreateTempFileName(wxT("wxft"), &file));
TestFd(file, true);
file.Close();
wxFFile ffile(tmp.m_name);
wxFFile ffile(tmp.GetName());
TestFILE(ffile, true);
}