]> git.saurik.com Git - wxWidgets.git/commitdiff
move all non-interactive FTP tests from the console sample to a new CppUnit FTPTestCa...
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sat, 29 May 2010 07:56:08 +0000 (07:56 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sat, 29 May 2010 07:56:08 +0000 (07:56 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64422 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
samples/console/console.cpp
tests/Makefile.in
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/test.bkl
tests/test_test.dsp
tests/test_vc7_test.vcproj
tests/test_vc8_test.vcproj
tests/test_vc9_test.vcproj
tests/uris/ftp.cpp [new file with mode: 0644]

index 26f7ce0f195f8d1aed80e3a340324039c603fdf8..71acd820f8193f6815240439475b199df6c9a88d 100644 (file)
     #define TEST_FILECONF
     #define TEST_FILENAME
     #define TEST_FILETIME
-    #define TEST_FTP
     #define TEST_INFO_FUNCTIONS
     #define TEST_LOCALE
     #define TEST_LOG
     #define TEST_SCOPEGUARD
     #define TEST_SNGLINST
 //    #define TEST_SOCKETS  --FIXME! (RN)
-    #define TEST_STACKWALKER
-    #define TEST_STDPATHS
 #else // #if TEST_ALL
     #define TEST_DATETIME
     #define TEST_VOLUME
+    #define TEST_STDPATHS
+    #define TEST_STACKWALKER
+    #define TEST_FTP
 #endif
 
 // some tests are interactive, define this to run them
@@ -2367,9 +2367,11 @@ static void TestSocketClient()
 static wxFTP *ftp;
 
 #ifdef FTP_ANONYMOUS
+    static const wxChar *hostname = wxT("ftp.wxwidgets.org");
     static const wxChar *directory = wxT("/pub");
     static const wxChar *filename = wxT("welcome.msg");
 #else
+    static const wxChar *hostname = "localhost";
     static const wxChar *directory = wxT("/etc");
     static const wxChar *filename = wxT("issue");
 #endif
@@ -2379,12 +2381,8 @@ static bool TestFtpConnect()
     wxPuts(wxT("*** Testing FTP connect ***"));
 
 #ifdef FTP_ANONYMOUS
-    static const wxChar *hostname = wxT("ftp.wxwidgets.org");
-
     wxPrintf(wxT("--- Attempting to connect to %s:21 anonymously...\n"), hostname);
 #else // !FTP_ANONYMOUS
-    static const wxChar *hostname = "localhost";
-
     wxChar user[256];
     wxFgets(user, WXSIZEOF(user), stdin);
     user[wxStrlen(user) - 1] = '\0'; // chop off '\n'
@@ -2415,140 +2413,6 @@ static bool TestFtpConnect()
     return true;
 }
 
-static void TestFtpList()
-{
-    wxPuts(wxT("*** Testing wxFTP file listing ***\n"));
-
-    // test CWD
-    if ( !ftp->ChDir(directory) )
-    {
-        wxPrintf(wxT("ERROR: failed to cd to %s\n"), directory);
-    }
-
-    wxPrintf(wxT("Current directory is '%s'\n"), ftp->Pwd().c_str());
-
-    // test NLIST and LIST
-    wxArrayString files;
-    if ( !ftp->GetFilesList(files) )
-    {
-        wxPuts(wxT("ERROR: failed to get NLIST of files"));
-    }
-    else
-    {
-        wxPrintf(wxT("Brief list of files under '%s':\n"), ftp->Pwd().c_str());
-        size_t count = files.GetCount();
-        for ( size_t n = 0; n < count; n++ )
-        {
-            wxPrintf(wxT("\t%s\n"), files[n].c_str());
-        }
-        wxPuts(wxT("End of the file list"));
-    }
-
-    if ( !ftp->GetDirList(files) )
-    {
-        wxPuts(wxT("ERROR: failed to get LIST of files"));
-    }
-    else
-    {
-        wxPrintf(wxT("Detailed list of files under '%s':\n"), ftp->Pwd().c_str());
-        size_t count = files.GetCount();
-        for ( size_t n = 0; n < count; n++ )
-        {
-            wxPrintf(wxT("\t%s\n"), files[n].c_str());
-        }
-        wxPuts(wxT("End of the file list"));
-    }
-
-    if ( !ftp->ChDir(wxT("..")) )
-    {
-        wxPuts(wxT("ERROR: failed to cd to .."));
-    }
-
-    wxPrintf(wxT("Current directory is '%s'\n"), ftp->Pwd().c_str());
-}
-
-static void TestFtpDownload()
-{
-    wxPuts(wxT("*** Testing wxFTP download ***\n"));
-
-    // test RETR
-    wxInputStream *in = ftp->GetInputStream(filename);
-    if ( !in )
-    {
-        wxPrintf(wxT("ERROR: couldn't get input stream for %s\n"), filename);
-    }
-    else
-    {
-        size_t size = in->GetSize();
-        wxPrintf(wxT("Reading file %s (%u bytes)..."), filename, size);
-        fflush(stdout);
-
-        wxChar *data = new wxChar[size];
-        if ( !in->Read(data, size) )
-        {
-            wxPuts(wxT("ERROR: read error"));
-        }
-        else
-        {
-            wxPrintf(wxT("\nContents of %s:\n%s\n"), filename, data);
-        }
-
-        delete [] data;
-        delete in;
-    }
-}
-
-static void TestFtpFileSize()
-{
-    wxPuts(wxT("*** Testing FTP SIZE command ***"));
-
-    if ( !ftp->ChDir(directory) )
-    {
-        wxPrintf(wxT("ERROR: failed to cd to %s\n"), directory);
-    }
-
-    wxPrintf(wxT("Current directory is '%s'\n"), ftp->Pwd().c_str());
-
-    if ( ftp->FileExists(filename) )
-    {
-        int size = ftp->GetFileSize(filename);
-        if ( size == -1 )
-            wxPrintf(wxT("ERROR: couldn't get size of '%s'\n"), filename);
-        else
-            wxPrintf(wxT("Size of '%s' is %d bytes.\n"), filename, size);
-    }
-    else
-    {
-        wxPrintf(wxT("ERROR: '%s' doesn't exist\n"), filename);
-    }
-}
-
-static void TestFtpMisc()
-{
-    wxPuts(wxT("*** Testing miscellaneous wxFTP functions ***"));
-
-    if ( ftp->SendCommand(wxT("STAT")) != '2' )
-    {
-        wxPuts(wxT("ERROR: STAT failed"));
-    }
-    else
-    {
-        wxPrintf(wxT("STAT returned:\n\n%s\n"), ftp->GetLastResult().c_str());
-    }
-
-    if ( ftp->SendCommand(wxT("HELP SITE")) != '2' )
-    {
-        wxPuts(wxT("ERROR: HELP SITE failed"));
-    }
-    else
-    {
-        wxPrintf(wxT("The list of site-specific commands:\n\n%s\n"),
-               ftp->GetLastResult().c_str());
-    }
-}
-
-#if TEST_INTERACTIVE
-
 static void TestFtpInteractive()
 {
     wxPuts(wxT("\n*** Interactive wxFTP test ***"));
@@ -2557,7 +2421,7 @@ static void TestFtpInteractive()
 
     for ( ;; )
     {
-        wxPrintf(wxT("Enter FTP command: "));
+        wxPrintf(wxT("Enter FTP command (or 'quit' to escape): "));
         if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
             break;
 
@@ -2590,6 +2454,10 @@ static void TestFtpInteractive()
                 wxPuts(wxT("--- End of the file list"));
             }
         }
+        else if ( start == wxT("QUIT") )
+        {
+            break;      // get out of here!
+        }
         else // !list
         {
             wxChar ch = ftp->SendCommand(buf);
@@ -2606,43 +2474,6 @@ static void TestFtpInteractive()
     wxPuts(wxT("\n*** done ***"));
 }
 
-#endif // TEST_INTERACTIVE
-
-static void TestFtpUpload()
-{
-    wxPuts(wxT("*** Testing wxFTP uploading ***\n"));
-
-    // upload a file
-    static const wxChar *file1 = wxT("test1");
-    static const wxChar *file2 = wxT("test2");
-    wxOutputStream *out = ftp->GetOutputStream(file1);
-    if ( out )
-    {
-        wxPrintf(wxT("--- Uploading to %s ---\n"), file1);
-        out->Write("First hello", 11);
-        delete out;
-    }
-
-    // send a command to check the remote file
-    if ( ftp->SendCommand(wxString(wxT("STAT ")) + file1) != '2' )
-    {
-        wxPrintf(wxT("ERROR: STAT %s failed\n"), file1);
-    }
-    else
-    {
-        wxPrintf(wxT("STAT %s returned:\n\n%s\n"),
-               file1, ftp->GetLastResult().c_str());
-    }
-
-    out = ftp->GetOutputStream(file2);
-    if ( out )
-    {
-        wxPrintf(wxT("--- Uploading to %s ---\n"), file1);
-        out->Write("Second hello", 12);
-        delete out;
-    }
-}
-
 #endif // TEST_FTP
 
 // ----------------------------------------------------------------------------
@@ -2710,6 +2541,8 @@ static void TestStackWalk(const char *argv0)
 
     StackDump dump(argv0);
     dump.Walk();
+    
+    wxPuts("\n");
 }
 
 #endif // wxUSE_STACKWALKER
