X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7d9cfc5483c227e513b5e2a3fa693ce07eed6e00..e1efca652844273c3e8d32c7e5f442b87e455ca7:/tests/lists/lists.cpp diff --git a/tests/lists/lists.cpp b/tests/lists/lists.cpp index 1cdd916a4e..c3ffc33859 100644 --- a/tests/lists/lists.cpp +++ b/tests/lists/lists.cpp @@ -49,7 +49,7 @@ private: // 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 +// also include in its 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 @@ -61,7 +61,7 @@ public: static size_t GetNumber() { return ms_bars; } - const wxChar *GetName() const { return m_name; } + const wxChar *GetName() const { return m_name.c_str(); } private: wxString m_name; @@ -75,49 +75,40 @@ size_t Baz::ms_bars = 0; WX_DECLARE_LIST(Baz, wxListBazs); #include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxListBazs); +WX_DEFINE_LIST(wxListBazs) WX_DECLARE_LIST(int, wxListInt); -WX_DEFINE_LIST(wxListInt); +WX_DEFINE_LIST(wxListInt) void ListsTestCase::wxListTest() { wxListInt list1; int dummy[5]; - int i; + size_t i; - for ( i = 0; i < 5; ++i ) + for ( i = 0; i < WXSIZEOF(dummy); ++i ) list1.Append(dummy + i); - CPPUNIT_ASSERT( list1.GetCount() == 5 ); - CPPUNIT_ASSERT( list1.Item(3)->GetData() == dummy + 3 ); + CPPUNIT_ASSERT_EQUAL( WXSIZEOF(dummy), list1.GetCount() ); + CPPUNIT_ASSERT_EQUAL( dummy + 3, list1.Item(3)->GetData() ); CPPUNIT_ASSERT( list1.Find(dummy + 4) ); - wxListInt::compatibility_iterator node = list1.GetFirst(); - i = 0; - - while (node) + wxListInt::compatibility_iterator node; + for ( i = 0, node = list1.GetFirst(); node; ++i, node = node->GetNext() ) { - CPPUNIT_ASSERT( node->GetData() == dummy + i ); - node = node->GetNext(); - ++i; + CPPUNIT_ASSERT_EQUAL( dummy + i, node->GetData() ); } - CPPUNIT_ASSERT( size_t(i) == list1.GetCount() ); + CPPUNIT_ASSERT_EQUAL( 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) + for ( i = 0, node = list1.GetFirst(); i < 3; ++i, node = node->GetNext() ) { int* t = node->GetData(); - CPPUNIT_ASSERT( t == dummy + i ); - node = node->GetNext(); - ++i; + CPPUNIT_ASSERT_EQUAL( dummy + i, t ); } } @@ -157,14 +148,47 @@ void ListsTestCase::wxStdListTest() { CPPUNIT_ASSERT( *it == i + &i ); } + + list1.clear(); + CPPUNIT_ASSERT( list1.empty() ); + + it = list1.insert(list1.end(), (int *)1); + CPPUNIT_ASSERT_EQUAL( (int *)1, *it ); + CPPUNIT_ASSERT( it == list1.begin() ); + CPPUNIT_ASSERT_EQUAL( (int *)1, list1.front() ); + + it = list1.insert(list1.end(), (int *)2); + CPPUNIT_ASSERT_EQUAL( (int *)2, *it ); + CPPUNIT_ASSERT( ++it == list1.end() ); + CPPUNIT_ASSERT_EQUAL( (int *)2, list1.back() ); + + it = list1.begin(); + wxListInt::iterator it2 = list1.insert(++it, (int *)3); + CPPUNIT_ASSERT_EQUAL( (int *)3, *it2 ); + + it = list1.begin(); + it = list1.erase(++it, list1.end()); + CPPUNIT_ASSERT_EQUAL( 1, list1.size() ); + CPPUNIT_ASSERT( it == list1.end() ); + + wxListInt list2; + list2.push_back((int *)3); + list2.push_back((int *)4); + list1.insert(list1.begin(), list2.begin(), list2.end()); + CPPUNIT_ASSERT_EQUAL( 3, list1.size() ); + CPPUNIT_ASSERT_EQUAL( (int *)3, list1.front() ); + + list1.insert(list1.end(), list2.begin(), list2.end()); + CPPUNIT_ASSERT_EQUAL( 5, list1.size() ); + CPPUNIT_ASSERT_EQUAL( (int *)4, list1.back() ); } void ListsTestCase::wxListCtorTest() { { wxListBazs list1; - list1.Append(new Baz(_T("first"))); - list1.Append(new Baz(_T("second"))); + list1.Append(new Baz(wxT("first"))); + list1.Append(new Baz(wxT("second"))); CPPUNIT_ASSERT( list1.GetCount() == 2 ); CPPUNIT_ASSERT( Baz::GetNumber() == 2 );