From 5bef244072c8cbfa413903cbd1af23802b9d69ba Mon Sep 17 00:00:00 2001 From: Nick Draper <nick.draper@stfc.ac.uk> Date: Mon, 6 Apr 2020 16:51:42 +0100 Subject: [PATCH] Add a unit test to prevent regression --- qt/widgets/common/CMakeLists.txt | 3 + .../common/test/FitPropertyBrowserTest.h | 57 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 qt/widgets/common/test/FitPropertyBrowserTest.h diff --git a/qt/widgets/common/CMakeLists.txt b/qt/widgets/common/CMakeLists.txt index c5e06592e17..6a92f428600 100644 --- a/qt/widgets/common/CMakeLists.txt +++ b/qt/widgets/common/CMakeLists.txt @@ -931,6 +931,7 @@ set(TEST_FILES test/FileDialogHandlerTest.h test/FindFilesThreadPoolManagerTest.h test/FindFilesWorkerTest.h + test/FitPropertyBrowserTest.h test/FunctionModelTest.h test/FunctionMultiDomainPresenterTest.h test/FunctionBrowserUtilsTest.h @@ -976,6 +977,7 @@ set( test/FileDialogHandlerTest.h test/FindFilesThreadPoolManagerTest.h test/FindFilesWorkerTest.h + test/FitPropertyBrowserTest.h test/FunctionModelTest.h test/FunctionMultiDomainPresenterTest.h test/FunctionBrowserUtilsTest.h @@ -1047,6 +1049,7 @@ set( test/FileDialogHandlerTest.h test/FindFilesThreadPoolManagerTest.h test/FindFilesWorkerTest.h + test/FitPropertyBrowserTest.h test/InterfaceManagerTest.h test/QtJSONUtilsTest.h test/RepoModelTest.h diff --git a/qt/widgets/common/test/FitPropertyBrowserTest.h b/qt/widgets/common/test/FitPropertyBrowserTest.h new file mode 100644 index 00000000000..60044de0128 --- /dev/null +++ b/qt/widgets/common/test/FitPropertyBrowserTest.h @@ -0,0 +1,57 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source, +// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS +// SPDX - License - Identifier: GPL - 3.0 + +#pragma once + +#include "MantidQtWidgets/Common/FitPropertyBrowser.h" +#include "MantidAPI/IFunction1D.h" +#include "MantidAPI/ParamFunction.h" +#include "MantidAPI/FunctionFactory.h" +#include <cxxtest/TestSuite.h> + +using namespace Mantid::API; + +class FitPropertyBrowserTest_Funct : public ParamFunction, public IFunction1D { +public: + FitPropertyBrowserTest_Funct() { + declareParameter("b0"); + declareParameter("b1"); + } + + std::string name() const override { return "FitPropertyBrowserTest_Funct"; } + + void function1D(double *out, const double *xValues, + const size_t nData) const override { + UNUSED_ARG(out); + UNUSED_ARG(xValues); + UNUSED_ARG(nData); + } + void functionDeriv1D(Jacobian *out, const double *xValues, + const size_t nData) override { + UNUSED_ARG(out); + UNUSED_ARG(xValues); + UNUSED_ARG(nData); + } +}; + +DECLARE_FUNCTION(FitPropertyBrowserTest_Funct) + +class FitPropertyBrowserTest : public CxxTest::TestSuite { +public: + //This is a very specific test for a bug that is now fixed to prevent regression + void test_FunctionFactory_notification_is_released() { + + //create a FunctionBrowser + auto fpBrowser = std::make_unique<MantidQt::MantidWidgets::FitPropertyBrowser>(); + //initialise it - this adds an observer on the function factory update message + fpBrowser->init(); + //delete the FunctionBrowser + fpBrowser.reset(); + //Make sure the FunctionFactory does not have a dead link as an observer + TS_ASSERT_THROWS_NOTHING(FunctionFactory::Instance().unsubscribe("FitPropertyBrowserTest_Funct");) + } + +}; -- GitLab