Don't run FTP unit test by default any longer
ftp.wxwidgets.org seems to have gone, breaking the existing test (thanks chris for all the fish...), so don't hardcode this URL in the test and, without it, don't run the test by default any more and require specifying a working FTP host (as well as an existing directory and a file on it) when running it manually. Rewrite the test using normal functions instead of Java-like structure imposed by CppUnit to make it simple to skip it.
This commit is contained in:
@@ -22,114 +22,73 @@
|
|||||||
|
|
||||||
#include <wx/protocol/ftp.h>
|
#include <wx/protocol/ftp.h>
|
||||||
|
|
||||||
#define FTP_ANONYMOUS
|
// For this to run, the following environment variables need to be defined:
|
||||||
|
//
|
||||||
#ifdef FTP_ANONYMOUS
|
// - WX_FTP_TEST_HOST: the host to use for testing (e.g. ftp.example.com)
|
||||||
static const char *hostname = "ftp.wxwidgets.org";
|
// - WX_FTP_TEST_DIR: the directory in which to perform most of the tests
|
||||||
static const char *directory = "/pub/2.8.11";
|
// - WX_FTP_TEST_FILE: name of an existing file in this directory
|
||||||
static const char *invalid_filename = "a_file_which_does_not_exist";
|
//
|
||||||
static const char *valid_filename = "MD5SUM";
|
// Optionally, WX_FTP_TEST_USER and WX_FTP_TEST_PASS may also be defined,
|
||||||
// NOTE: choose a small file or otherwise the FTPTestCase::Download()
|
// otherwise anonymous FTP is used.
|
||||||
// function will take (a lot of) time to complete!
|
TEST_CASE("FTP", "[net][.]")
|
||||||
#else
|
|
||||||
static const char *hostname = "localhost";
|
|
||||||
static const char *user = "guest";
|
|
||||||
static const char *password = "";
|
|
||||||
static const char *directory = "/etc";
|
|
||||||
static const char *invalid_filename = "issue";
|
|
||||||
static const char *valid_filename = "hosts";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// test class
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class FTPTestCase : public CppUnit::TestCase
|
|
||||||
{
|
{
|
||||||
public:
|
wxString hostname,
|
||||||
FTPTestCase() {}
|
directory,
|
||||||
|
valid_filename;
|
||||||
|
if ( !wxGetEnv("WX_FTP_TEST_HOST", &hostname) ||
|
||||||
|
!wxGetEnv("WX_FTP_TEST_DIR", &directory) ||
|
||||||
|
!wxGetEnv("WX_FTP_TEST_FILE", &valid_filename) )
|
||||||
|
{
|
||||||
|
WARN("Skipping FTPTestCase because required WX_FTP_TEST_XXX "
|
||||||
|
"environment variables are not defined.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void setUp();
|
const wxString user = wxGetenv("WX_FTP_TEST_USER");
|
||||||
virtual void tearDown();
|
const wxString password = wxGetenv("WX_FTP_TEST_PASS");
|
||||||
|
|
||||||
private:
|
class SocketInit
|
||||||
CPPUNIT_TEST_SUITE( FTPTestCase );
|
{
|
||||||
CPPUNIT_TEST( List );
|
public:
|
||||||
CPPUNIT_TEST( Download );
|
SocketInit() { wxSocketBase::Initialize(); }
|
||||||
CPPUNIT_TEST( FileSize );
|
~SocketInit() { wxSocketBase::Shutdown(); }
|
||||||
CPPUNIT_TEST( Pwd );
|
} socketInit;
|
||||||
CPPUNIT_TEST( Misc );
|
|
||||||
#ifndef FTP_ANONYMOUS
|
|
||||||
CPPUNIT_TEST( Upload );
|
|
||||||
#endif
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
|
|
||||||
void List();
|
|
||||||
void Download();
|
|
||||||
void FileSize();
|
|
||||||
void Pwd();
|
|
||||||
void Misc();
|
|
||||||
void Upload();
|
|
||||||
|
|
||||||
wxFTP *m_ftp;
|
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(FTPTestCase);
|
|
||||||
};
|
|
||||||
|
|
||||||
// NOTE: we do not run FTPTestCase suite by default because buildslaves typically
|
|
||||||
// do not have FTP connectivity enabled by default...
|
|
||||||
//CPPUNIT_TEST_SUITE_REGISTRATION( FTPTestCase );
|
|
||||||
|
|
||||||
// also include in its own registry so that these tests can be run alone
|
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FTPTestCase, "FTPTestCase" );
|
|
||||||
|
|
||||||
|
|
||||||
void FTPTestCase::setUp()
|
|
||||||
{
|
|
||||||
wxSocketBase::Initialize();
|
|
||||||
|
|
||||||
// wxFTP cannot be a static variable as its ctor needs to access
|
// wxFTP cannot be a static variable as its ctor needs to access
|
||||||
// wxWidgets internals after it has been initialized
|
// wxWidgets internals after it has been initialized
|
||||||
m_ftp = new wxFTP;
|
wxFTP ftp;
|
||||||
|
|
||||||
#ifndef FTP_ANONYMOUS
|
if ( !user.empty() )
|
||||||
m_ftp->SetUser(user);
|
{
|
||||||
m_ftp->SetPassword(password);
|
ftp.SetUser(user);
|
||||||
#endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
|
ftp.SetPassword(password);
|
||||||
|
}
|
||||||
|
|
||||||
CPPUNIT_ASSERT( m_ftp->Connect(hostname) );
|
REQUIRE( ftp.Connect(hostname) );
|
||||||
}
|
|
||||||
|
|
||||||
void FTPTestCase::tearDown()
|
SECTION("List")
|
||||||
{
|
{
|
||||||
delete m_ftp;
|
|
||||||
|
|
||||||
wxSocketBase::Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FTPTestCase::List()
|
|
||||||
{
|
|
||||||
// test CWD
|
// test CWD
|
||||||
CPPUNIT_ASSERT( m_ftp->ChDir(directory) );
|
CPPUNIT_ASSERT( ftp.ChDir(directory) );
|
||||||
|
|
||||||
// test NLIST and LIST
|
// test NLIST and LIST
|
||||||
wxArrayString files;
|
wxArrayString files;
|
||||||
CPPUNIT_ASSERT( m_ftp->GetFilesList(files) );
|
CPPUNIT_ASSERT( ftp.GetFilesList(files) );
|
||||||
CPPUNIT_ASSERT( m_ftp->GetDirList(files) );
|
CPPUNIT_ASSERT( ftp.GetDirList(files) );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( m_ftp->ChDir(wxT("..")) );
|
CPPUNIT_ASSERT( ftp.ChDir(wxT("..")) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FTPTestCase::Download()
|
SECTION("Download")
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT( m_ftp->ChDir(directory) );
|
CPPUNIT_ASSERT( ftp.ChDir(directory) );
|
||||||
|
|
||||||
// test RETR
|
// test RETR
|
||||||
wxInputStream *in1 = m_ftp->GetInputStream(invalid_filename);
|
wxInputStream *in1 = ftp.GetInputStream("bloordyblop");
|
||||||
CPPUNIT_ASSERT( in1 == NULL );
|
CPPUNIT_ASSERT( in1 == NULL );
|
||||||
delete in1;
|
delete in1;
|
||||||
|
|
||||||
wxInputStream *in2 = m_ftp->GetInputStream(valid_filename);
|
wxInputStream *in2 = ftp.GetInputStream(valid_filename);
|
||||||
CPPUNIT_ASSERT( in2 != NULL );
|
CPPUNIT_ASSERT( in2 != NULL );
|
||||||
|
|
||||||
size_t size = in2->GetSize();
|
size_t size = in2->GetSize();
|
||||||
@@ -138,46 +97,49 @@ void FTPTestCase::Download()
|
|||||||
|
|
||||||
delete [] data;
|
delete [] data;
|
||||||
delete in2;
|
delete in2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FTPTestCase::FileSize()
|
SECTION("FileSize")
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT( m_ftp->ChDir(directory) );
|
CPPUNIT_ASSERT( ftp.ChDir(directory) );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( m_ftp->FileExists(valid_filename) );
|
CPPUNIT_ASSERT( ftp.FileExists(valid_filename) );
|
||||||
|
|
||||||
int size = m_ftp->GetFileSize(valid_filename);
|
int size = ftp.GetFileSize(valid_filename);
|
||||||
CPPUNIT_ASSERT( size != -1 );
|
CPPUNIT_ASSERT( size != -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FTPTestCase::Pwd()
|
SECTION("Pwd")
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT_EQUAL( "/", m_ftp->Pwd() );
|
CPPUNIT_ASSERT_EQUAL( "/", ftp.Pwd() );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( m_ftp->ChDir(directory) );
|
CPPUNIT_ASSERT( ftp.ChDir(directory) );
|
||||||
CPPUNIT_ASSERT_EQUAL( directory, m_ftp->Pwd() );
|
CPPUNIT_ASSERT_EQUAL( directory, ftp.Pwd() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FTPTestCase::Misc()
|
SECTION("Misc")
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT( m_ftp->SendCommand(wxT("STAT")) == '2' );
|
CPPUNIT_ASSERT( ftp.SendCommand(wxT("STAT")) == '2' );
|
||||||
CPPUNIT_ASSERT( m_ftp->SendCommand(wxT("HELP SITE")) == '2' );
|
CPPUNIT_ASSERT( ftp.SendCommand(wxT("HELP SITE")) == '2' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("Upload")
|
||||||
|
{
|
||||||
|
if ( user.empty() )
|
||||||
|
{
|
||||||
|
WARN("Skipping upload test when using anonymous FTP.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef FTP_ANONYMOUS
|
|
||||||
void FTPTestCase::Upload()
|
|
||||||
{
|
|
||||||
// upload a file
|
// upload a file
|
||||||
static const wxChar *file1 = wxT("test1");
|
static const wxChar *file1 = wxT("test1");
|
||||||
wxOutputStream *out = m_ftp->GetOutputStream(file1);
|
wxOutputStream *out = ftp.GetOutputStream(file1);
|
||||||
CPPUNIT_ASSERT( out != NULL );
|
CPPUNIT_ASSERT( out != NULL );
|
||||||
CPPUNIT_ASSERT( out->Write("First hello", 11).GetLastError() == wxSTREAM_NO_ERROR );
|
CPPUNIT_ASSERT( out->Write("First hello", 11).GetLastError() == wxSTREAM_NO_ERROR );
|
||||||
delete out;
|
delete out;
|
||||||
|
|
||||||
// send a command to check the remote file
|
// send a command to check the remote file
|
||||||
CPPUNIT_ASSERT( m_ftp->SendCommand(wxString(wxT("STAT ")) + file1) == '2' );
|
CPPUNIT_ASSERT( ftp.SendCommand(wxString(wxT("STAT ")) + file1) == '2' );
|
||||||
CPPUNIT_ASSERT( m_ftp->GetLastResult() == "11" );
|
CPPUNIT_ASSERT( ftp.GetLastResult() == "11" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user