-// ----------------------------------------------------------------------------
-// wxHashTable
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_HASH
-
-#include "wx/hash.h"
-
-struct Foo
-{
- Foo(int n_) { n = n_; count++; }
- ~Foo() { count--; }
-
- int n;
-
- static size_t count;
-};
-
-size_t Foo::count = 0;
-
-WX_DECLARE_LIST(Foo, wxListFoos);
-WX_DECLARE_HASH(Foo, wxListFoos, wxHashFoos);
-
-#include "wx/listimpl.cpp"
-
-WX_DEFINE_LIST(wxListFoos);
-
-static void TestHash()
-{
- puts("*** Testing wxHashTable ***\n");
-
- {
- wxHashFoos hash;
- hash.DeleteContents(TRUE);
-
- printf("Hash created: %u foos in hash, %u foos totally\n",
- hash.GetCount(), Foo::count);
-
- static const int hashTestData[] =
- {
- 0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
- };
-
- size_t n;
- for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
- {
- hash.Put(hashTestData[n], n, new Foo(n));
- }
-
- printf("Hash filled: %u foos in hash, %u foos totally\n",
- hash.GetCount(), Foo::count);
-
- puts("Hash access test:");
- for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
- {
- printf("\tGetting element with key %d, value %d: ",
- hashTestData[n], n);
- Foo *foo = hash.Get(hashTestData[n], n);
- if ( !foo )
- {
- printf("ERROR, not found.\n");
- }
- else
- {
- printf("%d (%s)\n", foo->n,
- (size_t)foo->n == n ? "ok" : "ERROR");
- }
- }
-
- printf("\nTrying to get an element not in hash: ");
-
- if ( hash.Get(1234) || hash.Get(1, 0) )
- {
- puts("ERROR: found!");
- }
- else
- {
- puts("ok (not found)");
- }
- }
-
- printf("Hash destroyed: %u foos left\n", Foo::count);
-}
-
-#endif // TEST_HASH
-
-// ----------------------------------------------------------------------------
-// wxHashMap
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_HASHMAP
-
-#include "wx/hashmap.h"
-
-// test compilation of basic map types
-WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash, wxPointerEqual, myPtrHashMap );
-WX_DECLARE_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual, myLongHashMap );
-WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash, wxIntegerEqual,
- myUnsignedHashMap );
-WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash, wxIntegerEqual,
- myTestHashMap1 );
-WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash, wxIntegerEqual,
- myTestHashMap2 );
-WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash, wxIntegerEqual,
- myTestHashMap3 );
-WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash, wxIntegerEqual,
- myTestHashMap4 );
-WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
- myStringHashMap );
-
-typedef myStringHashMap::iterator Itor;
-
-static void TestHashMap()
-{
- puts("*** Testing wxHashMap ***\n");
- myStringHashMap sh(0); // as small as possible
- wxString buf;
- size_t i;
- const size_t count = 10000;
-
- // init with some data
- for( i = 0; i < count; ++i )
- {
- buf.Printf(wxT("%d"), i );
- sh[buf] = wxT("A") + buf + wxT("C");
- }
-
- // test that insertion worked
- if( sh.size() != count )
- {
- printf("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n", sh.size(), count);
- }
-
- for( i = 0; i < count; ++i )
- {
- buf.Printf(wxT("%d"), i );
- if( sh[buf] != wxT("A") + buf + wxT("C") )
- {
- printf("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n");
- return;
- }
- }
-
- // check that iterators work
- Itor it;
- for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
- {
- if( i == count )
- {
- printf("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n");
- return;
- }
-
- if( it->second != sh[it->first] )
- {
- printf("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n");
- return;
- }
- }
-
- if( sh.size() != i )
- {
- printf("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n", i, count);
- }
-
- // test copy ctor, assignment operator
- myStringHashMap h1( sh ), h2( 0 );
- h2 = sh;
-
- for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
- {
- if( h1[it->first] != it->second )
- {
- printf("*** ERROR: COPY CTOR BROKEN %s ***\n", it->first.c_str());
- }
-
- if( h2[it->first] != it->second )
- {
- printf("*** ERROR: OPERATOR= BROKEN %s ***\n", it->first.c_str());
- }
- }
-
- // other tests
- for( i = 0; i < count; ++i )
- {
- buf.Printf(wxT("%d"), i );
- size_t sz = sh.size();
-
- // test find() and erase(it)
- if( i < 100 )
- {
- it = sh.find( buf );
- if( it != sh.end() )
- {
- sh.erase( it );
-
- if( sh.find( buf ) != sh.end() )
- {
- printf("*** ERROR: FOUND DELETED ELEMENT %u ***\n", i);
- }
- }
- else
- printf("*** ERROR: CANT FIND ELEMENT %u ***\n", i);
- }
- else
- // test erase(key)
- {
- size_t c = sh.erase( buf );
- if( c != 1 )
- printf("*** ERROR: SHOULD RETURN 1 ***\n");
-
- if( sh.find( buf ) != sh.end() )
- {
- printf("*** ERROR: FOUND DELETED ELEMENT %u ***\n", i);
- }
- }
-
- // count should decrease
- if( sh.size() != sz - 1 )
- {
- printf("*** ERROR: COUNT DID NOT DECREASE ***\n");
- }
- }
-
- printf("*** Finished testing wxHashMap ***\n");
-}
-
-#endif TEST_HASHMAP
-
-// ----------------------------------------------------------------------------
-// wxList
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_LIST
-
-#include "wx/list.h"
-
-WX_DECLARE_LIST(Bar, wxListBars);
-#include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxListBars);
-
-static void TestListCtor()
-{
- puts("*** Testing wxList construction ***\n");
-
- {
- wxListBars list1;
- list1.Append(new Bar(_T("first")));
- list1.Append(new Bar(_T("second")));
-
- printf("After 1st list creation: %u objects in the list, %u objects total.\n",
- list1.GetCount(), Bar::GetNumber());
-
- wxListBars list2;
- list2 = list1;
-
- printf("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n",
- list1.GetCount(), list2.GetCount(), Bar::GetNumber());
-
- list1.DeleteContents(TRUE);
- }
-
- printf("After list destruction: %u objects left.\n", Bar::GetNumber());
-}
-
-#endif // TEST_LIST
-