]>
Commit | Line | Data |
---|---|---|
4827cbd9 VS |
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 | ||
20f46e8d VS |
14 | #include "wx/wxprec.h" |
15 | ||
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | #ifndef WX_PRECOMP | |
21 | #include "wx/wx.h" | |
22 | #endif // WX_PRECOMP | |
23 | ||
4827cbd9 VS |
24 | #include "wx/filesys.h" |
25 | ||
26 | #include "wx/cppunit.h" | |
27 | ||
28 | #if wxUSE_FILESYSTEM | |
29 | ||
30 | // ---------------------------------------------------------------------------- | |
31 | // helpers | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | // a hack to let us use wxFileSystemHandler's protected methods: | |
35 | class UrlTester : public wxFileSystemHandler | |
36 | { | |
37 | public: | |
38 | UrlTester() : wxFileSystemHandler() {} | |
39 | ||
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); } | |
44 | ||
45 | bool CanOpen(const wxString& WXUNUSED(url)) { return false; } | |
46 | wxFSFile *OpenFile(wxFileSystem& WXUNUSED(fs), | |
47 | const wxString& WXUNUSED(url)) { return NULL; } | |
48 | ||
49 | ||
50 | }; | |
51 | ||
52 | ||
53 | // ---------------------------------------------------------------------------- | |
54 | // test class | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
57 | class FileSystemTestCase : public CppUnit::TestCase | |
58 | { | |
59 | public: | |
60 | FileSystemTestCase() { } | |
61 | ||
62 | private: | |
63 | CPPUNIT_TEST_SUITE( FileSystemTestCase ); | |
64 | CPPUNIT_TEST( UrlParsing ); | |
6b0c752f | 65 | CPPUNIT_TEST( FileNameToUrlConversion ); |
4827cbd9 VS |
66 | CPPUNIT_TEST_SUITE_END(); |
67 | ||
68 | void UrlParsing(); | |
6b0c752f | 69 | void FileNameToUrlConversion(); |
4827cbd9 | 70 | |
20f46e8d | 71 | DECLARE_NO_COPY_CLASS(FileSystemTestCase) |
4827cbd9 VS |
72 | }; |
73 | ||
74 | // register in the unnamed registry so that these tests are run by default | |
75 | CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemTestCase ); | |
76 | ||
77 | // also include in it's own registry so that these tests can be run alone | |
78 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemTestCase, "FileSystemTestCase" ); | |
79 | ||
80 | void FileSystemTestCase::UrlParsing() | |
81 | { | |
82 | static const struct Data | |
83 | { | |
20f46e8d VS |
84 | const wxChar *url; |
85 | const wxChar *protocol, *left, *right, *anchor; | |
4827cbd9 VS |
86 | } data[] = |
87 | { | |
88 | // simple case: | |
89 | { _T("http://www.root.cz/index.html"), | |
90 | _T("http"), _T(""), _T("//www.root.cz/index.html"), _T("")}, | |
91 | // anchors: | |
92 | { _T("http://www.root.cz/index.html#lbl"), | |
93 | _T("http"), _T(""), _T("//www.root.cz/index.html"), _T("lbl")}, | |
94 | // file is default protocol: | |
95 | { _T("testfile.html"), | |
96 | _T("file"), _T(""), _T("testfile.html"), _T("")}, | |
97 | // stacked protocols: | |
98 | { _T("file:myzipfile.zip#zip:index.htm"), | |
99 | _T("zip"), _T("file:myzipfile.zip"), _T("index.htm"), _T("")}, | |
100 | // changes to ':' parsing often break things: | |
101 | { _T("file:a#b:foo"), | |
102 | _T("b"), _T("file:a"), _T("foo"), _T("")} | |
103 | }; | |
104 | ||
105 | UrlTester tst; | |
106 | for ( size_t n = 0; n < WXSIZEOF(data); n++ ) | |
107 | { | |
108 | const Data& d = data[n]; | |
109 | CPPUNIT_ASSERT( tst.Protocol(d.url) == d.protocol ); | |
110 | CPPUNIT_ASSERT( tst.LeftLocation(d.url) == d.left ); | |
111 | CPPUNIT_ASSERT( tst.RightLocation(d.url) == d.right ); | |
112 | CPPUNIT_ASSERT( tst.Anchor(d.url) == d.anchor ); | |
113 | } | |
114 | } | |
6b0c752f VS |
115 | |
116 | void FileSystemTestCase::FileNameToUrlConversion() | |
117 | { | |
118 | #ifdef __WINDOWS__ | |
119 | wxFileName fn1(_T("\\\\server\\share\\path\\to\\file")); | |
120 | wxString url1 = wxFileSystem::FileNameToURL(fn1); | |
121 | ||
122 | CPPUNIT_ASSERT( fn1.SameAs(wxFileSystem::URLToFileName(url1)) ); | |
123 | #endif | |
124 | } | |
4827cbd9 VS |
125 | |
126 | #endif // wxUSE_FILESYSTEM |