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