]>
git.saurik.com Git - wxWidgets.git/blob - tests/file/filefn.cpp
ed2a9ded71ba79d8bd35e099ee1d37a5ceafef86
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/file/filefn.cpp
3 // Purpose: generic file functions unit test
4 // Author: Francesco Montorsi (extracted from console sample)
7 // Copyright: (c) 2010 wxWidgets team
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
23 #include "wx/filefn.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class FileFunctionsTestCase
: public CppUnit::TestCase
34 FileFunctionsTestCase() { }
37 CPPUNIT_TEST_SUITE( FileFunctionsTestCase
);
38 CPPUNIT_TEST( CopyFile
);
39 CPPUNIT_TEST_SUITE_END();
43 wxDECLARE_NO_COPY_CLASS(FileFunctionsTestCase
);
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 CPPUNIT_TEST_SUITE_REGISTRATION( FileFunctionsTestCase
);
51 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileFunctionsTestCase
, "FileFunctionsTestCase" );
53 // ----------------------------------------------------------------------------
54 // tests implementation
55 // ----------------------------------------------------------------------------
57 void FileFunctionsTestCase::CopyFile()
59 static const wxChar
*filename1
= wxT("horse.bmp");
60 static const wxChar
*filename2
= wxT("test_copy");
62 CPPUNIT_ASSERT( wxCopyFile(filename1
, filename2
) );
64 // verify that the two files have the same contents!
65 wxFFile
f1(filename1
, wxT("rb")),
66 f2(filename2
, wxT("rb"));
68 CPPUNIT_ASSERT( f1
.IsOpened() && f2
.IsOpened() );
71 CPPUNIT_ASSERT( f1
.ReadAll(&s1
) && f2
.ReadAll(&s2
) );
72 CPPUNIT_ASSERT( (s1
.length() == s2
.length()) &&
73 (memcmp(s1
.c_str(), s2
.c_str(), s1
.length()) == 0) );
75 CPPUNIT_ASSERT( f1
.Close() && f2
.Close() );
76 CPPUNIT_ASSERT( wxRemoveFile(filename2
) );
81 TODO: other file functions to test:
83 bool wxFileExists(const wxString& filename);
85 bool wxDirExists(const wxString& pathName);
87 bool wxIsAbsolutePath(const wxString& filename);
89 wxChar* wxFileNameFromPath(wxChar *path);
90 wxString wxFileNameFromPath(const wxString& path);
92 wxString wxPathOnly(const wxString& path);
94 wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
95 wxString wxFindNextFile();
97 bool wxIsWild(const wxString& pattern);
99 bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
101 bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
103 bool wxRemoveFile(const wxString& file);
105 bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
109 bool wxSetWorkingDirectory(const wxString& d);
111 bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
113 bool wxRmdir(const wxString& dir, int flags = 0);
115 wxFileKind wxGetFileKind(int fd);
116 wxFileKind wxGetFileKind(FILE *fp);
118 bool wxIsWritable(const wxString &path);
119 bool wxIsReadable(const wxString &path);
120 bool wxIsExecutable(const wxString &path);