]>
git.saurik.com Git - wxWidgets.git/blob - tests/filesys/filesystest.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 // ----------------------------------------------------------------------------
24 #include "wx/filesys.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 // a hack to let us use wxFileSystemHandler's protected methods:
33 class UrlTester
: public wxFileSystemHandler
36 UrlTester() : wxFileSystemHandler() {}
38 wxString
Protocol(const wxString
& p
) { return GetProtocol(p
); }
39 wxString
LeftLocation(const wxString
& p
) { return GetLeftLocation(p
); }
40 wxString
RightLocation(const wxString
& p
) { return GetRightLocation(p
); }
41 wxString
Anchor(const wxString
& p
) { return GetAnchor(p
); }
43 bool CanOpen(const wxString
& WXUNUSED(url
)) { return false; }
44 wxFSFile
*OpenFile(wxFileSystem
& WXUNUSED(fs
),
45 const wxString
& WXUNUSED(url
)) { return NULL
; }
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 class FileSystemTestCase
: public CppUnit::TestCase
58 FileSystemTestCase() { }
61 CPPUNIT_TEST_SUITE( FileSystemTestCase
);
62 CPPUNIT_TEST( UrlParsing
);
63 CPPUNIT_TEST( FileNameToUrlConversion
);
64 CPPUNIT_TEST_SUITE_END();
67 void FileNameToUrlConversion();
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 { wxT("http://www.root.cz/index.html"),
88 wxT("http"), wxT(""), wxT("//www.root.cz/index.html"), wxT("")},
90 { wxT("http://www.root.cz/index.html#lbl"),
91 wxT("http"), wxT(""), wxT("//www.root.cz/index.html"), wxT("lbl")},
92 // file is default protocol:
93 { wxT("testfile.html"),
94 wxT("file"), wxT(""), wxT("testfile.html"), wxT("")},
96 { wxT("file:myzipfile.zip#zip:index.htm"),
97 wxT("zip"), wxT("file:myzipfile.zip"), wxT("index.htm"), wxT("")},
98 // changes to ':' parsing often break things:
99 { wxT("file:a#b:foo"),
100 wxT("b"), wxT("file:a"), wxT("foo"), wxT("")}
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 void FileSystemTestCase::FileNameToUrlConversion()
117 wxFileName
fn1(wxT("\\\\server\\share\\path\\to\\file"));
118 wxString url1
= wxFileSystem::FileNameToURL(fn1
);
120 CPPUNIT_ASSERT( fn1
.SameAs(wxFileSystem::URLToFileName(url1
)) );
124 #endif // wxUSE_FILESYSTEM