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 );
// 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
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,
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()
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;
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
}
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;
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();
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");
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