]>
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 // ----------------------------------------------------------------------------
15 #include "wx/filesys.h"
17 #include "wx/cppunit.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 // a hack to let us use wxFileSystemHandler's protected methods:
26 class UrlTester
: public wxFileSystemHandler
29 UrlTester() : wxFileSystemHandler() {}
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
); }
36 bool CanOpen(const wxString
& WXUNUSED(url
)) { return false; }
37 wxFSFile
*OpenFile(wxFileSystem
& WXUNUSED(fs
),
38 const wxString
& WXUNUSED(url
)) { return NULL
; }
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 class FileSystemTestCase
: public CppUnit::TestCase
51 FileSystemTestCase() { }
54 CPPUNIT_TEST_SUITE( FileSystemTestCase
);
55 CPPUNIT_TEST( UrlParsing
);
56 CPPUNIT_TEST_SUITE_END();
60 DECLARE_NO_COPY_CLASS(FileSystemTestCase
);
63 // register in the unnamed registry so that these tests are run by default
64 CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemTestCase
);
66 // also include in it's own registry so that these tests can be run alone
67 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemTestCase
, "FileSystemTestCase" );
69 void FileSystemTestCase::UrlParsing()
71 static const struct Data
74 const wchar_t *protocol
, *left
, *right
, *anchor
;
78 { _T("http://www.root.cz/index.html"),
79 _T("http"), _T(""), _T("//www.root.cz/index.html"), _T("")},
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("")},
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:
91 _T("b"), _T("file:a"), _T("foo"), _T("")}
95 for ( size_t n
= 0; n
< WXSIZEOF(data
); n
++ )
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
);
105 #endif // wxUSE_FILESYSTEM