@@ -2750,6 +2583,8 @@ static void TestStandardPaths()
                     wxT("fr"),
                     wxStandardPaths::ResourceCat_Messages
                   ).c_str());
+                  
+    wxPuts("\n");
 }
 
 #endif // TEST_STDPATHS
@@ -2809,6 +2644,8 @@ static void TestFSVolume()
                  vol.GetFlags() & wxFS_VOL_REMOVABLE ? wxT("removable")
                                                      : wxT("fixed"));
     }
+    
+    wxPuts("\n");
 }
 
 #endif // TEST_VOLUME
@@ -2832,12 +2669,15 @@ static void TestDateTimeInteractive()
 
     for ( ;; )
     {
-        wxPrintf(wxT("Enter a date: "));
+        wxPrintf(wxT("Enter a date (or 'quit' to escape): "));
         if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
             break;
 
         // kill the last '\n'
         buf[wxStrlen(buf) - 1] = 0;
+        
+        if ( wxString(buf).CmpNoCase("quit") == 0 )
+            break;
 
         wxDateTime dt;
         const wxChar *p = dt.ParseDate(buf);
@@ -2859,8 +2699,8 @@ static void TestDateTimeInteractive()
                  dt.GetWeekOfMonth(wxDateTime::Sunday_First),
                  dt.GetWeekOfYear(wxDateTime::Monday_First));
     }
