]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/controls/listboxtest.cpp
Revert "Show the name of the actually tested class in text entry unit tests."
[wxWidgets.git] / tests / controls / listboxtest.cpp
index 6c3419c65cf26d38359dc47f9a7da55260dd9ada..32cc9defc2c6cd800be6fce10d704905671265b5 100644 (file)
@@ -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()
 {
-#ifndef(__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