From d34bce842bf0ed4f0f03186a440060d8ba52cac6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin <vadim@wxwidgets.org> Date: Wed, 5 Jan 2000 02:42:22 +0000 Subject: [PATCH] wxCmdLineParser tests git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5247 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/console/console.cpp | 78 ++++++++++++++++++++++++++++++++++++- samples/life/life.cpp | 5 ++- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 66584979ea..2ad4cca93e 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -30,18 +30,59 @@ // what to test? //#define TEST_ARRAYS +#define TEST_CMDLINE //#define TEST_DIR //#define TEST_LOG //#define TEST_LONGLONG //#define TEST_MIME //#define TEST_STRINGS -#define TEST_THREADS +//#define TEST_THREADS //#define TEST_TIME // ============================================================================ // implementation // ============================================================================ +#ifdef TEST_CMDLINE + +// ---------------------------------------------------------------------------- +// wxCmdLineParser +// ---------------------------------------------------------------------------- + +#include <wx/cmdline.h> +#include <wx/datetime.h> + +static void ShowCmdLine(const wxCmdLineParser& parser) +{ + wxString s = "Input files: "; + + size_t count = parser.GetParamCount(); + for ( size_t param = 0; param < count; param++ ) + { + s << parser.GetParam(param) << ' '; + } + + s << '\n' + << "Verbose:\t" << (parser.Found("v") ? "yes" : "no") << '\n' + << "Quiet:\t" << (parser.Found("q") ? "yes" : "no") << '\n'; + + wxString strVal; + long lVal; + wxDateTime dt; + if ( parser.Found("o", &strVal) ) + s << "Output file:\t" << strVal << '\n'; + if ( parser.Found("i", &strVal) ) + s << "Input dir:\t" << strVal << '\n'; + if ( parser.Found("s", &lVal) ) + s << "Size:\t" << lVal << '\n'; + if ( parser.Found("d", &dt) ) + s << "Date:\t" << dt.FormatISODate() << '\n'; + + wxLogMessage(s); +} + +#endif // TEST_CMDLINE + // ---------------------------------------------------------------------------- // wxDir // ---------------------------------------------------------------------------- @@ -1538,6 +1579,41 @@ int main(int argc, char **argv) fprintf(stderr, "Failed to initialize the wxWindows library, aborting."); } +#ifdef TEST_CMDLINE + static const wxCmdLineEntryDesc cmdLineDesc[] = + { + { wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" }, + { wxCMD_LINE_SWITCH, "q", "quiet", "be quiet" }, + + { wxCMD_LINE_OPTION, "o", "output", "output file" }, + { wxCMD_LINE_OPTION, "i", "input", "input dir" }, + { wxCMD_LINE_OPTION, "s", "size", "output block size", wxCMD_LINE_VAL_NUMBER }, + { wxCMD_LINE_OPTION, "d", "date", "output file date", wxCMD_LINE_VAL_NUMBER }, + + { wxCMD_LINE_PARAM, NULL, NULL, "input file", + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE }, + + { wxCMD_LINE_NONE } + }; + + wxCmdLineParser parser(cmdLineDesc, argc, argv); + + switch ( parser.Parse() ) + { + case -1: + wxLogMessage("Help was given, terminating."); + break; + + case 0: + ShowCmdLine(parser); + break; + + default: + wxLogMessage("Syntax error detected, aborting."); + break; + } +#endif // TEST_CMDLINE + #ifdef TEST_STRINGS if ( 0 ) { diff --git a/samples/life/life.cpp b/samples/life/life.cpp index 29a7d4d754..2f6871caab 100644 --- a/samples/life/life.cpp +++ b/samples/life/life.cpp @@ -522,7 +522,8 @@ LifeCanvas::LifeCanvas(wxWindow *parent, Life *life) { m_life = life; m_cellsize = 8; - m_bmp = NULL; + m_bmp = NULL; + Reset(); } @@ -812,7 +813,7 @@ bool Life::HasChanged(int x, int y) const { wxASSERT(x < m_width || y < m_height); - return (m_cells[y * m_width + x] & CELL_MARK); + return (m_cells[y * m_width + x] & CELL_MARK) != 0; } void Life::SetCell(int x, int y, bool alive) -- 2.47.2