move all non-interactive FTP tests from the console sample to a new CppUnit FTPTestCase test.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64422 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -117,6 +117,7 @@ TEST_OBJECTS = \
|
||||
test_misc.o \
|
||||
test_queue.o \
|
||||
test_tls.o \
|
||||
test_ftp.o \
|
||||
test_uris.o \
|
||||
test_url.o \
|
||||
test_vectors.o \
|
||||
@@ -546,6 +547,9 @@ test_queue.o: $(srcdir)/thread/queue.cpp $(TEST_ODEP)
|
||||
test_tls.o: $(srcdir)/thread/tls.cpp $(TEST_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/thread/tls.cpp
|
||||
|
||||
test_ftp.o: $(srcdir)/uris/ftp.cpp $(TEST_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/uris/ftp.cpp
|
||||
|
||||
test_uris.o: $(srcdir)/uris/uris.cpp $(TEST_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/uris/uris.cpp
|
||||
|
||||
|
@@ -101,6 +101,7 @@ TEST_OBJECTS = \
|
||||
$(OBJS)\test_misc.obj \
|
||||
$(OBJS)\test_queue.obj \
|
||||
$(OBJS)\test_tls.obj \
|
||||
$(OBJS)\test_ftp.obj \
|
||||
$(OBJS)\test_uris.obj \
|
||||
$(OBJS)\test_url.obj \
|
||||
$(OBJS)\test_vectors.obj \
|
||||
@@ -588,6 +589,9 @@ $(OBJS)\test_queue.obj: .\thread\queue.cpp
|
||||
$(OBJS)\test_tls.obj: .\thread\tls.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\thread\tls.cpp
|
||||
|
||||
$(OBJS)\test_ftp.obj: .\uris\ftp.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\uris\ftp.cpp
|
||||
|
||||
$(OBJS)\test_uris.obj: .\uris\uris.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\uris\uris.cpp
|
||||
|
||||
|
@@ -93,6 +93,7 @@ TEST_OBJECTS = \
|
||||
$(OBJS)\test_misc.o \
|
||||
$(OBJS)\test_queue.o \
|
||||
$(OBJS)\test_tls.o \
|
||||
$(OBJS)\test_ftp.o \
|
||||
$(OBJS)\test_uris.o \
|
||||
$(OBJS)\test_url.o \
|
||||
$(OBJS)\test_vectors.o \
|
||||
@@ -569,6 +570,9 @@ $(OBJS)\test_queue.o: ./thread/queue.cpp
|
||||
$(OBJS)\test_tls.o: ./thread/tls.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_ftp.o: ./uris/ftp.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_uris.o: ./uris/uris.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
|
@@ -95,6 +95,7 @@ TEST_OBJECTS = \
|
||||
$(OBJS)\test_misc.obj \
|
||||
$(OBJS)\test_queue.obj \
|
||||
$(OBJS)\test_tls.obj \
|
||||
$(OBJS)\test_ftp.obj \
|
||||
$(OBJS)\test_uris.obj \
|
||||
$(OBJS)\test_url.obj \
|
||||
$(OBJS)\test_vectors.obj \
|
||||
@@ -714,6 +715,9 @@ $(OBJS)\test_queue.obj: .\thread\queue.cpp
|
||||
$(OBJS)\test_tls.obj: .\thread\tls.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\thread\tls.cpp
|
||||
|
||||
$(OBJS)\test_ftp.obj: .\uris\ftp.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\uris\ftp.cpp
|
||||
|
||||
$(OBJS)\test_uris.obj: .\uris\uris.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\uris\uris.cpp
|
||||
|
||||
|
@@ -331,6 +331,7 @@ TEST_OBJECTS = &
|
||||
$(OBJS)\test_misc.obj &
|
||||
$(OBJS)\test_queue.obj &
|
||||
$(OBJS)\test_tls.obj &
|
||||
$(OBJS)\test_ftp.obj &
|
||||
$(OBJS)\test_uris.obj &
|
||||
$(OBJS)\test_url.obj &
|
||||
$(OBJS)\test_vectors.obj &
|
||||
@@ -626,6 +627,9 @@ $(OBJS)\test_queue.obj : .AUTODEPEND .\thread\queue.cpp
|
||||
$(OBJS)\test_tls.obj : .AUTODEPEND .\thread\tls.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_ftp.obj : .AUTODEPEND .\uris\ftp.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_uris.obj : .AUTODEPEND .\uris\uris.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
|
@@ -92,6 +92,7 @@
|
||||
thread/misc.cpp
|
||||
thread/queue.cpp
|
||||
thread/tls.cpp
|
||||
uris/ftp.cpp
|
||||
uris/uris.cpp
|
||||
uris/url.cpp
|
||||
vectors/vectors.cpp
|
||||
|
@@ -345,6 +345,10 @@ SOURCE=.\fswatcher\fswatchertest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\uris\ftp.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\hashes\hashes.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@@ -694,6 +694,9 @@
|
||||
<File
|
||||
RelativePath=".\fswatcher\fswatchertest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\uris\ftp.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\hashes\hashes.cpp">
|
||||
</File>
|
||||
|
@@ -999,6 +999,10 @@
|
||||
RelativePath=".\fswatcher\fswatchertest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\uris\ftp.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\hashes\hashes.cpp"
|
||||
>
|
||||
|
@@ -1,16 +1,10 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<!--
|
||||
|
||||
This project was generated by
|
||||
Bakefile 0.2.8 (http://www.bakefile.org)
|
||||
Do not modify, all changes will be overwritten!
|
||||
|
||||
-->
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Version="9,00"
|
||||
Name="test"
|
||||
ProjectGUID="{2F45723C-ED6B-5F60-8BFF-6B3609464A7B}"
|
||||
TargetFrameworkVersion="0"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
@@ -18,7 +12,6 @@
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
@@ -51,7 +44,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/MP"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;."
|
||||
AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;F:\cppunit\include;."
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;__WXMSW__;_UNICODE;_CONSOLE;wxUSE_GUI=0"
|
||||
ExceptionHandling="1"
|
||||
BasicRuntimeChecks="3"
|
||||
@@ -86,7 +79,7 @@
|
||||
OutputFile="vc_mswud\test.exe"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories=".\..\lib\vc_lib"
|
||||
AdditionalLibraryDirectories=".\..\lib\vc_lib;F:\cppunit\lib"
|
||||
GenerateManifest="true"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="vc_mswud\test.pdb"
|
||||
@@ -104,8 +97,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
OutputFile="vc_mswud\test_vc9_test.bsc"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="vc_mswud\test_vc9_test.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
@@ -185,9 +178,9 @@
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="vc_mswu\test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
@@ -200,8 +193,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
OutputFile="vc_mswu\test_vc9_test.bsc"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="vc_mswu\test_vc9_test.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
@@ -296,8 +289,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
OutputFile="vc_mswunivud\test_vc9_test.bsc"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="vc_mswunivud\test_vc9_test.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
@@ -377,9 +370,9 @@
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="vc_mswunivu\test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
@@ -392,8 +385,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
OutputFile="vc_mswunivu\test_vc9_test.bsc"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="vc_mswunivu\test_vc9_test.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
@@ -488,8 +481,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
OutputFile="vc_mswuddll\test_vc9_test.bsc"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="vc_mswuddll\test_vc9_test.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
@@ -569,9 +562,9 @@
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="vc_mswudll\test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
@@ -584,8 +577,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
OutputFile="vc_mswudll\test_vc9_test.bsc"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="vc_mswudll\test_vc9_test.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
@@ -680,8 +673,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
OutputFile="vc_mswunivuddll\test_vc9_test.bsc"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="vc_mswunivuddll\test_vc9_test.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
@@ -761,9 +754,9 @@
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="vc_mswunivudll\test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
@@ -776,8 +769,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
OutputFile="vc_mswunivudll\test_vc9_test.bsc"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile="vc_mswunivudll\test_vc9_test.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
@@ -791,7 +784,6 @@
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
@@ -971,6 +963,10 @@
|
||||
RelativePath=".\fswatcher\fswatchertest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\uris\ftp.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\hashes\hashes.cpp"
|
||||
>
|
||||
@@ -1154,7 +1150,5 @@
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
||||
|
180
tests/uris/ftp.cpp
Normal file
180
tests/uris/ftp.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/uris/ftp.cpp
|
||||
// Purpose: wxFTP unit test
|
||||
// Author: Francesco Montorsi (extracted from console sample)
|
||||
// Created: 2010-05-23
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2010 wxWidgets team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include <wx/protocol/ftp.h>
|
||||
|
||||
#define FTP_ANONYMOUS
|
||||
|
||||
#ifdef FTP_ANONYMOUS
|
||||
static const char *hostname = "ftp.wxwidgets.org";
|
||||
static const char *directory = "/pub/2.8.11";
|
||||
static const char *invalid_filename = "a_file_which_does_not_exist";
|
||||
static const char *valid_filename = "MD5SUM";
|
||||
// NOTE: choose a small file or otherwise the FTPTestCase::Download()
|
||||
// function will take (a lot of) time to complete!
|
||||
#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:
|
||||
FTPTestCase() {}
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( FTPTestCase );
|
||||
CPPUNIT_TEST( List );
|
||||
CPPUNIT_TEST( Download );
|
||||
CPPUNIT_TEST( FileSize );
|
||||
CPPUNIT_TEST( Misc );
|
||||
#ifndef FTP_ANONYMOUS
|
||||
CPPUNIT_TEST( Upload );
|
||||
#endif
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void List();
|
||||
void Download();
|
||||
void FileSize();
|
||||
void Misc();
|
||||
void Upload();
|
||||
|
||||
wxFTP *m_ftp;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(FTPTestCase)
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( FTPTestCase );
|
||||
|
||||
// also include in it's 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
|
||||
// wxWidgets internals after it has been initialized
|
||||
m_ftp = new wxFTP;
|
||||
|
||||
#ifndef FTP_ANONYMOUS
|
||||
m_ftp->SetUser(user);
|
||||
m_ftp->SetPassword(password);
|
||||
#endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
|
||||
}
|
||||
|
||||
void FTPTestCase::tearDown()
|
||||
{
|
||||
delete m_ftp;
|
||||
|
||||
wxSocketBase::Shutdown();
|
||||
}
|
||||
|
||||
void FTPTestCase::List()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_ftp->Connect(hostname) );
|
||||
|
||||
// test CWD
|
||||
CPPUNIT_ASSERT( m_ftp->ChDir(directory) );
|
||||
|
||||
// test NLIST and LIST
|
||||
wxArrayString files;
|
||||
CPPUNIT_ASSERT( m_ftp->GetFilesList(files) );
|
||||
CPPUNIT_ASSERT( m_ftp->GetDirList(files) );
|
||||
|
||||
CPPUNIT_ASSERT( m_ftp->ChDir(wxT("..")) );
|
||||
}
|
||||
|
||||
void FTPTestCase::Download()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_ftp->Connect(hostname) );
|
||||
CPPUNIT_ASSERT( m_ftp->ChDir(directory) );
|
||||
|
||||
// test RETR
|
||||
wxInputStream *in1 = m_ftp->GetInputStream(invalid_filename);
|
||||
CPPUNIT_ASSERT( in1 == NULL );
|
||||
delete in1;
|
||||
|
||||
wxInputStream *in2 = m_ftp->GetInputStream(valid_filename);
|
||||
CPPUNIT_ASSERT( in2 != NULL );
|
||||
|
||||
size_t size = in2->GetSize();
|
||||
wxChar *data = new wxChar[size];
|
||||
CPPUNIT_ASSERT( in2->Read(data, size).GetLastError() == wxSTREAM_NO_ERROR );
|
||||
|
||||
delete [] data;
|
||||
delete in2;
|
||||
}
|
||||
|
||||
void FTPTestCase::FileSize()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_ftp->Connect(hostname) );
|
||||
|
||||
CPPUNIT_ASSERT( m_ftp->ChDir(directory) );
|
||||
|
||||
CPPUNIT_ASSERT( m_ftp->FileExists(valid_filename) );
|
||||
|
||||
int size = m_ftp->GetFileSize(valid_filename);
|
||||
CPPUNIT_ASSERT( size != -1 );
|
||||
}
|
||||
|
||||
void FTPTestCase::Misc()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_ftp->Connect(hostname) );
|
||||
|
||||
CPPUNIT_ASSERT( m_ftp->SendCommand(wxT("STAT")) == '2' );
|
||||
CPPUNIT_ASSERT( m_ftp->SendCommand(wxT("HELP SITE")) == '2' );
|
||||
}
|
||||
|
||||
#ifndef FTP_ANONYMOUS
|
||||
void FTPTestCase::Upload()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_ftp->Connect(hostname) );
|
||||
|
||||
// upload a file
|
||||
static const wxChar *file1 = wxT("test1");
|
||||
wxOutputStream *out = m_ftp->GetOutputStream(file1);
|
||||
CPPUNIT_ASSERT( out != NULL );
|
||||
CPPUNIT_ASSERT( out->Write("First hello", 11).GetLastError() == wxSTREAM_NO_ERROR );
|
||||
delete out;
|
||||
|
||||
// send a command to check the remote file
|
||||
CPPUNIT_ASSERT( m_ftp->SendCommand(wxString(wxT("STAT ")) + file1) == '2' );
|
||||
CPPUNIT_ASSERT( m_ftp->GetLastResult() == "11" );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user