]> git.saurik.com Git - wxWidgets.git/blob - tests/filesys/filesys.cpp
added wxFileSystem test
[wxWidgets.git] / tests / filesys / filesys.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/filesys/filesys.cpp
3 // Purpose: wxFileSystem unit test
4 // Author: Vaclav Slavik
5 // Created: 2004-03-28
6 // RCS-ID: $Id$
7 // Copyright: (c) 2004 Vaclav Slavik
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "wx/wx.h"
15 #include "wx/filesys.h"
16
17 #include "wx/cppunit.h"
18
19 #if wxUSE_FILESYSTEM
20
21 // ----------------------------------------------------------------------------
22 // helpers
23 // ----------------------------------------------------------------------------
24
25 // a hack to let us use wxFileSystemHandler's protected methods:
26 class UrlTester : public wxFileSystemHandler
27 {
28 public:
29 UrlTester() : wxFileSystemHandler() {}
30
31 wxString Protocol(const wxString& p) { return GetProtocol(p); }
32 wxString LeftLocation(const wxString& p) { return GetLeftLocation(p); }
33 wxString RightLocation(const wxString& p) { return GetRightLocation(p); }
34 wxString Anchor(const wxString& p) { return GetAnchor(p); }
35
36 bool CanOpen(const wxString& WXUNUSED(url)) { return false; }
37 wxFSFile *OpenFile(wxFileSystem& WXUNUSED(fs),
38 const wxString& WXUNUSED(url)) { return NULL; }
39
40
41 };
42
43
44 // ----------------------------------------------------------------------------
45 // test class
46 // ----------------------------------------------------------------------------
47
48 class FileSystemTestCase : public CppUnit::TestCase
49 {
50 public:
51 FileSystemTestCase() { }
52
53 private:
54 CPPUNIT_TEST_SUITE( FileSystemTestCase );
55 CPPUNIT_TEST( UrlParsing );
56 CPPUNIT_TEST_SUITE_END();
57
58 void UrlParsing();
59
60 DECLARE_NO_COPY_CLASS(FileSystemTestCase);
61 };
62
63 // register in the unnamed registry so that these tests are run by default
64 CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemTestCase );
65
66 // also include in it's own registry so that these tests can be run alone
67 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemTestCase, "FileSystemTestCase" );
68
69 void FileSystemTestCase::UrlParsing()
70 {
71 static const struct Data
72 {
73 const wchar_t *url;
74 const wchar_t *protocol, *left, *right, *anchor;
75 } data[] =
76 {
77 // simple case:
78 { _T("http://www.root.cz/index.html"),
79 _T("http"), _T(""), _T("//www.root.cz/index.html"), _T("")},
80 // anchors:
81 { _T("http://www.root.cz/index.html#lbl"),
82 _T("http"), _T(""), _T("//www.root.cz/index.html"), _T("lbl")},
83 // file is default protocol:
84 { _T("testfile.html"),
85 _T("file"), _T(""), _T("testfile.html"), _T("")},
86 // stacked protocols:
87 { _T("file:myzipfile.zip#zip:index.htm"),
88 _T("zip"), _T("file:myzipfile.zip"), _T("index.htm"), _T("")},
89 // changes to ':' parsing often break things:
90 { _T("file:a#b:foo"),
91 _T("b"), _T("file:a"), _T("foo"), _T("")}
92 };
93
94 UrlTester tst;
95 for ( size_t n = 0; n < WXSIZEOF(data); n++ )
96 {
97 const Data& d = data[n];
98 CPPUNIT_ASSERT( tst.Protocol(d.url) == d.protocol );
99 CPPUNIT_ASSERT( tst.LeftLocation(d.url) == d.left );
100 CPPUNIT_ASSERT( tst.RightLocation(d.url) == d.right );
101 CPPUNIT_ASSERT( tst.Anchor(d.url) == d.anchor );
102 }
103 }
104
105 #endif // wxUSE_FILESYSTEM