Test that adding window to 2 sizers results in an assert

Check that adding a window to either the same, or different, sizer the
second time asserts -- but that it can still be moved to another sizer
if it is detached from the first one first.

Also document that SetContainingSizer() should never be called from
outside the library.

See #17166.
This commit is contained in:
Vadim Zeitlin
2019-09-27 16:12:18 +02:00
parent 7bba2d09fd
commit e46385e964
2 changed files with 25 additions and 3 deletions

View File

@@ -26,6 +26,7 @@
#include "wx/uiaction.h"
#include "wx/caret.h"
#include "wx/cshelp.h"
#include "wx/scopedptr.h"
#include "wx/tooltip.h"
class WindowTestCase
@@ -379,3 +380,19 @@ TEST_CASE_METHOD(WindowTestCase, "Window::FindWindowBy", "[window]")
CHECK( wxWindow::FindWindowByName("noname") == NULL );
CHECK( wxWindow::FindWindowByLabel("nolabel") == NULL );
}
TEST_CASE_METHOD(WindowTestCase, "Window::SizerErrors", "[window][sizer][error]")
{
wxWindow* const child = new wxWindow(m_window, wxID_ANY);
wxScopedPtr<wxSizer> const sizer1(new wxBoxSizer(wxHORIZONTAL));
wxScopedPtr<wxSizer> const sizer2(new wxBoxSizer(wxHORIZONTAL));
REQUIRE_NOTHROW( sizer1->Add(child) );
CHECK_THROWS_AS( sizer1->Add(child), TestAssertFailure );
CHECK_THROWS_AS( sizer2->Add(child), TestAssertFailure );
CHECK_NOTHROW( sizer1->Detach(child) );
CHECK_NOTHROW( sizer2->Add(child) );
REQUIRE_NOTHROW( delete child );
}