/////////////////////////////////////////////////////////////////////////////
// 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!
#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_LOCALE
#define TEST_LOG
#define TEST_MIME
+ #define TEST_MODULE
#define TEST_PATHLIST
#define TEST_ODBC
#define TEST_PRINTF
#define TEST_WCHAR
#define TEST_ZIP
#else // #if TEST_ALL
- #define TEST_STACKWALKER
+ #define TEST_INFO_FUNCTIONS
#endif
// some tests are interactive, define this to run them
#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"
}
else
{
- typedef int (*wxStrlenType)(const char *);
+ typedef int (wxSTDCALL *wxStrlenType)(const char *);
wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
if ( !pfnStrlen )
{
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
-#endif // TEST_DLLLOADER
+#endif // TEST_DYNLIB
// ----------------------------------------------------------------------------
// wxGet/SetEnv
}
}
-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_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();
#ifdef TEST_STACKWALKER
+#if wxUSE_STACKWALKER
+
#include "wx/stackwalk.h"
class StackDump : public wxStackWalker
{
}
- virtual void Walk()
+ virtual void Walk(size_t skip = 1)
{
wxPuts(_T("Stack dump:"));
- wxStackWalker::Walk();
+ wxStackWalker::Walk(skip);
}
protected:
dump.Walk();
}
+#endif // wxUSE_STACKWALKER
+
#endif // TEST_STACKWALKER
// ----------------------------------------------------------------------------
wxTheApp->SetAppName(_T("console"));
- wxStandardPaths& stdp = wxStandardPaths::Get();
+ 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
#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);
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();
TestDllListLoaded();
-#endif // TEST_DLLLOADER
+#endif // TEST_DYNLIB
#ifdef TEST_ENVIRON
TestEnvironment();
#endif // TEST_FILE
#ifdef TEST_FILENAME
- TestFileNameConstruction();
- TestFileNameMakeRelative();
- TestFileNameMakeAbsolute();
- TestFileNameSplit();
TestFileNameTemp();
TestFileNameCwd();
TestFileNameDirManip();
#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();
#endif
#ifdef TEST_STACKWALKER
+#if wxUSE_STACKWALKER
TestStackWalk(argv[0]);
+#endif
#endif // TEST_STACKWALKER
#ifdef TEST_STDPATHS
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;
}
-