Add unit test for no events when adding first wxNotebook page

Adding the first page shouldn't generate any events even if the
selection does change (from -1 to 0) internally.
This commit is contained in:
Vadim Zeitlin
2019-01-28 18:21:32 +01:00
parent 665b5a76a8
commit 6fdcfd8199

View File

@@ -20,7 +20,9 @@
#endif // WX_PRECOMP #endif // WX_PRECOMP
#include "wx/notebook.h" #include "wx/notebook.h"
#include "bookctrlbasetest.h" #include "bookctrlbasetest.h"
#include "testableframe.h"
class NotebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase class NotebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase
{ {
@@ -118,4 +120,25 @@ void NotebookTestCase::NoEventsOnDestruction()
CHECK( m_numPageChanges == 1 ); CHECK( m_numPageChanges == 1 );
} }
TEST_CASE("wxNotebook::NoEventsForFirstPage", "[wxNotebook][event]")
{
wxNotebook* const
notebook = new wxNotebook(wxTheApp->GetTopWindow(), wxID_ANY,
wxDefaultPosition, wxSize(400, 200));
CHECK( notebook->GetSelection() == wxNOT_FOUND );
EventCounter countPageChanging(notebook, wxEVT_NOTEBOOK_PAGE_CHANGING);
EventCounter countPageChanged(notebook, wxEVT_NOTEBOOK_PAGE_CHANGED);
notebook->AddPage(new wxPanel(notebook), "First page");
// The selection should have been changed.
CHECK( notebook->GetSelection() == 0 );
// But no events should have been generated.
CHECK( countPageChanging.GetCount() == 0 );
CHECK( countPageChanged.GetCount() == 0 );
}
#endif //wxUSE_NOTEBOOK #endif //wxUSE_NOTEBOOK