From 69fc85873dfe7a9ea4f25ffc34bec7c0ee719368 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Sun, 13 Jun 2010 14:30:55 +0000 Subject: [PATCH 1/1] moved non-interactive tests for wxDynamicLibrary, wxGet/SetEnv, wxTempFile, wxCopyFile to appropriate CppUnit test suites; 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 --- interface/wx/filefn.h | 3 + samples/console/console.cpp | 276 +----------------------------------- tests/Makefile.in | 12 ++ tests/file/filefn.cpp | 123 ++++++++++++++++ tests/file/filetest.cpp | 10 ++ tests/makefile.bcc | 12 ++ tests/makefile.gcc | 12 ++ tests/makefile.vc | 12 ++ tests/makefile.wat | 12 ++ tests/misc/dynamiclib.cpp | 86 +++++++++++ tests/misc/environ.cpp | 75 ++++++++++ tests/test.bkl | 3 + tests/test_test.dsp | 12 ++ tests/test_vc7_test.vcproj | 9 ++ tests/test_vc8_test.vcproj | 12 ++ tests/test_vc9_test.vcproj | 54 ++++--- 16 files changed, 435 insertions(+), 288 deletions(-) create mode 100644 tests/file/filefn.cpp create mode 100644 tests/misc/dynamiclib.cpp create mode 100644 tests/misc/environ.cpp diff --git a/interface/wx/filefn.h b/interface/wx/filefn.h index 9659221bdb..3d07e3491b 100644 --- a/interface/wx/filefn.h +++ b/interface/wx/filefn.h @@ -24,6 +24,9 @@ class wxPathList : public wxArrayString { public: + /** + Standard constructor. + */ wxPathList(); /** diff --git a/samples/console/console.cpp b/samples/console/console.cpp index c696083ca8..bc31024863 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -106,9 +106,6 @@ #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 @@ -119,6 +116,7 @@ #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(""); - 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); diff --git a/tests/Makefile.in b/tests/Makefile.in index 91ecf7e7d9..90b2855e4a 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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 index 0000000000..ed2a9ded71 --- /dev/null +++ b/tests/file/filefn.cpp @@ -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 diff --git a/tests/file/filetest.cpp b/tests/file/filetest.cpp index 33300577cb..85e70ab8e6 100644 --- a/tests/file/filetest.cpp +++ b/tests/file/filetest.cpp @@ -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 diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 67337b2015..e104f20bf9 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -53,6 +53,7 @@ TEST_OBJECTS = \ $(OBJS)\test_stopwatch.obj \ $(OBJS)\test_timertest.obj \ $(OBJS)\test_exec.obj \ + $(OBJS)\test_filefn.obj \ $(OBJS)\test_filetest.obj \ $(OBJS)\test_filekind.obj \ $(OBJS)\test_filenametest.obj \ @@ -67,6 +68,8 @@ TEST_OBJECTS = \ $(OBJS)\test_longlongtest.obj \ $(OBJS)\test_convautotest.obj \ $(OBJS)\test_mbconvtest.obj \ + $(OBJS)\test_dynamiclib.obj \ + $(OBJS)\test_environ.obj \ $(OBJS)\test_misctests.obj \ $(OBJS)\test_module.obj \ $(OBJS)\test_pathlist.obj \ @@ -448,6 +451,9 @@ $(OBJS)\test_timertest.obj: .\events\timertest.cpp $(OBJS)\test_exec.obj: .\exec\exec.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\exec\exec.cpp +$(OBJS)\test_filefn.obj: .\file\filefn.cpp + $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\file\filefn.cpp + $(OBJS)\test_filetest.obj: .\file\filetest.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\file\filetest.cpp @@ -490,6 +496,12 @@ $(OBJS)\test_convautotest.obj: .\mbconv\convautotest.cpp $(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp +$(OBJS)\test_dynamiclib.obj: .\misc\dynamiclib.cpp + $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\misc\dynamiclib.cpp + +$(OBJS)\test_environ.obj: .\misc\environ.cpp + $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\misc\environ.cpp + $(OBJS)\test_misctests.obj: .\misc\misctests.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\misc\misctests.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 9edc69b7f3..fccd347e5c 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -45,6 +45,7 @@ TEST_OBJECTS = \ $(OBJS)\test_stopwatch.o \ $(OBJS)\test_timertest.o \ $(OBJS)\test_exec.o \ + $(OBJS)\test_filefn.o \ $(OBJS)\test_filetest.o \ $(OBJS)\test_filekind.o \ $(OBJS)\test_filenametest.o \ @@ -59,6 +60,8 @@ TEST_OBJECTS = \ $(OBJS)\test_longlongtest.o \ $(OBJS)\test_convautotest.o \ $(OBJS)\test_mbconvtest.o \ + $(OBJS)\test_dynamiclib.o \ + $(OBJS)\test_environ.o \ $(OBJS)\test_misctests.o \ $(OBJS)\test_module.o \ $(OBJS)\test_pathlist.o \ @@ -429,6 +432,9 @@ $(OBJS)\test_timertest.o: ./events/timertest.cpp $(OBJS)\test_exec.o: ./exec/exec.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_filefn.o: ./file/filefn.cpp + $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_filetest.o: ./file/filetest.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< @@ -471,6 +477,12 @@ $(OBJS)\test_convautotest.o: ./mbconv/convautotest.cpp $(OBJS)\test_mbconvtest.o: ./mbconv/mbconvtest.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_dynamiclib.o: ./misc/dynamiclib.cpp + $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< + +$(OBJS)\test_environ.o: ./misc/environ.cpp + $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_misctests.o: ./misc/misctests.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index b485b46766..4d1592bf04 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -47,6 +47,7 @@ TEST_OBJECTS = \ $(OBJS)\test_stopwatch.obj \ $(OBJS)\test_timertest.obj \ $(OBJS)\test_exec.obj \ + $(OBJS)\test_filefn.obj \ $(OBJS)\test_filetest.obj \ $(OBJS)\test_filekind.obj \ $(OBJS)\test_filenametest.obj \ @@ -61,6 +62,8 @@ TEST_OBJECTS = \ $(OBJS)\test_longlongtest.obj \ $(OBJS)\test_convautotest.obj \ $(OBJS)\test_mbconvtest.obj \ + $(OBJS)\test_dynamiclib.obj \ + $(OBJS)\test_environ.obj \ $(OBJS)\test_misctests.obj \ $(OBJS)\test_module.obj \ $(OBJS)\test_pathlist.obj \ @@ -574,6 +577,9 @@ $(OBJS)\test_timertest.obj: .\events\timertest.cpp $(OBJS)\test_exec.obj: .\exec\exec.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\exec\exec.cpp +$(OBJS)\test_filefn.obj: .\file\filefn.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\file\filefn.cpp + $(OBJS)\test_filetest.obj: .\file\filetest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\file\filetest.cpp @@ -616,6 +622,12 @@ $(OBJS)\test_convautotest.obj: .\mbconv\convautotest.cpp $(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp +$(OBJS)\test_dynamiclib.obj: .\misc\dynamiclib.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\misc\dynamiclib.cpp + +$(OBJS)\test_environ.obj: .\misc\environ.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\misc\environ.cpp + $(OBJS)\test_misctests.obj: .\misc\misctests.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\misc\misctests.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index a6a6e50b25..a758537668 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -283,6 +283,7 @@ TEST_OBJECTS = & $(OBJS)\test_stopwatch.obj & $(OBJS)\test_timertest.obj & $(OBJS)\test_exec.obj & + $(OBJS)\test_filefn.obj & $(OBJS)\test_filetest.obj & $(OBJS)\test_filekind.obj & $(OBJS)\test_filenametest.obj & @@ -297,6 +298,8 @@ TEST_OBJECTS = & $(OBJS)\test_longlongtest.obj & $(OBJS)\test_convautotest.obj & $(OBJS)\test_mbconvtest.obj & + $(OBJS)\test_dynamiclib.obj & + $(OBJS)\test_environ.obj & $(OBJS)\test_misctests.obj & $(OBJS)\test_module.obj & $(OBJS)\test_pathlist.obj & @@ -486,6 +489,9 @@ $(OBJS)\test_timertest.obj : .AUTODEPEND .\events\timertest.cpp $(OBJS)\test_exec.obj : .AUTODEPEND .\exec\exec.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< +$(OBJS)\test_filefn.obj : .AUTODEPEND .\file\filefn.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< + $(OBJS)\test_filetest.obj : .AUTODEPEND .\file\filetest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< @@ -528,6 +534,12 @@ $(OBJS)\test_convautotest.obj : .AUTODEPEND .\mbconv\convautotest.cpp $(OBJS)\test_mbconvtest.obj : .AUTODEPEND .\mbconv\mbconvtest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< +$(OBJS)\test_dynamiclib.obj : .AUTODEPEND .\misc\dynamiclib.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< + +$(OBJS)\test_environ.obj : .AUTODEPEND .\misc\environ.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< + $(OBJS)\test_misctests.obj : .AUTODEPEND .\misc\misctests.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< diff --git a/tests/misc/dynamiclib.cpp b/tests/misc/dynamiclib.cpp new file mode 100644 index 0000000000..f05090d575 --- /dev/null +++ b/tests/misc/dynamiclib.cpp @@ -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 index 0000000000..01d1e9b877 --- /dev/null +++ b/tests/misc/environ.cpp @@ -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()); +} diff --git a/tests/test.bkl b/tests/test.bkl index 398d90a1e2..3a0a5af5f3 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -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 diff --git a/tests/test_test.dsp b/tests/test_test.dsp index 919aa02151..976585634a 100644 --- a/tests/test_test.dsp +++ b/tests/test_test.dsp @@ -285,6 +285,14 @@ SOURCE=.\dummy.cpp # End Source File # Begin Source File +SOURCE=.\misc\dynamiclib.cpp +# End Source File +# Begin Source File + +SOURCE=.\misc\environ.cpp +# End Source File +# Begin Source File + SOURCE=.\weakref\evtconnection.cpp # End Source File # Begin Source File @@ -313,6 +321,10 @@ SOURCE=.\config\fileconf.cpp # End Source File # Begin Source File +SOURCE=.\file\filefn.cpp +# End Source File +# Begin Source File + SOURCE=.\filekind\filekind.cpp # End Source File # Begin Source File diff --git a/tests/test_vc7_test.vcproj b/tests/test_vc7_test.vcproj index 22709850d6..48f402dfe5 100644 --- a/tests/test_vc7_test.vcproj +++ b/tests/test_vc7_test.vcproj @@ -649,6 +649,12 @@ UsePrecompiledHeader="1"/> + + + + @@ -670,6 +676,9 @@ + + diff --git a/tests/test_vc8_test.vcproj b/tests/test_vc8_test.vcproj index b93b72186b..ee86d82baa 100644 --- a/tests/test_vc8_test.vcproj +++ b/tests/test_vc8_test.vcproj @@ -939,6 +939,14 @@ /> + + + + @@ -967,6 +975,10 @@ RelativePath=".\config\fileconf.cpp" > + + diff --git a/tests/test_vc9_test.vcproj b/tests/test_vc9_test.vcproj index 81d73b4506..74ea5490fc 100644 --- a/tests/test_vc9_test.vcproj +++ b/tests/test_vc9_test.vcproj @@ -1,10 +1,16 @@ + + + + + + + @@ -931,6 +947,10 @@ RelativePath=".\config\fileconf.cpp" > + + @@ -1162,5 +1182,7 @@ + + -- 2.45.2