2004-03-28 15:44:26 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/filesys/filesys.cpp
|
|
|
|
// Purpose: wxFileSystem unit test
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 2004-03-28
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2004 Vaclav Slavik
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-11-22 00:00:19 -05:00
|
|
|
#include "testprec.h"
|
2004-04-01 02:17:50 -05:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
2004-03-28 15:44:26 -05:00
|
|
|
#include "wx/filesys.h"
|
|
|
|
|
|
|
|
#if wxUSE_FILESYSTEM
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// helpers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// a hack to let us use wxFileSystemHandler's protected methods:
|
|
|
|
class UrlTester : public wxFileSystemHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UrlTester() : wxFileSystemHandler() {}
|
|
|
|
|
|
|
|
wxString Protocol(const wxString& p) { return GetProtocol(p); }
|
|
|
|
wxString LeftLocation(const wxString& p) { return GetLeftLocation(p); }
|
|
|
|
wxString RightLocation(const wxString& p) { return GetRightLocation(p); }
|
|
|
|
wxString Anchor(const wxString& p) { return GetAnchor(p); }
|
|
|
|
|
|
|
|
bool CanOpen(const wxString& WXUNUSED(url)) { return false; }
|
|
|
|
wxFSFile *OpenFile(wxFileSystem& WXUNUSED(fs),
|
|
|
|
const wxString& WXUNUSED(url)) { return NULL; }
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FileSystemTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileSystemTestCase() { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( FileSystemTestCase );
|
|
|
|
CPPUNIT_TEST( UrlParsing );
|
2004-06-23 18:18:45 -04:00
|
|
|
CPPUNIT_TEST( FileNameToUrlConversion );
|
2010-03-28 11:41:29 -04:00
|
|
|
CPPUNIT_TEST( UnicodeFileNameToUrlConversion );
|
2004-03-28 15:44:26 -05:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void UrlParsing();
|
2004-06-23 18:18:45 -04:00
|
|
|
void FileNameToUrlConversion();
|
2010-03-28 11:41:29 -04:00
|
|
|
void UnicodeFileNameToUrlConversion();
|
2004-03-28 15:44:26 -05:00
|
|
|
|
2004-04-01 02:17:50 -05:00
|
|
|
DECLARE_NO_COPY_CLASS(FileSystemTestCase)
|
2004-03-28 15:44:26 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemTestCase );
|
|
|
|
|
2011-04-30 06:57:04 -04:00
|
|
|
// also include in its own registry so that these tests can be run alone
|
2004-03-28 15:44:26 -05:00
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemTestCase, "FileSystemTestCase" );
|
|
|
|
|
|
|
|
void FileSystemTestCase::UrlParsing()
|
|
|
|
{
|
|
|
|
static const struct Data
|
|
|
|
{
|
2004-04-01 02:17:50 -05:00
|
|
|
const wxChar *url;
|
|
|
|
const wxChar *protocol, *left, *right, *anchor;
|
2004-03-28 15:44:26 -05:00
|
|
|
} data[] =
|
|
|
|
{
|
|
|
|
// simple case:
|
2009-07-23 16:30:22 -04:00
|
|
|
{ wxT("http://www.root.cz/index.html"),
|
|
|
|
wxT("http"), wxT(""), wxT("//www.root.cz/index.html"), wxT("")},
|
2004-03-28 15:44:26 -05:00
|
|
|
// anchors:
|
2009-07-23 16:30:22 -04:00
|
|
|
{ wxT("http://www.root.cz/index.html#lbl"),
|
|
|
|
wxT("http"), wxT(""), wxT("//www.root.cz/index.html"), wxT("lbl")},
|
2004-03-28 15:44:26 -05:00
|
|
|
// file is default protocol:
|
2009-07-23 16:30:22 -04:00
|
|
|
{ wxT("testfile.html"),
|
|
|
|
wxT("file"), wxT(""), wxT("testfile.html"), wxT("")},
|
2004-03-28 15:44:26 -05:00
|
|
|
// stacked protocols:
|
2009-07-23 16:30:22 -04:00
|
|
|
{ wxT("file:myzipfile.zip#zip:index.htm"),
|
|
|
|
wxT("zip"), wxT("file:myzipfile.zip"), wxT("index.htm"), wxT("")},
|
2004-03-28 15:44:26 -05:00
|
|
|
// changes to ':' parsing often break things:
|
2009-07-23 16:30:22 -04:00
|
|
|
{ wxT("file:a#b:foo"),
|
|
|
|
wxT("b"), wxT("file:a"), wxT("foo"), wxT("")}
|
2004-03-28 15:44:26 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
UrlTester tst;
|
|
|
|
for ( size_t n = 0; n < WXSIZEOF(data); n++ )
|
|
|
|
{
|
|
|
|
const Data& d = data[n];
|
|
|
|
CPPUNIT_ASSERT( tst.Protocol(d.url) == d.protocol );
|
|
|
|
CPPUNIT_ASSERT( tst.LeftLocation(d.url) == d.left );
|
|
|
|
CPPUNIT_ASSERT( tst.RightLocation(d.url) == d.right );
|
|
|
|
CPPUNIT_ASSERT( tst.Anchor(d.url) == d.anchor );
|
|
|
|
}
|
|
|
|
}
|
2010-03-28 11:41:29 -04:00
|
|
|
|
2004-06-23 18:18:45 -04:00
|
|
|
void FileSystemTestCase::FileNameToUrlConversion()
|
|
|
|
{
|
|
|
|
#ifdef __WINDOWS__
|
2009-07-23 16:30:22 -04:00
|
|
|
wxFileName fn1(wxT("\\\\server\\share\\path\\to\\file"));
|
2004-06-23 18:18:45 -04:00
|
|
|
wxString url1 = wxFileSystem::FileNameToURL(fn1);
|
2010-03-28 11:41:29 -04:00
|
|
|
|
2004-06-23 18:18:45 -04:00
|
|
|
CPPUNIT_ASSERT( fn1.SameAs(wxFileSystem::URLToFileName(url1)) );
|
|
|
|
#endif
|
|
|
|
}
|
2004-03-28 15:44:26 -05:00
|
|
|
|
2010-03-28 11:41:29 -04:00
|
|
|
void FileSystemTestCase::UnicodeFileNameToUrlConversion()
|
|
|
|
{
|
2010-03-28 13:52:19 -04:00
|
|
|
const unsigned char filename_utf8[] = {
|
2010-03-28 11:41:29 -04:00
|
|
|
0x4b, 0x72, 0xc3, 0xa1, 0x73, 0x79, 0x50, 0xc5,
|
|
|
|
0x99, 0xc3, 0xad, 0x72, 0x6f, 0x64, 0x79, 0x2e,
|
|
|
|
0x6a, 0x70, 0x67, 0x00
|
|
|
|
// KrásyPřírody.jpg
|
|
|
|
};
|
2010-03-28 13:52:19 -04:00
|
|
|
wxFileName filename(wxString::FromUTF8((const char*)filename_utf8));
|
2010-03-28 11:41:29 -04:00
|
|
|
|
|
|
|
wxString url = wxFileSystem::FileNameToURL(filename);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( filename.SameAs(wxFileSystem::URLToFileName(url)) );
|
|
|
|
}
|
|
|
|
|
2004-03-28 15:44:26 -05:00
|
|
|
#endif // wxUSE_FILESYSTEM
|