-
-    wxPuts(wxT("\n*** done ***"));
+    
+    wxPuts("\n");
 }
 
 #endif // TEST_INTERACTIVE
@@ -3056,17 +2896,7 @@ int main(int argc, char **argv)
 
     if ( TestFtpConnect() )
     {
-        #if TEST_ALL
-            TestFtpList();
-            TestFtpDownload();
-            TestFtpMisc();
-            TestFtpFileSize();
-            TestFtpUpload();
-        #endif // TEST_ALL
-
-        #if TEST_INTERACTIVE
-            //TestFtpInteractive();
-        #endif
+        TestFtpInteractive();
     }
     //else: connecting to the FTP server failed
 
index e5fd2ee4e682cdbddd23316c58c908a4ab3b25b3..3fc0cd9d42c1cbd3cd05223d0f7697e02b00fb56 100644 (file)
@@ -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
 
index a079fb90597dea031dca8a202c209a9ab7f84879..fe9307786545d63dea5a8025f26b2a2dabf51260 100644 (file)
@@ -101,6 +101,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_misc.obj \\r
        $(OBJS)\test_queue.obj \\r
        $(OBJS)\test_tls.obj \\r
+       $(OBJS)\test_ftp.obj \\r
        $(OBJS)\test_uris.obj \\r
        $(OBJS)\test_url.obj \\r
        $(OBJS)\test_vectors.obj \\r
@@ -588,6 +589,9 @@ $(OBJS)\test_queue.obj: .\thread\queue.cpp
 $(OBJS)\test_tls.obj: .\thread\tls.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\thread\tls.cpp\r
 \r
+$(OBJS)\test_ftp.obj: .\uris\ftp.cpp\r
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\uris\ftp.cpp\r
+\r
 $(OBJS)\test_uris.obj: .\uris\uris.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\uris\uris.cpp\r
 \r
index 42d881e88e69f40f22dda5de216b1edb4f6f6d48..f93cc1b112828b953fbfe1846742ffc57ad23eb7 100644 (file)
@@ -93,6 +93,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_misc.o \\r
        $(OBJS)\test_queue.o \\r
        $(OBJS)\test_tls.o \\r
+       $(OBJS)\test_ftp.o \\r
        $(OBJS)\test_uris.o \\r
        $(OBJS)\test_url.o \\r
        $(OBJS)\test_vectors.o \\r
