filefn.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/file/filefn.cpp
  3. // Purpose: generic file functions unit test
  4. // Author: Francesco Montorsi (extracted from console sample)
  5. // Created: 2010-06-13
  6. // Copyright: (c) 2010 wxWidgets team
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // ----------------------------------------------------------------------------
  9. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #if wxUSE_FILE
  16. #include "wx/ffile.h"
  17. #include "wx/filefn.h"
  18. #include "testfile.h"
  19. // ----------------------------------------------------------------------------
  20. // test class
  21. // ----------------------------------------------------------------------------
  22. class FileFunctionsTestCase : public CppUnit::TestCase
  23. {
  24. public:
  25. FileFunctionsTestCase() { }
  26. private:
  27. CPPUNIT_TEST_SUITE( FileFunctionsTestCase );
  28. CPPUNIT_TEST( CopyFile );
  29. CPPUNIT_TEST_SUITE_END();
  30. void CopyFile();
  31. wxDECLARE_NO_COPY_CLASS(FileFunctionsTestCase);
  32. };
  33. // ----------------------------------------------------------------------------
  34. // CppUnit macros
  35. // ----------------------------------------------------------------------------
  36. CPPUNIT_TEST_SUITE_REGISTRATION( FileFunctionsTestCase );
  37. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileFunctionsTestCase, "FileFunctionsTestCase" );
  38. // ----------------------------------------------------------------------------
  39. // tests implementation
  40. // ----------------------------------------------------------------------------
  41. void FileFunctionsTestCase::CopyFile()
  42. {
  43. static const wxChar *filename1 = wxT("horse.bmp");
  44. static const wxChar *filename2 = wxT("test_copy");
  45. CPPUNIT_ASSERT( wxCopyFile(filename1, filename2) );
  46. // verify that the two files have the same contents!
  47. wxFFile f1(filename1, wxT("rb")),
  48. f2(filename2, wxT("rb"));
  49. CPPUNIT_ASSERT( f1.IsOpened() && f2.IsOpened() );
  50. wxString s1, s2;
  51. CPPUNIT_ASSERT( f1.ReadAll(&s1) && f2.ReadAll(&s2) );
  52. CPPUNIT_ASSERT( (s1.length() == s2.length()) &&
  53. (memcmp(s1.c_str(), s2.c_str(), s1.length()) == 0) );
  54. CPPUNIT_ASSERT( f1.Close() && f2.Close() );
  55. CPPUNIT_ASSERT( wxRemoveFile(filename2) );
  56. }
  57. /*
  58. TODO: other file functions to test:
  59. bool wxFileExists(const wxString& filename);
  60. bool wxDirExists(const wxString& pathName);
  61. bool wxIsAbsolutePath(const wxString& filename);
  62. wxChar* wxFileNameFromPath(wxChar *path);
  63. wxString wxFileNameFromPath(const wxString& path);
  64. wxString wxPathOnly(const wxString& path);
  65. wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
  66. wxString wxFindNextFile();
  67. bool wxIsWild(const wxString& pattern);
  68. bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
  69. bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
  70. bool wxRemoveFile(const wxString& file);
  71. bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
  72. wxString wxGetCwd();
  73. bool wxSetWorkingDirectory(const wxString& d);
  74. bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
  75. bool wxRmdir(const wxString& dir, int flags = 0);
  76. wxFileKind wxGetFileKind(int fd);
  77. wxFileKind wxGetFileKind(FILE *fp);
  78. bool wxIsWritable(const wxString &path);
  79. bool wxIsReadable(const wxString &path);
  80. bool wxIsExecutable(const wxString &path);
  81. */
  82. #endif // wxUSE_FILE