]>
git.saurik.com Git - wxWidgets.git/blob - tests/filesys/filesys.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/filesys/filesys.cpp
3 // Purpose: wxFileSystem unit test
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2004 Vaclav Slavik
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
14 #include "wx/wxprec.h"
24 #include "wx/filesys.h"
26 #include "wx/cppunit.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 // a hack to let us use wxFileSystemHandler's protected methods:
35 class UrlTester
: public wxFileSystemHandler
38 UrlTester() : wxFileSystemHandler() {}
40 wxString
Protocol(const wxString
& p
) { return GetProtocol(p
); }
41 wxString
LeftLocation(const wxString
& p
) { return GetLeftLocation(p
); }
42 wxString
RightLocation(const wxString
& p
) { return GetRightLocation(p
); }
43 wxString
Anchor(const wxString
& p
) { return GetAnchor(p
); }
45 bool CanOpen(const wxString
& WXUNUSED(url
)) { return false; }
46 wxFSFile
*OpenFile(wxFileSystem
& WXUNUSED(fs
),
47 const wxString
& WXUNUSED(url
)) { return NULL
; }
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 class FileSystemTestCase
: public CppUnit::TestCase
60 FileSystemTestCase() { }
63 CPPUNIT_TEST_SUITE( FileSystemTestCase
);
64 CPPUNIT_TEST( UrlParsing
);
65 CPPUNIT_TEST_SUITE_END();
69 DECLARE_NO_COPY_CLASS(FileSystemTestCase
)
72 // register in the unnamed registry so that these tests are run by default
73 CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemTestCase
);
75 // also include in it's own registry so that these tests can be run alone
76 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemTestCase
, "FileSystemTestCase" );
78 void FileSystemTestCase::UrlParsing()
80 static const struct Data
83 const wxChar
*protocol
, *left
, *right
, *anchor
;
87 { _T("http://www.root.cz/index.html"),
88 _T("http"), _T(""), _T("//www.root.cz/index.html"), _T("")},
90 { _T("http://www.root.cz/index.html#lbl"),
91 _T("http"), _T(""), _T("//www.root.cz/index.html"), _T("lbl")},
92 // file is default protocol:
93 { _T("testfile.html"),
94 _T("file"), _T(""), _T("testfile.html"), _T("")},
96 { _T("file:myzipfile.zip#zip:index.htm"),
97 _T("zip"), _T("file:myzipfile.zip"), _T("index.htm"), _T("")},
98 // changes to ':' parsing often break things:
100 _T("b"), _T("file:a"), _T("foo"), _T("")}
104 for ( size_t n
= 0; n
< WXSIZEOF(data
); n
++ )
106 const Data
& d
= data
[n
];
107 CPPUNIT_ASSERT( tst
.Protocol(d
.url
) == d
.protocol
);
108 CPPUNIT_ASSERT( tst
.LeftLocation(d
.url
) == d
.left
);
109 CPPUNIT_ASSERT( tst
.RightLocation(d
.url
) == d
.right
);
110 CPPUNIT_ASSERT( tst
.Anchor(d
.url
) == d
.anchor
);
114 #endif // wxUSE_FILESYSTEM