testfile.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/testfile.h
  3. // Purpose: TestFile class
  4. // Author: Mike Wetherell
  5. // Copyright: (c) 2005 Mike Wetherell
  6. // Licence: wxWindows licence
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_TESTS_TEMPFILE_H_
  9. #define _WX_TESTS_TEMPFILE_H_
  10. #include "wx/filefn.h"
  11. #include "wx/filename.h"
  12. #include <ostream>
  13. // define stream inserter for wxFileName to use it in CPPUNIT_ASSERT_EQUAL()
  14. inline std::ostream& operator<<(std::ostream& o, const wxFileName& fn)
  15. {
  16. return o << fn.GetFullPath();
  17. }
  18. // ----------------------------------------------------------------------------
  19. // TestFile: self deleting test file in temporary directory
  20. // ----------------------------------------------------------------------------
  21. class TestFile
  22. {
  23. public:
  24. TestFile()
  25. {
  26. wxFile file;
  27. m_name = wxFileName::CreateTempFileName(wxT("wxtest"), &file);
  28. file.Write("Before", 6);
  29. }
  30. ~TestFile() { if (wxFileExists(m_name)) wxRemoveFile(m_name); }
  31. wxString GetName() const { return m_name; }
  32. private:
  33. wxString m_name;
  34. };
  35. #endif // _WX_TESTS_TEMPFILE_H_