Skip to content

Commit

Permalink
Update Spectroscopy test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
robertapplin committed Sep 20, 2024
1 parent 71301ea commit 74a8a67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions qt/widgets/common/src/UserInputValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ bool UserInputValidator::checkFileFinderWidgetIsValid(const QString &name, const
* @param name :: the "name" of the widget so as to be recognised by the user.
* @param widget :: the widget to check
* @param silent True if an error should not be added to the validator.
* @param autoLoad True if the data should be reloaded if it is not in the ADS.
* @returns True if the input was valid
*/
bool UserInputValidator::checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool const silent,
Expand Down
42 changes: 21 additions & 21 deletions qt/widgets/spectroscopy/test/DataValidationHelperTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ GNU_DIAG_OFF_SUGGEST_OVERRIDE
class MockDataSelector : public DataSelector {
public:
/// Public Methods
MOCK_CONST_METHOD0(getCurrentDataName, QString());
MOCK_METHOD0(isValid, bool());
MOCK_CONST_METHOD1(getCurrentDataName, QString(bool const));
MOCK_METHOD1(isValid, bool(bool const));
};

GNU_DIAG_ON_SUGGEST_OVERRIDE
Expand Down Expand Up @@ -193,54 +193,54 @@ class DataValidationHelperTest : public CxxTest::TestSuite {

private:
template <typename Functor> void assertTheDataIsCheckedOneTime(Functor const &functor, DataType const &primaryType) {
ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(WORKSPACE_NAME)));
ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true));
ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(WORKSPACE_NAME)));
ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true));

EXPECT_CALL(*m_dataSelector, getCurrentDataName()).Times(1);
EXPECT_CALL(*m_dataSelector, isValid()).Times(1);
EXPECT_CALL(*m_dataSelector, getCurrentDataName(true)).Times(1);
EXPECT_CALL(*m_dataSelector, isValid(true)).Times(1);

(void)functor(m_uiv.get(), m_dataSelector.get(), ERROR_LABEL, primaryType, false);
(void)functor(m_uiv.get(), m_dataSelector.get(), ERROR_LABEL, primaryType, false, true);
}

template <typename Functor>
void assertTheDataIsCheckedNTimes(Functor const &functor, int nTimes, DataType const &primaryType,
std::vector<DataType> const &otherTypes) {
ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(WORKSPACE_NAME)));
ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true));
ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(WORKSPACE_NAME)));
ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true));

EXPECT_CALL(*m_dataSelector, getCurrentDataName()).Times(nTimes);
EXPECT_CALL(*m_dataSelector, isValid()).Times(nTimes);
EXPECT_CALL(*m_dataSelector, getCurrentDataName(true)).Times(nTimes);
EXPECT_CALL(*m_dataSelector, isValid(true)).Times(nTimes);

(void)functor(m_uiv.get(), m_dataSelector.get(), ERROR_LABEL, primaryType, otherTypes, false);
(void)functor(m_uiv.get(), m_dataSelector.get(), ERROR_LABEL, primaryType, otherTypes, false, true);
}

template <typename Functor>
void assertThatTheDataIsValid(std::string const &workspaceName, std::string const &errorLabel,
Functor const &functor) {
ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(workspaceName)));
ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true));
ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(workspaceName)));
ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true));

TS_ASSERT(functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false));
TS_ASSERT(functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false, true));
TS_ASSERT(m_uiv->generateErrorMessage().empty());
}

template <typename Functor>
void assertThatTheDataIsInvalid(std::string const &workspaceName, std::string const &errorLabel,
Functor const &functor) {
ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(workspaceName)));
ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true));
ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(workspaceName)));
ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true));

TS_ASSERT(!functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false));
TS_ASSERT(!functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false, true));
TS_ASSERT(!m_uiv->generateErrorMessage().empty());
}

template <typename Functor>
void assertErrorMessage(std::string const &workspaceName, std::string const &errorLabel, Functor const &functor,
std::string const &errorMessage) {
ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(workspaceName)));
ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true));
ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(workspaceName)));
ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true));

(void)functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false);
(void)functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false, true);

TS_ASSERT_EQUALS(m_uiv->generateErrorMessage(), errorMessage);
}
Expand Down

0 comments on commit 74a8a67

Please sign in to comment.