diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h index ff57ea6612b45ef37908977490cd51f937310eb6..d3d55547b6b3e45f41d742cfe23580c688f619b1 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h @@ -3,6 +3,9 @@ #include <string> +namespace MantidQt { +namespace CustomInterfaces { + /** Settings related to calibration in the engineering diffraction custom interface. This is just a data holder. @@ -35,5 +38,8 @@ struct EnggDiffCalibSettings { std::string m_templateGSAS_PRM; }; +} // namespace CustomInterfaces +} // namespace MantidQt + #endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFCALIBSETTINGS_H_ diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h index b6d0577741f531ad0952d3159de2de24dd2e2e5e..7635712d0f079d0bf73b632e2d33b3990e9a5b60 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h @@ -69,7 +69,7 @@ public: std::vector<std::string> logMsgs() const { return m_logMsgs; } - virtual std::string getRBNumber() const; + std::string getRBNumber() const; EnggDiffCalibSettings currentCalibSettings() const { return m_calibSettings; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h index b56ec4456c1136ef115943a359e2a5783d87b3bf..cc70a3ab293c716e458ea698103e0a0778262a1c 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h @@ -79,6 +79,19 @@ public: */ virtual std::string getRBNumber() const = 0; + /** + * + * @return calibration settings object with current user settings + */ + virtual EnggDiffCalibSettings currentCalibSettings() const = 0; + + /** + * What's the instrument this interface is using? + * + * @param current instrumentselection + */ + virtual std::string currentInstrument() const = 0; + /** * Save settings (normally when closing the interface). This * concerns only GUI settings, such as window max/min status and diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp index 6af961ff039103571ec0c74f6bdbbee8a7eb79f4..18948878677e06f7eb9c40434097bb9aa29b58c6 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp @@ -66,20 +66,28 @@ void EnggDiffractionPresenter::notify( } void EnggDiffractionPresenter::processStart() { + EnggDiffCalibSettings cs = m_view->currentCalibSettings(); +} + +void EnggDiffractionPresenter::processLoadExistingCalib() { + EnggDiffCalibSettings cs = m_view->currentCalibSettings(); +} + +void EnggDiffractionPresenter::processCalcCalib() { + EnggDiffCalibSettings cs = m_view->currentCalibSettings(); +} + +void EnggDiffractionPresenter::processLogMsg() { std::vector<std::string> msgs = m_view->logMsgs(); for (size_t i = 0; i < msgs.size(); i++) { g_log.information() << msgs[i] << std::endl; } } -void EnggDiffractionPresenter::processLoadExistingCalib() {} - -void EnggDiffractionPresenter::processCalcCalib() {} - -void EnggDiffractionPresenter::processLogMsg() {} - void EnggDiffractionPresenter::processInstChange() { - g_log.error() << "Changing instrument is not supported!" << std::endl; + const std::string err = "Changing instrument is not supported!"; + g_log.error() << err << std::endl; + m_view->userError("Fatal error", err); } void EnggDiffractionPresenter::processShutDown() { diff --git a/Code/Mantid/MantidQt/CustomInterfaces/test/EnggDiffractionPresenterTest.h b/Code/Mantid/MantidQt/CustomInterfaces/test/EnggDiffractionPresenterTest.h new file mode 100644 index 0000000000000000000000000000000000000000..2d64f110d1763c8e7fa54dfcca0dfad814835c18 --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/test/EnggDiffractionPresenterTest.h @@ -0,0 +1,133 @@ +#ifndef MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONPRESENTERTEST_H +#define MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONPRESENTERTEST_H + +#include "MantidAPI/FrameworkManager.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h" + +#include <cxxtest/TestSuite.h> +#include "EnggDiffractionViewMock.h" + +using namespace MantidQt::CustomInterfaces; +using testing::TypedEq; +using testing::Return; + +class EnggDiffractionPresenterTest : public CxxTest::TestSuite { + +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static EnggDiffractionPresenterTest *createSuite() { + return new EnggDiffractionPresenterTest(); + } + + static void destroySuite(EnggDiffractionPresenterTest *suite) { + delete suite; + } + + EnggDiffractionPresenterTest() { + Mantid::API::FrameworkManager::Instance(); // make sure framework is + // initialized + } + + void setUp() { + m_view.reset(new testing::NiceMock<MockEnggDiffractionView>()); + m_presenter.reset( + new MantidQt::CustomInterfaces::EnggDiffractionPresenter(m_view.get())); + } + + void tearDown() { + TS_ASSERT(testing::Mock::VerifyAndClearExpectations(m_view.get())); + } + + void test_start() { + testing::NiceMock<MockEnggDiffractionView> mockView; + MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView); + + std::vector<std::string> sv; + sv.push_back("dummy msg"); + EXPECT_CALL(mockView, logMsgs()).Times(1).WillOnce(Return(sv)); + + // No errors/warnings + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); + + pres.notify(IEnggDiffractionPresenter::LogMsg); + } + + void test_loadExistingCalib() { + testing::NiceMock<MockEnggDiffractionView> mockView; + MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView); + + // will need basic calibration settings from the user + EnggDiffCalibSettings calibSettings; + EXPECT_CALL(mockView, currentCalibSettings()).Times(1).WillOnce( + Return(calibSettings)); + + // No errors/warnings + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); + + pres.notify(IEnggDiffractionPresenter::LoadExistingCalib); + } + + void test_calcCalib() { + testing::NiceMock<MockEnggDiffractionView> mockView; + MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView); + + // will need basic calibration settings from the user + EnggDiffCalibSettings calibSettings; + EXPECT_CALL(mockView, currentCalibSettings()).Times(1).WillOnce( + Return(calibSettings)); + + // No errors/warnings + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); + + pres.notify(IEnggDiffractionPresenter::CalcCalib); + } + + void test_logMsg() { + testing::NiceMock<MockEnggDiffractionView> mockView; + MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView); + + std::vector<std::string> sv; + sv.push_back("dummy log"); + EXPECT_CALL(mockView, logMsgs()).Times(1).WillOnce(Return(sv)); + + // No errors/warnings + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); + + pres.notify(IEnggDiffractionPresenter::LogMsg); + } + + void test_instChange() { + testing::NiceMock<MockEnggDiffractionView> mockView; + MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView); + + // 1 error, no warnings + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(1); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); + + pres.notify(IEnggDiffractionPresenter::InstrumentChange); + } + + void test_shutDown() { + testing::NiceMock<MockEnggDiffractionView> mockView; + MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView); + + EXPECT_CALL(mockView, saveSettings()).Times(1); + // No errors, no warnings + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); + + pres.notify(IEnggDiffractionPresenter::ShutDown); + } + +private: + boost::scoped_ptr<testing::NiceMock<MockEnggDiffractionView>> m_view; + boost::scoped_ptr<MantidQt::CustomInterfaces::EnggDiffractionPresenter> + m_presenter; +}; + +#endif // MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONPRESENTERTEST_H diff --git a/Code/Mantid/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h b/Code/Mantid/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h new file mode 100644 index 0000000000000000000000000000000000000000..91c50245f57f4775fcfa30dc10720be416157803 --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h @@ -0,0 +1,38 @@ +#ifndef MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONVIEWMOCK_H +#define MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONVIEWMOCK_H + +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h" + +#include <gmock/gmock.h> + +// This is a simple mock for the tomo interface view when using SCARF. +class MockEnggDiffractionView + : public MantidQt::CustomInterfaces::IEnggDiffractionView { + +public: + // void userWarning(const std::string &warn, const std::string &description); + MOCK_METHOD2(userWarning, + void(const std::string &warn, const std::string &description)); + + // void userError(const std::string &err, const std::string &description); + MOCK_METHOD2(userError, + void(const std::string &err, const std::string &description)); + + // std::vector<std::string> logMsgs() const; + MOCK_CONST_METHOD0(logMsgs, std::vector<std::string>()); + + // virtual std::string getRBNumber() const; + MOCK_CONST_METHOD0(getRBNumber, std::string()); + + // EnggDiffCalibSettings currentCalibSettings() const; + MOCK_CONST_METHOD0(currentCalibSettings, + MantidQt::CustomInterfaces::EnggDiffCalibSettings()); + + // std::string currentInstrument() const; + MOCK_CONST_METHOD0(currentInstrument, std::string()); + + // void saveSettings() const; + MOCK_CONST_METHOD0(saveSettings, void()); +}; + +#endif // MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONVIEWMOCK_H