class wxPathList : public wxArrayString
{
public:
+ /**
+ Standard constructor.
+ */
wxPathList();
/**
#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
#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 )
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
// ----------------------------------------------------------------------------
#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);
test_stopwatch.o \
test_timertest.o \
test_exec.o \
+ test_filefn.o \
test_filetest.o \
test_filekind.o \
test_filenametest.o \
test_longlongtest.o \
test_convautotest.o \
test_mbconvtest.o \
+ test_dynamiclib.o \
+ test_environ.o \
test_misctests.o \
test_module.o \
test_pathlist.o \
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
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
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// 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
CPPUNIT_TEST( RoundTripUTF8 );
CPPUNIT_TEST( RoundTripUTF16 );
CPPUNIT_TEST( RoundTripUTF32 );
+ CPPUNIT_TEST( TempFile );
CPPUNIT_TEST_SUITE_END();
void RoundTripUTF8() { DoRoundTripTest(wxConvUTF8); }
void RoundTripUTF32() { DoRoundTripTest(wxMBConvUTF32()); }
void DoRoundTripTest(const wxMBConv& conv);
+ void TempFile();
wxDECLARE_NO_COPY_CLASS(FileTestCase);
};
}
}
+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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
$(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
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// 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__
+}
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// 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());
+}
events/stopwatch.cpp
events/timertest.cpp
exec/exec.cpp
+ file/filefn.cpp
file/filetest.cpp
filekind/filekind.cpp
filename/filenametest.cpp
longlong/longlongtest.cpp
mbconv/convautotest.cpp
mbconv/mbconvtest.cpp
+ misc/dynamiclib.cpp
+ misc/environ.cpp
misc/misctests.cpp
misc/module.cpp
misc/pathlist.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
# 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
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
/>\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
<?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
/>\r
</Platforms>\r
<ToolFiles>\r
+ \r
</ToolFiles>\r
<Configurations>\r
<Configuration\r
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
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