]> git.saurik.com Git - wxWidgets.git/blame - tests/filesys/filesystest.cpp
Don't append text following CDATA section to its node itself.
[wxWidgets.git] / tests / filesys / filesystest.cpp
CommitLineData
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
8899b155 14#include "testprec.h"
20f46e8d
VS
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
4827cbd9
VS
26#if wxUSE_FILESYSTEM
27
28// ----------------------------------------------------------------------------
29// helpers
30// ----------------------------------------------------------------------------
31
32// a hack to let us use wxFileSystemHandler's protected methods:
33class UrlTester : public wxFileSystemHandler
34{
35public:
36 UrlTester() : wxFileSystemHandler() {}
37
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); }
42
43 bool CanOpen(const wxString& WXUNUSED(url)) { return false; }
44 wxFSFile *OpenFile(wxFileSystem& WXUNUSED(fs),
45 const wxString& WXUNUSED(url)) { return NULL; }
46
47
48};
49
50
51// ----------------------------------------------------------------------------
52// test class
53// ----------------------------------------------------------------------------
54
55class FileSystemTestCase : public CppUnit::TestCase
56{
57public:
58 FileSystemTestCase() { }
59
60private:
61 CPPUNIT_TEST_SUITE( FileSystemTestCase );
62 CPPUNIT_TEST( UrlParsing );
6b0c752f 63 CPPUNIT_TEST( FileNameToUrlConversion );
4827cbd9
VS
64 CPPUNIT_TEST_SUITE_END();
65
66 void UrlParsing();
6b0c752f 67 void FileNameToUrlConversion();
4827cbd9 68
20f46e8d 69 DECLARE_NO_COPY_CLASS(FileSystemTestCase)
4827cbd9
VS
70};
71
72// register in the unnamed registry so that these tests are run by default
73CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemTestCase );
74
75// also include in it's own registry so that these tests can be run alone
76CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemTestCase, "FileSystemTestCase" );
77
78void FileSystemTestCase::UrlParsing()
79{
80 static const struct Data
81 {
20f46e8d
VS
82 const wxChar *url;
83 const wxChar *protocol, *left, *right, *anchor;
4827cbd9
VS
84 } data[] =
85 {
86 // simple case:
9a83f860
VZ
87 { wxT("http://www.root.cz/index.html"),
88 wxT("http"), wxT(""), wxT("//www.root.cz/index.html"), wxT("")},
4827cbd9 89 // anchors:
9a83f860
VZ
90 { wxT("http://www.root.cz/index.html#lbl"),
91 wxT("http"), wxT(""), wxT("//www.root.cz/index.html"), wxT("lbl")},
4827cbd9 92 // file is default protocol:
9a83f860
VZ
93 { wxT("testfile.html"),
94 wxT("file"), wxT(""), wxT("testfile.html"), wxT("")},
4827cbd9 95 // stacked protocols:
9a83f860
VZ
96 { wxT("file:myzipfile.zip#zip:index.htm"),
97 wxT("zip"), wxT("file:myzipfile.zip"), wxT("index.htm"), wxT("")},
4827cbd9 98 // changes to ':' parsing often break things:
9a83f860
VZ
99 { wxT("file:a#b:foo"),
100 wxT("b"), wxT("file:a"), wxT("foo"), wxT("")}
4827cbd9
VS
101 };
102
103 UrlTester tst;
104 for ( size_t n = 0; n < WXSIZEOF(data); n++ )
105 {
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 );
111 }
112}
6b0c752f
VS
113
114void FileSystemTestCase::FileNameToUrlConversion()
115{
116#ifdef __WINDOWS__
9a83f860 117 wxFileName fn1(wxT("\\\\server\\share\\path\\to\\file"));
6b0c752f
VS
118 wxString url1 = wxFileSystem::FileNameToURL(fn1);
119
120 CPPUNIT_ASSERT( fn1.SameAs(wxFileSystem::URLToFileName(url1)) );
121#endif
122}
4827cbd9
VS
123
124#endif // wxUSE_FILESYSTEM