From b1a5cedd6431174616a2db0e7752fd118a3f8657 Mon Sep 17 00:00:00 2001
From: Bruce Toll <btoll@dhsus.com>
Date: Fri, 23 Oct 2020 08:27:58 -0400
Subject: [PATCH] Extra tests for WContainerWidget addwidget family

Include tests for WContainerWidget's addWidget(), insertWidget(), and
insertBefore() methods that are analogous to the addNew() tests.

At present, none of these tests pass.

For consistency, it might make sense for addWidget() to be upgraded to
match the behavior of addNew().

I suspect that calling insertWidget() or insertBefore() with a global
widget indicates a programming error. So, I don't think the tests should
pass as written. Perhaps they should check for a std::invalid_argument
exception, if called with a global widget?
---
 test/widgets/WContainerWidgetTest.C | 67 +++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/test/widgets/WContainerWidgetTest.C b/test/widgets/WContainerWidgetTest.C
index 28fb51dd..9886c390 100644
--- a/test/widgets/WContainerWidgetTest.C
+++ b/test/widgets/WContainerWidgetTest.C
@@ -37,3 +37,70 @@ BOOST_AUTO_TEST_CASE( containerwidget_addnew )
   auto messageBox = testApp.root()->addNew<WMessageBox>();
   BOOST_CHECK_NE(messageBox->parent(), testApp.root());
 }
+
+BOOST_AUTO_TEST_CASE( containerwidget_addwidget )
+{
+  Wt::Test::WTestEnvironment environment;
+  Wt::WApplication testApp(environment);
+
+  auto container = testApp.root()->addWidget(std::make_unique<WContainerWidget>());
+  BOOST_CHECK_EQUAL(container->parent(), testApp.root());
+
+  auto popupMenu = testApp.root()->addWidget(std::make_unique<WPopupMenu>());
+  BOOST_CHECK_NE(popupMenu->parent(), testApp.root());
+
+  auto popupWidget = testApp.root()->addWidget(std::make_unique<WPopupWidget>(std::make_unique<WContainerWidget>()));
+  BOOST_CHECK_NE(popupWidget->parent(), testApp.root());
+
+  auto dialog = testApp.root()->addWidget(std::make_unique<WDialog>());
+  BOOST_CHECK_NE(dialog->parent(), testApp.root());
+
+  auto messageBox = testApp.root()->addWidget(std::make_unique<WMessageBox>());
+  BOOST_CHECK_NE(messageBox->parent(), testApp.root());
+}
+
+BOOST_AUTO_TEST_CASE( containerwidget_insertwidget )
+{
+  Wt::Test::WTestEnvironment environment;
+  Wt::WApplication testApp(environment);
+
+  auto containerZero = testApp.root()->addWidget(std::make_unique<WContainerWidget>());
+
+  auto container = testApp.root()->insertWidget(0, std::make_unique<WContainerWidget>());
+  BOOST_CHECK_EQUAL(container->parent(), testApp.root());
+
+  auto popupMenu = testApp.root()->insertWidget(0, std::make_unique<WPopupMenu>());
+  BOOST_CHECK_NE(popupMenu->parent(), testApp.root());
+
+  auto popupWidget = testApp.root()->insertWidget(0, std::make_unique<WPopupWidget>(std::make_unique<WContainerWidget>()));
+  BOOST_CHECK_NE(popupWidget->parent(), testApp.root());
+
+  auto dialog = testApp.root()->insertWidget(0, std::make_unique<WDialog>());
+  BOOST_CHECK_NE(dialog->parent(), testApp.root());
+
+  auto messageBox = testApp.root()->insertWidget(0, std::make_unique<WMessageBox>());
+  BOOST_CHECK_NE(messageBox->parent(), testApp.root());
+}
+
+BOOST_AUTO_TEST_CASE( containerwidget_insertbefore )
+{
+  Wt::Test::WTestEnvironment environment;
+  Wt::WApplication testApp(environment);
+
+  auto containerZero = testApp.root()->addWidget(std::make_unique<WContainerWidget>());
+
+  auto container = testApp.root()->insertBefore(std::make_unique<WContainerWidget>(), containerZero);
+  BOOST_CHECK_EQUAL(container->parent(), testApp.root());
+
+  auto popupMenu = testApp.root()->insertBefore(std::make_unique<WPopupMenu>(), containerZero);
+  BOOST_CHECK_NE(popupMenu->parent(), testApp.root());
+
+  auto popupWidget = testApp.root()->insertBefore(std::make_unique<WPopupWidget>(std::make_unique<WContainerWidget>()), containerZero);
+  BOOST_CHECK_NE(popupWidget->parent(), testApp.root());
+
+  auto dialog = testApp.root()->insertBefore(std::make_unique<WDialog>(), containerZero);
+  BOOST_CHECK_NE(dialog->parent(), testApp.root());
+
+  auto messageBox = testApp.root()->insertBefore(std::make_unique<WMessageBox>(), containerZero);
+  BOOST_CHECK_NE(messageBox->parent(), testApp.root());
+}
-- 
2.25.4

