]>
git.saurik.com Git - wxWidgets.git/blob - tests/file/filefn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/file/filefn.cpp
3 // Purpose: generic file functions unit test
4 // Author: Francesco Montorsi (extracted from console sample)
6 // Copyright: (c) 2010 wxWidgets team
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
22 #include "wx/filefn.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class FileFunctionsTestCase
: public CppUnit::TestCase
33 FileFunctionsTestCase() { }
36 CPPUNIT_TEST_SUITE( FileFunctionsTestCase
);
37 CPPUNIT_TEST( CopyFile
);
38 CPPUNIT_TEST_SUITE_END();
42 wxDECLARE_NO_COPY_CLASS(FileFunctionsTestCase
);
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 CPPUNIT_TEST_SUITE_REGISTRATION( FileFunctionsTestCase
);
50 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileFunctionsTestCase
, "FileFunctionsTestCase" );
52 // ----------------------------------------------------------------------------
53 // tests implementation
54 // ----------------------------------------------------------------------------
56 void FileFunctionsTestCase::CopyFile()
58 static const wxChar
*filename1
= wxT("horse.bmp");
59 static const wxChar
*filename2
= wxT("test_copy");
61 CPPUNIT_ASSERT( wxCopyFile(filename1
, filename2
) );
63 // verify that the two files have the same contents!
64 wxFFile
f1(filename1
, wxT("rb")),
65 f2(filename2
, wxT("rb"));
67 CPPUNIT_ASSERT( f1
.IsOpened() && f2
.IsOpened() );
70 CPPUNIT_ASSERT( f1
.ReadAll(&s1
) && f2
.ReadAll(&s2
) );
71 CPPUNIT_ASSERT( (s1
.length() == s2
.length()) &&
72 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) == 0) );
74 CPPUNIT_ASSERT( f1
.Close() && f2
.Close() );
75 CPPUNIT_ASSERT( wxRemoveFile(filename2
) );
80 TODO: other file functions to test:
82 bool wxFileExists(const wxString& filename);
84 bool wxDirExists(const wxString& pathName);
86 bool wxIsAbsolutePath(const wxString& filename);
88 wxChar* wxFileNameFromPath(wxChar *path);
89 wxString wxFileNameFromPath(const wxString& path);
91 wxString wxPathOnly(const wxString& path);
93 wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
94 wxString wxFindNextFile();
96 bool wxIsWild(const wxString& pattern);
98 bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
100 bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
102 bool wxRemoveFile(const wxString& file);
104 bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
108 bool wxSetWorkingDirectory(const wxString& d);
110 bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
112 bool wxRmdir(const wxString& dir, int flags = 0);
114 wxFileKind wxGetFileKind(int fd);
115 wxFileKind wxGetFileKind(FILE *fp);
117 bool wxIsWritable(const wxString &path);
118 bool wxIsReadable(const wxString &path);
119 bool wxIsExecutable(const wxString &path);