X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a6856aa899706c5fef9dd4c10bfaac66f9114195..e5354813181461c154044d52a464b29fa1aefaf8:/tests/controls/listboxtest.cpp?ds=sidebyside diff --git a/tests/controls/listboxtest.cpp b/tests/controls/listboxtest.cpp index 5718b47e42..32cc9defc2 100644 --- a/tests/controls/listboxtest.cpp +++ b/tests/controls/listboxtest.cpp @@ -43,11 +43,11 @@ private: WXUISIM_TEST( ClickEvents ); WXUISIM_TEST( ClickNotOnItem ); CPPUNIT_TEST( HitTest ); - CPPUNIT_TEST( Sort ); - //We also run all tests as an ownerdrawn list box we do not need to + //We also run all tests as an ownerdrawn list box. We do not need to //run the wxITEM_CONTAINER_TESTS as they are tested with wxCheckListBox #ifdef __WXMSW__ CPPUNIT_TEST( PseudoTest_OwnerDrawn ); + CPPUNIT_TEST( Sort ); CPPUNIT_TEST( MultipleSelect ); WXUISIM_TEST( ClickEvents ); WXUISIM_TEST( ClickNotOnItem ); @@ -72,7 +72,7 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( ListBoxTestCase ); -// 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( ListBoxTestCase, "ListBoxTestCase" ); //initialise the static variable @@ -100,7 +100,7 @@ void ListBoxTestCase::tearDown() void ListBoxTestCase::Sort() { -#if !defined(__WXGTK__) && !defined(__WXOSX__) +#ifndef __WXOSX__ wxDELETE(m_list); m_list = new wxListBox(wxTheApp->GetTopWindow(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, 0, @@ -170,6 +170,12 @@ void ListBoxTestCase::MultipleSelect() CPPUNIT_ASSERT(!m_list->IsSelected(1)); CPPUNIT_ASSERT(m_list->IsSelected(2)); CPPUNIT_ASSERT(!m_list->IsSelected(3)); + + m_list->SetSelection(0); + m_list->SetSelection(wxNOT_FOUND); + + m_list->GetSelections(selected); + CPPUNIT_ASSERT_EQUAL(0, selected.Count()); } void ListBoxTestCase::ClickEvents() @@ -178,8 +184,8 @@ void ListBoxTestCase::ClickEvents() wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), wxTestableFrame); - EventCounter count(frame, wxEVT_COMMAND_LISTBOX_SELECTED); - EventCounter count1(frame, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED); + EventCounter selected(frame, wxEVT_LISTBOX); + EventCounter dclicked(frame, wxEVT_LISTBOX_DCLICK); wxUIActionSimulator sim; @@ -199,12 +205,12 @@ void ListBoxTestCase::ClickEvents() sim.MouseClick(); wxYield(); - CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount()); + CPPUNIT_ASSERT_EQUAL(1, selected.GetCount()); sim.MouseDblClick(); wxYield(); - CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount()); + CPPUNIT_ASSERT_EQUAL(1, dclicked.GetCount()); #endif } @@ -214,8 +220,8 @@ void ListBoxTestCase::ClickNotOnItem() wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), wxTestableFrame); - EventCounter count(frame, wxEVT_COMMAND_LISTBOX_SELECTED); - EventCounter count1(frame, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED); + EventCounter selected(frame, wxEVT_LISTBOX); + EventCounter dclicked(frame, wxEVT_LISTBOX_DCLICK); wxUIActionSimulator sim; @@ -226,6 +232,13 @@ void ListBoxTestCase::ClickNotOnItem() m_list->Append(testitems); + // It is important to set a valid selection: if the control doesn't have + // any, clicking anywhere in it, even outside of any item, selects the + // first item in the control under GTK resulting in a selection changed + // event. This is not a wx bug, just the native platform behaviour so + // simply avoid it by starting with a valid selection. + m_list->SetSelection(0); + m_list->Update(); m_list->Refresh(); @@ -239,13 +252,13 @@ void ListBoxTestCase::ClickNotOnItem() wxYield(); //If we are not clicking on an item we shouldn't have any events - CPPUNIT_ASSERT_EQUAL(0, frame->GetEventCount()); + CPPUNIT_ASSERT_EQUAL(0, selected.GetCount()); + CPPUNIT_ASSERT_EQUAL(0, dclicked.GetCount()); #endif } void ListBoxTestCase::HitTest() { -#if defined(__WXMSW__) || defined(__WXOSX__) wxArrayString testitems; testitems.Add("item 0"); testitems.Add("item 1"); @@ -253,12 +266,14 @@ void ListBoxTestCase::HitTest() m_list->Append(testitems); - CPPUNIT_ASSERT(m_list->HitTest(wxPoint(10, 10)) != wxNOT_FOUND); - CPPUNIT_ASSERT(m_list->HitTest(10, 10) != wxNOT_FOUND); - - CPPUNIT_ASSERT(m_list->HitTest(wxPoint(290, 190)) == wxNOT_FOUND); - CPPUNIT_ASSERT(m_list->HitTest(290, 190) == wxNOT_FOUND); +#ifdef __WXGTK__ + // The control needs to be realized for HitTest() to work. + wxYield(); #endif + + CPPUNIT_ASSERT_EQUAL( 0, m_list->HitTest(5, 5) ); + + CPPUNIT_ASSERT_EQUAL( wxNOT_FOUND, m_list->HitTest(290, 190) ); } #endif //wxUSE_LISTBOX