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
This commit is contained in:
Francesco Montorsi 2010-06-13 14:30:55 +00:00
parent 16a97d7e9a
commit 69fc85873d
16 changed files with 435 additions and 288 deletions

View File

@ -24,6 +24,9 @@
class wxPathList : public wxArrayString
{
public:
/**
Standard constructor.
*/
wxPathList();
/**

View File

@ -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("<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);

View 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

123
tests/file/filefn.cpp Normal file
View File

@ -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

View 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

View File

@ -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

View File

@ -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) $<

View File

@ -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

View File

@ -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) $<

86
tests/misc/dynamiclib.cpp Normal file
View File

@ -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__
}

75
tests/misc/environ.cpp Normal file
View File

@ -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());
}

View 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

View File

@ -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

View File

@ -649,6 +649,12 @@
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
<File
RelativePath=".\misc\dynamiclib.cpp">
</File>
<File
RelativePath=".\misc\environ.cpp">
</File>
<File
RelativePath=".\weakref\evtconnection.cpp">
</File>
@ -670,6 +676,9 @@
<File
RelativePath=".\config\fileconf.cpp">
</File>
<File
RelativePath=".\file\filefn.cpp">
</File>
<File
RelativePath=".\filekind\filekind.cpp">
</File>

View File

@ -939,6 +939,14 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\misc\dynamiclib.cpp"
>
</File>
<File
RelativePath=".\misc\environ.cpp"
>
</File>
<File
RelativePath=".\weakref\evtconnection.cpp"
>
@ -967,6 +975,10 @@
RelativePath=".\config\fileconf.cpp"
>
</File>
<File
RelativePath=".\file\filefn.cpp"
>
</File>
<File
RelativePath=".\filekind\filekind.cpp"
>

View File

@ -1,10 +1,16 @@
<?xml version="1.0" encoding="Windows-1252"?>
<!--
This project was generated by
Bakefile 0.2.8 (http://www.bakefile.org)
Do not modify, all changes will be overwritten!
-->
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Version="9.00"
Name="test"
ProjectGUID="{2F45723C-ED6B-5F60-8BFF-6B3609464A7B}"
TargetFrameworkVersion="0"
>
<Platforms>
<Platform
@ -12,6 +18,7 @@
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
@ -44,7 +51,7 @@
Name="VCCLCompilerTool"
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;.;F:\cppunit\include"
AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;."
PreprocessorDefinitions="WIN32;_DEBUG;__WXMSW__;_UNICODE;_CONSOLE;wxUSE_GUI=0"
ExceptionHandling="1"
BasicRuntimeChecks="3"
@ -79,7 +86,7 @@
OutputFile="vc_mswud\test.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories=".\..\lib\vc_lib;F:\cppunit\lib"
AdditionalLibraryDirectories=".\..\lib\vc_lib"
GenerateManifest="true"
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswud\test.pdb"
@ -97,8 +104,8 @@
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="vc_mswud\test_vc9_test.bsc"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
@ -178,9 +185,9 @@
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswu\test.pdb"
SubSystem="1"
TargetMachine="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@ -193,8 +200,8 @@
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="vc_mswu\test_vc9_test.bsc"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
@ -289,8 +296,8 @@
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="vc_mswunivud\test_vc9_test.bsc"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
@ -370,9 +377,9 @@
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswunivu\test.pdb"
SubSystem="1"
TargetMachine="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@ -385,8 +392,8 @@
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="vc_mswunivu\test_vc9_test.bsc"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
@ -481,8 +488,8 @@
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="vc_mswuddll\test_vc9_test.bsc"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
@ -562,9 +569,9 @@
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswudll\test.pdb"
SubSystem="1"
TargetMachine="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@ -577,8 +584,8 @@
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="vc_mswudll\test_vc9_test.bsc"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
@ -673,8 +680,8 @@
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="vc_mswunivuddll\test_vc9_test.bsc"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
@ -754,9 +761,9 @@
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswunivudll\test.pdb"
SubSystem="1"
TargetMachine="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@ -769,8 +776,8 @@
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="vc_mswunivudll\test_vc9_test.bsc"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
@ -784,6 +791,7 @@
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
@ -903,6 +911,14 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\misc\dynamiclib.cpp"
>
</File>
<File
RelativePath=".\misc\environ.cpp"
>
</File>
<File
RelativePath=".\weakref\evtconnection.cpp"
>
@ -931,6 +947,10 @@
RelativePath=".\config\fileconf.cpp"
>
</File>
<File
RelativePath=".\file\filefn.cpp"
>
</File>
<File
RelativePath=".\filekind\filekind.cpp"
>
@ -1162,5 +1182,7 @@
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>