From 7d9cfc5483c227e513b5e2a3fa693ce07eed6e00 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Wed, 8 Dec 2004 22:39:22 +0000 Subject: [PATCH] Moved tests for wxHashMap, wxHashSet and wxList from console sample and converted them to unit tests. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30911 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/console/console.cpp | 423 -------------------------------------------- tests/Makefile.in | 8 + tests/hashes/hashes.cpp | 168 +++++++++++++++++- tests/lists/lists.cpp | 188 ++++++++++++++++++++ tests/makefile.bcc | 8 + tests/makefile.gcc | 8 + tests/makefile.vc | 8 + tests/makefile.wat | 8 + tests/test.bkl | 1 + tests/test.dsp | 8 + 10 files changed, 404 insertions(+), 424 deletions(-) create mode 100644 tests/lists/lists.cpp diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 0a961b1..0498957 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -61,10 +61,7 @@ #define TEST_FILENAME #define TEST_FILETIME // #define TEST_FTP --FIXME! (RN) - #define TEST_HASHMAP - #define TEST_HASHSET #define TEST_INFO_FUNCTIONS - #define TEST_LIST #define TEST_LOCALE #define TEST_LOG #define TEST_MIME @@ -99,33 +96,6 @@ #define TEST_INTERACTIVE 0 #endif -// ---------------------------------------------------------------------------- -// test class for container objects -// ---------------------------------------------------------------------------- - -#if defined(TEST_LIST) - -class Bar // Foo is already taken in the hash test -{ -public: - Bar(const wxString& name) : m_name(name) { ms_bars++; } - Bar(const Bar& bar) : m_name(bar.m_name) { ms_bars++; } - ~Bar() { ms_bars--; } - - static size_t GetNumber() { return ms_bars; } - - const wxChar *GetName() const { return m_name; } - -private: - wxString m_name; - - static size_t ms_bars; -}; - -size_t Bar::ms_bars = 0; - -#endif // defined(TEST_LIST) - // ============================================================================ // implementation // ============================================================================ @@ -969,386 +939,6 @@ static void TestFileSetTimes() #endif // TEST_FILETIME // ---------------------------------------------------------------------------- -// 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 ); - -// same as: -// WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual, -// myStringHashMap ); -WX_DECLARE_STRING_HASH_MAP(wxString, myStringHashMap); - -typedef myStringHashMap::iterator Itor; - -static void TestHashMap() -{ - wxPuts(_T("*** 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 ) - { - wxPrintf(_T("*** 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") ) - { - wxPrintf(_T("*** 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 ) - { - wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n")); - return; - } - - if( it->second != sh[it->first] ) - { - wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n")); - return; - } - } - - if( sh.size() != i ) - { - wxPrintf(_T("*** 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 ) - { - wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it->first.c_str()); - } - - if( h2[it->first] != it->second ) - { - wxPrintf(_T("*** 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() ) - { - wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i); - } - } - else - wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i); - } - else - // test erase(key) - { - size_t c = sh.erase( buf ); - if( c != 1 ) - wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n")); - - if( sh.find( buf ) != sh.end() ) - { - wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i); - } - } - - // count should decrease - if( sh.size() != sz - 1 ) - { - wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n")); - } - } - - wxPrintf(_T("*** Finished testing wxHashMap ***\n")); -} - -#endif // TEST_HASHMAP - -// ---------------------------------------------------------------------------- -// wxHashSet -// ---------------------------------------------------------------------------- - -#ifdef TEST_HASHSET - -#include "wx/hashset.h" - -// test compilation of basic map types -WX_DECLARE_HASH_SET( int*, wxPointerHash, wxPointerEqual, myPtrHashSet ); -WX_DECLARE_HASH_SET( long, wxIntegerHash, wxIntegerEqual, myLongHashSet ); -WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash, wxIntegerEqual, - myUnsignedHashSet ); -WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash, wxIntegerEqual, - myTestHashSet1 ); -WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual, - myTestHashSet2 ); -WX_DECLARE_HASH_SET( short, wxIntegerHash, wxIntegerEqual, - myTestHashSet3 ); -WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash, wxIntegerEqual, - myTestHashSet4 ); -WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual, - myTestHashSet5 ); - -struct MyStruct -{ - int* ptr; - wxString str; -}; - -class MyHash -{ -public: - unsigned long operator()(const MyStruct& s) const - { return m_dummy(s.ptr); } - MyHash& operator=(const MyHash&) { return *this; } -private: - wxPointerHash m_dummy; -}; - -class MyEqual -{ -public: - bool operator()(const MyStruct& s1, const MyStruct& s2) const - { return s1.ptr == s2.ptr; } - MyEqual& operator=(const MyEqual&) { return *this; } -}; - -WX_DECLARE_HASH_SET( MyStruct, MyHash, MyEqual, mySet ); - -typedef myTestHashSet5 wxStringHashSet; - -static void TestHashSet() -{ - wxPrintf(_T("*** Testing wxHashSet ***\n")); - - wxStringHashSet set1; - - set1.insert( _T("abc") ); - set1.insert( _T("bbc") ); - set1.insert( _T("cbc") ); - set1.insert( _T("abc") ); - - if( set1.size() != 3 ) - wxPrintf(_T("*** ERROR IN INSERT ***\n")); - - mySet set2; - int dummy; - MyStruct tmp; - - tmp.ptr = &dummy; tmp.str = _T("ABC"); - set2.insert( tmp ); - tmp.ptr = &dummy + 1; - set2.insert( tmp ); - tmp.ptr = &dummy; tmp.str = _T("CDE"); - set2.insert( tmp ); - - if( set2.size() != 2 ) - wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n")); - - mySet::iterator it = set2.find( tmp ); - - if( it == set2.end() ) - wxPrintf(_T("*** ERROR IN FIND - 1 ***\n")); - if( it->ptr != &dummy ) - wxPrintf(_T("*** ERROR IN FIND - 2 ***\n")); - if( it->str != _T("ABC") ) - wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n")); - - wxPrintf(_T("*** Finished testing wxHashSet ***\n")); -} - -#endif // TEST_HASHSET - -// ---------------------------------------------------------------------------- -// wxList -// ---------------------------------------------------------------------------- - -#ifdef TEST_LIST - -#include "wx/list.h" - -WX_DECLARE_LIST(Bar, wxListBars); -#include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxListBars); - -WX_DECLARE_LIST(int, wxListInt); -WX_DEFINE_LIST(wxListInt); - -static void TestList() -{ - wxPuts(_T("*** Testing wxList operations ***\n")); - { - wxListInt list1; - int dummy[5]; - int i; - - for ( i = 0; i < 5; ++i ) - list1.Append(dummy + i); - - if ( list1.GetCount() != 5 ) - wxPuts(_T("Wrong number of items in list\n")); - - if ( list1.Item(3)->GetData() != dummy + 3 ) - wxPuts(_T("Error in Item()\n")); - - if ( !list1.Find(dummy + 4) ) - wxPuts(_T("Error in Find()\n")); - - wxListInt::compatibility_iterator node = list1.GetFirst(); - i = 0; - - while (node) - { - if ( node->GetData() != dummy + i ) - wxPuts(_T("Error in compatibility_iterator\n")); - node = node->GetNext(); - ++i; - } - - if ( size_t(i) != list1.GetCount() ) - wxPuts(_T("Error in compatibility_iterator\n")); - - list1.Insert(dummy + 0); - list1.Insert(1, dummy + 1); - list1.Insert(list1.GetFirst()->GetNext()->GetNext(), dummy + 2); - - node = list1.GetFirst(); - i = 0; - - while (i < 3) - { - int* t = node->GetData(); - if ( t != dummy + i ) - wxPuts(_T("Error in Insert\n")); - node = node->GetNext(); - ++i; - } - } - - wxPuts(_T("*** Testing wxList operations finished ***\n")); - - wxPuts(_T("*** Testing std::list operations ***\n")); - - { - wxListInt list1; - wxListInt::iterator it, en; - wxListInt::reverse_iterator rit, ren; - int i; - for ( i = 0; i < 5; ++i ) - list1.push_back(i + &i); - - for ( it = list1.begin(), en = list1.end(), i = 0; - it != en; ++it, ++i ) - if ( *it != i + &i ) - wxPuts(_T("Error in iterator\n")); - - for ( rit = list1.rbegin(), ren = list1.rend(), i = 4; - rit != ren; ++rit, --i ) - if ( *rit != i + &i ) - wxPuts(_T("Error in reverse_iterator\n")); - - if ( *list1.rbegin() != *--list1.end() || - *list1.begin() != *--list1.rend() ) - wxPuts(_T("Error in iterator/reverse_iterator\n")); - if ( *list1.begin() != *--++list1.begin() || - *list1.rbegin() != *--++list1.rbegin() ) - wxPuts(_T("Error in iterator/reverse_iterator\n")); - - if ( list1.front() != &i || list1.back() != &i + 4 ) - wxPuts(_T("Error in front()/back()\n")); - - list1.erase(list1.begin()); - list1.erase(--list1.end()); - - for ( it = list1.begin(), en = list1.end(), i = 1; - it != en; ++it, ++i ) - if ( *it != i + &i ) - wxPuts(_T("Error in erase()\n")); - } - - wxPuts(_T("*** Testing std::list operations finished ***\n")); -} - -static void TestListCtor() -{ - wxPuts(_T("*** Testing wxList construction ***\n")); - - { - wxListBars list1; - list1.Append(new Bar(_T("first"))); - list1.Append(new Bar(_T("second"))); - - wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"), - list1.GetCount(), Bar::GetNumber()); - - wxListBars list2; - list2 = list1; - - wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"), - list1.GetCount(), list2.GetCount(), Bar::GetNumber()); - -#if !wxUSE_STL - list1.DeleteContents(true); -#else - WX_CLEAR_LIST(wxListBars, list1); -#endif - } - - wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber()); -} - -#endif // TEST_LIST - -// ---------------------------------------------------------------------------- // wxLocale // ---------------------------------------------------------------------------- @@ -4518,11 +4108,6 @@ int main(int argc, char **argv) TestFileConfRead(); #endif // TEST_FILECONF -#ifdef TEST_LIST - TestListCtor(); - TestList(); -#endif // TEST_LIST - #ifdef TEST_LOCALE TestDefaultLang(); #endif // TEST_LOCALE @@ -4599,14 +4184,6 @@ int main(int argc, char **argv) #endif #endif // TEST_FTP -#ifdef TEST_HASHMAP - TestHashMap(); -#endif // TEST_HASHMAP - -#ifdef TEST_HASHSET - TestHashSet(); -#endif // TEST_HASHSET - #ifdef TEST_MIME wxLog::AddTraceMask(_T("mime")); #if TEST_ALL diff --git a/tests/Makefile.in b/tests/Makefile.in index 8a10025..dfcee0b 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -49,6 +49,7 @@ TEST_OBJECTS = \ test_fontmaptest.o \ test_formatconvertertest.o \ test_hashes.o \ + test_lists.o \ test_longlongtest.o \ test_mbconvtest.o \ test_regextest.o \ @@ -58,6 +59,7 @@ TEST_OBJECTS = \ test_unicode.o \ test_crt.o \ test_bstream.o \ + test_datastreamtest.o \ test_ffilestream.o \ test_filestream.o \ test_memstream.o \ @@ -180,6 +182,9 @@ test_formatconvertertest.o: $(srcdir)/formatconverter/formatconvertertest.cpp $( test_hashes.o: $(srcdir)/hashes/hashes.cpp $(TEST_ODEP) $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $< +test_lists.o: $(srcdir)/lists/lists.cpp $(TEST_ODEP) + $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $< + test_longlongtest.o: $(srcdir)/longlong/longlongtest.cpp $(TEST_ODEP) $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $< @@ -207,6 +212,9 @@ test_crt.o: $(srcdir)/strings/crt.cpp $(TEST_ODEP) test_bstream.o: $(srcdir)/streams/bstream.cpp $(TEST_ODEP) $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $< +test_datastreamtest.o: $(srcdir)/streams/datastreamtest.cpp $(TEST_ODEP) + $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $< + test_ffilestream.o: $(srcdir)/streams/ffilestream.cpp $(TEST_ODEP) $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $< diff --git a/tests/hashes/hashes.cpp b/tests/hashes/hashes.cpp index 062822f..e33d6ff 100644 --- a/tests/hashes/hashes.cpp +++ b/tests/hashes/hashes.cpp @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Name: tests/hashes/hashes.cpp -// Purpose: wxArray unit test +// Purpose: wxHashTable, wxHashMap, wxHashSet unit test // Author: Vadim Zeitlin, Mattia Barbon // Created: 2004-05-16 // RCS-ID: $Id$ @@ -295,10 +295,176 @@ void HashesTestCase::wxTypedHashTableTest() CPPUNIT_ASSERT( Foo::count == 0 ); } +// 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 ); + +// same as: +// WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual, +// myStringHashMap ); +WX_DECLARE_STRING_HASH_MAP(wxString, myStringHashMap); + +typedef myStringHashMap::iterator Itor; + void HashesTestCase::wxHashMapTest() { + 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 + CPPUNIT_ASSERT( sh.size() == count ); + + for( i = 0; i < count; ++i ) + { + buf.Printf(wxT("%d"), i ); + CPPUNIT_ASSERT( sh[buf] == wxT("A") + buf + wxT("C") ); + } + + // check that iterators work + Itor it; + for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i ) + { + CPPUNIT_ASSERT( i != count ); + CPPUNIT_ASSERT( it->second == sh[it->first] ); + } + + CPPUNIT_ASSERT( sh.size() == i ); + + // test copy ctor, assignment operator + myStringHashMap h1( sh ), h2( 0 ); + h2 = sh; + + for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i ) + { + CPPUNIT_ASSERT( h1[it->first] == it->second ); + CPPUNIT_ASSERT( h2[it->first] == it->second ); + } + + // 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 ); + CPPUNIT_ASSERT( it != sh.end() ); + + sh.erase( it ); + + CPPUNIT_ASSERT( sh.find( buf ) == sh.end() ); + } + else + // test erase(key) + { + size_t c = sh.erase( buf ); + CPPUNIT_ASSERT( c == 1 ); + CPPUNIT_ASSERT( sh.find( buf ) == sh.end() ); + } + + // count should decrease + CPPUNIT_ASSERT( sh.size() == sz - 1 ); + } } +// test compilation of basic set types +WX_DECLARE_HASH_SET( int*, wxPointerHash, wxPointerEqual, myPtrHashSet ); +WX_DECLARE_HASH_SET( long, wxIntegerHash, wxIntegerEqual, myLongHashSet ); +WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash, wxIntegerEqual, + myUnsignedHashSet ); +WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash, wxIntegerEqual, + myTestHashSet1 ); +WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual, + myTestHashSet2 ); +WX_DECLARE_HASH_SET( short, wxIntegerHash, wxIntegerEqual, + myTestHashSet3 ); +WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash, wxIntegerEqual, + myTestHashSet4 ); +WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual, + myTestHashSet5 ); + +struct MyStruct +{ + int* ptr; + wxString str; +}; + +class MyHash +{ +public: + unsigned long operator()(const MyStruct& s) const + { return m_dummy(s.ptr); } + MyHash& operator=(const MyHash&) { return *this; } +private: + wxPointerHash m_dummy; +}; + +class MyEqual +{ +public: + bool operator()(const MyStruct& s1, const MyStruct& s2) const + { return s1.ptr == s2.ptr; } + MyEqual& operator=(const MyEqual&) { return *this; } +}; + +WX_DECLARE_HASH_SET( MyStruct, MyHash, MyEqual, mySet ); + +typedef myTestHashSet5 wxStringHashSet; + void HashesTestCase::wxHashSetTest() { + wxStringHashSet set1; + + set1.insert( _T("abc") ); + + CPPUNIT_ASSERT( set1.size() == 1 ); + + set1.insert( _T("bbc") ); + set1.insert( _T("cbc") ); + + CPPUNIT_ASSERT( set1.size() == 3 ); + + set1.insert( _T("abc") ); + + CPPUNIT_ASSERT( set1.size() == 3 ); + + mySet set2; + int dummy; + MyStruct tmp; + + tmp.ptr = &dummy; tmp.str = _T("ABC"); + set2.insert( tmp ); + tmp.ptr = &dummy + 1; + set2.insert( tmp ); + tmp.ptr = &dummy; tmp.str = _T("CDE"); + set2.insert( tmp ); + + CPPUNIT_ASSERT( set2.size() == 2 ); + + mySet::iterator it = set2.find( tmp ); + + CPPUNIT_ASSERT( it != set2.end() ); + CPPUNIT_ASSERT( it->ptr == &dummy ); + CPPUNIT_ASSERT( it->str == _T("ABC") ); } diff --git a/tests/lists/lists.cpp b/tests/lists/lists.cpp new file mode 100644 index 0000000..1cdd916 --- /dev/null +++ b/tests/lists/lists.cpp @@ -0,0 +1,188 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/lists/lists.cpp +// Purpose: wxList unit test +// Author: Vadim Zeitlin, Mattia Barbon +// Created: 2004-12-08 +// RCS-ID: $Id$ +// Copyright: (c) 2004 Vadim Zeitlin, Mattia Barbon +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif // WX_PRECOMP + +#include "wx/list.h" + +// -------------------------------------------------------------------------- +// test class +// -------------------------------------------------------------------------- + +class ListsTestCase : public CppUnit::TestCase +{ +public: + ListsTestCase() { } + +private: + CPPUNIT_TEST_SUITE( ListsTestCase ); + CPPUNIT_TEST( wxListTest ); + CPPUNIT_TEST( wxStdListTest ); + CPPUNIT_TEST( wxListCtorTest ); + CPPUNIT_TEST_SUITE_END(); + + void wxListTest(); + void wxStdListTest(); + void wxListCtorTest(); + + DECLARE_NO_COPY_CLASS(ListsTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( ListsTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListsTestCase, "ListsTestCase" ); + +class Baz // Foo is already taken in the hash test +{ +public: + Baz(const wxString& name) : m_name(name) { ms_bars++; } + Baz(const Baz& bar) : m_name(bar.m_name) { ms_bars++; } + ~Baz() { ms_bars--; } + + static size_t GetNumber() { return ms_bars; } + + const wxChar *GetName() const { return m_name; } + +private: + wxString m_name; + + static size_t ms_bars; +}; + +size_t Baz::ms_bars = 0; + +#include "wx/list.h" + +WX_DECLARE_LIST(Baz, wxListBazs); +#include "wx/listimpl.cpp" +WX_DEFINE_LIST(wxListBazs); + +WX_DECLARE_LIST(int, wxListInt); +WX_DEFINE_LIST(wxListInt); + +void ListsTestCase::wxListTest() +{ + wxListInt list1; + int dummy[5]; + int i; + + for ( i = 0; i < 5; ++i ) + list1.Append(dummy + i); + + CPPUNIT_ASSERT( list1.GetCount() == 5 ); + CPPUNIT_ASSERT( list1.Item(3)->GetData() == dummy + 3 ); + CPPUNIT_ASSERT( list1.Find(dummy + 4) ); + + wxListInt::compatibility_iterator node = list1.GetFirst(); + i = 0; + + while (node) + { + CPPUNIT_ASSERT( node->GetData() == dummy + i ); + node = node->GetNext(); + ++i; + } + + CPPUNIT_ASSERT( size_t(i) == list1.GetCount() ); + + list1.Insert(dummy + 0); + list1.Insert(1, dummy + 1); + list1.Insert(list1.GetFirst()->GetNext()->GetNext(), dummy + 2); + + node = list1.GetFirst(); + i = 0; + + while (i < 3) + { + int* t = node->GetData(); + CPPUNIT_ASSERT( t == dummy + i ); + node = node->GetNext(); + ++i; + } +} + +void ListsTestCase::wxStdListTest() +{ + wxListInt list1; + wxListInt::iterator it, en; + wxListInt::reverse_iterator rit, ren; + int i; + for ( i = 0; i < 5; ++i ) + list1.push_back(i + &i); + + for ( it = list1.begin(), en = list1.end(), i = 0; + it != en; ++it, ++i ) + { + CPPUNIT_ASSERT( *it == i + &i ); + } + + for ( rit = list1.rbegin(), ren = list1.rend(), i = 4; + rit != ren; ++rit, --i ) + { + CPPUNIT_ASSERT( *rit == i + &i ); + } + + CPPUNIT_ASSERT( *list1.rbegin() == *--list1.end() && + *list1.begin() == *--list1.rend() ); + CPPUNIT_ASSERT( *list1.begin() == *--++list1.begin() && + *list1.rbegin() == *--++list1.rbegin() ); + + CPPUNIT_ASSERT( list1.front() == &i && list1.back() == &i + 4 ); + + list1.erase(list1.begin()); + list1.erase(--list1.end()); + + for ( it = list1.begin(), en = list1.end(), i = 1; + it != en; ++it, ++i ) + { + CPPUNIT_ASSERT( *it == i + &i ); + } +} + +void ListsTestCase::wxListCtorTest() +{ + { + wxListBazs list1; + list1.Append(new Baz(_T("first"))); + list1.Append(new Baz(_T("second"))); + + CPPUNIT_ASSERT( list1.GetCount() == 2 ); + CPPUNIT_ASSERT( Baz::GetNumber() == 2 ); + + wxListBazs list2; + list2 = list1; + + CPPUNIT_ASSERT( list1.GetCount() == 2 ); + CPPUNIT_ASSERT( list2.GetCount() == 2 ); + CPPUNIT_ASSERT( Baz::GetNumber() == 2 ); + +#if !wxUSE_STL + list1.DeleteContents(true); +#else + WX_CLEAR_LIST(wxListBazs, list1); +#endif + } + + CPPUNIT_ASSERT( Baz::GetNumber() == 0 ); +} + diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 37b4b27..aee62dd 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -43,6 +43,7 @@ TEST_OBJECTS = \ $(OBJS)\test_fontmaptest.obj \ $(OBJS)\test_formatconvertertest.obj \ $(OBJS)\test_hashes.obj \ + $(OBJS)\test_lists.obj \ $(OBJS)\test_longlongtest.obj \ $(OBJS)\test_mbconvtest.obj \ $(OBJS)\test_regextest.obj \ @@ -52,6 +53,7 @@ TEST_OBJECTS = \ $(OBJS)\test_unicode.obj \ $(OBJS)\test_crt.obj \ $(OBJS)\test_bstream.obj \ + $(OBJS)\test_datastreamtest.obj \ $(OBJS)\test_ffilestream.obj \ $(OBJS)\test_filestream.obj \ $(OBJS)\test_memstream.obj \ @@ -226,6 +228,9 @@ $(OBJS)\test_formatconvertertest.obj: .\formatconverter\formatconvertertest.cpp $(OBJS)\test_hashes.obj: .\hashes\hashes.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $** +$(OBJS)\test_lists.obj: .\lists\lists.cpp + $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $** + $(OBJS)\test_longlongtest.obj: .\longlong\longlongtest.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $** @@ -253,6 +258,9 @@ $(OBJS)\test_crt.obj: .\strings\crt.cpp $(OBJS)\test_bstream.obj: .\streams\bstream.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $** +$(OBJS)\test_datastreamtest.obj: .\streams\datastreamtest.cpp + $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $** + $(OBJS)\test_ffilestream.obj: .\streams\ffilestream.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $** diff --git a/tests/makefile.gcc b/tests/makefile.gcc index f9f5108..9703708 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -33,6 +33,7 @@ TEST_OBJECTS = \ $(OBJS)\test_fontmaptest.o \ $(OBJS)\test_formatconvertertest.o \ $(OBJS)\test_hashes.o \ + $(OBJS)\test_lists.o \ $(OBJS)\test_longlongtest.o \ $(OBJS)\test_mbconvtest.o \ $(OBJS)\test_regextest.o \ @@ -42,6 +43,7 @@ TEST_OBJECTS = \ $(OBJS)\test_unicode.o \ $(OBJS)\test_crt.o \ $(OBJS)\test_bstream.o \ + $(OBJS)\test_datastreamtest.o \ $(OBJS)\test_ffilestream.o \ $(OBJS)\test_filestream.o \ $(OBJS)\test_memstream.o \ @@ -219,6 +221,9 @@ $(OBJS)\test_formatconvertertest.o: ./formatconverter/formatconvertertest.cpp $(OBJS)\test_hashes.o: ./hashes/hashes.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $< +$(OBJS)\test_lists.o: ./lists/lists.cpp + $(CXX) -c -o $@ $(TEST_CXXFLAGS) $< + $(OBJS)\test_longlongtest.o: ./longlong/longlongtest.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $< @@ -246,6 +251,9 @@ $(OBJS)\test_crt.o: ./strings/crt.cpp $(OBJS)\test_bstream.o: ./streams/bstream.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $< +$(OBJS)\test_datastreamtest.o: ./streams/datastreamtest.cpp + $(CXX) -c -o $@ $(TEST_CXXFLAGS) $< + $(OBJS)\test_ffilestream.o: ./streams/ffilestream.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 5af3ea7..a9d584d 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -36,6 +36,7 @@ TEST_OBJECTS = \ $(OBJS)\test_fontmaptest.obj \ $(OBJS)\test_formatconvertertest.obj \ $(OBJS)\test_hashes.obj \ + $(OBJS)\test_lists.obj \ $(OBJS)\test_longlongtest.obj \ $(OBJS)\test_mbconvtest.obj \ $(OBJS)\test_regextest.obj \ @@ -45,6 +46,7 @@ TEST_OBJECTS = \ $(OBJS)\test_unicode.obj \ $(OBJS)\test_crt.obj \ $(OBJS)\test_bstream.obj \ + $(OBJS)\test_datastreamtest.obj \ $(OBJS)\test_ffilestream.obj \ $(OBJS)\test_filestream.obj \ $(OBJS)\test_memstream.obj \ @@ -282,6 +284,9 @@ $(OBJS)\test_formatconvertertest.obj: .\formatconverter\formatconvertertest.cpp $(OBJS)\test_hashes.obj: .\hashes\hashes.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $** +$(OBJS)\test_lists.obj: .\lists\lists.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $** + $(OBJS)\test_longlongtest.obj: .\longlong\longlongtest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $** @@ -309,6 +314,9 @@ $(OBJS)\test_crt.obj: .\strings\crt.cpp $(OBJS)\test_bstream.obj: .\streams\bstream.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $** +$(OBJS)\test_datastreamtest.obj: .\streams\datastreamtest.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $** + $(OBJS)\test_ffilestream.obj: .\streams\ffilestream.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $** diff --git a/tests/makefile.wat b/tests/makefile.wat index be02b7a..f84db85 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -197,6 +197,7 @@ TEST_OBJECTS = & $(OBJS)\test_fontmaptest.obj & $(OBJS)\test_formatconvertertest.obj & $(OBJS)\test_hashes.obj & + $(OBJS)\test_lists.obj & $(OBJS)\test_longlongtest.obj & $(OBJS)\test_mbconvtest.obj & $(OBJS)\test_regextest.obj & @@ -206,6 +207,7 @@ TEST_OBJECTS = & $(OBJS)\test_unicode.obj & $(OBJS)\test_crt.obj & $(OBJS)\test_bstream.obj & + $(OBJS)\test_datastreamtest.obj & $(OBJS)\test_ffilestream.obj & $(OBJS)\test_filestream.obj & $(OBJS)\test_memstream.obj & @@ -278,6 +280,9 @@ $(OBJS)\test_formatconvertertest.obj : .AUTODEPEND .\formatconverter\formatconv $(OBJS)\test_hashes.obj : .AUTODEPEND .\hashes\hashes.cpp $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $< +$(OBJS)\test_lists.obj : .AUTODEPEND .\lists\lists.cpp + $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $< + $(OBJS)\test_longlongtest.obj : .AUTODEPEND .\longlong\longlongtest.cpp $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $< @@ -305,6 +310,9 @@ $(OBJS)\test_crt.obj : .AUTODEPEND .\strings\crt.cpp $(OBJS)\test_bstream.obj : .AUTODEPEND .\streams\bstream.cpp $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $< +$(OBJS)\test_datastreamtest.obj : .AUTODEPEND .\streams\datastreamtest.cpp + $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $< + $(OBJS)\test_ffilestream.obj : .AUTODEPEND .\streams\ffilestream.cpp $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $< diff --git a/tests/test.bkl b/tests/test.bkl index 03f3c71..24dce9b 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -29,6 +29,7 @@ fontmap/fontmaptest.cpp formatconverter/formatconvertertest.cpp hashes/hashes.cpp + lists/lists.cpp longlong/longlongtest.cpp mbconv/mbconvtest.cpp regex/regextest.cpp diff --git a/tests/test.dsp b/tests/test.dsp index 5767e25..29d9910 100644 --- a/tests/test.dsp +++ b/tests/test.dsp @@ -451,6 +451,10 @@ SOURCE=.\strings\crt.cpp # End Source File # Begin Source File +SOURCE=.\streams\datastreamtest.cpp +# End Source File +# Begin Source File + SOURCE=.\datetime\datetimetest.cpp # End Source File # Begin Source File @@ -493,6 +497,10 @@ SOURCE=.\hashes\hashes.cpp # End Source File # Begin Source File +SOURCE=.\lists\lists.cpp +# End Source File +# Begin Source File + SOURCE=.\longlong\longlongtest.cpp # End Source File # Begin Source File -- 2.7.4