// what to test (in alphabetic order)?
//#define TEST_ARRAYS
+//#define TEST_CHARSET
//#define TEST_CMDLINE
//#define TEST_DATETIME
//#define TEST_DIR
//#define TEST_HASH
//#define TEST_INFO_FUNCTIONS
//#define TEST_LIST
-#define TEST_LOCALE
+//#define TEST_LOCALE
//#define TEST_LOG
//#define TEST_LONGLONG
//#define TEST_MIME
//#define TEST_PATHLIST
+//#define TEST_REGCONF
//#define TEST_REGISTRY
+//#define TEST_SNGLINST
//#define TEST_SOCKETS
//#define TEST_STREAMS
-//#define TEST_STRINGS
+#define TEST_STRINGS
//#define TEST_THREADS
//#define TEST_TIMER
//#define TEST_VCARD -- don't enable this (VZ)
//#define TEST_ZIP
//#define TEST_ZLIB
-
-#ifdef TEST_DATETIME
-#include <math.h>
-#endif
-
+#ifdef TEST_SNGLINST
+ #include <wx/snglinst.h>
+#endif // TEST_SNGLINST
// ----------------------------------------------------------------------------
// test class for container objects
#endif // MakePrintable() is used
+// ----------------------------------------------------------------------------
+// wxFontMapper::CharsetToEncoding
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_CHARSET
+
+#include <wx/fontmap.h>
+
+static void TestCharset()
+{
+ static const wxChar *charsets[] =
+ {
+ // some vali charsets
+ _T("us-ascii "),
+ _T("iso8859-1 "),
+ _T("iso-8859-12 "),
+ _T("koi8-r "),
+ _T("utf-7 "),
+ _T("cp1250 "),
+ _T("windows-1252"),
+
+ // and now some bogus ones
+ _T(" "),
+ _T("cp1249 "),
+ _T("iso--8859-1 "),
+ _T("iso-8859-19 "),
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(charsets); n++ )
+ {
+ wxFontEncoding enc = wxTheFontMapper->CharsetToEncoding(charsets[n]);
+ wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"),
+ charsets[n],
+ wxTheFontMapper->GetEncodingName(enc).c_str(),
+ wxTheFontMapper->GetEncodingDescription(enc).c_str());
+ }
+}
+
+#endif // TEST_CHARSET
+
// ----------------------------------------------------------------------------
// wxCmdLineParser
// ----------------------------------------------------------------------------
#include <wx/dir.h>
+#ifdef __UNIX__
+ static const wxChar *ROOTDIR = _T("/");
+ static const wxChar *TESTDIR = _T("/usr");
+#elif defined(__WXMSW__)
+ static const wxChar *ROOTDIR = _T("c:\\");
+ static const wxChar *TESTDIR = _T("d:\\");
+#else
+ #error "don't know where the root directory is"
+#endif
+
static void TestDirEnumHelper(wxDir& dir,
int flags = wxDIR_DEFAULT,
const wxString& filespec = wxEmptyString)
static void TestDirEnum()
{
+ puts("*** Testing wxDir::GetFirst/GetNext ***");
+
wxDir dir(wxGetCwd());
puts("Enumerating everything in current directory:");
puts("Enumerating files including hidden in current directory:");
TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
-#ifdef __UNIX__
- dir.Open("/");
-#elif defined(__WXMSW__)
- dir.Open("c:\\");
-#else
- #error "don't know where the root directory is"
-#endif
+ dir.Open(ROOTDIR);
puts("Enumerating everything in root directory:");
TestDirEnumHelper(dir, wxDIR_DEFAULT);
TestDirEnumHelper(dirNo);
}
+class DirPrintTraverser : public wxDirTraverser
+{
+public:
+ virtual wxDirTraverseResult OnFile(const wxString& filename)
+ {
+ return wxDIR_CONTINUE;
+ }
+
+ virtual wxDirTraverseResult OnDir(const wxString& dirname)
+ {
+ wxString path, name, ext;
+ wxSplitPath(dirname, &path, &name, &ext);
+
+ if ( !ext.empty() )
+ name << _T('.') << ext;
+
+ wxString indent;
+ for ( const wxChar *p = path.c_str(); *p; p++ )
+ {
+ if ( wxIsPathSeparator(*p) )
+ indent += _T(" ");
+ }
+
+ printf("%s%s\n", indent.c_str(), name.c_str());
+
+ return wxDIR_CONTINUE;
+ }
+};
+
+static void TestDirTraverse()
+{
+ puts("*** Testing wxDir::Traverse() ***");
+
+ // enum all files
+ wxArrayString files;
+ size_t n = wxDir::GetAllFiles(TESTDIR, &files);
+ printf("There are %u files under '%s'\n", n, TESTDIR);
+ if ( n > 1 )
+ {
+ printf("First one is '%s'\n", files[0u].c_str());
+ printf(" last one is '%s'\n", files[n - 1].c_str());
+ }
+
+ // enum again with custom traverser
+ wxDir dir(TESTDIR);
+ DirPrintTraverser traverser;
+ dir.Traverse(traverser, _T(""), wxDIR_DIRS | wxDIR_HIDDEN);
+}
+
#endif // TEST_DIR
// ----------------------------------------------------------------------------
printf("After 2nd wxSetEnv: getenv(%s) = %s\n", var, MyGetEnv(var).c_str());
wxUnsetEnv(var);
printf("After wxUnsetEnv: getenv(%s) = %s\n", var, MyGetEnv(var).c_str());
- printf("PATH = %s\n", MyGetEnv(_T("PATH")));
+ printf("PATH = %s\n", MyGetEnv(_T("PATH")).c_str());
}
#endif // TEST_ENVIRON
_T("klingonese"), // I bet on some systems it does exist...
};
+ wxPrintf(_T("The default system encoding is %s (%d)\n"),
+ wxLocale::GetSystemEncodingName().c_str(),
+ wxLocale::GetSystemEncoding());
+
for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ )
{
const char *langStr = langStrings[n];
if ( langStr )
+ {
+ // FIXME: this doesn't do anything at all under Windows, we need
+ // to create a new wxLocale!
wxSetEnv(_T("LC_ALL"), langStr);
+ }
int lang = gs_localeDefault.GetSystemLanguage();
printf("Locale for '%s' is %s.\n",
static void TestLongLongComparison()
{
+#if wxUSE_LONGLONG_WX
puts("*** Testing wxLongLong comparison ***\n");
static const long testLongs[] =
res == (ls[m] == testLongs[n]) ? "ok" : "ERROR");
}
}
+#endif // wxUSE_LONGLONG_WX
}
#undef MAKE_LL
#endif // TEST_PATHLIST
// ----------------------------------------------------------------------------
-// registry
+// registry and related stuff
// ----------------------------------------------------------------------------
// this is for MSW only
#ifndef __WXMSW__
+ #undef TEST_REGCONF
#undef TEST_REGISTRY
#endif
+#ifdef TEST_REGCONF
+
+#include <wx/confbase.h>
+#include <wx/msw/regconf.h>
+
+static void TestRegConfWrite()
+{
+ wxRegConfig regconf(_T("console"), _T("wxwindows"));
+ regconf.Write(_T("Hello"), wxString(_T("world")));
+}
+
+#endif // TEST_REGCONF
+
#ifdef TEST_REGISTRY
#include <wx/msw/registry.h>
#ifdef TEST_DATETIME
+#include <math.h>
+
#include <wx/date.h>
#include <wx/datetime.h>
puts("");
}
+static void TestStringMatch()
+{
+ wxPuts(_T("*** Testing wxString::Matches() ***"));
+
+ static const struct StringMatchTestData
+ {
+ const wxChar *text;
+ const wxChar *wildcard;
+ bool matches;
+ } stringMatchTestData[] =
+ {
+ { _T("foobar"), _T("foo*"), 1 },
+ { _T("foobar"), _T("*oo*"), 1 },
+ { _T("foobar"), _T("*bar"), 1 },
+ { _T("foobar"), _T("??????"), 1 },
+ { _T("foobar"), _T("f??b*"), 1 },
+ { _T("foobar"), _T("f?b*"), 0 },
+ { _T("foobar"), _T("*goo*"), 0 },
+ { _T("foobar"), _T("*foo"), 0 },
+ { _T("foobarfoo"), _T("*foo"), 1 },
+ { _T(""), _T("*"), 1 },
+ { _T(""), _T("?"), 0 },
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(stringMatchTestData); n++ )
+ {
+ const StringMatchTestData& data = stringMatchTestData[n];
+ bool matches = wxString(data.text).Matches(data.wildcard);
+ wxPrintf(_T("'%s' %s '%s' (%s)\n"),
+ data.wildcard,
+ matches ? _T("matches") : _T("doesn't match"),
+ data.text,
+ matches == data.matches ? _T("ok") : _T("ERROR"));
+ }
+
+ wxPuts(_T(""));
+}
+
#endif // TEST_STRINGS
// ----------------------------------------------------------------------------
int main(int argc, char **argv)
{
- if ( !wxInitialize() )
+ wxInitializer initializer;
+ if ( !initializer )
{
fprintf(stderr, "Failed to initialize the wxWindows library, aborting.");
+
+ return -1;
}
-#ifdef TEST_USLEEP
- puts("Sleeping for 3 seconds... z-z-z-z-z...");
- wxUsleep(3000);
-#endif // TEST_USLEEP
+#ifdef TEST_SNGLINST
+ wxSingleInstanceChecker checker;
+ if ( checker.Create(_T(".wxconsole.lock")) )
+ {
+ if ( checker.IsAnotherRunning() )
+ {
+ wxPrintf(_T("Another instance of the program is running, exiting.\n"));
+
+ return 1;
+ }
+
+ // wait some time to give time to launch another instance
+ wxPrintf(_T("Press \"Enter\" to continue..."));
+ wxFgetc(stdin);
+ }
+ else // failed to create
+ {
+ wxPrintf(_T("Failed to init wxSingleInstanceChecker.\n"));
+ }
+#endif // TEST_SNGLINST
+
+#ifdef TEST_CHARSET
+ TestCharset();
+#endif // TEST_CHARSET
#ifdef TEST_CMDLINE
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
TestPChar();
TestString();
- }
TestStringSub();
- if ( 0 )
- {
TestStringConstruction();
TestStringFormat();
TestStringFind();
TestStringTokenizer();
TestStringReplace();
}
+ TestStringMatch();
#endif // TEST_STRINGS
#ifdef TEST_ARRAYS
#endif // TEST_ARRAYS
#ifdef TEST_DIR
- TestDirEnum();
+ if ( 0 )
+ TestDirEnum();
+ TestDirTraverse();
#endif // TEST_DIR
#ifdef TEST_DLLLOADER
TestPathList();
#endif // TEST_PATHLIST
+#ifdef TEST_REGCONF
+ TestRegConfWrite();
+#endif // TEST_REGCONF
+
#ifdef TEST_REGISTRY
if ( 0 )
TestRegistryRead();
TestDateTimeInteractive();
#endif // TEST_DATETIME
+#ifdef TEST_USLEEP
+ puts("Sleeping for 3 seconds... z-z-z-z-z...");
+ wxUsleep(3000);
+#endif // TEST_USLEEP
+
#ifdef TEST_VCARD
if ( 0 )
TestVCardRead();
TestZlibStreamRead();
#endif // TEST_ZLIB
- wxUninitialize();
-
return 0;
}