X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/232fdc630c42eb165f7659981043e794be03b3b7..1ec4e9c2b72a01a7ba7da569e0f8d04a81aaba10:/tests/controls/listboxtest.cpp?ds=sidebyside diff --git a/tests/controls/listboxtest.cpp b/tests/controls/listboxtest.cpp index 68ce0d7941..afab5f80ed 100644 --- a/tests/controls/listboxtest.cpp +++ b/tests/controls/listboxtest.cpp @@ -43,7 +43,7 @@ private: WXUISIM_TEST( ClickEvents ); WXUISIM_TEST( ClickNotOnItem ); CPPUNIT_TEST( HitTest ); - //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 ); @@ -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_COMMAND_LISTBOX_SELECTED); + EventCounter dclicked(frame, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED); 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_COMMAND_LISTBOX_SELECTED); + EventCounter dclicked(frame, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED); 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