From 0287ae5c754c6d6f573f1980954f278c6120bff2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 10 Apr 2011 15:36:07 +0000 Subject: [PATCH] Re-define push_back() in wxSortedArrayString to behave correctly. Adding items to wxSortedArrayString should always keep them sorted but while Add() did this, push_back() didn't breaking the class invariant. Redefine push_back() in _WX_DEFINE_SORTED_TYPEARRAY_2 macro to fix this and add a unit test checking that wxSortedArrayString::push_back() does work now. Closes #13134. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67429 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dynarray.h | 2 ++ tests/arrays/arrays.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index 5eced995d9..56abaae013 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -546,6 +546,8 @@ public: \ \ size_t Add(T lItem) \ { return base::Add(lItem, (CMPFUNC)m_fnCompare); } \ + void push_back(T lItem) \ + { Add(lItem); } \ \ void RemoveAt(size_t uiIndex, size_t nRemove = 1) \ { base::erase(begin() + uiIndex, begin() + uiIndex + nRemove); } \ diff --git a/tests/arrays/arrays.cpp b/tests/arrays/arrays.cpp index 4d276963db..8d32cf2a1f 100644 --- a/tests/arrays/arrays.cpp +++ b/tests/arrays/arrays.cpp @@ -160,6 +160,7 @@ public: private: CPPUNIT_TEST_SUITE( ArraysTestCase ); CPPUNIT_TEST( wxStringArrayTest ); + CPPUNIT_TEST( SortedArray ); CPPUNIT_TEST( wxStringArraySplitTest ); CPPUNIT_TEST( wxStringArrayJoinTest ); CPPUNIT_TEST( wxStringArraySplitJoinTest ); @@ -175,6 +176,7 @@ private: CPPUNIT_TEST_SUITE_END(); void wxStringArrayTest(); + void SortedArray(); void wxStringArraySplitTest(); void wxStringArrayJoinTest(); void wxStringArraySplitJoinTest(); @@ -340,6 +342,18 @@ void ArraysTestCase::wxStringArrayTest() CPPUNIT_ASSERT_EQUAL( "Foo", a5[2] ); } +void ArraysTestCase::SortedArray() +{ + wxSortedArrayString a; + a.Add("d"); + a.Add("c"); + CPPUNIT_ASSERT_EQUAL( 0, a.Index("c") ); + + a.push_back("b"); + a.push_back("a"); + CPPUNIT_ASSERT_EQUAL( 0, a.Index("a") ); +} + void ArraysTestCase::wxStringArraySplitTest() { // test wxSplit: -- 2.45.2