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