#include "wx/defs.h"
-#if wxUSE_GUI
- #error "This sample can't be compiled in GUI mode."
-#endif // wxUSE_GUI
-
#include <stdio.h>
#include "wx/string.h"
tests individually in the "#else" branch below.
*/
-// what to test (in alphabetic order)? uncomment the line below to do all tests
-//#define TEST_ALL
-#ifdef TEST_ALL
+// what to test (in alphabetic order)? Define TEST_ALL to 0 to do a single
+// test, define it to 1 to do all tests.
+#define TEST_ALL 0
+
+
+#if TEST_ALL
+
#define TEST_ARRAYS
#define TEST_CHARSET
#define TEST_CMDLINE
#define TEST_FILECONF
#define TEST_FILENAME
#define TEST_FILETIME
- #define TEST_FTP
+ // #define TEST_FTP --FIXME! (RN)
#define TEST_HASH
#define TEST_HASHMAP
#define TEST_HASHSET
#define TEST_REGISTRY
#define TEST_SCOPEGUARD
#define TEST_SNGLINST
- #define TEST_SOCKETS
+// #define TEST_SOCKETS --FIXME! (RN)
#define TEST_STREAMS
#define TEST_STRINGS
#define TEST_TEXTSTREAM
#define TEST_TIMER
#define TEST_UNICODE
// #define TEST_VCARD -- don't enable this (VZ)
- #define TEST_VOLUME
+// #define TEST_VOLUME --FIXME! (RN)
#define TEST_WCHAR
#define TEST_ZIP
#define TEST_ZLIB
+ #define TEST_GZIP
- #undef TEST_ALL
- static const bool TEST_ALL = true;
-#else
- #define TEST_HASHSET
+#else // #if TEST_ALL
+
+ #define TEST_FILENAME
- static const bool TEST_ALL = false;
#endif
// some tests are interactive, define this to run them
#ifdef TEST_INTERACTIVE
#undef TEST_INTERACTIVE
- static const bool TEST_INTERACTIVE = true;
+ #define TEST_INTERACTIVE 1
#else
- static const bool TEST_INTERACTIVE = false;
+ #define TEST_INTERACTIVE 0
#endif
// ----------------------------------------------------------------------------
cont = dir.GetNext(&filename);
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestDirEnum()
TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT);
wxPuts(_T("Enumerating object files in current directory:"));
- TestDirEnumHelper(dir, wxDIR_DEFAULT, "*.o*");
+ TestDirEnumHelper(dir, wxDIR_DEFAULT, _T("*.o*"));
wxPuts(_T("Enumerating directories in current directory:"));
TestDirEnumHelper(dir, wxDIR_DIRS);
TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
wxPuts(_T("Enumerating files in non existing directory:"));
- wxDir dirNo("nosuchdir");
+ wxDir dirNo(_T("nosuchdir"));
TestDirEnumHelper(dirNo);
}
class DirPrintTraverser : public wxDirTraverser
{
public:
- virtual wxDirTraverseResult OnFile(const wxString& filename)
+ virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename))
{
return wxDIR_CONTINUE;
}
wxPuts(_T("Now enumerating directories:"));
wxDir dir(TESTDIR);
DirPrintTraverser traverser;
- dir.Traverse(traverser, _T(""), wxDIR_DIRS | wxDIR_HIDDEN);
+ dir.Traverse(traverser, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN);
}
static void TestDirExists()
wxPrintf(_T("Testing wxShell: "));
fflush(stdout);
- if ( wxShell(SHELL_COMMAND) )
+ if ( wxShell(_T(SHELL_COMMAND)) )
wxPuts(_T("Ok."));
else
wxPuts(_T("ERROR."));
wxPrintf(_T("Testing wxExecute: "));
fflush(stdout);
- if ( wxExecute(COMMAND, true /* sync */) == 0 )
+ if ( wxExecute(_T(COMMAND), true /* sync */) == 0 )
wxPuts(_T("Ok."));
else
wxPuts(_T("ERROR."));
wxPrintf(_T("Testing wxExecute with redirection:\n"));
wxArrayString output;
- if ( wxExecute(REDIRECT_COMMAND, output) != 0 )
+ if ( wxExecute(_T(REDIRECT_COMMAND), output) != 0 )
{
wxPuts(_T("ERROR."));
}
wxPrintf(_T("ERROR: can't open test file.\n"));
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestTextFileRead()
wxPrintf(_T("ERROR: can't open '%s'\n"), file.GetName());
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestFileCopy()
}
else
{
- wxFFile f1(filename1, "rb"),
- f2(filename2, "rb");
+ wxFFile f1(filename1, _T("rb")),
+ f2(filename2, _T("rb"));
if ( !f1.IsOpened() || !f2.IsOpened() )
{
wxPuts(_T("ERROR: failed to remove the file"));
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
#endif // TEST_FILE
#include "wx/filename.h"
-static void DumpFileName(const wxFileName& fn)
+#if 0
+static void DumpFileName(const wxChar *desc, const wxFileName& fn)
{
+ wxPuts(desc);
+
wxString full = fn.GetFullPath();
wxString vol, path, name, ext;
wxPrintf(_T("\t%u: %s\n"), n, dirs[n].c_str());
}
}
+#endif
static struct FileNameInfo
{
isAbsolute ? "absolute" : "relative",
isAbsolute == fni.isAbsolute ? "ok" : "ERROR");
- if ( !fn.Normalize(wxPATH_NORM_ALL, _T(""), fni.format) )
+ if ( !fn.Normalize(wxPATH_NORM_ALL, wxEmptyString, fni.format) )
{
wxPuts(_T("ERROR (couldn't be normalized)"));
}
}
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestFileNameSplit()
if ( ext != fni.ext )
wxPrintf(_T(" (ERROR: ext = '%s')"), fni.ext);
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
}
switch ( fni.format )
{
case wxPATH_UNIX:
- base = "/usr/bin/";
+ base = _T("/usr/bin/");
break;
case wxPATH_DOS:
- base = "c:\\";
+ base = _T("c:\\");
break;
case wxPATH_MAC:
case wxPATH_NATIVE: // make gcc happy
default:
- wxFAIL_MSG( "unexpected path format" );
+ wxFAIL_MSG( _T("unexpected path format") );
}
wxPrintf(_T("'%s' relative to '%s': "),
wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str());
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
+}
+
+static void TestFileNameDirManip()
+{
+ // TODO: test AppendDir(), RemoveDir(), ...
}
static void TestFileNameComparison()
}
}
+#if 0
static void TestFileSetTimes()
{
wxFileName fn(_T("testdata.fc"));
wxPrintf(_T("ERROR: Touch() failed.\n"));
}
}
+#endif
#endif // TEST_FILETIME
WX_DEFINE_LIST(wxListFoos);
+#include "wx/timer.h"
+
static void TestHash()
{
wxPuts(_T("*** Testing wxHashTable ***\n"));
+ const int COUNT = 100;
+
+ wxStopWatch sw;
+
+ sw.Start();
{
wxHashTable hash(wxKEY_INTEGER, 10), hash2(wxKEY_STRING);
wxObject o;
int i;
- for ( i = 0; i < 100; ++i )
+ for ( i = 0; i < COUNT; ++i )
hash.Put(i, &o + i);
hash.BeginFind();
it = hash.Next();
}
- if (i != 100)
+ if (i != COUNT)
wxPuts(_T("Error in wxHashTable::compatibility_iterator\n"));
for ( i = 99; i >= 0; --i )
if( hash.Get(i) != &o + i )
wxPuts(_T("Error in wxHashTable::Get/Put\n"));
- for ( i = 0; i < 100; ++i )
+ for ( i = 0; i < COUNT; ++i )
hash.Put(i, &o + i + 20);
for ( i = 99; i >= 0; --i )
if( hash.Get(i) != &o + i)
wxPuts(_T("Error (2) in wxHashTable::Get/Put\n"));
- for ( i = 0; i < 50; ++i )
+ for ( i = 0; i < COUNT/2; ++i )
if( hash.Delete(i) != &o + i)
wxPuts(_T("Error in wxHashTable::Delete\n"));
- for ( i = 50; i < 100; ++i )
+ for ( i = COUNT/2; i < COUNT; ++i )
if( hash.Get(i) != &o + i)
wxPuts(_T("Error (3) in wxHashTable::Get/Put\n"));
- for ( i = 0; i < 50; ++i )
+ for ( i = 0; i < COUNT/2; ++i )
if( hash.Get(i) != &o + i + 20)
wxPuts(_T("Error (4) in wxHashTable::Put/Delete\n"));
- for ( i = 0; i < 50; ++i )
+ for ( i = 0; i < COUNT/2; ++i )
if( hash.Delete(i) != &o + i + 20)
wxPuts(_T("Error (2) in wxHashTable::Delete\n"));
- for ( i = 0; i < 50; ++i )
+ for ( i = 0; i < COUNT/2; ++i )
if( hash.Get(i) != NULL)
wxPuts(_T("Error (5) in wxHashTable::Put/Delete\n"));
if (hash2.Get(_T("bar")) != &o + 2)
wxPuts(_T("Error (2) in wxHashTable::Get/Put\n"));
}
-#if !wxUSE_STL
+
+ // and now some corner-case testing; 3 and 13 hash to the same bucket
+ {
+ wxHashTable hash(wxKEY_INTEGER, 10);
+ wxObject dummy;
+
+ hash.Put(3, &dummy);
+ hash.Delete(3);
+
+ if (hash.Get(3) != NULL)
+ wxPuts(_T("Corner case 1 failure\n"));
+
+ hash.Put(3, &dummy);
+ hash.Put(13, &dummy);
+ hash.Delete(3);
+
+ if (hash.Get(3) != NULL)
+ wxPuts(_T("Corner case 2 failure\n"));
+
+ hash.Delete(13);
+
+ if (hash.Get(13) != NULL)
+ wxPuts(_T("Corner case 3 failure\n"));
+
+ hash.Put(3, &dummy);
+ hash.Put(13, &dummy);
+ hash.Delete(13);
+
+ if (hash.Get(13) != NULL)
+ wxPuts(_T("Corner case 4 failure\n"));
+
+ hash.Delete(3);
+
+ if (hash.Get(3) != NULL)
+ wxPuts(_T("Corner case 5 failure\n"));
+ }
+
+ {
+ wxHashTable hash(wxKEY_INTEGER, 10);
+ wxObject dummy;
+
+ hash.Put(3, 7, &dummy + 7);
+ hash.Put(4, 8, &dummy + 8);
+
+ if (hash.Get(7) != NULL) wxPuts(_T("Key/Hash 1 failure\n"));
+ if (hash.Get(3, 7) != &dummy + 7) wxPuts(_T("Key/Hash 2 failure\n"));
+ if (hash.Get(4) != NULL) wxPuts(_T("Key/Hash 3 failure\n"));
+ if (hash.Get(3) != NULL) wxPuts(_T("Key/Hash 4 failure\n"));
+ if (hash.Get(8) != NULL) wxPuts(_T("Key/Hash 5 failure\n"));
+ if (hash.Get(8, 4) != NULL) wxPuts(_T("Key/Hash 6 failure\n"));
+
+ if (hash.Delete(7) != NULL) wxPuts(_T("Key/Hash 7 failure\n"));
+ if (hash.Delete(3) != NULL) wxPuts(_T("Key/Hash 8 failure\n"));
+ if (hash.Delete(3, 7) != &dummy + 7) wxPuts(_T("Key/Hash 8 failure\n"));
+ }
+
{
wxHashFoos hash;
hash.DeleteContents(true);
{
wxPuts(_T("ok (not found)"));
}
+
+ Foo* foo = hash.Delete(0);
+
+ wxPrintf(_T("Removed 1 foo: %u foos still there\n"), Foo::count);
+
+ delete foo;
+
+ wxPrintf(_T("Foo deleted: %u foos left\n"), Foo::count);
}
-#endif
wxPrintf(_T("Hash destroyed: %u foos left\n"), Foo::count);
wxPuts(_T("*** Testing wxHashTable finished ***\n"));
+
+ wxPrintf(_T("Time: %ld\n"), sw.Time());
}
#endif // TEST_HASH
if ( *it != i + &i )
wxPuts(_T("Error in erase()\n"));
}
-
+
wxPuts(_T("*** Testing std::list operations finished ***\n"));
}
mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestMimeOverride()
wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
mimetypes);
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestMimeFilename()
wxString cmd;
if ( !ft->GetOpenCommand(&cmd,
- wxFileType::MessageParameters(fname, _T(""))) )
+ wxFileType::MessageParameters(fname, wxEmptyString)) )
cmd = _T("<no command available>");
else
cmd = wxString(_T('"')) + cmd + _T('"');
}
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestMimeAssociate()
delete ft;
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
#endif // TEST_MIME
wxPrintf(_T("Host name is %s (%s).\n"),
wxGetHostName().c_str(), wxGetFullHostName().c_str());
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestUserInfo()
wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
#endif // TEST_INFO_FUNCTIONS
{ return a.GetHi() == b.GetHi() && a.GetLo() == b.GetLo(); }
#endif // wxUSE_LONGLONG_WX
+#if 0
static void TestSpeed()
{
static const long max = 100000000;
{
l += n;
}
+ wxUnusedVar(l);
wxPrintf(_T("Summing longs took %ld milliseconds.\n"), sw.Time());
}
{
l += n;
}
+ wxUnusedVar(l);
wxPrintf(_T("Summing wxLongLong_t took %ld milliseconds.\n"), sw.Time());
}
wxPrintf(_T("Summing wxLongLongs took %ld milliseconds.\n"), sw.Time());
}
}
+#endif
static void TestLongLongConversion()
{
wxPuts(_T("*** Testing wxLongLong conversions ***\n"));
- wxLongLong a;
size_t nTested = 0;
for ( size_t n = 0; n < 100000; n++ )
{
- a = RAND_LL();
-
#if wxUSE_LONGLONG_NATIVE
+ wxLongLong a = RAND_LL();
+
wxLongLongNative b(a.GetHi(), a.GetLo());
- wxASSERT_MSG( a == b, "conversions failure" );
+ if( a != b)
+ wxPuts( _T("conversions failure") );
#else
wxPuts(_T("Can't do it without native long long type, test skipped."));
if ( !(nTested % 1000) )
{
- putchar('.');
+ wxPutchar('.');
fflush(stdout);
}
{
wxPuts(_T("*** Testing wxLongLong multiplication ***\n"));
- wxLongLong a, b;
size_t nTested = 0;
for ( size_t n = 0; n < 100000; n++ )
{
- a = RAND_LL();
- b = RAND_LL();
-
#if wxUSE_LONGLONG_NATIVE
+ wxLongLong a = RAND_LL();
+ wxLongLong b = RAND_LL();
+
wxLongLongNative aa(a.GetHi(), a.GetLo());
wxLongLongNative bb(b.GetHi(), b.GetLo());
- wxASSERT_MSG( a*b == aa*bb, "multiplication failure" );
+ if( a*b != aa*bb )
+ wxPuts( _T("multiplication failure") );
#else // !wxUSE_LONGLONG_NATIVE
wxPuts(_T("Can't do it without native long long type, test skipped."));
if ( !(nTested % 1000) )
{
- putchar('.');
+ wxPutchar('.');
fflush(stdout);
}
wxLongLongNative m(ll.GetHi(), ll.GetLo());
wxLongLongNative p = m / l, s = m % l;
- wxASSERT_MSG( q == p && r == s, "division failure" );
+
+ if(q != p || r != s)
+ wxPuts( _T("division failure") );
#else // !wxUSE_LONGLONG_NATIVE
// verify the result
wxASSERT_MSG( ll == q*l + r, "division failure" );
if ( !(nTested % 1000) )
{
- putchar('.');
+ wxPutchar('.');
fflush(stdout);
}
#if wxUSE_LONGLONG_NATIVE
wxASSERT_MSG( c == wxLongLongNative(a.GetHi(), a.GetLo()) +
wxLongLongNative(b.GetHi(), b.GetLo()),
- "addition failure" );
+ _T("addition failure") );
#else // !wxUSE_LONGLONG_NATIVE
wxASSERT_MSG( c - b == a, "addition failure" );
#endif // wxUSE_LONGLONG_NATIVE
if ( !(nTested % 1000) )
{
- putchar('.');
+ wxPutchar('.');
fflush(stdout);
}
if ( !(nTested % 1000) )
{
- putchar('.');
+ wxPutchar('.');
fflush(stdout);
}
wxPuts(_T("*** Testing wxLongLong printing ***\n"));
#ifdef wxLongLongFmtSpec
+#ifndef __MINGW32__
wxLongLong ll = wxLL(0x1234567890abcdef);
wxString s = wxString::Format(_T("%") wxLongLongFmtSpec _T("x"), ll);
+#else
+ wxString s = _T("MinGW compiler does not allow wxLongLong in '...'");
+#endif
wxPrintf(_T("0x1234567890abcdef -> %s (%s)\n"),
s.c_str(), s == _T("1234567890abcdef") ? _T("ok") : _T("ERROR"));
#else // !wxLongLongFmtSpec
wxPrintf(_T("'%s' is %sa valid RE (%s)\n"),
data.pattern,
- ok ? _T("") : _T("not "),
+ ok ? wxEmptyString : _T("not "),
ok == data.correct ? _T("ok") : _T("ERROR"));
}
}
wxPrintf(_T("%s =~ s/RE/%s/g: %u match%s, result = '%s' ("),
data.text, data.repl,
- nRepl, nRepl == 1 ? _T("") : _T("es"),
+ nRepl, nRepl == 1 ? wxEmptyString : _T("es"),
text.c_str());
if ( text == data.result && nRepl == data.count )
{
* This exercises the output formatting code.
*/
+wxChar *PointerNull = NULL;
+
static void
fp_test (void)
{
}
}
}
- wxPrintf(_T("%10s\n"), (wxChar *) NULL);
- wxPrintf(_T("%-10s\n"), (wxChar *) NULL);
+ wxPrintf(_T("%10s\n"), PointerNull);
+ wxPrintf(_T("%-10s\n"), PointerNull);
}
static void TestPrintf()
static wxChar longstr[] = _T("Good morning, Doctor Chandra. This is Hal. \
I am ready for my first lesson today.");
int result = 0;
+ wxString test_format;
fmtchk(_T("%.4x"));
fmtchk(_T("%04x"));
fmtst2chk(_T("%*.*x"));
fmtst2chk(_T("%0*.*x"));
- wxPrintf(_T("bad format:\t\"%b\"\n"));
+ wxString bad_format = _T("bad format:\t\"%b\"\n");
+ wxPrintf(bad_format.c_str());
wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL);
wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345);
wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L);
wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L);
wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L);
- wxPrintf(_T("left-adjusted ZLDN:\t\"%-010ld\"\n"), -123456);
+ test_format = _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
+ wxPrintf(test_format.c_str(), -123456);
wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
- wxPrintf(_T("zero-padded string:\t\"%010s\"\n"), shortstr);
- wxPrintf(_T("left-adjusted Z string:\t\"%-010s\"\n"), shortstr);
+ test_format = _T("zero-padded string:\t\"%010s\"\n");
+ wxPrintf(test_format.c_str(), shortstr);
+ test_format = _T("left-adjusted Z string:\t\"%-010s\"\n");
+ wxPrintf(test_format.c_str(), shortstr);
wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr);
wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr);
- wxPrintf(_T("null string:\t\"%s\"\n"), (wxChar *)NULL);
+ wxPrintf(_T("null string:\t\"%s\"\n"), PointerNull);
wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr);
wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34);
fflush (stdout);
}
+#ifndef __WATCOMC__
+ // Open Watcom cause compiler error here
+ // Error! E173: col(24) floating-point constant too small to represent
wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
+#endif
#define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n")
wxPrintf (FORMAT, 0.0, 0.0, 0.0);
wxChar buf[200];
wxSprintf(buf, _T("%07") wxLongLongFmtSpec _T("o"), wxLL(040000000000));
+ #if 0
+ // for some reason below line fails under Borland
wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf);
+ #endif
if (wxStrcmp (buf, _T("40000000000")) != 0)
{
result = 1;
wxPuts (_T("\tFAILED"));
}
- wxPuts (_T(""));
+ wxUnusedVar(result);
+ wxPuts (wxEmptyString);
}
#endif // wxLongLong_t
{
int prec;
wxChar buf[100];
+ wxString test_format;
prec = 0;
wxSprintf (buf, _T("%.*g"), prec, 3.3);
if (wxStrcmp (buf, _T(" 3")) != 0)
wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3"));
prec = 3;
- wxSprintf (buf, _T("%04.*o"), prec, 33);
+ test_format = _T("%04.*o");
+ wxSprintf (buf, test_format.c_str(), prec, 33);
if (wxStrcmp (buf, _T(" 041")) != 0)
wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 041"));
prec = 7;
- wxSprintf (buf, _T("%09.*u"), prec, 33);
+ test_format = _T("%09.*u");
+ wxSprintf (buf, test_format.c_str(), prec, 33);
if (wxStrcmp (buf, _T(" 0000033")) != 0)
wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 0000033"));
prec = 3;
- wxSprintf (buf, _T("%04.*x"), prec, 33);
+ test_format = _T("%04.*x");
+ wxSprintf (buf, test_format.c_str(), prec, 33);
if (wxStrcmp (buf, _T(" 021")) != 0)
wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021"));
prec = 3;
- wxSprintf (buf, _T("%04.*X"), prec, 33);
+ test_format = _T("%04.*X");
+ wxSprintf (buf, test_format.c_str(), prec, 33);
if (wxStrcmp (buf, _T(" 021")) != 0)
wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021"));
}
#include "wx/confbase.h"
#include "wx/msw/regconf.h"
+#if 0
static void TestRegConfWrite()
{
- wxRegConfig regconf(_T("console"), _T("wxwindows"));
- regconf.Write(_T("Hello"), wxString(_T("world")));
+ wxConfig *config = new wxConfig(_T("myapp"));
+ config->SetPath(_T("/group1"));
+ config->Write(_T("entry1"), _T("foo"));
+ config->SetPath(_T("/group2"));
+ config->Write(_T("entry1"), _T("bar"));
+}
+#endif
+
+static void TestRegConfRead()
+{
+ wxConfig *config = new wxConfig(_T("myapp"));
+
+ wxString str;
+ long dummy;
+ config->SetPath(_T("/"));
+ wxPuts(_T("Enumerating / subgroups:"));
+ bool bCont = config->GetFirstGroup(str, dummy);
+ while(bCont)
+ {
+ wxPuts(str);
+ bCont = config->GetNextGroup(str, dummy);
+ }
}
#endif // TEST_REGCONF
wxPrintf(_T(" (raw value '%s')"), val.c_str());
}
- putchar('\n');
+ wxPutchar('\n');
cont = key.GetNextValue(value, dummy);
}
wxRegKey key;
- key.SetName("HKEY_CLASSES_ROOT\\.ddf" );
+ key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
key.Create();
- key = "ddxf_auto_file" ;
- key.SetName("HKEY_CLASSES_ROOT\\.flo" );
+ key = _T("ddxf_auto_file") ;
+ key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
key.Create();
- key = "ddxf_auto_file" ;
- key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
+ key = _T("ddxf_auto_file") ;
+ key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
key.Create();
- key = "program,0" ;
- key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
+ key = _T("program,0") ;
+ key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
key.Create();
- key = "program \"%1\"" ;
+ key = _T("program \"%1\"") ;
- key.SetName("HKEY_CLASSES_ROOT\\.ddf" );
+ key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
key.DeleteSelf();
- key.SetName("HKEY_CLASSES_ROOT\\.flo" );
+ key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
key.DeleteSelf();
- key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
+ key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
key.DeleteSelf();
- key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
+ key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
key.DeleteSelf();
}
static void TestScopeGuard()
{
- ON_BLOCK_EXIT0(function0);
- ON_BLOCK_EXIT1(function1, 17);
- ON_BLOCK_EXIT2(function2, 3.14, 'p');
+ wxON_BLOCK_EXIT0(function0);
+ wxON_BLOCK_EXIT1(function1, 17);
+ wxON_BLOCK_EXIT2(function2, 3.14, 'p');
Object obj;
- ON_BLOCK_EXIT_OBJ0(obj, &Object::method0);
- ON_BLOCK_EXIT_OBJ1(obj, &Object::method1, 7);
- ON_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();
{
wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
- if ( ftp.SendCommand("STAT") != '2' )
+ if ( ftp.SendCommand(_T("STAT")) != '2' )
{
wxPuts(_T("ERROR: STAT failed"));
}
wxPrintf(_T("STAT returned:\n\n%s\n"), ftp.GetLastResult().c_str());
}
- if ( ftp.SendCommand("HELP SITE") != '2' )
+ if ( ftp.SendCommand(_T("HELP SITE")) != '2' )
{
wxPuts(_T("ERROR: HELP SITE failed"));
}
// special handling of LIST and NLST as they require data connection
wxString start(buf, 4);
start.MakeUpper();
- if ( start == "LIST" || start == "NLST" )
+ if ( start == _T("LIST") || start == _T("NLST") )
{
wxString wildcard;
if ( wxStrlen(buf) > 4 )
wildcard = buf + 5;
wxArrayString files;
- if ( !ftp.GetList(files, wildcard, start == "LIST") )
+ if ( !ftp.GetList(files, wildcard, start == _T("LIST")) )
{
wxPrintf(_T("ERROR: failed to get %s of files\n"), start.c_str());
}
}
// send a command to check the remote file
- if ( ftp.SendCommand(wxString("STAT ") + file1) != '2' )
+ if ( ftp.SendCommand(wxString(_T("STAT ")) + file1) != '2' )
{
wxPrintf(_T("ERROR: STAT %s failed\n"), file1);
}
{
wxPuts(_T("*** Testing wxFileInputStream ***"));
- static const wxChar *filename = _T("testdata.fs");
+ static const wxString filename = _T("testdata.fs");
{
wxFileOutputStream fsOut(filename);
fsOut.Write("foo", 3);
wxPrintf(_T("File stream size: %u\n"), fsIn.GetSize());
while ( !fsIn.Eof() )
{
- putchar(fsIn.GetC());
+ wxPutchar(fsIn.GetC());
}
if ( !wxRemoveFile(filename) )
{
- wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename);
+ wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename.c_str());
}
wxPuts(_T("\n*** wxFileInputStream test done ***"));
wxPrintf(_T("Memory stream size: %u\n"), memInpStream.GetSize());
while ( !memInpStream.Eof() )
{
- putchar(memInpStream.GetC());
+ wxPutchar(memInpStream.GetC());
}
wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
}
}
- putchar('.');
+ wxPutchar('.');
fflush(stdout);
}
if ( !!value )
wxPrintf(_T(" = %s"), value.c_str());
- putchar('\n');
+ wxPutchar('\n');
DumpVObject(level + 1, *vcObj);
wxPutchar(_T('\n'));
}
+#include "wx/textfile.h"
+
+static void TestUnicodeTextFileRead()
+{
+ wxPuts(_T("Testing wxTextFile in Unicode build\n"));
+
+ wxTextFile file;
+ if ( file.Open(_T("testdata.fc"), wxConvLocal) )
+ {
+ const size_t count = file.GetLineCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ const wxString& s = file[n];
+
+ wxPrintf(_T("Line %u: \"%s\" (len %u, last char = '%c')\n"),
+ (unsigned)n, s.c_str(), (unsigned)s.length(), s.Last());
+ }
+ }
+}
+
#endif // TEST_UNICODE
#ifdef TEST_WCHAR
}
}
- wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text), *wxConvCurrent);
+ wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text));
if ( s.empty() )
s = _T("<< conversion failed >>");
wxPrintf(_T("String in current cset: %s\n"), s.c_str());
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestEncodingConverter()
wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf);
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
#endif // TEST_WCHAR
{
wxPuts(_T("*** Testing ZIP reading ***\n"));
- static const wxChar *filename = _T("foo");
+ static const wxString filename = _T("foo");
wxZipInputStream istr(TESTFILE_ZIP, filename);
wxPrintf(_T("Archive size: %u\n"), istr.GetSize());
- wxPrintf(_T("Dumping the file '%s':\n"), filename);
+ wxPrintf(_T("Dumping the file '%s':\n"), filename.c_str());
while ( !istr.Eof() )
{
- putchar(istr.GetC());
+ wxPutchar(istr.GetC());
fflush(stdout);
}
#include "wx/zstream.h"
#include "wx/wfstream.h"
-static const wxChar *FILENAME_GZ = _T("test.gz");
+static const wxString FILENAME_GZ = _T("test.gz");
static const wxChar *TEST_DATA = _T("hello and hello and hello and hello and hello");
static void TestZlibStreamWrite()
wxPuts(_T("Dumping the file:"));
while ( !istr.Eof() )
{
- putchar(istr.GetC());
+ wxPutchar(istr.GetC());
fflush(stdout);
}
#endif // TEST_ZLIB
+// ----------------------------------------------------------------------------
+// Gzip streams
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_GZIP
+
+#include "wx/wfstream.h"
+#include "wx/gzstream.h"
+#include "wx/filename.h"
+#include "wx/txtstrm.h"
+
+// Reads two input streams and verifies that they are the same (and non-emtpy)
+//
+void GzipVerify(wxInputStream &in1, wxInputStream &in2)
+{
+ if (!in1 || !in2) {
+ wxPuts(_T(" Can't verify"));
+ return;
+ }
+
+ const int BUFSIZE = 8192;
+ wxCharBuffer buf1(BUFSIZE);
+ wxCharBuffer buf2(BUFSIZE);
+ bool none = true;
+
+ for (;;)
+ {
+ int n1 = in1.Read(buf1.data(), BUFSIZE).LastRead();
+ int n2 = in2.Read(buf2.data(), BUFSIZE).LastRead();
+
+ if (n1 != n2 || (n1 && memcmp(buf1, buf2, n1) != 0) || (!n1 && none)) {
+ wxPuts(_T(" Failure"));
+ break;
+ }
+
+ if (!n1) {
+ wxPuts(_T(" Success"));
+ break;
+ }
+
+ none = false;
+ }
+
+ while (in1.IsOk())
+ in1.Read(buf1.data(), BUFSIZE);
+ while (in2.IsOk())
+ in2.Read(buf2.data(), BUFSIZE);
+}
+
+// Write a gzip file and read it back.
+//
+void TestGzip()
+{
+ wxPuts(_T("*** Testing gzip streams ***\n"));
+
+ const wxString testname = _T("gziptest");
+ const wxString gzipname = testname + _T(".gz");
+
+ // write some random test data to a testfile
+ wxPuts(_T("Writing random test data to ") + testname + _T("..."));
+ {
+ wxFFileOutputStream outstream(testname);
+ wxTextOutputStream textout(outstream);
+
+ for (int i = 0; i < 1000 && outstream.Ok(); i++)
+ textout << rand() << rand() << rand() << rand() << endl;
+
+ wxPuts(_T(" Done"));
+ }
+
+ wxFileName fn(testname);
+ wxDateTime dt = fn.GetModificationTime();
+ wxFFileInputStream instream(testname);
+
+ // try writing a gzip file
+ wxPuts(_T("Writing ") + gzipname + _T(" using wxGzipOutputStream..."));
+ {
+ wxFFileOutputStream outstream(gzipname);
+ wxGzipOutputStream gzip(outstream, testname, dt);
+
+ if (!gzip.Write(instream))
+ wxPuts(_T(" Failure"));
+ else
+ wxPuts(_T(" Success"));
+ }
+
+ // try reading the gzip file
+ wxPuts(_T("Reading ") + gzipname + _T(" using wxGzipInputStream..."));
+ {
+ instream.SeekI(0);
+ wxFFileInputStream instream2(gzipname);
+ wxGzipInputStream gzip(instream2);
+ GzipVerify(instream, gzip);
+
+ if (gzip.GetName() != fn.GetFullName())
+ wxPuts(gzipname + _T(" contains incorrect filename: ")
+ + gzip.GetName());
+ if (dt.IsValid() && gzip.GetDateTime() != dt)
+ wxPuts(gzipname + _T(" contains incorrect timestamp: ")
+ + gzip.GetDateTime().Format());
+ }
+
+#ifdef __UNIX__
+ // then verify it using gzip program if it is in the path
+ wxPuts(_T("Reading ") + gzipname + _T(" using gzip program..."));
+ wxFFile file(popen((_T("gzip -d -c ") + gzipname).mb_str(), "r"));
+ if (file.fp()) {
+ wxFFileInputStream instream2(file);
+ instream.SeekI(0);
+ GzipVerify(instream, instream2);
+ pclose(file.fp());
+ file.Detach();
+ }
+
+ // try reading a gzip created by gzip program
+ wxPuts(_T("Reading output of gzip program using wxGzipInputStream..."));
+ file.Attach(popen((_T("gzip -c ") + testname).mb_str(), "r"));
+ if (file.fp()) {
+ wxFFileInputStream instream2(file);
+ wxGzipInputStream gzip(instream2);
+ instream.SeekI(0);
+ GzipVerify(instream, gzip);
+ pclose(file.fp());
+ file.Detach();
+ }
+#endif
+
+ wxPuts(_T("\n--- Done gzip streams ---"));
+}
+
+#endif // TEST_GZIP
+
// ----------------------------------------------------------------------------
// date time
// ----------------------------------------------------------------------------
}
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
// test conversions to JDN &c
}
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
// test SetToWeekDay()
struct WeekDateTestData
wxPuts(_T("\n*** wxDateTime DST test ***"));
wxPrintf(_T("DST is%s in effect now.\n\n"),
- wxDateTime::Now().IsDST() ? _T("") : _T(" not"));
+ wxDateTime::Now().IsDST() ? wxEmptyString : _T(" not"));
// taken from http://www.energy.ca.gov/daylightsaving.html
static const Date datesDST[2][2004 - 1900 + 1] =
}
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
for ( year = 1990; year < 2005; year++ )
{
for ( size_t d = 0; d < WXSIZEOF(formatTestDates) + 1; d++ )
{
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
wxDateTime dt = d == 0 ? wxDateTime::Now() : formatTestDates[d - 1].DT();
for ( size_t n = 0; n < WXSIZEOF(formatTestFormats); n++ )
}
if ( !(i % 100) )
- putchar('.');
+ wxPutchar('.');
}
wxPuts(_T(", done"));
wxPrintf(_T(" (ERROR: should be %s)\n"), dt2.FormatISODate().c_str());
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
}
wxPrintf(_T("\t%s\n"), hol[n].Format(format).c_str());
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestTimeZoneBug()
date += wxDateSpan::Day();
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestTimeSpanFormat()
ts2.Format(formats[n]).c_str());
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
#endif // TEST_DATETIME
{
wxPuts(_T("\n*** wxTextInputStream test ***"));
- wxFileInputStream fsIn(_T("testdata.fc"));
+ wxString filename = _T("testdata.fc");
+ wxFileInputStream fsIn(filename);
if ( !fsIn.Ok() )
{
wxPuts(_T("ERROR: couldn't open file."));
break;
}
- putchar(m_ch);
+ wxPutchar(m_ch);
fflush(stdout);
wxThread::Sleep(100);
// wait until all threads terminate
gs_cond.Wait();
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestJoinableThreads()
thread.Run();
wxPrintf(_T("\nThread terminated with exit code %lu.\n"),
- (unsigned long)thread.Wait());
+ (unsigned long)thread.Wait());
}
static void TestThreadSuspend()
// wait until the thread terminates
gs_cond.Wait();
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestThreadDelete()
wxPuts(_T("\nDeleted a joinable thread which already terminated."));
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
class MyWaitingThread : public wxThread
int m_i;
};
-WX_DEFINE_ARRAY(wxThread *, ArrayThreads);
+WX_DEFINE_ARRAY_PTR(wxThread *, ArrayThreads);
static void TestSemaphore()
{
if ( *it != i )
wxPuts(_T("Error in erase()\n"));
}
-
+
wxPuts(_T("*** Testing std::vector operations finished ***\n"));
}
{
ArrayBars bars;
- Bar bar("second bar (two copies!)");
+ Bar bar(_T("second bar (two copies!)"));
wxPrintf(_T("Initially: %u objects in the array, %u objects total.\n"),
bars.GetCount(), Bar::GetNumber());
- bars.Add(new Bar("first bar"));
+ bars.Add(new Bar(_T("first bar")));
bars.Add(bar,2);
wxPrintf(_T("Now: %u objects in the array, %u objects total.\n"),
const wxChar *end = wxStrchr(s, _T('!'));
TEST_CTOR((start, end), _T("really"));
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestString()
}
else
{
- putchar('\n');
+ wxPutchar('\n');
}
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestStringFormat()
wxPrintf(_T("Number 18: %s\n"), wxString::Format(_T("%03d"), 18).c_str());
wxPrintf(_T("Number 18: %s\n"), s.c_str());
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
// returns "not found" for npos, value for all others
}
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestStringTokenizer()
else
{
// nothing to compare with
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
}
delete [] buf;
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
static void TestStringReplace()
}
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
+#if !TEST_ALL
static void TestStringMatch()
{
wxPuts(_T("*** Testing wxString::Matches() ***"));
matches == data.matches ? _T("ok") : _T("ERROR"));
}
- wxPuts(_T(""));
+ wxPuts(wxEmptyString);
}
+#endif
// Sigh, I want Test::Simple, Test::More and Test::Harness...
void ok(int line, bool ok, const wxString& msg = wxEmptyString)
}
}
+#if 0
+void is(int line, const wxChar* got, const wxChar* expected,
+ const wxString& msg = wxEmptyString)
+{
+ bool isOk = wxStrcmp( got, expected ) == 0;
+ ok(line, isOk, msg);
+ if( !isOk )
+ {
+ wxPuts(_T("Got: ") + wxString(got));
+ wxPuts(_T("Expected: ") + wxString(expected));
+ }
+}
+#endif
+
void is(int line, const wxChar& got, const wxChar& expected,
const wxString& msg = wxEmptyString)
{
ok(line, isOk, msg);
if( !isOk )
{
- wxPuts("Got: " + got);
- wxPuts("Expected: " + expected);
+ wxPuts(_T("Got: ") + got);
+ wxPuts(_T("Expected: ") + expected);
+ }
+}
+
+void is(int line, size_t got, size_t expected,
+ const wxString& msg = wxEmptyString)
+{
+ bool isOk = got == expected;
+ ok(line, isOk, msg);
+ if( !isOk )
+ {
+ wxPuts(wxString::Format(_T("Got: %d"), got));
+ wxPuts(wxString::Format(_T("Expected: %d"), expected));
}
}
+#define is_m( got, expected, message ) is( __LINE__, (got), (expected), (message) )
+#define is_nom( got, expected ) is( __LINE__, (got), (expected), wxEmptyString )
+
void TestStdString()
{
wxPuts(_T("*** Testing std::string operations ***\n"));
is( __LINE__, *it2, _T('g') );
ok( __LINE__, it3 == s7.end() );
+ // find
+ // 0 1 2
+ // 01234567890123456789012345
+ s1 = _T("abcdefgABCDEFGabcABCabcABC");
+ s2 = _T("gAB");
+
+ is_nom( s1.find(_T('A')), 7u );
+ is_nom( s1.find(_T('A'), 7), 7u );
+ is_nom( s1.find(_T('Z')), wxString::npos );
+ is_nom( s1.find(_T('C'), 22), 25u );
+
+ is_nom( s1.find(_T("gAB")), 6u );
+ is_nom( s1.find(_T("gAB"), 7), wxString::npos );
+ is_nom( s1.find(_T("gAB"), 6), 6u );
+
+ is_nom( s1.find(_T("gABZZZ"), 2, 3), 6u );
+ is_nom( s1.find(_T("gABZZZ"), 7, 3), wxString::npos );
+
+ is_nom( s1.find(s2), 6u );
+ is_nom( s1.find(s2, 7), wxString::npos );
+ is_nom( s1.find(s2, 6), 6u );
+
+ // find_first_not_of
+ // 0 1 2 3
+ // 01234567890123456789012345678901234
+ s1 = _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
+ s2 = _T("aaaaaa");
+
+ is_nom( s1.find_first_not_of(_T('a')), 6u );
+ is_nom( s1.find_first_not_of(_T('a'), 7), 7u );
+ is_nom( s2.find_first_not_of(_T('a')), wxString::npos );
+
+ is_nom( s1.find_first_not_of(_T("abde"), 4), 7u );
+ is_nom( s1.find_first_not_of(_T("abde"), 7), 7u );
+ is_nom( s1.find_first_not_of(_T("abcdefghijkl")), wxString::npos );
+
+ is_nom( s1.find_first_not_of(_T("abcdefghi"), 0, 4), 9u );
+
+ // find_first_of
+ is_nom( s1.find_first_of(_T('c')), 7u );
+ is_nom( s1.find_first_of(_T('v')), wxString::npos );
+ is_nom( s1.find_first_of(_T('c'), 10), 24u );
+
+ is_nom( s1.find_first_of(_T("ijkl")), 13u );
+ is_nom( s1.find_first_of(_T("ddcfg"), 17), 24u );
+ is_nom( s1.find_first_of(_T("ddcfga"), 17, 5), 24u );
+
+ // find_last_not_of
+ // 0 1 2 3
+ // 01234567890123456789012345678901234
+ s1 = _T("aaaaaabcdefghlkjiaaaaaabcdbcdbcdbcd");
+ s2 = _T("aaaaaa");
+
+ is_nom( s2.find_last_not_of(_T('a')), wxString::npos );
+ is_nom( s1.find_last_not_of(_T('d')), 33u );
+ is_nom( s1.find_last_not_of(_T('d'), 25), 24u );
+
+ is_nom( s1.find_last_not_of(_T("bcd")), 22u );
+ is_nom( s1.find_last_not_of(_T("abc"), 24), 16u );
+
+ is_nom( s1.find_last_not_of(_T("abcdefghijklmnopqrstuv"), 24, 3), 16u );
+
+ // find_last_of
+ is_nom( s2.find_last_of(_T('c')), wxString::npos );
+ is_nom( s1.find_last_of(_T('a')), 22u );
+ is_nom( s1.find_last_of(_T('b'), 24), 23u );
+
+ is_nom( s1.find_last_of(_T("ijklm")), 16u );
+ is_nom( s1.find_last_of(_T("ijklma"), 33, 4), 16u );
+ is_nom( s1.find_last_of(_T("a"), 17), 17u );
+
// test insert
s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = _T("aaaa");
s9 = s10 = _T("cdefg");
is( __LINE__, s6, s9);
is( __LINE__, s7, _T("QWwertyP") );
+ // rfind
+ // 0 1 2
+ // 01234567890123456789012345
+ s1 = _T("abcdefgABCDEFGabcABCabcABC");
+ s2 = _T("gAB");
+ s3 = _T("ab");
+
+ is_nom( s1.rfind(_T('A')), 23u );
+ is_nom( s1.rfind(_T('A'), 7), 7u );
+ is_nom( s1.rfind(_T('Z')), wxString::npos );
+ is_nom( s1.rfind(_T('C'), 22), 19u );
+
+ is_nom( s1.rfind(_T("cAB")), 22u );
+ is_nom( s1.rfind(_T("cAB"), 15), wxString::npos );
+ is_nom( s1.rfind(_T("cAB"), 21), 16u );
+
+ is_nom( s1.rfind(_T("gABZZZ"), 7, 3), 6u );
+ is_nom( s1.rfind(_T("gABZZZ"), 5, 3), wxString::npos );
+
+ is_nom( s1.rfind(s2), 6u );
+ is_nom( s1.rfind(s2, 5), wxString::npos );
+ is_nom( s1.rfind(s2, 6), 6u );
+ is_nom( s1.rfind(s3, 1), 0u );
+
+ // resize
+ s1 = s2 = s3 = s4 = _T("abcABCdefDEF");
+
+ s1.resize( 12 );
+ s2.resize( 10 );
+ s3.resize( 14, _T(' ') );
+ s4.resize( 14, _T('W') );
+
+ is_nom( s1, _T("abcABCdefDEF") );
+ is_nom( s2, _T("abcABCdefD") );
+ is_nom( s3, _T("abcABCdefDEF ") );
+ is_nom( s4, _T("abcABCdefDEFWW") );
+
+ // substr
+ s1 = _T("abcdefgABCDEFG");
+
+ is_nom( s1.substr( 0, 14 ), s1 );
+ is_nom( s1.substr( 1, 13 ), _T("bcdefgABCDEFG") );
+ is_nom( s1.substr( 1, 20 ), _T("bcdefgABCDEFG") );
+ is_nom( s1.substr( 14, 30 ), _T("") );
+
wxPuts(_T("*** Testing std::string operations finished ***\n"));
}
wxChar **wargv = new wxChar *[argc + 1];
{
- for ( int n = 0; n < argc; n++ )
+ int n;
+
+ for (n = 0; n < argc; n++ )
{
wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
wargv[n] = wxStrdup(warg);
#endif // TEST_CMDLINE
#ifdef TEST_STRINGS
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestPChar();
TestString();
TestStringSub();
TestStringFind();
TestStringTokenizer();
TestStringReplace();
- }
- else
- {
+ #else
TestStringMatch();
- }
+ #endif
TestStdString();
#endif // TEST_STRINGS
#ifdef TEST_ARRAYS
- if ( 1 || TEST_ALL )
- {
+ #if TEST_ALL
wxArrayString a1;
a1.Add(_T("tiger"));
a1.Add(_T("cat"));
wxArrayString a2(a1);
PrintArray(_T("a2"), a2);
-#if !wxUSE_STL
+ #if !wxUSE_STL
wxSortedArrayString a3(a1);
-#else
+ #else
wxSortedArrayString a3;
for (wxArrayString::iterator it = a1.begin(), en = a1.end();
it != en; ++it)
a3.Add(*it);
-#endif
+ #endif
PrintArray(_T("a3"), a3);
wxPuts(_T("*** After deleting three strings from a1"));
PrintArray(_T("a2"), a2);
PrintArray(_T("a3"), a3);
-#if !wxUSE_STL
+ #if !wxUSE_STL
wxPuts(_T("*** After reassigning a1 to a2 and a3"));
a3 = a2 = a1;
PrintArray(_T("a2"), a2);
PrintArray(_T("a3"), a3);
-#endif
+ #endif
wxPuts(_T("*** After sorting a1"));
- a1.Sort(wxStringCompareAscending);
+ a1.Sort(false);
PrintArray(_T("a1"), a1);
wxPuts(_T("*** After sorting a1 in reverse order"));
- a1.Sort(wxStringCompareDescending);
+ a1.Sort(true);
PrintArray(_T("a1"), a1);
-#if !wxUSE_STL
+ #if !wxUSE_STL
wxPuts(_T("*** After sorting a1 by the string length"));
a1.Sort(&StringLenCompare);
PrintArray(_T("a1"), a1);
-#endif
+ #endif
TestArrayOfObjects();
TestArrayOfUShorts();
- }
+ #endif
TestArrayOfInts();
TestStlArray();
#endif // TEST_ARRAYS
#ifdef TEST_DIR
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestDirExists();
TestDirEnum();
- }
+ #endif
TestDirTraverse();
#endif // TEST_DIR
#endif // TEST_LOG
#ifdef TEST_FILE
- if ( TEST_ALL )
- {
- TestFileRead();
- TestTextFileRead();
- TestFileCopy();
- }
+ TestFileRead();
+ TestTextFileRead();
+ TestFileCopy();
#endif // TEST_FILE
#ifdef TEST_FILENAME
- if ( 0 )
- {
- wxFileName fn;
- fn.Assign(_T("c:\\foo"), _T("bar.baz"));
- fn.Assign(_T("/u/os9-port/Viewer/tvision/WEI2HZ-3B3-14_05-04-00MSC1.asc"));
-
- DumpFileName(fn);
- }
-
TestFileNameConstruction();
- if ( TEST_ALL )
- {
- TestFileNameConstruction();
- TestFileNameMakeRelative();
- TestFileNameMakeAbsolute();
- TestFileNameSplit();
- TestFileNameTemp();
- TestFileNameCwd();
- TestFileNameComparison();
- TestFileNameOperations();
- }
+ TestFileNameMakeRelative();
+ TestFileNameMakeAbsolute();
+ TestFileNameSplit();
+ TestFileNameTemp();
+ TestFileNameCwd();
+ TestFileNameDirManip();
+ TestFileNameComparison();
+ TestFileNameOperations();
#endif // TEST_FILENAME
#ifdef TEST_FILETIME
TestFileGetTimes();
- if ( 0 )
+ #if 0
TestFileSetTimes();
+ #endif
#endif // TEST_FILETIME
#ifdef TEST_FTP
wxLog::AddTraceMask(FTP_TRACE_MASK);
if ( TestFtpConnect() )
{
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestFtpList();
TestFtpDownload();
TestFtpMisc();
TestFtpFileSize();
TestFtpUpload();
- }
+ #endif
- if ( TEST_INTERACTIVE )
+ #if TEST_INTERACTIVE
TestFtpInteractive();
+ #endif
}
//else: connecting to the FTP server failed
- if ( 0 )
+ #if 0
TestFtpWuFtpd();
+ #endif
#endif // TEST_FTP
#ifdef TEST_LONGLONG
// seed pseudo random generator
srand((unsigned)time(NULL));
- if ( 0 )
- {
+ #if 0
TestSpeed();
- }
+ #endif
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestMultiplication();
TestDivision();
TestAddition();
TestLongLongComparison();
TestLongLongToString();
TestLongLongPrintf();
- }
+ #endif
#endif // TEST_LONGLONG
#ifdef TEST_HASH
#ifdef TEST_MIME
wxLog::AddTraceMask(_T("mime"));
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestMimeEnum();
TestMimeOverride();
TestMimeAssociate();
- }
+ #endif
TestMimeFilename();
#endif // TEST_MIME
#ifdef TEST_INFO_FUNCTIONS
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestOsInfo();
TestUserInfo();
- if ( TEST_INTERACTIVE )
+ #if TEST_INTERACTIVE
TestDiskInfo();
- }
+ #endif
+ #endif
#endif // TEST_INFO_FUNCTIONS
#ifdef TEST_PATHLIST
#endif // TEST_PRINTF
#ifdef TEST_REGCONF
+ #if 0
TestRegConfWrite();
+ #endif
+ TestRegConfRead();
#endif // TEST_REGCONF
#ifdef TEST_REGEX
// TODO: write a real test using src/regex/tests file
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestRegExCompile();
TestRegExMatch();
TestRegExSubmatch();
TestRegExReplacement();
- if ( TEST_INTERACTIVE )
+ #if TEST_INTERACTIVE
TestRegExInteractive();
- }
+ #endif
+ #endif
#endif // TEST_REGEX
#ifdef TEST_REGISTRY
#endif // TEST_SOCKETS
#ifdef TEST_STREAMS
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestFileStream();
- }
+ #endif
TestMemoryStream();
#endif // TEST_STREAMS
if ( nCPUs != -1 )
wxThread::SetConcurrency(nCPUs);
- TestDetachedThreads();
- if ( TEST_ALL )
- {
TestJoinableThreads();
+
+ #if TEST_ALL
+ TestJoinableThreads();
+ TestDetachedThreads();
TestThreadSuspend();
TestThreadDelete();
TestThreadConditions();
TestThreadExec();
TestSemaphore();
- }
+ #endif
#endif // TEST_THREADS
#ifdef TEST_TIMER
#endif // TEST_TIMER
#ifdef TEST_DATETIME
- if ( TEST_ALL )
- {
+ #if TEST_ALL
TestTimeSet();
TestTimeStatic();
TestTimeRange();
TestTimeMS();
TestTimeZoneBug();
- }
+ #endif
- TestTimeWNumber();
-
- if ( TEST_INTERACTIVE )
+ #if TEST_INTERACTIVE
TestDateTimeInteractive();
+ #endif
#endif // TEST_DATETIME
#ifdef TEST_SCOPEGUARD
#endif // TEST_VOLUME
#ifdef TEST_UNICODE
- TestUnicodeToFromAscii();
+ TestUnicodeTextFileRead();
+ #if TEST_ALL
+ TestUnicodeToFromAscii();
+ #endif
#endif // TEST_UNICODE
#ifdef TEST_WCHAR
TestZlibStreamRead();
#endif // TEST_ZLIB
+#ifdef TEST_GZIP
+ TestGzip();
+#endif
+
+ wxUnusedVar(argc);
+ wxUnusedVar(argv);
return 0;
}