@@ -569,6 +570,9 @@ $(OBJS)\test_queue.o: ./thread/queue.cpp
 $(OBJS)\test_tls.o: ./thread/tls.cpp\r
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\test_ftp.o: ./uris/ftp.cpp\r
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
+\r
 $(OBJS)\test_uris.o: ./uris/uris.cpp\r
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
 \r
index cc32e910700d9a2036f098e338b5daaf2499c149..0b787b683ab4db8937eafc48898519082091d054 100644 (file)
@@ -95,6 +95,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_misc.obj \\r
        $(OBJS)\test_queue.obj \\r
        $(OBJS)\test_tls.obj \\r
+       $(OBJS)\test_ftp.obj \\r
        $(OBJS)\test_uris.obj \\r
        $(OBJS)\test_url.obj \\r
        $(OBJS)\test_vectors.obj \\r
@@ -714,6 +715,9 @@ $(OBJS)\test_queue.obj: .\thread\queue.cpp
 $(OBJS)\test_tls.obj: .\thread\tls.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\thread\tls.cpp\r
 \r
+$(OBJS)\test_ftp.obj: .\uris\ftp.cpp\r
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\uris\ftp.cpp\r
+\r
 $(OBJS)\test_uris.obj: .\uris\uris.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\uris\uris.cpp\r
 \r
index 67b82aead304dc362aab21ed9d911bd6d8bf64ab..90a8887763c8849976c1490e326506441d436e18 100644 (file)
@@ -331,6 +331,7 @@ TEST_OBJECTS =  &
        $(OBJS)\test_misc.obj &\r
        $(OBJS)\test_queue.obj &\r
        $(OBJS)\test_tls.obj &\r
+       $(OBJS)\test_ftp.obj &\r
        $(OBJS)\test_uris.obj &\r
        $(OBJS)\test_url.obj &\r
        $(OBJS)\test_vectors.obj &\r
@@ -626,6 +627,9 @@ $(OBJS)\test_queue.obj :  .AUTODEPEND .\thread\queue.cpp
 $(OBJS)\test_tls.obj :  .AUTODEPEND .\thread\tls.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
 \r
+$(OBJS)\test_ftp.obj :  .AUTODEPEND .\uris\ftp.cpp\r
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
+\r
 $(OBJS)\test_uris.obj :  .AUTODEPEND .\uris\uris.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
 \r
index 3ce77af3afdfdce63b37131bdedb6493f6054369..34e0e723c1ad5297a9c7b848990ac68b30433743 100644 (file)
@@ -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
index 981800bbbc5185722fcfdf977d4fb99e99f4c326..b79c58606a4e3c1a73ee036df4190883d021cfba 100644 (file)
@@ -345,6 +345,10 @@ SOURCE=.\fswatcher\fswatchertest.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\uris\ftp.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\hashes\hashes.cpp\r
 # End Source File\r
 # Begin Source File\r
index 284639384dbc853cfad8293ee22724aa83c977e7..6237a140f1424b8b09047fe0a9f930e65cd8d825 100644 (file)
                        <File\r
                                RelativePath=".\fswatcher\fswatchertest.cpp">\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\uris\ftp.cpp">\r
+                       </File>\r
                        <File\r
                                RelativePath=".\hashes\hashes.cpp">\r
                        </File>\r
index 8215eacc9ff4a003b57ea0f26d19cd8853c76959..c3b9d9b5e29e9c8bc4d61d939c9deebccdf5df76 100644 (file)
                                RelativePath=".\fswatcher\fswatchertest.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\uris\ftp.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\hashes\hashes.cpp"\r
                                >\r
index 2b48c4b5d23791b4f1688c6bc7a1893b67780aa0..7b1b284d9d53e112312c464c1662f0282d907e2c 100644 (file)
@@ -1,16 +1,10 @@
 <?xml version="1.0" encoding="Windows-1252"?>\r
