From 6fdcfd819937d44e7d8a541c9401cd4554e5a311 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 28 Jan 2019 18:21:32 +0100 Subject: [PATCH] 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. --- tests/controls/notebooktest.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/controls/notebooktest.cpp b/tests/controls/notebooktest.cpp index 1812d08a97..4309a46ee5 100644 --- a/tests/controls/notebooktest.cpp +++ b/tests/controls/notebooktest.cpp @@ -20,7 +20,9 @@ #endif // WX_PRECOMP #include "wx/notebook.h" + #include "bookctrlbasetest.h" +#include "testableframe.h" class NotebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase { @@ -118,4 +120,25 @@ void NotebookTestCase::NoEventsOnDestruction() 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