#include "wx/file.h"
#include "wx/app.h"
#include "wx/log.h"
+#include "wx/apptrait.h"
+#include "wx/platinfo.h"
+#include "wx/wxchar.h"
// without this pragma, the stupid compiler precompiles #defines below so that
// changing them doesn't "take place" later!
#define TEST_WCHAR
#define TEST_ZIP
#else // #if TEST_ALL
- #define TEST_MODULE
+ #define TEST_TIMER
#endif
// some tests are interactive, define this to run them
static void ShowCmdLine(const wxCmdLineParser& parser)
{
- wxString s = _T("Input files: ");
+ wxString s = _T("Command line parsed successfully:\nInput files: ");
size_t count = parser.GetParamCount();
for ( size_t param = 0; param < count; param++ )
wxPuts(wxEmptyString);
}
+static void TestTempFile()
+{
+ wxPuts(_T("*** wxTempFile test ***"));
+
+ wxTempFile tmpFile;
+ if ( tmpFile.Open(_T("test2")) && tmpFile.Write(_T("the answer is 42")) )
+ {
+ if ( tmpFile.Commit() )
+ wxPuts(_T("File committed."));
+ else
+ wxPuts(_T("ERROR: could't commit temp file."));
+
+ wxRemoveFile(_T("test2"));
+ }
+
+ wxPuts(wxEmptyString);
+}
+
#endif // TEST_FILE
// ----------------------------------------------------------------------------
#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_STDPATHS
#include "wx/stdpaths.h"
+#include "wx/wxchar.h" // wxPrintf
static void TestStandardPaths()
{
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("Executable path:\t%s\n"), stdp.GetExecutablePath().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"),
fsOut.Write("foo", 3);
}
- wxFileInputStream fsIn(filename);
- wxPrintf(_T("File stream size: %u\n"), fsIn.GetSize());
- while ( !fsIn.Eof() )
{
- wxPutchar(fsIn.GetC());
+ wxFileInputStream fsIn(filename);
+ wxPrintf(_T("File stream size: %u\n"), fsIn.GetSize());
+ while ( !fsIn.Eof() )
+ {
+ wxPutchar(fsIn.GetC());
+ }
}
if ( !wxRemoveFile(filename) )
wxPuts(_T(", ok."));
}
+#include "wx/timer.h"
+#include "wx/evtloop.h"
+
+void TestTimer()
+{
+ wxPuts(_T("*** Testing wxTimer ***\n"));
+
+ class MyTimer : public wxTimer
+ {
+ public:
+ MyTimer() : wxTimer() { m_num = 0; }
+
+ virtual void Notify()
+ {
+ wxPrintf(_T("%d"), m_num++);
+ fflush(stdout);
+
+ if ( m_num == 10 )
+ {
+ wxPrintf(_T("... exiting the event loop"));
+ Stop();
+
+ wxEventLoop::GetActive()->Exit(0);
+ wxPuts(_T(", ok."));
+ }
+
+ fflush(stdout);
+ }
+
+ private:
+ int m_num;
+ };
+
+ wxEventLoop loop;
+
+ wxTimer timer1;
+ timer1.Start(100, true /* one shot */);
+ timer1.Stop();
+ timer1.Start(100, true /* one shot */);
+
+ MyTimer timer;
+ timer.Start(500);
+
+ loop.Run();
+}
+
#endif // TEST_TIMER
// ----------------------------------------------------------------------------
TestFileRead();
TestTextFileRead();
TestFileCopy();
+ TestTempFile();
#endif // TEST_FILE
#ifdef TEST_FILENAME
wxLog::AddTraceMask(_T("mime"));
#if TEST_ALL
TestMimeEnum();
+ #endif
TestMimeOverride();
TestMimeAssociate();
- #endif
TestMimeFilename();
#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_TIMER
TestStopWatch();
+ TestTimer();
#endif // TEST_TIMER
#ifdef TEST_DATETIME