-<!--\r
-\r
-  This project was generated by\r
-  Bakefile 0.2.8 (http://www.bakefile.org)\r
-  Do not modify, all changes will be overwritten!\r
-\r
--->\r
 <VisualStudioProject\r
        ProjectType="Visual C++"\r
-       Version="9.00"\r
+       Version="9,00"\r
        Name="test"\r
        ProjectGUID="{2F45723C-ED6B-5F60-8BFF-6B3609464A7B}"\r
+       TargetFrameworkVersion="0"\r
        >\r
        <Platforms>\r
                <Platform\r
@@ -18,7 +12,6 @@
                />\r
        </Platforms>\r
        <ToolFiles>\r
-               \r
        </ToolFiles>\r
        <Configurations>\r
                <Configuration\r
@@ -51,7 +44,7 @@
                                Name="VCCLCompilerTool"\r
                                AdditionalOptions="/MP"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;."\r
+                               AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;F:\cppunit\include;."\r
                                PreprocessorDefinitions="WIN32;_DEBUG;__WXMSW__;_UNICODE;_CONSOLE;wxUSE_GUI=0"\r
                                ExceptionHandling="1"\r
                                BasicRuntimeChecks="3"\r
@@ -86,7 +79,7 @@
                                OutputFile="vc_mswud\test.exe"\r
                                LinkIncremental="2"\r
                                SuppressStartupBanner="true"\r
-                               AdditionalLibraryDirectories=".\..\lib\vc_lib"\r
+                               AdditionalLibraryDirectories=".\..\lib\vc_lib;F:\cppunit\lib"\r
                                GenerateManifest="true"\r
                                GenerateDebugInformation="true"\r
                                ProgramDatabaseFile="vc_mswud\test.pdb"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               OutputFile="vc_mswud\test_vc9_test.bsc"\r
                                SuppressStartupBanner="true"\r
+                               OutputFile="vc_mswud\test_vc9_test.bsc"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                                GenerateDebugInformation="true"\r
                                ProgramDatabaseFile="vc_mswu\test.pdb"\r
                                SubSystem="1"\r
-                               TargetMachine="1"\r
                                OptimizeReferences="2"\r
                                EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               OutputFile="vc_mswu\test_vc9_test.bsc"\r
                                SuppressStartupBanner="true"\r
+                               OutputFile="vc_mswu\test_vc9_test.bsc"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               OutputFile="vc_mswunivud\test_vc9_test.bsc"\r
                                SuppressStartupBanner="true"\r
+                               OutputFile="vc_mswunivud\test_vc9_test.bsc"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                                GenerateDebugInformation="true"\r
                                ProgramDatabaseFile="vc_mswunivu\test.pdb"\r
                                SubSystem="1"\r
-                               TargetMachine="1"\r
                                OptimizeReferences="2"\r
                                EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               OutputFile="vc_mswunivu\test_vc9_test.bsc"\r
                                SuppressStartupBanner="true"\r
+                               OutputFile="vc_mswunivu\test_vc9_test.bsc"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               OutputFile="vc_mswuddll\test_vc9_test.bsc"\r
                                SuppressStartupBanner="true"\r
+                               OutputFile="vc_mswuddll\test_vc9_test.bsc"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                                GenerateDebugInformation="true"\r
                                ProgramDatabaseFile="vc_mswudll\test.pdb"\r
                                SubSystem="1"\r
-                               TargetMachine="1"\r
                                OptimizeReferences="2"\r
                                EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               OutputFile="vc_mswudll\test_vc9_test.bsc"\r
                                SuppressStartupBanner="true"\r
+                               OutputFile="vc_mswudll\test_vc9_test.bsc"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               OutputFile="vc_mswunivuddll\test_vc9_test.bsc"\r
                                SuppressStartupBanner="true"\r
+                               OutputFile="vc_mswunivuddll\test_vc9_test.bsc"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                                GenerateDebugInformation="true"\r
                                ProgramDatabaseFile="vc_mswunivudll\test.pdb"\r
                                SubSystem="1"\r
-                               TargetMachine="1"\r
                                OptimizeReferences="2"\r
                                EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               OutputFile="vc_mswunivudll\test_vc9_test.bsc"\r
                                SuppressStartupBanner="true"\r
+                               OutputFile="vc_mswunivudll\test_vc9_test.bsc"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                </Configuration>\r
        </Configurations>\r
        <References>\r
-               \r
        </References>\r
        <Files>\r
                <Filter\r
                                RelativePath=".\fswatcher\fswatchertest.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\uris\ftp.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\hashes\hashes.cpp"\r
                                >\r
                </Filter>\r
        </Files>\r
        <Globals>\r
-               \r
        </Globals>\r
 </VisualStudioProject>\r
-\r
diff --git a/tests/uris/ftp.cpp b/tests/uris/ftp.cpp
new file mode 100644 (file)
index 0000000..671b606
--- /dev/null
@@ -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
+
+