/////////////////////////////////////////////////////////////////////////////
// Name: samples/console/console.cpp
-// Purpose: a sample console (as opposed to GUI) progam using wxWidgets
+// Purpose: A sample console (as opposed to GUI) program using wxWidgets
// Author: Vadim Zeitlin
// Modified by:
// Created: 04.10.99
#include "wx/file.h"
#include "wx/app.h"
#include "wx/log.h"
+#include "wx/apptrait.h"
+#include "wx/platinfo.h"
// without this pragma, the stupid compiler precompiles #defines below so that
// changing them doesn't "take place" later!
#if TEST_ALL
-
#define TEST_CMDLINE
#define TEST_DATETIME
#define TEST_DIR
- #define TEST_DLLLOADER
+ #define TEST_DYNLIB
#define TEST_ENVIRON
#define TEST_EXECUTE
#define TEST_FILE
#define TEST_FILENAME
#define TEST_FILETIME
// #define TEST_FTP --FIXME! (RN)
- #define TEST_HASHMAP
- #define TEST_HASHSET
#define TEST_INFO_FUNCTIONS
- #define TEST_LIST
#define TEST_LOCALE
#define TEST_LOG
#define TEST_MIME
+ #define TEST_MODULE
#define TEST_PATHLIST
#define TEST_ODBC
#define TEST_PRINTF
#define TEST_SCOPEGUARD
#define TEST_SNGLINST
// #define TEST_SOCKETS --FIXME! (RN)
+ #define TEST_STACKWALKER
+ #define TEST_STDPATHS
#define TEST_STREAMS
#define TEST_TEXTSTREAM
#define TEST_THREADS
// #define TEST_VOLUME --FIXME! (RN)
#define TEST_WCHAR
#define TEST_ZIP
-
#else // #if TEST_ALL
-
- #define TEST_DATETIME
-
+ #define TEST_INFO_FUNCTIONS
#endif
// some tests are interactive, define this to run them
#define TEST_INTERACTIVE 0
#endif
-// ----------------------------------------------------------------------------
-// test class for container objects
-// ----------------------------------------------------------------------------
-
-#if defined(TEST_LIST)
-
-class Bar // Foo is already taken in the hash test
-{
-public:
- Bar(const wxString& name) : m_name(name) { ms_bars++; }
- Bar(const Bar& bar) : m_name(bar.m_name) { ms_bars++; }
- ~Bar() { ms_bars--; }
-
- static size_t GetNumber() { return ms_bars; }
-
- const wxChar *GetName() const { return m_name; }
-
-private:
- wxString m_name;
-
- static size_t ms_bars;
-};
-
-size_t Bar::ms_bars = 0;
-
-#endif // defined(TEST_LIST)
-
// ============================================================================
// implementation
// ============================================================================
#ifdef __UNIX__
static const wxChar *ROOTDIR = _T("/");
static const wxChar *TESTDIR = _T("/usr/local/share");
-#elif defined(__WXMSW__)
+#elif defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
static const wxChar *ROOTDIR = _T("c:\\");
static const wxChar *TESTDIR = _T("d:\\");
#else
wxPuts(wxEmptyString);
}
+#if TEST_ALL
+
static void TestDirEnum()
{
wxPuts(_T("*** Testing wxDir::GetFirst/GetNext ***"));
TestDirEnumHelper(dirNo);
}
+#endif // TEST_ALL
+
class DirPrintTraverser : public wxDirTraverser
{
public:
dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN);
}
+#if TEST_ALL
+
static void TestDirExists()
{
wxPuts(_T("*** Testing wxDir::Exists() ***"));
}
}
+#endif // TEST_ALL
+
#endif // TEST_DIR
// ----------------------------------------------------------------------------
// wxDllLoader
// ----------------------------------------------------------------------------
-#ifdef TEST_DLLLOADER
+#ifdef TEST_DYNLIB
#include "wx/dynlib.h"
static const wxChar *FUNC_NAME = _T("lstrlenA");
#elif defined(__UNIX__)
// weird: using just libc.so does *not* work!
- static const wxChar *LIB_NAME = _T("/lib/libc-2.0.7.so");
+ static const wxChar *LIB_NAME = _T("/lib/libc.so.6");
static const wxChar *FUNC_NAME = _T("strlen");
#else
#error "don't know how to test wxDllLoader on this platform"
#endif
- wxPuts(_T("*** testing wxDllLoader ***\n"));
+ wxPuts(_T("*** testing basic wxDynamicLibrary functions ***\n"));
wxDynamicLibrary lib(LIB_NAME);
if ( !lib.IsLoaded() )
}
else
{
- typedef int (*wxStrlenType)(const char *);
+ typedef int (wxSTDCALL *wxStrlenType)(const char *);
wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
if ( !pfnStrlen )
{
}
else
{
+ wxPrintf(_T("Calling %s dynamically loaded from %s "),
+ FUNC_NAME, LIB_NAME);
+
if ( pfnStrlen("foo") != 3 )
{
wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
wxPuts(_T("... ok"));
}
}
+
+#ifdef __WXMSW__
+ static const wxChar *FUNC_NAME_AW = _T("lstrlen");
+
+ typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *);
+ wxStrlenTypeAorW
+ pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW);
+ if ( !pfnStrlenAorW )
+ {
+ wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
+ FUNC_NAME_AW, LIB_NAME);
+ }
+ else
+ {
+ if ( pfnStrlenAorW(_T("foobar")) != 6 )
+ {
+ wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
+ }
+ }
+#endif // __WXMSW__
}
}
-#endif // TEST_DLLLOADER
+#if defined(__WXMSW__) || defined(__UNIX__)
+
+static void TestDllListLoaded()
+{
+ wxPuts(_T("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
+
+ puts("\nLoaded modules:");
+ wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded();
+ const size_t count = dlls.GetCount();
+ for ( size_t n = 0; n < count; ++n )
+ {
+ const wxDynamicLibraryDetails& details = dlls[n];
+ printf("%-45s", details.GetPath().mb_str());
+
+ void *addr;
+ size_t len;
+ if ( details.GetAddress(&addr, &len) )
+ {
+ printf(" %08lx:%08lx",
+ (unsigned long)addr, (unsigned long)((char *)addr + len));
+ }
+
+ printf(" %s\n", details.GetVersion().mb_str());
+ }
+}
+
+#endif
+
+#endif // TEST_DYNLIB
// ----------------------------------------------------------------------------
// wxGet/SetEnv
wxPuts(_T("File dump:\n----------"));
- static const off_t len = 1024;
+ static const size_t len = 1024;
wxChar buf[len];
for ( ;; )
{
- off_t nRead = file.Read(buf, len);
- if ( nRead == wxInvalidOffset )
+ size_t nRead = file.Read(buf, len);
+ if ( nRead == (size_t)wxInvalidOffset )
{
wxPrintf(_T("Failed to read the file."));
break;
}
#endif
-static struct FileNameInfo
-{
- const wxChar *fullname;
- const wxChar *volume;
- const wxChar *path;
- const wxChar *name;
- const wxChar *ext;
- bool isAbsolute;
- wxPathFormat format;
-} filenames[] =
-{
- // Unix file names
- { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX },
- { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX },
- { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), true, wxPATH_UNIX },
- { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), false, wxPATH_UNIX },
- { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_UNIX },
- { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), true, wxPATH_UNIX },
- { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), true, wxPATH_UNIX },
- { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), false, wxPATH_UNIX },
- { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), true, wxPATH_UNIX },
-
- // Windows file names
- { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS },
- { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), false, wxPATH_DOS },
- { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS },
- { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS },
- { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), true, wxPATH_DOS },
- { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS },
- { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), true, wxPATH_DOS },
-
- // wxFileName support for Mac file names is broken currently
-#if 0
- // Mac file names
- { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), true, wxPATH_MAC },
- { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), true, wxPATH_MAC },
- { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), true, wxPATH_MAC },
- { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), false, wxPATH_MAC },
- { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC },
- { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC },
-#endif // 0
-
- // VMS file names
- { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), true, wxPATH_VMS },
- { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), false, wxPATH_VMS },
-};
-
-static void TestFileNameConstruction()
-{
- wxPuts(_T("*** testing wxFileName construction ***"));
-
- for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
- {
- const FileNameInfo& fni = filenames[n];
-
- wxFileName fn(fni.fullname, fni.format);
-
- wxString fullname = fn.GetFullPath(fni.format);
- if ( fullname != fni.fullname )
- {
- wxPrintf(_T("ERROR: fullname should be '%s'\n"), fni.fullname);
- }
-
- bool isAbsolute = fn.IsAbsolute(fni.format);
- wxPrintf(_T("'%s' is %s (%s)\n\t"),
- fullname.c_str(),
- isAbsolute ? "absolute" : "relative",
- isAbsolute == fni.isAbsolute ? "ok" : "ERROR");
-
- if ( !fn.Normalize(wxPATH_NORM_ALL, wxEmptyString, fni.format) )
- {
- wxPuts(_T("ERROR (couldn't be normalized)"));
- }
- else
- {
- wxPrintf(_T("normalized: '%s'\n"), fn.GetFullPath(fni.format).c_str());
- }
- }
-
- wxPuts(wxEmptyString);
-}
-
-static void TestFileNameSplit()
-{
- wxPuts(_T("*** testing wxFileName splitting ***"));
-
- for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
- {
- const FileNameInfo& fni = filenames[n];
- wxString volume, path, name, ext;
- wxFileName::SplitPath(fni.fullname,
- &volume, &path, &name, &ext, fni.format);
-
- wxPrintf(_T("%s -> volume = '%s', path = '%s', name = '%s', ext = '%s'"),
- fni.fullname,
- volume.c_str(), path.c_str(), name.c_str(), ext.c_str());
-
- if ( volume != fni.volume )
- wxPrintf(_T(" (ERROR: volume = '%s')"), fni.volume);
- if ( path != fni.path )
- wxPrintf(_T(" (ERROR: path = '%s')"), fni.path);
- if ( name != fni.name )
- wxPrintf(_T(" (ERROR: name = '%s')"), fni.name);
- if ( ext != fni.ext )
- wxPrintf(_T(" (ERROR: ext = '%s')"), fni.ext);
-
- wxPuts(wxEmptyString);
- }
-}
-
static void TestFileNameTemp()
{
wxPuts(_T("*** testing wxFileName temp file creation ***"));
}
}
-static void TestFileNameMakeRelative()
-{
- wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***"));
-
- for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
- {
- const FileNameInfo& fni = filenames[n];
-
- wxFileName fn(fni.fullname, fni.format);
-
- // choose the base dir of the same format
- wxString base;
- switch ( fni.format )
- {
- case wxPATH_UNIX:
- base = _T("/usr/bin/");
- break;
-
- case wxPATH_DOS:
- base = _T("c:\\");
- break;
-
- case wxPATH_MAC:
- case wxPATH_VMS:
- // TODO: I don't know how this is supposed to work there
- continue;
-
- case wxPATH_NATIVE: // make gcc happy
- default:
- wxFAIL_MSG( _T("unexpected path format") );
- }
-
- wxPrintf(_T("'%s' relative to '%s': "),
- fn.GetFullPath(fni.format).c_str(), base.c_str());
-
- if ( !fn.MakeRelativeTo(base, fni.format) )
- {
- wxPuts(_T("unchanged"));
- }
- else
- {
- wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str());
- }
- }
-}
-
-static void TestFileNameMakeAbsolute()
-{
- wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***"));
-
- for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
- {
- const FileNameInfo& fni = filenames[n];
- wxFileName fn(fni.fullname, fni.format);
-
- wxPrintf(_T("'%s' absolutized: "),
- fn.GetFullPath(fni.format).c_str());
- fn.MakeAbsolute();
- wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str());
- }
-
- wxPuts(wxEmptyString);
-}
-
static void TestFileNameDirManip()
{
// TODO: test AppendDir(), RemoveDir(), ...
#ifdef TEST_FILETIME
-#include <wx/filename.h>
-#include <wx/datetime.h>
+#include "wx/filename.h"
+#include "wx/datetime.h"
static void TestFileGetTimes()
{
#endif // TEST_FILETIME
-// ----------------------------------------------------------------------------
-// wxHashMap
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_HASHMAP
-
-#include "wx/hashmap.h"
-
-// test compilation of basic map types
-WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash, wxPointerEqual, myPtrHashMap );
-WX_DECLARE_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual, myLongHashMap );
-WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash, wxIntegerEqual,
- myUnsignedHashMap );
-WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash, wxIntegerEqual,
- myTestHashMap1 );
-WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash, wxIntegerEqual,
- myTestHashMap2 );
-WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash, wxIntegerEqual,
- myTestHashMap3 );
-WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash, wxIntegerEqual,
- myTestHashMap4 );
-
-// same as:
-// WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
-// myStringHashMap );
-WX_DECLARE_STRING_HASH_MAP(wxString, myStringHashMap);
-
-typedef myStringHashMap::iterator Itor;
-
-static void TestHashMap()
-{
- wxPuts(_T("*** Testing wxHashMap ***\n"));
- myStringHashMap sh(0); // as small as possible
- wxString buf;
- size_t i;
- const size_t count = 10000;
-
- // init with some data
- for( i = 0; i < count; ++i )
- {
- buf.Printf(wxT("%d"), i );
- sh[buf] = wxT("A") + buf + wxT("C");
- }
-
- // test that insertion worked
- if( sh.size() != count )
- {
- wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh.size(), count);
- }
-
- for( i = 0; i < count; ++i )
- {
- buf.Printf(wxT("%d"), i );
- if( sh[buf] != wxT("A") + buf + wxT("C") )
- {
- wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n"));
- return;
- }
- }
-
- // check that iterators work
- Itor it;
- for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
- {
- if( i == count )
- {
- wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n"));
- return;
- }
-
- if( it->second != sh[it->first] )
- {
- wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n"));
- return;
- }
- }
-
- if( sh.size() != i )
- {
- wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i, count);
- }
-
- // test copy ctor, assignment operator
- myStringHashMap h1( sh ), h2( 0 );
- h2 = sh;
-
- for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
- {
- if( h1[it->first] != it->second )
- {
- wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it->first.c_str());
- }
-
- if( h2[it->first] != it->second )
- {
- wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it->first.c_str());
- }
- }
-
- // other tests
- for( i = 0; i < count; ++i )
- {
- buf.Printf(wxT("%d"), i );
- size_t sz = sh.size();
-
- // test find() and erase(it)
- if( i < 100 )
- {
- it = sh.find( buf );
- if( it != sh.end() )
- {
- sh.erase( it );
-
- if( sh.find( buf ) != sh.end() )
- {
- wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i);
- }
- }
- else
- wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i);
- }
- else
- // test erase(key)
- {
- size_t c = sh.erase( buf );
- if( c != 1 )
- wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n"));
-
- if( sh.find( buf ) != sh.end() )
- {
- wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i);
- }
- }
-
- // count should decrease
- if( sh.size() != sz - 1 )
- {
- wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n"));
- }
- }
-
- wxPrintf(_T("*** Finished testing wxHashMap ***\n"));
-}
-
-#endif // TEST_HASHMAP
-
-// ----------------------------------------------------------------------------
-// wxHashSet
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_HASHSET
-
-#include "wx/hashset.h"
-
-// test compilation of basic map types
-WX_DECLARE_HASH_SET( int*, wxPointerHash, wxPointerEqual, myPtrHashSet );
-WX_DECLARE_HASH_SET( long, wxIntegerHash, wxIntegerEqual, myLongHashSet );
-WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash, wxIntegerEqual,
- myUnsignedHashSet );
-WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash, wxIntegerEqual,
- myTestHashSet1 );
-WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual,
- myTestHashSet2 );
-WX_DECLARE_HASH_SET( short, wxIntegerHash, wxIntegerEqual,
- myTestHashSet3 );
-WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash, wxIntegerEqual,
- myTestHashSet4 );
-WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual,
- myTestHashSet5 );
-
-struct MyStruct
-{
- int* ptr;
- wxString str;
-};
-
-class MyHash
-{
-public:
- unsigned long operator()(const MyStruct& s) const
- { return m_dummy(s.ptr); }
- MyHash& operator=(const MyHash&) { return *this; }
-private:
- wxPointerHash m_dummy;
-};
-
-class MyEqual
-{
-public:
- bool operator()(const MyStruct& s1, const MyStruct& s2) const
- { return s1.ptr == s2.ptr; }
- MyEqual& operator=(const MyEqual&) { return *this; }
-};
-
-WX_DECLARE_HASH_SET( MyStruct, MyHash, MyEqual, mySet );
-
-typedef myTestHashSet5 wxStringHashSet;
-
-static void TestHashSet()
-{
- wxPrintf(_T("*** Testing wxHashSet ***\n"));
-
- wxStringHashSet set1;
-
- set1.insert( _T("abc") );
- set1.insert( _T("bbc") );
- set1.insert( _T("cbc") );
- set1.insert( _T("abc") );
-
- if( set1.size() != 3 )
- wxPrintf(_T("*** ERROR IN INSERT ***\n"));
-
- mySet set2;
- int dummy;
- MyStruct tmp;
-
- tmp.ptr = &dummy; tmp.str = _T("ABC");
- set2.insert( tmp );
- tmp.ptr = &dummy + 1;
- set2.insert( tmp );
- tmp.ptr = &dummy; tmp.str = _T("CDE");
- set2.insert( tmp );
-
- if( set2.size() != 2 )
- wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n"));
-
- mySet::iterator it = set2.find( tmp );
-
- if( it == set2.end() )
- wxPrintf(_T("*** ERROR IN FIND - 1 ***\n"));
- if( it->ptr != &dummy )
- wxPrintf(_T("*** ERROR IN FIND - 2 ***\n"));
- if( it->str != _T("ABC") )
- wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n"));
-
- wxPrintf(_T("*** Finished testing wxHashSet ***\n"));
-}
-
-#endif // TEST_HASHSET
-
-// ----------------------------------------------------------------------------
-// wxList
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_LIST
-
-#include "wx/list.h"
-
-WX_DECLARE_LIST(Bar, wxListBars);
-#include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxListBars);
-
-WX_DECLARE_LIST(int, wxListInt);
-WX_DEFINE_LIST(wxListInt);
-
-static void TestList()
-{
- wxPuts(_T("*** Testing wxList operations ***\n"));
- {
- wxListInt list1;
- int dummy[5];
- int i;
-
- for ( i = 0; i < 5; ++i )
- list1.Append(dummy + i);
-
- if ( list1.GetCount() != 5 )
- wxPuts(_T("Wrong number of items in list\n"));
-
- if ( list1.Item(3)->GetData() != dummy + 3 )
- wxPuts(_T("Error in Item()\n"));
-
- if ( !list1.Find(dummy + 4) )
- wxPuts(_T("Error in Find()\n"));
-
- wxListInt::compatibility_iterator node = list1.GetFirst();
- i = 0;
-
- while (node)
- {
- if ( node->GetData() != dummy + i )
- wxPuts(_T("Error in compatibility_iterator\n"));
- node = node->GetNext();
- ++i;
- }
-
- if ( size_t(i) != list1.GetCount() )
- wxPuts(_T("Error in compatibility_iterator\n"));
-
- list1.Insert(dummy + 0);
- list1.Insert(1, dummy + 1);
- list1.Insert(list1.GetFirst()->GetNext()->GetNext(), dummy + 2);
-
- node = list1.GetFirst();
- i = 0;
-
- while (i < 3)
- {
- int* t = node->GetData();
- if ( t != dummy + i )
- wxPuts(_T("Error in Insert\n"));
- node = node->GetNext();
- ++i;
- }
- }
-
- wxPuts(_T("*** Testing wxList operations finished ***\n"));
-
- wxPuts(_T("*** Testing std::list operations ***\n"));
-
- {
- wxListInt list1;
- wxListInt::iterator it, en;
- wxListInt::reverse_iterator rit, ren;
- int i;
- for ( i = 0; i < 5; ++i )
- list1.push_back(i + &i);
-
- for ( it = list1.begin(), en = list1.end(), i = 0;
- it != en; ++it, ++i )
- if ( *it != i + &i )
- wxPuts(_T("Error in iterator\n"));
-
- for ( rit = list1.rbegin(), ren = list1.rend(), i = 4;
- rit != ren; ++rit, --i )
- if ( *rit != i + &i )
- wxPuts(_T("Error in reverse_iterator\n"));
-
- if ( *list1.rbegin() != *--list1.end() ||
- *list1.begin() != *--list1.rend() )
- wxPuts(_T("Error in iterator/reverse_iterator\n"));
- if ( *list1.begin() != *--++list1.begin() ||
- *list1.rbegin() != *--++list1.rbegin() )
- wxPuts(_T("Error in iterator/reverse_iterator\n"));
-
- if ( list1.front() != &i || list1.back() != &i + 4 )
- wxPuts(_T("Error in front()/back()\n"));
-
- list1.erase(list1.begin());
- list1.erase(--list1.end());
-
- for ( it = list1.begin(), en = list1.end(), i = 1;
- it != en; ++it, ++i )
- if ( *it != i + &i )
- wxPuts(_T("Error in erase()\n"));
- }
-
- wxPuts(_T("*** Testing std::list operations finished ***\n"));
-}
-
-static void TestListCtor()
-{
- wxPuts(_T("*** Testing wxList construction ***\n"));
-
- {
- wxListBars list1;
- list1.Append(new Bar(_T("first")));
- list1.Append(new Bar(_T("second")));
-
- wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"),
- list1.GetCount(), Bar::GetNumber());
-
- wxListBars list2;
- list2 = list1;
-
- wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"),
- list1.GetCount(), list2.GetCount(), Bar::GetNumber());
-
-#if !wxUSE_STL
- list1.DeleteContents(true);
-#else
- WX_CLEAR_LIST(wxListBars, list1);
-#endif
- }
-
- wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber());
-}
-
-#endif // TEST_LIST
-
// ----------------------------------------------------------------------------
// wxLocale
// ----------------------------------------------------------------------------
#endif // TEST_MIME
+// ----------------------------------------------------------------------------
+// module dependencies feature
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_MODULE
+
+#include "wx/module.h"
+
+class wxTestModule : public wxModule
+{
+protected:
+ virtual bool OnInit() { wxPrintf(_T("Load module: %s\n"), GetClassInfo()->GetClassName()); return true; }
+ virtual void OnExit() { wxPrintf(_T("Unload module: %s\n"), GetClassInfo()->GetClassName()); }
+};
+
+class wxTestModuleA : public wxTestModule
+{
+public:
+ wxTestModuleA();
+private:
+ DECLARE_DYNAMIC_CLASS(wxTestModuleA)
+};
+
+class wxTestModuleB : public wxTestModule
+{
+public:
+ wxTestModuleB();
+private:
+ DECLARE_DYNAMIC_CLASS(wxTestModuleB)
+};
+
+class wxTestModuleC : public wxTestModule
+{
+public:
+ wxTestModuleC();
+private:
+ DECLARE_DYNAMIC_CLASS(wxTestModuleC)
+};
+
+class wxTestModuleD : public wxTestModule
+{
+public:
+ wxTestModuleD();
+private:
+ DECLARE_DYNAMIC_CLASS(wxTestModuleD)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxTestModuleC, wxModule)
+wxTestModuleC::wxTestModuleC()
+{
+ AddDependency(CLASSINFO(wxTestModuleD));
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxTestModuleA, wxModule)
+wxTestModuleA::wxTestModuleA()
+{
+ AddDependency(CLASSINFO(wxTestModuleB));
+ AddDependency(CLASSINFO(wxTestModuleD));
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxTestModuleD, wxModule)
+wxTestModuleD::wxTestModuleD()
+{
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxTestModuleB, wxModule)
+wxTestModuleB::wxTestModuleB()
+{
+ AddDependency(CLASSINFO(wxTestModuleD));
+ AddDependency(CLASSINFO(wxTestModuleC));
+}
+
+#endif // TEST_MODULE
+
// ----------------------------------------------------------------------------
// misc information functions
// ----------------------------------------------------------------------------
#include "wx/utils.h"
+#if TEST_INTERACTIVE
static void TestDiskInfo()
{
wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
}
}
}
+#endif // TEST_INTERACTIVE
static void TestOsInfo()
{
wxPrintf(_T("Running under: %s, version %d.%d\n"),
wxGetOsDescription().c_str(), major, minor);
- wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
+ wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
wxPrintf(_T("Host name is %s (%s).\n"),
wxGetHostName().c_str(), wxGetFullHostName().c_str());
wxPuts(wxEmptyString);
}
+static void TestPlatformInfo()
+{
+ wxPuts(_T("*** Testing wxPlatformInfo functions ***\n"));
+
+ // get this platform
+ wxPlatformInfo plat;
+
+ wxPrintf(_T("Operating system family name is: %s\n"), plat.GetOperatingSystemFamilyName().c_str());
+ wxPrintf(_T("Operating system name is: %s\n"), plat.GetOperatingSystemIdName().c_str());
+ wxPrintf(_T("Port ID name is: %s\n"), plat.GetPortIdName().c_str());
+ wxPrintf(_T("Port ID short name is: %s\n"), plat.GetPortIdShortName().c_str());
+ wxPrintf(_T("Architecture is: %s\n"), plat.GetArchName().c_str());
+ wxPrintf(_T("Endianness is: %s\n"), plat.GetEndiannessName().c_str());
+
+ wxPuts(wxEmptyString);
+}
+
static void TestUserInfo()
{
wxPuts(_T("*** Testing user info functions ***\n"));
#ifdef TEST_ODBC
-#include <wx/db.h>
+#include "wx/db.h"
static void TestDbOpen()
{
wxON_BLOCK_EXIT2(function2, 3.14, 'p');
Object obj;
- wxON_BLOCK_EXIT_OBJ0(obj, &Object::method0);
- wxON_BLOCK_EXIT_OBJ1(obj, &Object::method1, 7);
- wxON_BLOCK_EXIT_OBJ2(obj, &Object::method2, 2.71, 'e');
+ wxON_BLOCK_EXIT_OBJ0(obj, Object::method0);
+ wxON_BLOCK_EXIT_OBJ1(obj, Object::method1, 7);
+ wxON_BLOCK_EXIT_OBJ2(obj, Object::method2, 2.71, 'e');
wxScopeGuard dismissed = wxMakeGuard(function0);
dismissed.Dismiss();
else
{
wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
- hostname, ftp.Pwd().c_str());
+ hostname, ftp.Pwd().c_str());
+ ftp.Close();
}
return true;
#endif // TEST_FTP
+// ----------------------------------------------------------------------------
+// stack backtrace
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_STACKWALKER
+
+#if wxUSE_STACKWALKER
+
+#include "wx/stackwalk.h"
+
+class StackDump : public wxStackWalker
+{
+public:
+ StackDump(const char *argv0)
+ : wxStackWalker(argv0)
+ {
+ }
+
+ virtual void Walk(size_t skip = 1)
+ {
+ wxPuts(_T("Stack dump:"));
+
+ wxStackWalker::Walk(skip);
+ }
+
+protected:
+ virtual void OnStackFrame(const wxStackFrame& frame)
+ {
+ printf("[%2d] ", frame.GetLevel());
+
+ wxString name = frame.GetName();
+ if ( !name.empty() )
+ {
+ printf("%-20.40s", name.mb_str());
+ }
+ else
+ {
+ printf("0x%08lx", (unsigned long)frame.GetAddress());
+ }
+
+ if ( frame.HasSourceLocation() )
+ {
+ printf("\t%s:%d",
+ frame.GetFileName().mb_str(),
+ frame.GetLine());
+ }
+
+ puts("");
+
+ wxString type, val;
+ for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ )
+ {
+ printf("\t%s %s = %s\n", type.mb_str(), name.mb_str(), val.mb_str());
+ }
+ }
+};
+
+static void TestStackWalk(const char *argv0)
+{
+ wxPuts(_T("*** Testing wxStackWalker ***\n"));
+
+ StackDump dump(argv0);
+ dump.Walk();
+}
+
+#endif // wxUSE_STACKWALKER
+
+#endif // TEST_STACKWALKER
+
+// ----------------------------------------------------------------------------
+// standard paths
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_STDPATHS
+
+#include "wx/stdpaths.h"
+
+static void TestStandardPaths()
+{
+ wxPuts(_T("*** Testing wxStandardPaths ***\n"));
+
+ wxTheApp->SetAppName(_T("console"));
+
+ wxStandardPathsBase& stdp = wxStandardPaths::Get();
+ wxPrintf(_T("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str());
+ wxPrintf(_T("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str());
+ wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str());
+ wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp.GetLocalDataDir().c_str());
+ wxPrintf(_T("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str());
+ wxPrintf(_T("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str());
+ wxPrintf(_T("Documents dir:\t\t%s\n"), stdp.GetDocumentsDir().c_str());
+ wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str());
+ wxPrintf(_T("Resources dir:\t\t%s\n"), stdp.GetResourcesDir().c_str());
+ wxPrintf(_T("Localized res. dir:\t%s\n"),
+ stdp.GetLocalizedResourcesDir(_T("fr")).c_str());
+ wxPrintf(_T("Message catalogs dir:\t%s\n"),
+ stdp.GetLocalizedResourcesDir
+ (
+ _T("fr"),
+ wxStandardPaths::ResourceCat_Messages
+ ).c_str());
+}
+
+#endif // TEST_STDPATHS
+
// ----------------------------------------------------------------------------
// streams
// ----------------------------------------------------------------------------
#ifdef TEST_TIMER
-#include "wx/timer.h"
+#include "wx/stopwatch.h"
#include "wx/utils.h"
static void TestStopWatch()
wxPrintf(_T("Full name from wxVCard API: %s\n"), value.c_str());
- // now show how to deal with multiply occuring properties
+ // now show how to deal with multiply occurring properties
DumpVCardAddresses(vcard);
DumpVCardPhoneNumbers(vcard);
#ifdef TEST_DATETIME
-#include <math.h>
-
+#include "wx/math.h"
#include "wx/datetime.h"
// this test miscellaneous static wxDateTime functions
int main(int argc, char **argv)
{
+#if wxUSE_UNICODE
+ wxChar **wxArgv = new wxChar *[argc + 1];
+
+ {
+ int n;
+
+ for (n = 0; n < argc; n++ )
+ {
+ wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
+ wxArgv[n] = wxStrdup(warg);
+ }
+
+ wxArgv[n] = NULL;
+ }
+#else // !wxUSE_UNICODE
+ #define wxArgv argv
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+
wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
wxInitializer initializer;
{ wxCMD_LINE_NONE }
};
-#if wxUSE_UNICODE
- wxChar **wargv = new wxChar *[argc + 1];
-
- {
- int n;
-
- for (n = 0; n < argc; n++ )
- {
- wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
- wargv[n] = wxStrdup(warg);
- }
-
- wargv[n] = NULL;
- }
-
- #define argv wargv
-#endif // wxUSE_UNICODE
-
- wxCmdLineParser parser(cmdLineDesc, argc, argv);
-
-#if wxUSE_UNICODE
- {
- for ( int n = 0; n < argc; n++ )
- free(wargv[n]);
-
- delete [] wargv;
- }
-#endif // wxUSE_UNICODE
+ wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
parser.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
wxCMD_LINE_VAL_STRING,
TestDirTraverse();
#endif // TEST_DIR
-#ifdef TEST_DLLLOADER
+#ifdef TEST_DYNLIB
TestDllLoad();
-#endif // TEST_DLLLOADER
+ TestDllListLoaded();
+#endif // TEST_DYNLIB
#ifdef TEST_ENVIRON
TestEnvironment();
TestFileConfRead();
#endif // TEST_FILECONF
-#ifdef TEST_LIST
- TestListCtor();
- TestList();
-#endif // TEST_LIST
-
#ifdef TEST_LOCALE
TestDefaultLang();
#endif // TEST_LOCALE
#endif // TEST_FILE
#ifdef TEST_FILENAME
- TestFileNameConstruction();
- TestFileNameMakeRelative();
- TestFileNameMakeAbsolute();
- TestFileNameSplit();
TestFileNameTemp();
TestFileNameCwd();
TestFileNameDirManip();
TestFtpMisc();
TestFtpFileSize();
TestFtpUpload();
- #endif
+ #endif // TEST_ALL
#if TEST_INTERACTIVE
TestFtpInteractive();
#endif
#endif // TEST_FTP
-#ifdef TEST_HASHMAP
- TestHashMap();
-#endif // TEST_HASHMAP
-
-#ifdef TEST_HASHSET
- TestHashSet();
-#endif // TEST_HASHSET
-
#ifdef TEST_MIME
wxLog::AddTraceMask(_T("mime"));
#if TEST_ALL
#endif // TEST_MIME
#ifdef TEST_INFO_FUNCTIONS
- #if TEST_ALL
- TestOsInfo();
- TestUserInfo();
+ TestOsInfo();
+ TestPlatformInfo();
+ TestUserInfo();
- #if TEST_INTERACTIVE
- TestDiskInfo();
- #endif
+ #if TEST_INTERACTIVE
+ TestDiskInfo();
#endif
#endif // TEST_INFO_FUNCTIONS
#ifdef TEST_DATETIME
#if TEST_ALL
- TestTimeSet();
TestTimeStatic();
TestTimeRange();
TestTimeZones();
- TestTimeTicks();
- TestTimeJDN();
TestTimeDST();
- TestTimeWDays();
- TestTimeWNumber();
- TestTimeParse();
- TestTimeArithmetics();
TestTimeHolidays();
TestTimeSpanFormat();
TestTimeMS();
TestScopeGuard();
#endif
+#ifdef TEST_STACKWALKER
+#if wxUSE_STACKWALKER
+ TestStackWalk(argv[0]);
+#endif
+#endif // TEST_STACKWALKER
+
+#ifdef TEST_STDPATHS
+ TestStandardPaths();
+#endif
+
#ifdef TEST_USLEEP
wxPuts(_T("Sleeping for 3 seconds... z-z-z-z-z..."));
wxUsleep(3000);
TestZipFileSystem();
#endif // TEST_ZIP
+#if wxUSE_UNICODE
+ {
+ for ( int n = 0; n < argc; n++ )
+ free(wxArgv[n]);
+
+ delete [] wxArgv;
+ }
+#endif // wxUSE_UNICODE
+
wxUnusedVar(argc);
wxUnusedVar(argv);
return 0;
}
-