Fix adding pages without associated window to wxTreebook

wxTreebook is supposed to allow not specifying any valid window for the
top-level pages, but this didn't work any longer, probably since the
changes of 02a92e23f3 (see #4379), as a
possibly null page was dereferenced without checking, resulting in a
crash.

Fix this by adding a missing check.

Also rename DoGetNonNullPage() to TryGetNonNullPage() to make it more
clear that this function can return null and add a unit test checking
that calling AddPage(NULL) really works (or at least doesn't crash).

See https://github.com/wxWidgets/wxWidgets/pull/921
This commit is contained in:
Vadim Zeitlin
2018-09-18 00:33:59 +02:00
parent 39e19a8f8c
commit b88d5e08ce
5 changed files with 32 additions and 8 deletions

View File

@@ -43,11 +43,13 @@ private:
wxBOOK_CTRL_BASE_TESTS();
CPPUNIT_TEST( Image );
CPPUNIT_TEST( SubPages );
CPPUNIT_TEST( ContainerPage );
CPPUNIT_TEST( Expand );
CPPUNIT_TEST( Delete );
CPPUNIT_TEST_SUITE_END();
void SubPages();
void ContainerPage();
void Expand();
void Delete();
@@ -92,6 +94,20 @@ void TreebookTestCase::SubPages()
CPPUNIT_ASSERT_EQUAL(3, m_treebook->GetPageParent(5));
}
void TreebookTestCase::ContainerPage()
{
// Get rid of the pages added in setUp().
m_treebook->DeleteAllPages();
CHECK( m_treebook->GetPageCount() == 0 );
// Adding a page without the associated window should be allowed.
REQUIRE_NOTHROW( m_treebook->AddPage(NULL, "Container page") );
CHECK( m_treebook->GetPageParent(0) == -1 );
m_treebook->AddSubPage(new wxPanel(m_treebook), "Child page");
CHECK( m_treebook->GetPageParent(1) == 0 );
}
void TreebookTestCase::Expand()
{
wxPanel* subpanel1 = new wxPanel(m_treebook);