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

@@ -41,5 +41,30 @@ private:
wxString m_name;
};
// ----------------------------------------------------------------------------
// TempFile: just a self deleting file
// ----------------------------------------------------------------------------
class TempFile
{
public:
explicit TempFile(const wxString& name = wxString()) : m_name(name) { }
void Assign(const wxString& name) { m_name = name; }
const wxString& GetName() const { return m_name; }
~TempFile()
{
if ( !m_name.empty() )
wxRemoveFile(m_name);
}
private:
wxString m_name;
wxDECLARE_NO_COPY_CLASS(TempFile);
};
#endif // _WX_TESTS_TEMPFILE_H_