#include "SegfaultApp.h" #include #include #include #include #include namespace TestCase { namespace SegfaultOnF5 { std::unique_ptr createApplication(const Wt::WEnvironment& env) { return std::make_unique(env); } DefaultWidget::DefaultWidget() { createLayout(); setupConnections(); } void DefaultWidget::setupForFail() { tmpl_Layout->setCondition("if_Layer2", true); tmpl_Layout->setCondition("if_Fault", true); btn_Fail = tmpl_Layout->bindNew("btn_Fail", "This Button should not be seen in the example"); btn_Fail->clicked().connect([this](){ addNew("This also should never be seen, but the connection itself is key"); }); btn_Fail->clicked().preventPropagation(); } void DefaultWidget::handlePathChange(const std::string& path) { if(path.rfind("/fault", 0) == 0) { faultContainer->setHidden(false); tmpl_Layout->setHidden(true); } } void DefaultWidget::createLayout() { faultContainer = addNew(); faultContainer->addNew("If this Widget is shown on Application Startup and navigated away from the app, Destruction should cause a Segfault."); faultContainer->addNew(); faultContainer->addNew("On the other hand, if after starting here and this button is pressed to show the other widget, it should not."); faultContainer->addNew(); btn_Success = faultContainer->addNew("Click to avoid Sefault"); faultContainer->setHidden(true); tmpl_Layout = addNew( "
" "

" "This is the default Widget to be shown. If you see this before navigating away, a Segfault should not happen" "

" "${}" "

This should be seen

" "${}" "${btn_Fail}" "${}" "${
}" "
" ); tmpl_Layout->setCondition("if_Fault", false); } void DefaultWidget::setupConnections() { tmpl_Layout->clicked().connect([this](){ this->btn_Fail->setDisabled(true); }); btn_Success->clicked().connect([this](){ faultContainer->setHidden(true); tmpl_Layout->setHidden(false); Wt::WApplication::instance()->setInternalPath("/"); }); } Application::Application(const Wt::WEnvironment &env) : Wt::WApplication(env) { createLayout(); setupConnections(); wgt_Default->setupForFail(); wgt_Default->handlePathChange(internalPath()); } void Application::createLayout() { wgt_Default = root()->addNew(); } void Application::setupConnections() { internalPathChanged().connect(wgt_Default, &DefaultWidget::handlePathChange); } } }