X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/497c7dffd1554afd075bef81c73b40a841b8a98d..e1efca652844273c3e8d32c7e5f442b87e455ca7:/tests/controls/listctrltest.cpp?ds=sidebyside diff --git a/tests/controls/listctrltest.cpp b/tests/controls/listctrltest.cpp index 501d547f65..6bd305c124 100644 --- a/tests/controls/listctrltest.cpp +++ b/tests/controls/listctrltest.cpp @@ -5,6 +5,7 @@ // Created: 2008-11-26 // RCS-ID: $Id$ // Copyright: (c) 2008 Vadim Zeitlin +// (c) 2010 Steven Lamerton /////////////////////////////////////////////////////////////////////////////// // ---------------------------------------------------------------------------- @@ -13,6 +14,8 @@ #include "testprec.h" +#if wxUSE_LISTCTRL + #ifdef __BORLANDC__ #pragma hdrstop #endif @@ -22,12 +25,15 @@ #endif // WX_PRECOMP #include "wx/listctrl.h" +#include "listbasetest.h" +#include "testableframe.h" +#include "wx/uiaction.h" // ---------------------------------------------------------------------------- // test class // ---------------------------------------------------------------------------- -class ListCtrlTestCase : public CppUnit::TestCase +class ListCtrlTestCase : public ListBaseTestCase, public CppUnit::TestCase { public: ListCtrlTestCase() { } @@ -35,16 +41,23 @@ public: virtual void setUp(); virtual void tearDown(); + virtual wxListCtrl *GetList() const { return m_list; } + private: CPPUNIT_TEST_SUITE( ListCtrlTestCase ); -#ifdef wxHAS_LISTCTRL_COLUMN_ORDER - CPPUNIT_TEST( ColumnsOrder ); -#endif // wxHAS_LISTCTRL_COLUMN_ORDER + wxLIST_BASE_TESTS(); + CPPUNIT_TEST( EditLabel ); + WXUISIM_TEST( ColumnClick ); + WXUISIM_TEST( ColumnDrag ); CPPUNIT_TEST_SUITE_END(); -#ifdef wxHAS_LISTCTRL_COLUMN_ORDER - void ColumnsOrder(); -#endif // wxHAS_LISTCTRL_COLUMN_ORDER + void EditLabel(); +#if wxUSE_UIACTIONSIMULATOR + // Column events are only supported in wxListCtrl currently so we test them + // here rather than in ListBaseTest + void ColumnClick(); + void ColumnDrag(); +#endif // wxUSE_UIACTIONSIMULATOR wxListCtrl *m_list; @@ -54,7 +67,7 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase ); -// 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( ListCtrlTestCase, "ListCtrlTestCase" ); // ---------------------------------------------------------------------------- @@ -64,6 +77,8 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" ); void ListCtrlTestCase::setUp() { m_list = new wxListCtrl(wxTheApp->GetTopWindow()); + m_list->SetWindowStyle(wxLC_REPORT); + m_list->SetSize(400, 200); } void ListCtrlTestCase::tearDown() @@ -72,73 +87,77 @@ void ListCtrlTestCase::tearDown() m_list = NULL; } -// ---------------------------------------------------------------------------- -// the tests themselves -// ---------------------------------------------------------------------------- - -#ifdef wxHAS_LISTCTRL_COLUMN_ORDER +void ListCtrlTestCase::EditLabel() +{ + m_list->InsertColumn(0, "Column 0"); + m_list->InsertItem(0, "foo"); + m_list->EditLabel(0); +} -void ListCtrlTestCase::ColumnsOrder() +#if wxUSE_UIACTIONSIMULATOR +void ListCtrlTestCase::ColumnDrag() { - static const int NUM_COLS; - int n; - wxListItem li; - li.SetMask(wxLIST_MASK_TEXT); + wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), + wxTestableFrame); + + EventCounter count(m_list, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG); + EventCounter count1(m_list, wxEVT_COMMAND_LIST_COL_DRAGGING); + EventCounter count2(m_list, wxEVT_COMMAND_LIST_COL_END_DRAG); - // first set up some columns m_list->InsertColumn(0, "Column 0"); m_list->InsertColumn(1, "Column 1"); m_list->InsertColumn(2, "Column 2"); + m_list->Update(); + m_list->SetFocus(); + + wxUIActionSimulator sim; + + wxPoint pt = m_list->ClientToScreen(wxPoint(m_list->GetColumnWidth(0), 5)); + + sim.MouseMove(pt); + wxYield(); - // and a couple of test items too - m_list->InsertItem(0, "Item 0"); - m_list->SetItem(0, 1, "first in first"); + sim.MouseDown(); + wxYield(); - m_list->InsertItem(1, "Item 1"); - m_list->SetItem(1, 2, "second in second"); + sim.MouseMove(pt.x + 50, pt.y); + wxYield(); + sim.MouseUp(); + wxYield(); - // check that the order is natural in the beginning - const wxArrayInt orderOrig = m_list->GetColumnsOrder(); - for ( n = 0; n < NUM_COLS; n++ ) - CPPUNIT_ASSERT_EQUAL( n, orderOrig[n] ); + CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG)); + CPPUNIT_ASSERT(frame->GetEventCount(wxEVT_COMMAND_LIST_COL_DRAGGING) > 0); + CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_END_DRAG)); + + m_list->ClearAll(); +} + +void ListCtrlTestCase::ColumnClick() +{ + wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), + wxTestableFrame); - // then rearrange them: using { 2, 0, 1 } order means that column 2 is - // shown first, then column 0 and finally column 1 - wxArrayInt order(3); - order[0] = 2; - order[1] = 0; - order[2] = 1; - m_list->SetColumnsOrder(order); + EventCounter count(m_list, wxEVT_COMMAND_LIST_COL_CLICK); + EventCounter count1(m_list, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK); - // check that we get back the same order as we set - const wxArrayInt orderNew = m_list->GetColumnsOrder(); - for ( n = 0; n < NUM_COLS; n++ ) - CPPUNIT_ASSERT_EQUAL( order[n], orderNew[n] ); - // and the order -> index mappings for individual columns - for ( n = 0; n < NUM_COLS; n++ ) - CPPUNIT_ASSERT_EQUAL( order[n], m_list->GetColumnIndexFromOrder(n) ); + m_list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60); - // and also the reverse mapping - CPPUNIT_ASSERT_EQUAL( 1, m_list->GetColumnOrder(0) ); - CPPUNIT_ASSERT_EQUAL( 2, m_list->GetColumnOrder(1) ); - CPPUNIT_ASSERT_EQUAL( 0, m_list->GetColumnOrder(2) ); + wxUIActionSimulator sim; + sim.MouseMove(m_list->ClientToScreen(wxPoint(4, 4))); + wxYield(); - // finally check that accessors still use indices, not order - CPPUNIT_ASSERT( m_list->GetColumn(0, li) ); - CPPUNIT_ASSERT_EQUAL( "Column 0", li.GetText() ); + sim.MouseClick(); + sim.MouseClick(wxMOUSE_BTN_RIGHT); + wxYield(); - li.SetId(0); - li.SetColumn(1); - CPPUNIT_ASSERT( m_list->GetItem(li) ); - CPPUNIT_ASSERT_EQUAL( "first in first", li.GetText() ); + CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_CLICK)); + CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK)); - li.SetId(1); - li.SetColumn(2); - CPPUNIT_ASSERT( m_list->GetItem(li) ); - CPPUNIT_ASSERT_EQUAL( "second in second", li.GetText() ); + m_list->ClearAll(); } +#endif // wxUSE_UIACTIONSIMULATOR -#endif // wxHAS_LISTCTRL_COLUMN_ORDER +#endif // wxUSE_LISTCTRL