Skip to content
Snippets Groups Projects
Commit bdb59964 authored by Matthew Andrew's avatar Matthew Andrew
Browse files

Updated IndirectSpectrumSelectionPresenterTest Re #28057

parent 25c0a21e
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include <cxxtest/TestSuite.h> #include <cxxtest/TestSuite.h>
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include "IndirectFittingModelLegacy.h" #include "IndirectFittingModel.h"
#include "IndirectSpectrumSelectionPresenterLegacy.h" #include "IndirectSpectrumSelectionPresenter.h"
#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/IAlgorithm.h" #include "MantidAPI/IAlgorithm.h"
#include "MantidAPI/IFunction.h" #include "MantidAPI/IFunction.h"
...@@ -48,33 +48,34 @@ static QApplicationHolder MAIN_QAPPLICATION; ...@@ -48,33 +48,34 @@ static QApplicationHolder MAIN_QAPPLICATION;
GNU_DIAG_OFF_SUGGEST_OVERRIDE GNU_DIAG_OFF_SUGGEST_OVERRIDE
/// Mock object to mock the view /// Mock object to mock the view
class MockIndirectSpectrumSelectionView class MockIndirectSpectrumSelectionView : public IndirectSpectrumSelectionView {
: public IndirectSpectrumSelectionViewLegacy {
public: public:
/// Signals /// Signals
void emitSelectedSpectraChanged(std::string const &spectra) { void emitSelectedSpectraChanged(std::string const &spectra) {
emit selectedSpectraChanged(spectra); emit selectedSpectraChanged(spectra);
} }
void emitSelectedSpectraChanged(std::size_t minimum, std::size_t maximum) { void emitSelectedSpectraChanged(IDA::WorkspaceIndex minimum,
IDA::WorkspaceIndex maximum) {
emit selectedSpectraChanged(minimum, maximum); emit selectedSpectraChanged(minimum, maximum);
} }
void emitMaskSpectrumChanged(int spectrum) { void emitMaskSpectrumChanged(IDA::WorkspaceIndex spectrum) {
emit maskSpectrumChanged(spectrum); emit maskSpectrumChanged(spectrum);
} }
/// Public methods /// Public methods
MOCK_CONST_METHOD0(minimumSpectrum, std::size_t()); MOCK_CONST_METHOD0(minimumSpectrum, IDA::WorkspaceIndex());
MOCK_CONST_METHOD0(maximumSpectrum, std::size_t()); MOCK_CONST_METHOD0(maximumSpectrum, IDA::WorkspaceIndex());
MOCK_CONST_METHOD0(spectraString, std::string()); MOCK_CONST_METHOD0(spectraString, std::string());
MOCK_CONST_METHOD0(maskString, std::string()); MOCK_CONST_METHOD0(maskString, std::string());
MOCK_METHOD1(displaySpectra, void(std::string const &spectraString)); MOCK_METHOD1(displaySpectra, void(std::string const &spectraString));
MOCK_METHOD2(displaySpectra, void(int minimum, int maximum)); MOCK_METHOD1(displaySpectra, void(std::pair<IDA::WorkspaceIndex, IDA::WorkspaceIndex>));
MOCK_METHOD2(setSpectraRange, void(int minimum, int maximum)); MOCK_METHOD2(setSpectraRange,
void(IDA::WorkspaceIndex minimum, IDA::WorkspaceIndex maximum));
MOCK_METHOD0(showSpectraErrorLabel, void()); MOCK_METHOD0(showSpectraErrorLabel, void());
MOCK_METHOD0(hideSpectraErrorLabel, void()); MOCK_METHOD0(hideSpectraErrorLabel, void());
...@@ -83,28 +84,28 @@ public: ...@@ -83,28 +84,28 @@ public:
MOCK_METHOD0(clear, void()); MOCK_METHOD0(clear, void());
/// Public slots /// Public slots
MOCK_METHOD1(setMinimumSpectrum, void(std::size_t spectrum)); MOCK_METHOD1(setMinimumSpectrum, void(IDA::WorkspaceIndex spectrum));
MOCK_METHOD1(setMaximumSpectrum, void(std::size_t spectrum)); MOCK_METHOD1(setMaximumSpectrum, void(IDA::WorkspaceIndex spectrum));
MOCK_METHOD1(setSpectraString, void(std::string const &spectraString)); MOCK_METHOD1(setSpectraString, void(std::string const &spectraString));
MOCK_METHOD1(setMaskString, void(std::string const &maskString)); MOCK_METHOD1(setMaskString, void(std::string const &maskString));
}; };
/// Note that there is limited (if any) interaction going from this model to the /// Note that there is limited (if any) interaction going from this model to the
/// IndirectSpectrumSelectionViewLegacy, meaning that not many methods are /// IndirectSpectrumSelectionView, meaning that not many methods are
/// required for mocking. /// required for mocking.
class MockIndirectSpectrumSelectionModel : public IndirectFittingModelLegacy { class MockIndirectSpectrumSelectionModel : public IndirectFittingModel {
public: public:
/// Public methods /// Public methods
MOCK_CONST_METHOD2(getExcludeRegion, MOCK_CONST_METHOD2(getExcludeRegion,
std::string(std::size_t dataIndex, std::size_t index)); std::string(TableDatasetIndex dataIndex, IDA::WorkspaceIndex index));
MOCK_CONST_METHOD0(isMultiFit, bool()); MOCK_CONST_METHOD0(isMultiFit, bool());
private: private:
std::string sequentialFitOutputName() const override { return ""; }; std::string sequentialFitOutputName() const override { return ""; };
std::string simultaneousFitOutputName() const override { return ""; }; std::string simultaneousFitOutputName() const override { return ""; };
std::string singleFitOutputName(std::size_t index, std::string singleFitOutputName(TableDatasetIndex index,
std::size_t spectrum) const override { IDA::WorkspaceIndex spectrum) const override {
UNUSED_ARG(index); UNUSED_ARG(index);
UNUSED_ARG(spectrum); UNUSED_ARG(spectrum);
return ""; return "";
...@@ -133,7 +134,7 @@ public: ...@@ -133,7 +134,7 @@ public:
void setUp() override { void setUp() override {
m_view = std::make_unique<NiceMock<MockIndirectSpectrumSelectionView>>(); m_view = std::make_unique<NiceMock<MockIndirectSpectrumSelectionView>>();
m_model = std::make_unique<NiceMock<MockIndirectSpectrumSelectionModel>>(); m_model = std::make_unique<NiceMock<MockIndirectSpectrumSelectionModel>>();
m_presenter = std::make_unique<IndirectSpectrumSelectionPresenterLegacy>( m_presenter = std::make_unique<IndirectSpectrumSelectionPresenter>(
std::move(m_model.get()), std::move(m_view.get())); std::move(m_model.get()), std::move(m_view.get()));
SetUpADSWithWorkspace ads("WorkspaceName", createWorkspace(10)); SetUpADSWithWorkspace ads("WorkspaceName", createWorkspace(10));
...@@ -156,7 +157,7 @@ public: ...@@ -156,7 +157,7 @@ public:
///---------------------------------------------------------------------- ///----------------------------------------------------------------------
void test_that_the_model_and_view_have_been_instantiated_correctly() { void test_that_the_model_and_view_have_been_instantiated_correctly() {
std::size_t const maxSpectrum(3); IDA::WorkspaceIndex const maxSpectrum(3);
ON_CALL(*m_view, maximumSpectrum()).WillByDefault(Return(maxSpectrum)); ON_CALL(*m_view, maximumSpectrum()).WillByDefault(Return(maxSpectrum));
ON_CALL(*m_model, isMultiFit()).WillByDefault(Return(false)); ON_CALL(*m_model, isMultiFit()).WillByDefault(Return(false));
...@@ -174,10 +175,12 @@ public: ...@@ -174,10 +175,12 @@ public:
test_that_invoking_a_presenter_method_will_call_the_relevant_methods_in_the_model_and_view() { test_that_invoking_a_presenter_method_will_call_the_relevant_methods_in_the_model_and_view() {
std::string const excludeRegion("0-1"); std::string const excludeRegion("0-1");
ON_CALL(*m_model, getExcludeRegion(0, 0)) ON_CALL(*m_model, getExcludeRegion(TableDatasetIndex(0), IDA::WorkspaceIndex(0)))
.WillByDefault(Return(excludeRegion)); .WillByDefault(Return(excludeRegion));
Expectation getMask = EXPECT_CALL(*m_model, getExcludeRegion(0, 0)) Expectation getMask =
EXPECT_CALL(*m_model, getExcludeRegion(TableDatasetIndex(0),
IDA::WorkspaceIndex(0)))
.Times(1) .Times(1)
.WillOnce(Return(excludeRegion)); .WillOnce(Return(excludeRegion));
EXPECT_CALL(*m_view, setMaskString(excludeRegion)).Times(1).After(getMask); EXPECT_CALL(*m_view, setMaskString(excludeRegion)).Times(1).After(getMask);
...@@ -223,10 +226,10 @@ public: ...@@ -223,10 +226,10 @@ public:
void void
test_that_the_maskSpectrumChanged_signal_will_change_the_mask_by_calling_displayBinMask() { test_that_the_maskSpectrumChanged_signal_will_change_the_mask_by_calling_displayBinMask() {
std::size_t const maskSpectrum(0); IDA::WorkspaceIndex const maskSpectrum(0);
Expectation getMask = Expectation getMask =
EXPECT_CALL(*m_model, getExcludeRegion(0, maskSpectrum)) EXPECT_CALL(*m_model, getExcludeRegion(TableDatasetIndex(0), maskSpectrum))
.Times(1) .Times(1)
.WillOnce(Return("0")); .WillOnce(Return("0"));
EXPECT_CALL(*m_view, setMaskString("0")).Times(1).After(getMask); EXPECT_CALL(*m_view, setMaskString("0")).Times(1).After(getMask);
...@@ -236,10 +239,11 @@ public: ...@@ -236,10 +239,11 @@ public:
void void
test_that_the_maskSpectrumChanged_signal_will_change_the_mask_to_an_empty_string_if_the_index_provided_is_out_of_range() { test_that_the_maskSpectrumChanged_signal_will_change_the_mask_to_an_empty_string_if_the_index_provided_is_out_of_range() {
std::size_t const maskSpectrum(11); IDA::WorkspaceIndex const maskSpectrum(11);
Expectation getMask = Expectation getMask =
EXPECT_CALL(*m_model, getExcludeRegion(0, maskSpectrum)) EXPECT_CALL(*m_model,
getExcludeRegion(TableDatasetIndex(0), maskSpectrum))
.Times(1) .Times(1)
.WillOnce(Return("")); .WillOnce(Return(""));
EXPECT_CALL(*m_view, setMaskString("")).Times(1).After(getMask); EXPECT_CALL(*m_view, setMaskString("")).Times(1).After(getMask);
...@@ -253,7 +257,7 @@ public: ...@@ -253,7 +257,7 @@ public:
void void
test_that_minimumSpectrum_returns_the_spectrum_number_that_it_is_set_as() { test_that_minimumSpectrum_returns_the_spectrum_number_that_it_is_set_as() {
std::size_t const minSpectrum(3); IDA::WorkspaceIndex const minSpectrum(3);
EXPECT_CALL(*m_view, setMinimumSpectrum(minSpectrum)).Times(1); EXPECT_CALL(*m_view, setMinimumSpectrum(minSpectrum)).Times(1);
EXPECT_CALL(*m_view, minimumSpectrum()) EXPECT_CALL(*m_view, minimumSpectrum())
...@@ -266,7 +270,7 @@ public: ...@@ -266,7 +270,7 @@ public:
void void
test_that_maximumSpectrum_returns_the_spectrum_number_that_it_is_set_as() { test_that_maximumSpectrum_returns_the_spectrum_number_that_it_is_set_as() {
std::size_t const maxSpectrum(3); IDA::WorkspaceIndex const maxSpectrum(3);
EXPECT_CALL(*m_view, setMaximumSpectrum(maxSpectrum)).Times(1); EXPECT_CALL(*m_view, setMaximumSpectrum(maxSpectrum)).Times(1);
EXPECT_CALL(*m_view, maximumSpectrum()) EXPECT_CALL(*m_view, maximumSpectrum())
...@@ -310,19 +314,20 @@ public: ...@@ -310,19 +314,20 @@ public:
void void
test_that_displaySpectra_will_set_the_minimum_and_maximum_of_the_spectraString() { test_that_displaySpectra_will_set_the_minimum_and_maximum_of_the_spectraString() {
int const minSpectrum(2); IDA::WorkspaceIndex const minSpectrum(2);
int const maxSpectrum(5); IDA::WorkspaceIndex const maxSpectrum(5);
EXPECT_CALL(*m_view, displaySpectra(minSpectrum, maxSpectrum)).Times(1); EXPECT_CALL(*m_view, displaySpectra(std::make_pair(minSpectrum, maxSpectrum))).Times(1);
EXPECT_CALL(*m_view, spectraString()).Times(1).WillOnce(Return("2-5")); EXPECT_CALL(*m_view, spectraString()).Times(1).WillOnce(Return("2-5"));
m_view->displaySpectra(minSpectrum, maxSpectrum); m_view->displaySpectra(
std::make_pair(minSpectrum, maxSpectrum));
m_view->spectraString(); m_view->spectraString();
} }
void test_that_setSpectraRange_will_set_the_minimum_and_maximum_spectrums() { void test_that_setSpectraRange_will_set_the_minimum_and_maximum_spectrums() {
int const minSpectrum(2); IDA::WorkspaceIndex const minSpectrum(2);
int const maxSpectrum(5); IDA::WorkspaceIndex const maxSpectrum(5);
EXPECT_CALL(*m_view, setSpectraRange(minSpectrum, maxSpectrum)).Times(1); EXPECT_CALL(*m_view, setSpectraRange(minSpectrum, maxSpectrum)).Times(1);
EXPECT_CALL(*m_view, minimumSpectrum()).Times(1).WillOnce(Return(2)); EXPECT_CALL(*m_view, minimumSpectrum()).Times(1).WillOnce(Return(2));
...@@ -362,5 +367,5 @@ public: ...@@ -362,5 +367,5 @@ public:
private: private:
std::unique_ptr<MockIndirectSpectrumSelectionView> m_view; std::unique_ptr<MockIndirectSpectrumSelectionView> m_view;
std::unique_ptr<MockIndirectSpectrumSelectionModel> m_model; std::unique_ptr<MockIndirectSpectrumSelectionModel> m_model;
std::unique_ptr<IndirectSpectrumSelectionPresenterLegacy> m_presenter; std::unique_ptr<IndirectSpectrumSelectionPresenter> m_presenter;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment