]> git.saurik.com Git - wxWidgets.git/commitdiff
moved non-interactive tests for wxDynamicLibrary, wxGet/SetEnv, wxTempFile, wxCopyFil...
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sun, 13 Jun 2010 14:30:55 +0000 (14:30 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sun, 13 Jun 2010 14:30:55 +0000 (14:30 +0000)
removed wxFile and wxTextFile tests (complete testsuites already exist for them)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64583 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

16 files changed:
interface/wx/filefn.h
samples/console/console.cpp
tests/Makefile.in
tests/file/filefn.cpp [new file with mode: 0644]
tests/file/filetest.cpp
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/misc/dynamiclib.cpp [new file with mode: 0644]
tests/misc/environ.cpp [new file with mode: 0644]
tests/test.bkl
tests/test_test.dsp
tests/test_vc7_test.vcproj
tests/test_vc8_test.vcproj
tests/test_vc9_test.vcproj

index 9659221bdb21c49402590291d069811238d2c5fe..3d07e3491bc9a43ba843676ff1a80f3543724ea1 100644 (file)
@@ -24,6 +24,9 @@
 class wxPathList : public wxArrayString
 {
 public:
+    /**
+        Standard constructor.
+    */
     wxPathList();
 
     /**
index c696083ca8b6ab566a1dcd4c97cac4f3f7f52692..bc31024863eadbd988c213cbc69817466bab78f6 100644 (file)
 
 #if TEST_ALL
     #define TEST_DIR
-    #define TEST_DYNLIB
-    #define TEST_ENVIRON
-    #define TEST_FILE
 #else // #if TEST_ALL
     #define TEST_DATETIME
     #define TEST_VOLUME
     #define TEST_REGEX
     #define TEST_INFO_FUNCTIONS
     #define TEST_MIME
+    #define TEST_DYNLIB
 #endif
 
 // some tests are interactive, define this to run them
@@ -328,79 +326,13 @@ static void TestDirExists()
 
 #include "wx/dynlib.h"
 
-static void TestDllLoad()
-{
-#if defined(__WXMSW__)
-    static const wxChar *LIB_NAME = wxT("kernel32.dll");
-    static const wxChar *FUNC_NAME = wxT("lstrlenA");
-#elif defined(__UNIX__)
-    // weird: using just libc.so does *not* work!
-    static const wxChar *LIB_NAME = wxT("/lib/libc.so.6");
-    static const wxChar *FUNC_NAME = wxT("strlen");
-#else
-    #error "don't know how to test wxDllLoader on this platform"
-#endif
-
-    wxPuts(wxT("*** testing basic wxDynamicLibrary functions ***\n"));
-
-    wxDynamicLibrary lib(LIB_NAME);
-    if ( !lib.IsLoaded() )
-    {
-        wxPrintf(wxT("ERROR: failed to load '%s'.\n"), LIB_NAME);
-    }
-    else
-    {
-        typedef int (wxSTDCALL *wxStrlenType)(const char *);
-        wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
-        if ( !pfnStrlen )
-        {
-            wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
-                     FUNC_NAME, LIB_NAME);
-        }
-        else
-        {
-            wxPrintf(wxT("Calling %s dynamically loaded from %s "),
-                     FUNC_NAME, LIB_NAME);
-
-            if ( pfnStrlen("foo") != 3 )
-            {
-                wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
-            }
-            else
-            {
-                wxPuts(wxT("... ok"));
-            }
-        }
-
-#ifdef __WXMSW__
-        static const wxChar *FUNC_NAME_AW = wxT("lstrlen");
-
-        typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *);
-        wxStrlenTypeAorW
-            pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW);
-        if ( !pfnStrlenAorW )
-        {
-            wxPrintf(wxT("ERROR: function '%s' wasn't found in '%s'.\n"),
-                     FUNC_NAME_AW, LIB_NAME);
-        }
-        else
-        {
-            if ( pfnStrlenAorW(wxT("foobar")) != 6 )
-            {
-                wxPrintf(wxT("ERROR: loaded function is not wxStrlen()!\n"));
-            }
-        }
-#endif // __WXMSW__
-    }
-}
-
 #if defined(__WXMSW__) || defined(__UNIX__)
 
 static void TestDllListLoaded()
 {
     wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
 
-    puts("\nLoaded modules:");
+    wxPuts("Loaded modules:");
     wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded();
     const size_t count = dlls.GetCount();
     for ( size_t n = 0; n < count; ++n )
@@ -418,202 +350,14 @@ static void TestDllListLoaded()
 
         printf(" %s\n", (const char *)details.GetVersion().mb_str());
     }
+    
+    wxPuts(wxEmptyString);
 }
 
 #endif
 
 #endif // TEST_DYNLIB
 
-// ----------------------------------------------------------------------------
-// wxGet/SetEnv
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_ENVIRON
-
-#include "wx/utils.h"
-
-static wxString MyGetEnv(const wxString& var)
-{
-    wxString val;
-    if ( !wxGetEnv(var, &val) )
-        val = wxT("<empty>");
-    else
-        val = wxString(wxT('\'')) + val + wxT('\'');
-
-    return val;
-}
-
-static void TestEnvironment()
-{
-    const wxChar *var = wxT("wxTestVar");
-
-    wxPuts(wxT("*** testing environment access functions ***"));
-
-    wxPrintf(wxT("Initially getenv(%s) = %s\n"), var, MyGetEnv(var).c_str());
-    wxSetEnv(var, wxT("value for wxTestVar"));
-    wxPrintf(wxT("After wxSetEnv: getenv(%s) = %s\n"),  var, MyGetEnv(var).c_str());
-    wxSetEnv(var, wxT("another value"));
-    wxPrintf(wxT("After 2nd wxSetEnv: getenv(%s) = %s\n"),  var, MyGetEnv(var).c_str());
-    wxUnsetEnv(var);
-    wxPrintf(wxT("After wxUnsetEnv: getenv(%s) = %s\n"),  var, MyGetEnv(var).c_str());
-    wxPrintf(wxT("PATH = %s\n"),  MyGetEnv(wxT("PATH")).c_str());
-}
-
-#endif // TEST_ENVIRON
-
-// ----------------------------------------------------------------------------
-// file
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_FILE
-
-#include "wx/file.h"
-#include "wx/ffile.h"
-#include "wx/textfile.h"
-
-static void TestFileRead()
-{
-    wxPuts(wxT("*** wxFile read test ***"));
-
-    wxFile file(wxT("makefile.vc"));
-    if ( file.IsOpened() )
-    {
-        wxPrintf(wxT("File length: %lu\n"), file.Length());
-
-        wxPuts(wxT("File dump:\n----------"));
-
-        static const size_t len = 1024;
-        wxChar buf[len];
-        for ( ;; )
-        {
-            size_t nRead = file.Read(buf, len);
-            if ( nRead == (size_t)wxInvalidOffset )
-            {
-                wxPrintf(wxT("Failed to read the file."));
-                break;
-            }
-
-            fwrite(buf, nRead, 1, stdout);
-
-            if ( nRead < len )
-                break;
-        }
-
-        wxPuts(wxT("----------"));
-    }
-    else
-    {
-        wxPrintf(wxT("ERROR: can't open test file.\n"));
-    }
-
-    wxPuts(wxEmptyString);
-}
-
-static void TestTextFileRead()
-{
-    wxPuts(wxT("*** wxTextFile read test ***"));
-
-    wxTextFile file(wxT("makefile.vc"));
-    if ( file.Open() )
-    {
-        wxPrintf(wxT("Number of lines: %u\n"), file.GetLineCount());
-        wxPrintf(wxT("Last line: '%s'\n"), file.GetLastLine().c_str());
-
-        wxString s;
-
-        wxPuts(wxT("\nDumping the entire file:"));
-        for ( s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
-        {
-            wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
-        }
-        wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
-
-        wxPuts(wxT("\nAnd now backwards:"));
-        for ( s = file.GetLastLine();
-              file.GetCurrentLine() != 0;
-              s = file.GetPrevLine() )
-        {
-            wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
-        }
-        wxPrintf(wxT("%6u: %s\n"), file.GetCurrentLine() + 1, s.c_str());
-    }
-    else
-    {
-        wxPrintf(wxT("ERROR: can't open '%s'\n"), file.GetName());
-    }
-
-    wxPuts(wxEmptyString);
-}
-
-static void TestFileCopy()
-{
-    wxPuts(wxT("*** Testing wxCopyFile ***"));
-
-    static const wxChar *filename1 = wxT("makefile.vc");
-    static const wxChar *filename2 = wxT("test2");
-    if ( !wxCopyFile(filename1, filename2) )
-    {
-        wxPuts(wxT("ERROR: failed to copy file"));
-    }
-    else
-    {
-        wxFFile f1(filename1, wxT("rb")),
-                f2(filename2, wxT("rb"));
-
-        if ( !f1.IsOpened() || !f2.IsOpened() )
-        {
-            wxPuts(wxT("ERROR: failed to open file(s)"));
-        }
-        else
-        {
-            wxString s1, s2;
-            if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) )
-            {
-                wxPuts(wxT("ERROR: failed to read file(s)"));
-            }
-            else
-            {
-                if ( (s1.length() != s2.length()) ||
-                     (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) )
-                {
-                    wxPuts(wxT("ERROR: copy error!"));
-                }
-                else
-                {
-                    wxPuts(wxT("File was copied ok."));
-                }
-            }
-        }
-    }
-
-    if ( !wxRemoveFile(filename2) )
-    {
-        wxPuts(wxT("ERROR: failed to remove the file"));
-    }
-
-    wxPuts(wxEmptyString);
-}
-
-static void TestTempFile()
-{
-    wxPuts(wxT("*** wxTempFile test ***"));
-
-    wxTempFile tmpFile;
-    if ( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) )
-    {
-        if ( tmpFile.Commit() )
-            wxPuts(wxT("File committed."));
-        else
-            wxPuts(wxT("ERROR: could't commit temp file."));
-
-        wxRemoveFile(wxT("test2"));
-    }
-
-    wxPuts(wxEmptyString);
-}
-
-#endif // TEST_FILE
-
 // ----------------------------------------------------------------------------
 // MIME types
 // ----------------------------------------------------------------------------
@@ -1335,21 +1079,9 @@ int main(int argc, char **argv)
 #endif // TEST_DIR
 
 #ifdef TEST_DYNLIB
-    TestDllLoad();
     TestDllListLoaded();
 #endif // TEST_DYNLIB
 
-#ifdef TEST_ENVIRON
-    TestEnvironment();
-#endif // TEST_ENVIRON
-
-#ifdef TEST_FILE
-    TestFileRead();
-    TestTextFileRead();
-    TestFileCopy();
-    TestTempFile();
-#endif // TEST_FILE
-
 #ifdef TEST_FTP
     wxLog::AddTraceMask(FTP_TRACE_MASK);
 
index 91ecf7e7d9a8093786f7ff437d006417c3629a98..90b2855e4a7d18f13cd728c95000997b1575d824 100644 (file)
@@ -69,6 +69,7 @@ TEST_OBJECTS =  \
        test_stopwatch.o \
        test_timertest.o \
        test_exec.o \
+       test_filefn.o \
        test_filetest.o \
        test_filekind.o \
        test_filenametest.o \
@@ -83,6 +84,8 @@ TEST_OBJECTS =  \
        test_longlongtest.o \
        test_convautotest.o \
        test_mbconvtest.o \
+       test_dynamiclib.o \
+       test_environ.o \
        test_misctests.o \
        test_module.o \
        test_pathlist.o \
@@ -406,6 +409,9 @@ test_timertest.o: $(srcdir)/events/timertest.cpp $(TEST_ODEP)
 test_exec.o: $(srcdir)/exec/exec.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/exec/exec.cpp
 
+test_filefn.o: $(srcdir)/file/filefn.cpp $(TEST_ODEP)
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/file/filefn.cpp
+
 test_filetest.o: $(srcdir)/file/filetest.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/file/filetest.cpp
 
@@ -448,6 +454,12 @@ test_convautotest.o: $(srcdir)/mbconv/convautotest.cpp $(TEST_ODEP)
 test_mbconvtest.o: $(srcdir)/mbconv/mbconvtest.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/mbconv/mbconvtest.cpp
 
+test_dynamiclib.o: $(srcdir)/misc/dynamiclib.cpp $(TEST_ODEP)
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/misc/dynamiclib.cpp
+
+test_environ.o: $(srcdir)/misc/environ.cpp $(TEST_ODEP)
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/misc/environ.cpp
+
 test_misctests.o: $(srcdir)/misc/misctests.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/misc/misctests.cpp
 
diff --git a/tests/file/filefn.cpp b/tests/file/filefn.cpp
new file mode 100644 (file)
index 0000000..ed2a9de
--- /dev/null
@@ -0,0 +1,123 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/file/filefn.cpp
+// Purpose:     generic file functions unit test
+// Author:      Francesco Montorsi (extracted from console sample)
+// Created:     2010-06-13
+// RCS-ID:      $Id$
+// Copyright:   (c) 2010 wxWidgets team
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#if wxUSE_FILE
+
+#include "wx/ffile.h"
+#include "wx/filefn.h"
+
+#include "testfile.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class FileFunctionsTestCase : public CppUnit::TestCase
+{
+public:
+    FileFunctionsTestCase() { }
+
+private:
+    CPPUNIT_TEST_SUITE( FileFunctionsTestCase );
+        CPPUNIT_TEST( CopyFile );
+    CPPUNIT_TEST_SUITE_END();
+
+    void CopyFile();
+
+    wxDECLARE_NO_COPY_CLASS(FileFunctionsTestCase);
+};
+
+// ----------------------------------------------------------------------------
+// CppUnit macros
+// ----------------------------------------------------------------------------
+
+CPPUNIT_TEST_SUITE_REGISTRATION( FileFunctionsTestCase );
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileFunctionsTestCase, "FileFunctionsTestCase" );
+
+// ----------------------------------------------------------------------------
+// tests implementation
+// ----------------------------------------------------------------------------
+
+void FileFunctionsTestCase::CopyFile()
+{
+    static const wxChar *filename1 = wxT("horse.bmp");
+    static const wxChar *filename2 = wxT("test_copy");
+    
+    CPPUNIT_ASSERT( wxCopyFile(filename1, filename2) );
+
+    // verify that the two files have the same contents!
+    wxFFile f1(filename1, wxT("rb")),
+            f2(filename2, wxT("rb"));
+
+    CPPUNIT_ASSERT( f1.IsOpened() && f2.IsOpened() );
+    
+    wxString s1, s2;
+    CPPUNIT_ASSERT( f1.ReadAll(&s1) && f2.ReadAll(&s2) );
+    CPPUNIT_ASSERT( (s1.length() == s2.length()) &&
+                    (memcmp(s1.c_str(), s2.c_str(), s1.length()) == 0) );
+
+    CPPUNIT_ASSERT( f1.Close() && f2.Close() );
+    CPPUNIT_ASSERT( wxRemoveFile(filename2) );
+}
+
+
+/*
+    TODO: other file functions to test:
+
+bool wxFileExists(const wxString& filename);
+
+bool wxDirExists(const wxString& pathName);
+
+bool wxIsAbsolutePath(const wxString& filename);
+
+wxChar* wxFileNameFromPath(wxChar *path);
+wxString wxFileNameFromPath(const wxString& path);
+
+wxString wxPathOnly(const wxString& path);
+
+wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
+wxString wxFindNextFile();
+
+bool wxIsWild(const wxString& pattern);
+
+bool wxMatchWild(const wxString& pattern,  const wxString& text, bool dot_special = true);
+
+bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
+
+bool wxRemoveFile(const wxString& file);
+
+bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
+
+wxString wxGetCwd();
+
+bool wxSetWorkingDirectory(const wxString& d);
+
+bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
+
+bool wxRmdir(const wxString& dir, int flags = 0);
+
+wxFileKind wxGetFileKind(int fd);
+wxFileKind wxGetFileKind(FILE *fp);
+
+bool wxIsWritable(const wxString &path);
+bool wxIsReadable(const wxString &path);
+bool wxIsExecutable(const wxString &path);
+*/
+
+#endif // wxUSE_FILE
index 33300577cb81ca286d25afd770847d0b668a8d18..85e70ab8e6bf73f8e7116a807677e77549654fa0 100644 (file)
@@ -37,6 +37,7 @@ private:
         CPPUNIT_TEST( RoundTripUTF8 );
         CPPUNIT_TEST( RoundTripUTF16 );
         CPPUNIT_TEST( RoundTripUTF32 );
+        CPPUNIT_TEST( TempFile );
     CPPUNIT_TEST_SUITE_END();
 
     void RoundTripUTF8() { DoRoundTripTest(wxConvUTF8); }
@@ -44,6 +45,7 @@ private:
     void RoundTripUTF32() { DoRoundTripTest(wxMBConvUTF32()); }
 
     void DoRoundTripTest(const wxMBConv& conv);
+    void TempFile();
 
     wxDECLARE_NO_COPY_CLASS(FileTestCase);
 };
@@ -92,4 +94,12 @@ void FileTestCase::DoRoundTripTest(const wxMBConv& conv)
     }
 }
 
+void FileTestCase::TempFile()
+{
+    wxTempFile tmpFile;
+    CPPUNIT_ASSERT( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) );
+    CPPUNIT_ASSERT( tmpFile.Commit() );
+    CPPUNIT_ASSERT( wxRemoveFile(wxT("test2")) );
+}
+
 #endif // wxUSE_FILE
index 67337b20150f70c0615a2864fca61ab9905845ae..e104f20bf9653600acb65ec1a1f96cb85ecd2f9b 100644 (file)
@@ -53,6 +53,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_stopwatch.obj \\r
        $(OBJS)\test_timertest.obj \\r
        $(OBJS)\test_exec.obj \\r
+       $(OBJS)\test_filefn.obj \\r
        $(OBJS)\test_filetest.obj \\r
        $(OBJS)\test_filekind.obj \\r
        $(OBJS)\test_filenametest.obj \\r
@@ -67,6 +68,8 @@ TEST_OBJECTS =  \
        $(OBJS)\test_longlongtest.obj \\r
        $(OBJS)\test_convautotest.obj \\r
        $(OBJS)\test_mbconvtest.obj \\r
+       $(OBJS)\test_dynamiclib.obj \\r
+       $(OBJS)\test_environ.obj \\r
        $(OBJS)\test_misctests.obj \\r
        $(OBJS)\test_module.obj \\r
        $(OBJS)\test_pathlist.obj \\r
@@ -448,6 +451,9 @@ $(OBJS)\test_timertest.obj: .\events\timertest.cpp
 $(OBJS)\test_exec.obj: .\exec\exec.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\exec\exec.cpp\r
 \r
+$(OBJS)\test_filefn.obj: .\file\filefn.cpp\r
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\file\filefn.cpp\r
+\r
 $(OBJS)\test_filetest.obj: .\file\filetest.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\file\filetest.cpp\r
 \r
@@ -490,6 +496,12 @@ $(OBJS)\test_convautotest.obj: .\mbconv\convautotest.cpp
 $(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp\r
 \r
+$(OBJS)\test_dynamiclib.obj: .\misc\dynamiclib.cpp\r
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\misc\dynamiclib.cpp\r
+\r
+$(OBJS)\test_environ.obj: .\misc\environ.cpp\r
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\misc\environ.cpp\r
+\r
 $(OBJS)\test_misctests.obj: .\misc\misctests.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\misc\misctests.cpp\r
 \r
index 9edc69b7f34a5082bd10b173db78a9c7d3500c7d..fccd347e5c8f0d26a02cd4251268deb127809023 100644 (file)
@@ -45,6 +45,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_stopwatch.o \\r
        $(OBJS)\test_timertest.o \\r
        $(OBJS)\test_exec.o \\r
+       $(OBJS)\test_filefn.o \\r
        $(OBJS)\test_filetest.o \\r
        $(OBJS)\test_filekind.o \\r
        $(OBJS)\test_filenametest.o \\r
@@ -59,6 +60,8 @@ TEST_OBJECTS =  \
        $(OBJS)\test_longlongtest.o \\r
        $(OBJS)\test_convautotest.o \\r
        $(OBJS)\test_mbconvtest.o \\r
+       $(OBJS)\test_dynamiclib.o \\r
+       $(OBJS)\test_environ.o \\r
        $(OBJS)\test_misctests.o \\r
        $(OBJS)\test_module.o \\r
        $(OBJS)\test_pathlist.o \\r
@@ -429,6 +432,9 @@ $(OBJS)\test_timertest.o: ./events/timertest.cpp
 $(OBJS)\test_exec.o: ./exec/exec.cpp\r
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\test_filefn.o: ./file/filefn.cpp\r
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
+\r
 $(OBJS)\test_filetest.o: ./file/filetest.cpp\r
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
 \r
@@ -471,6 +477,12 @@ $(OBJS)\test_convautotest.o: ./mbconv/convautotest.cpp
 $(OBJS)\test_mbconvtest.o: ./mbconv/mbconvtest.cpp\r
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\test_dynamiclib.o: ./misc/dynamiclib.cpp\r
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
+\r
+$(OBJS)\test_environ.o: ./misc/environ.cpp\r
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
+\r
 $(OBJS)\test_misctests.o: ./misc/misctests.cpp\r
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<\r
 \r
index b485b46766d7f9165282d36950bc87ed493d230a..4d1592bf04d151a340f4581f8a5ae831b0e4b7b0 100644 (file)
@@ -47,6 +47,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_stopwatch.obj \\r
        $(OBJS)\test_timertest.obj \\r
        $(OBJS)\test_exec.obj \\r
+       $(OBJS)\test_filefn.obj \\r
        $(OBJS)\test_filetest.obj \\r
        $(OBJS)\test_filekind.obj \\r
        $(OBJS)\test_filenametest.obj \\r
@@ -61,6 +62,8 @@ TEST_OBJECTS =  \
        $(OBJS)\test_longlongtest.obj \\r
        $(OBJS)\test_convautotest.obj \\r
        $(OBJS)\test_mbconvtest.obj \\r
+       $(OBJS)\test_dynamiclib.obj \\r
+       $(OBJS)\test_environ.obj \\r
        $(OBJS)\test_misctests.obj \\r
        $(OBJS)\test_module.obj \\r
        $(OBJS)\test_pathlist.obj \\r
@@ -574,6 +577,9 @@ $(OBJS)\test_timertest.obj: .\events\timertest.cpp
 $(OBJS)\test_exec.obj: .\exec\exec.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\exec\exec.cpp\r
 \r
+$(OBJS)\test_filefn.obj: .\file\filefn.cpp\r
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\file\filefn.cpp\r
+\r
 $(OBJS)\test_filetest.obj: .\file\filetest.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\file\filetest.cpp\r
 \r
@@ -616,6 +622,12 @@ $(OBJS)\test_convautotest.obj: .\mbconv\convautotest.cpp
 $(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp\r
 \r
+$(OBJS)\test_dynamiclib.obj: .\misc\dynamiclib.cpp\r
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\misc\dynamiclib.cpp\r
+\r
+$(OBJS)\test_environ.obj: .\misc\environ.cpp\r
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\misc\environ.cpp\r
+\r
 $(OBJS)\test_misctests.obj: .\misc\misctests.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\misc\misctests.cpp\r
 \r
index a6a6e50b25574eb789a2e180f10d2bca7e37fe73..a7585376687e9e5657b27bd8d82cbc40053ce5b3 100644 (file)
@@ -283,6 +283,7 @@ TEST_OBJECTS =  &
        $(OBJS)\test_stopwatch.obj &\r
        $(OBJS)\test_timertest.obj &\r
        $(OBJS)\test_exec.obj &\r
+       $(OBJS)\test_filefn.obj &\r
        $(OBJS)\test_filetest.obj &\r
        $(OBJS)\test_filekind.obj &\r
        $(OBJS)\test_filenametest.obj &\r
@@ -297,6 +298,8 @@ TEST_OBJECTS =  &
        $(OBJS)\test_longlongtest.obj &\r
        $(OBJS)\test_convautotest.obj &\r
        $(OBJS)\test_mbconvtest.obj &\r
+       $(OBJS)\test_dynamiclib.obj &\r
+       $(OBJS)\test_environ.obj &\r
        $(OBJS)\test_misctests.obj &\r
        $(OBJS)\test_module.obj &\r
        $(OBJS)\test_pathlist.obj &\r
@@ -486,6 +489,9 @@ $(OBJS)\test_timertest.obj :  .AUTODEPEND .\events\timertest.cpp
 $(OBJS)\test_exec.obj :  .AUTODEPEND .\exec\exec.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
 \r
+$(OBJS)\test_filefn.obj :  .AUTODEPEND .\file\filefn.cpp\r
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
+\r
 $(OBJS)\test_filetest.obj :  .AUTODEPEND .\file\filetest.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
 \r
@@ -528,6 +534,12 @@ $(OBJS)\test_convautotest.obj :  .AUTODEPEND .\mbconv\convautotest.cpp
 $(OBJS)\test_mbconvtest.obj :  .AUTODEPEND .\mbconv\mbconvtest.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
 \r
+$(OBJS)\test_dynamiclib.obj :  .AUTODEPEND .\misc\dynamiclib.cpp\r
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
+\r
+$(OBJS)\test_environ.obj :  .AUTODEPEND .\misc\environ.cpp\r
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
+\r
 $(OBJS)\test_misctests.obj :  .AUTODEPEND .\misc\misctests.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<\r
 \r
diff --git a/tests/misc/dynamiclib.cpp b/tests/misc/dynamiclib.cpp
new file mode 100644 (file)
index 0000000..f05090d
--- /dev/null
@@ -0,0 +1,86 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/misc/dynamiclib.cpp
+// Purpose:     Test wxDynamicLibrary
+// Author:      Francesco Montorsi (extracted from console sample)
+// Created:     2010-06-13
+// RCS-ID:      $Id$
+// Copyright:   (c) 2010 wxWidgets team
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+#   pragma hdrstop
+#endif
+
+#include "wx/dynlib.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class DynamicLibraryTestCase : public CppUnit::TestCase
+{
+public:
+    DynamicLibraryTestCase() { }
+
+private:
+    CPPUNIT_TEST_SUITE( DynamicLibraryTestCase );
+        CPPUNIT_TEST( Load );
+    CPPUNIT_TEST_SUITE_END();
+
+    void Load();
+    
+    DECLARE_NO_COPY_CLASS(DynamicLibraryTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( DynamicLibraryTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DynamicLibraryTestCase, "DynamicLibraryTestCase" );
+
+void DynamicLibraryTestCase::Load()
+{
+#if defined(__WXMSW__)
+    static const wxChar *LIB_NAME = wxT("kernel32.dll");
+    static const wxChar *FUNC_NAME = wxT("lstrlenA");
+#elif defined(__UNIX__)
+    // weird: using just libc.so does *not* work!
+    static const wxChar *LIB_NAME = wxT("/lib/libc.so.6");
+    static const wxChar *FUNC_NAME = wxT("strlen");
+#else
+    #error "don't know how to test wxDllLoader on this platform"
+#endif
+
+    wxDynamicLibrary lib(LIB_NAME);
+    CPPUNIT_ASSERT( lib.IsLoaded() );
+
+    typedef int (wxSTDCALL *wxStrlenType)(const char *);
+    wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
+    
+    wxString errMsg = wxString::Format("ERROR: function '%s' wasn't found in '%s'.\n",
+                                       FUNC_NAME, LIB_NAME);
+    CPPUNIT_ASSERT_MESSAGE( errMsg.ToStdString(), pfnStrlen );
+
+    // Call the function dynamically loaded
+    CPPUNIT_ASSERT( pfnStrlen("foo") == 3 );
+
+#ifdef __WXMSW__
+    static const wxChar *FUNC_NAME_AW = wxT("lstrlen");
+
+    typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *);
+    wxStrlenTypeAorW
+        pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW);
+
+    wxString errMsg2 = wxString::Format("ERROR: function '%s' wasn't found in '%s'.\n",
+                                       FUNC_NAME_AW, LIB_NAME);
+    CPPUNIT_ASSERT_MESSAGE( errMsg2.ToStdString(), pfnStrlenAorW );
+
+    CPPUNIT_ASSERT( pfnStrlenAorW(wxT("foobar")) == 6 );
+#endif // __WXMSW__
+}
diff --git a/tests/misc/environ.cpp b/tests/misc/environ.cpp
new file mode 100644 (file)
index 0000000..01d1e9b
--- /dev/null
@@ -0,0 +1,75 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/misc/environ.cpp
+// Purpose:     Test wxGet/SetEnv
+// Author:      Francesco Montorsi (extracted from console sample)
+// Created:     2010-06-13
+// RCS-ID:      $Id$
+// Copyright:   (c) 2010 wxWidgets team
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+#   pragma hdrstop
+#endif
+
+#include "wx/utils.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class EnvTestCase : public CppUnit::TestCase
+{
+public:
+    EnvTestCase() { }
+
+private:
+    CPPUNIT_TEST_SUITE( EnvTestCase );
+        CPPUNIT_TEST( GetSet );
+        CPPUNIT_TEST( Path );
+    CPPUNIT_TEST_SUITE_END();
+
+    void GetSet();
+    void Path();
+    
+    DECLARE_NO_COPY_CLASS(EnvTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( EnvTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EnvTestCase, "EnvTestCase" );
+
+void EnvTestCase::GetSet()
+{
+    const wxChar *var = wxT("wxTestVar");
+    wxString contents;
+
+    CPPUNIT_ASSERT(!wxGetEnv(var, &contents));
+    CPPUNIT_ASSERT(contents.empty());
+
+    wxSetEnv(var, wxT("value for wxTestVar"));
+    CPPUNIT_ASSERT(wxGetEnv(var, &contents));
+    CPPUNIT_ASSERT(contents == wxT("value for wxTestVar"));
+
+    wxSetEnv(var, wxT("another value"));
+    CPPUNIT_ASSERT(wxGetEnv(var, &contents));
+    CPPUNIT_ASSERT(contents == wxT("another value"));
+
+    wxUnsetEnv(var);
+    CPPUNIT_ASSERT(!wxGetEnv(var, &contents));
+}
+
+void EnvTestCase::Path()
+{
+    wxString contents;
+    
+    CPPUNIT_ASSERT(wxGetEnv(wxT("PATH"), &contents));
+    CPPUNIT_ASSERT(!contents.empty());
+}
index 398d90a1e2d646390eb4585bc1eac7ada4f245ea..3a0a5af5f3360046e566fac726b8c15e7e70baf6 100644 (file)
@@ -44,6 +44,7 @@
             events/stopwatch.cpp
             events/timertest.cpp
             exec/exec.cpp
+            file/filefn.cpp
             file/filetest.cpp
             filekind/filekind.cpp
             filename/filenametest.cpp
@@ -58,6 +59,8 @@
             longlong/longlongtest.cpp
             mbconv/convautotest.cpp
             mbconv/mbconvtest.cpp
+            misc/dynamiclib.cpp
+            misc/environ.cpp
             misc/misctests.cpp
             misc/module.cpp
             misc/pathlist.cpp
index 919aa02151b3298c3d6de31cd46aaef57014adb5..976585634a7f02f16e29f5a9493453e3cb0b94b1 100644 (file)
@@ -285,6 +285,14 @@ SOURCE=.\dummy.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\misc\dynamiclib.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\misc\environ.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\weakref\evtconnection.cpp\r
 # End Source File\r
 # Begin Source File\r
@@ -313,6 +321,10 @@ SOURCE=.\config\fileconf.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\file\filefn.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\filekind\filekind.cpp\r
 # End Source File\r
 # Begin Source File\r
index 22709850d694a40f3b9f26a2e8ff18062c62931d..48f402dfe5708ab31628a25a59b8bd01d42e49bc 100644 (file)
                                                UsePrecompiledHeader="1"/>\r
                                </FileConfiguration>\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\misc\dynamiclib.cpp">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\misc\environ.cpp">\r
+                       </File>\r
                        <File\r
                                RelativePath=".\weakref\evtconnection.cpp">\r
                        </File>\r
                        <File\r
                                RelativePath=".\config\fileconf.cpp">\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\file\filefn.cpp">\r
+                       </File>\r
                        <File\r
                                RelativePath=".\filekind\filekind.cpp">\r
                        </File>\r
index b93b72186b4240eb2c1c86890da151bd516cf482..ee86d82baa04a703f166631bde4bbd2b42050b0e 100644 (file)
                                        />\r
                                </FileConfiguration>\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\misc\dynamiclib.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\misc\environ.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\weakref\evtconnection.cpp"\r
                                >\r
                                RelativePath=".\config\fileconf.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\file\filefn.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\filekind\filekind.cpp"\r
                                >\r
index 81d73b4506033d6a4ca8b074b168d0318a6b1bd3..74ea5490fc766050a8b92429fd6e0f900488ecfb 100644 (file)
@@ -1,10 +1,16 @@
 <?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
@@ -12,6 +18,7 @@
                />\r
        </Platforms>\r
        <ToolFiles>\r
+               \r
        </ToolFiles>\r
        <Configurations>\r
                <Configuration\r
@@ -44,7 +51,7 @@
                                Name="VCCLCompilerTool"\r
                                AdditionalOptions="/MP"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;.;F:\cppunit\include"\r
+                               AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;."\r
                                PreprocessorDefinitions="WIN32;_DEBUG;__WXMSW__;_UNICODE;_CONSOLE;wxUSE_GUI=0"\r
                                ExceptionHandling="1"\r
                                BasicRuntimeChecks="3"\r
@@ -79,7 +86,7 @@
                                OutputFile="vc_mswud\test.exe"\r
                                LinkIncremental="2"\r
                                SuppressStartupBanner="true"\r
-                               AdditionalLibraryDirectories=".\..\lib\vc_lib;F:\cppunit\lib"\r
+                               AdditionalLibraryDirectories=".\..\lib\vc_lib"\r
                                GenerateManifest="true"\r
                                GenerateDebugInformation="true"\r
                                ProgramDatabaseFile="vc_mswud\test.pdb"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               SuppressStartupBanner="true"\r
                                OutputFile="vc_mswud\test_vc9_test.bsc"\r
+                               SuppressStartupBanner="true"\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
-                               SuppressStartupBanner="true"\r
                                OutputFile="vc_mswu\test_vc9_test.bsc"\r
+                               SuppressStartupBanner="true"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               SuppressStartupBanner="true"\r
                                OutputFile="vc_mswunivud\test_vc9_test.bsc"\r
+                               SuppressStartupBanner="true"\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
-                               SuppressStartupBanner="true"\r
                                OutputFile="vc_mswunivu\test_vc9_test.bsc"\r
+                               SuppressStartupBanner="true"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               SuppressStartupBanner="true"\r
                                OutputFile="vc_mswuddll\test_vc9_test.bsc"\r
+                               SuppressStartupBanner="true"\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
-                               SuppressStartupBanner="true"\r
                                OutputFile="vc_mswudll\test_vc9_test.bsc"\r
+                               SuppressStartupBanner="true"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                        />\r
                        <Tool\r
                                Name="VCBscMakeTool"\r
-                               SuppressStartupBanner="true"\r
                                OutputFile="vc_mswunivuddll\test_vc9_test.bsc"\r
+                               SuppressStartupBanner="true"\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
-                               SuppressStartupBanner="true"\r
                                OutputFile="vc_mswunivudll\test_vc9_test.bsc"\r
+                               SuppressStartupBanner="true"\r
                        />\r
                        <Tool\r
                                Name="VCFxCopTool"\r
                </Configuration>\r
        </Configurations>\r
        <References>\r
+               \r
        </References>\r
        <Files>\r
                <Filter\r
                                        />\r
                                </FileConfiguration>\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\misc\dynamiclib.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\misc\environ.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\weakref\evtconnection.cpp"\r
                                >\r
                                RelativePath=".\config\fileconf.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\file\filefn.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\filekind\filekind.cpp"\r
                                >\r
                </Filter>\r
        </Files>\r
        <Globals>\r
+               \r
        </Globals>\r
 </VisualStudioProject>\r
+\r