]> git.saurik.com Git - wxWidgets.git/blame - tests/filesys/filesystest.cpp
Add missing XRC format docs for wxComboCtrl and wxEditableListBox.
[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
4827cbd9
VS
6// Copyright: (c) 2004 Vaclav Slavik
7///////////////////////////////////////////////////////////////////////////////
8
9// ----------------------------------------------------------------------------
10// headers
11// ----------------------------------------------------------------------------
12
8899b155 13#include "testprec.h"
20f46e8d
VS
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20 #include "wx/wx.h"
21#endif // WX_PRECOMP
22
4827cbd9
VS
23#include "wx/filesys.h"
24
4827cbd9
VS
25#if wxUSE_FILESYSTEM
26
27// ----------------------------------------------------------------------------
28// helpers
29// ----------------------------------------------------------------------------
30
31// a hack to let us use wxFileSystemHandler's protected methods:
32class UrlTester : public wxFileSystemHandler
33{
34public:
35 UrlTester() : wxFileSystemHandler() {}
36
37 wxString Protocol(const wxString& p) { return GetProtocol(p); }
38 wxString LeftLocation(const wxString& p) { return GetLeftLocation(p); }
39 wxString RightLocation(const wxString& p) { return GetRightLocation(p); }
40 wxString Anchor(const wxString& p) { return GetAnchor(p); }
41
42 bool CanOpen(const wxString& WXUNUSED(url)) { return false; }
43 wxFSFile *OpenFile(wxFileSystem& WXUNUSED(fs),
44 const wxString& WXUNUSED(url)) { return NULL; }
45
46
47};
48
49
50// ----------------------------------------------------------------------------
51// test class
52// ----------------------------------------------------------------------------
53
54class FileSystemTestCase : public CppUnit::TestCase
55{
56public:
57 FileSystemTestCase() { }
58
59private:
60 CPPUNIT_TEST_SUITE( FileSystemTestCase );
61 CPPUNIT_TEST( UrlParsing );
6b0c752f 62 CPPUNIT_TEST( FileNameToUrlConversion );
abd5e008 63 CPPUNIT_TEST( UnicodeFileNameToUrlConversion );
4827cbd9
VS
64 CPPUNIT_TEST_SUITE_END();
65
66 void UrlParsing();
6b0c752f 67 void FileNameToUrlConversion();
abd5e008 68 void UnicodeFileNameToUrlConversion();
4827cbd9 69
20f46e8d 70 DECLARE_NO_COPY_CLASS(FileSystemTestCase)
4827cbd9
VS
71};
72
73// register in the unnamed registry so that these tests are run by default
74CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemTestCase );
75
e3778b4d 76// also include in its own registry so that these tests can be run alone
4827cbd9
VS
77CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemTestCase, "FileSystemTestCase" );
78
79void FileSystemTestCase::UrlParsing()
80{
81 static const struct Data
82 {
20f46e8d
VS
83 const wxChar *url;
84 const wxChar *protocol, *left, *right, *anchor;
4827cbd9
VS
85 } data[] =
86 {
87 // simple case:
9a83f860
VZ
88 { wxT("http://www.root.cz/index.html"),
89 wxT("http"), wxT(""), wxT("//www.root.cz/index.html"), wxT("")},
4827cbd9 90 // anchors:
9a83f860
VZ
91 { wxT("http://www.root.cz/index.html#lbl"),
92 wxT("http"), wxT(""), wxT("//www.root.cz/index.html"), wxT("lbl")},
4827cbd9 93 // file is default protocol:
9a83f860
VZ
94 { wxT("testfile.html"),
95 wxT("file"), wxT(""), wxT("testfile.html"), wxT("")},
4827cbd9 96 // stacked protocols:
9a83f860
VZ
97 { wxT("file:myzipfile.zip#zip:index.htm"),
98 wxT("zip"), wxT("file:myzipfile.zip"), wxT("index.htm"), wxT("")},
4827cbd9 99 // changes to ':' parsing often break things:
9a83f860
VZ
100 { wxT("file:a#b:foo"),
101 wxT("b"), wxT("file:a"), wxT("foo"), wxT("")}
4827cbd9
VS
102 };
103
104 UrlTester tst;
105 for ( size_t n = 0; n < WXSIZEOF(data); n++ )
106 {
107 const Data& d = data[n];
108 CPPUNIT_ASSERT( tst.Protocol(d.url) == d.protocol );
109 CPPUNIT_ASSERT( tst.LeftLocation(d.url) == d.left );
110 CPPUNIT_ASSERT( tst.RightLocation(d.url) == d.right );
111 CPPUNIT_ASSERT( tst.Anchor(d.url) == d.anchor );
112 }
113}
abd5e008 114
6b0c752f
VS
115void FileSystemTestCase::FileNameToUrlConversion()
116{
117#ifdef __WINDOWS__
9a83f860 118 wxFileName fn1(wxT("\\\\server\\share\\path\\to\\file"));
6b0c752f 119 wxString url1 = wxFileSystem::FileNameToURL(fn1);
abd5e008 120
6b0c752f
VS
121 CPPUNIT_ASSERT( fn1.SameAs(wxFileSystem::URLToFileName(url1)) );
122#endif
123}
4827cbd9 124
abd5e008
VS
125void FileSystemTestCase::UnicodeFileNameToUrlConversion()
126{
b37dacdc 127 const unsigned char filename_utf8[] = {
abd5e008
VS
128 0x4b, 0x72, 0xc3, 0xa1, 0x73, 0x79, 0x50, 0xc5,
129 0x99, 0xc3, 0xad, 0x72, 0x6f, 0x64, 0x79, 0x2e,
130 0x6a, 0x70, 0x67, 0x00
131 // KrásyPřírody.jpg
132 };
b37dacdc 133 wxFileName filename(wxString::FromUTF8((const char*)filename_utf8));
abd5e008
VS
134
135 wxString url = wxFileSystem::FileNameToURL(filename);
136
137 CPPUNIT_ASSERT( filename.SameAs(wxFileSystem::URLToFileName(url)) );
138}
139
4827cbd9 140#endif // wxUSE_FILESYSTEM