The rounded corners look really dumb at this size.
[wxWidgets.git] / 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)
5 // Created: 2010-06-13
6 // Copyright: (c) 2010 wxWidgets team
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_FILE
20
21 #include "wx/ffile.h"
22 #include "wx/filefn.h"
23
24 #include "testfile.h"
25
26 // ----------------------------------------------------------------------------
27 // test class
28 // ----------------------------------------------------------------------------
29
30 class FileFunctionsTestCase : public CppUnit::TestCase
31 {
32 public:
33 FileFunctionsTestCase() { }
34
35 private:
36 CPPUNIT_TEST_SUITE( FileFunctionsTestCase );
37 CPPUNIT_TEST( CopyFile );
38 CPPUNIT_TEST_SUITE_END();
39
40 void CopyFile();
41
42 wxDECLARE_NO_COPY_CLASS(FileFunctionsTestCase);
43 };
44
45 // ----------------------------------------------------------------------------
46 // CppUnit macros
47 // ----------------------------------------------------------------------------
48
49 CPPUNIT_TEST_SUITE_REGISTRATION( FileFunctionsTestCase );
50 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileFunctionsTestCase, "FileFunctionsTestCase" );
51
52 // ----------------------------------------------------------------------------
53 // tests implementation
54 // ----------------------------------------------------------------------------
55
56 void FileFunctionsTestCase::CopyFile()
57 {
58 static const wxChar *filename1 = wxT("horse.bmp");
59 static const wxChar *filename2 = wxT("test_copy");
60
61 CPPUNIT_ASSERT( wxCopyFile(filename1, filename2) );
62
63 // verify that the two files have the same contents!
64 wxFFile f1(filename1, wxT("rb")),
65 f2(filename2, wxT("rb"));
66
67 CPPUNIT_ASSERT( f1.IsOpened() && f2.IsOpened() );
68
69 wxString s1, s2;
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) );
73
74 CPPUNIT_ASSERT( f1.Close() && f2.Close() );
75 CPPUNIT_ASSERT( wxRemoveFile(filename2) );
76 }
77
78
79 /*
80 TODO: other file functions to test:
81
82 bool wxFileExists(const wxString& filename);
83
84 bool wxDirExists(const wxString& pathName);
85
86 bool wxIsAbsolutePath(const wxString& filename);
87
88 wxChar* wxFileNameFromPath(wxChar *path);
89 wxString wxFileNameFromPath(const wxString& path);
90
91 wxString wxPathOnly(const wxString& path);
92
93 wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
94 wxString wxFindNextFile();
95
96 bool wxIsWild(const wxString& pattern);
97
98 bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
99
100 bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
101
102 bool wxRemoveFile(const wxString& file);
103
104 bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
105
106 wxString wxGetCwd();
107
108 bool wxSetWorkingDirectory(const wxString& d);
109
110 bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
111
112 bool wxRmdir(const wxString& dir, int flags = 0);
113
114 wxFileKind wxGetFileKind(int fd);
115 wxFileKind wxGetFileKind(FILE *fp);
116
117 bool wxIsWritable(const wxString &path);
118 bool wxIsReadable(const wxString &path);
119 bool wxIsExecutable(const wxString &path);
120 */
121
122 #endif // wxUSE_FILE