]> git.saurik.com Git - wxWidgets.git/blame - tests/file/filefn.cpp
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[wxWidgets.git] / tests / file / filefn.cpp
CommitLineData
69fc8587
FM
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
31class FileFunctionsTestCase : public CppUnit::TestCase
32{
33public:
34 FileFunctionsTestCase() { }
35
36private:
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
50CPPUNIT_TEST_SUITE_REGISTRATION( FileFunctionsTestCase );
51CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileFunctionsTestCase, "FileFunctionsTestCase" );
52
53// ----------------------------------------------------------------------------
54// tests implementation
55// ----------------------------------------------------------------------------
56
57void 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
83bool wxFileExists(const wxString& filename);
84
85bool wxDirExists(const wxString& pathName);
86
87bool wxIsAbsolutePath(const wxString& filename);
88
89wxChar* wxFileNameFromPath(wxChar *path);
90wxString wxFileNameFromPath(const wxString& path);
91
92wxString wxPathOnly(const wxString& path);
93
94wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
95wxString wxFindNextFile();
96
97bool wxIsWild(const wxString& pattern);
98
99bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
100
101bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
102
103bool wxRemoveFile(const wxString& file);
104
105bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
106
107wxString wxGetCwd();
108
109bool wxSetWorkingDirectory(const wxString& d);
110
111bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
112
113bool wxRmdir(const wxString& dir, int flags = 0);
114
115wxFileKind wxGetFileKind(int fd);
116wxFileKind wxGetFileKind(FILE *fp);
117
118bool wxIsWritable(const wxString &path);
119bool wxIsReadable(const wxString &path);
120bool wxIsExecutable(const wxString &path);
121*/
122
123#endif // wxUSE_FILE