forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IValidatorTest.h
53 lines (45 loc) · 1.65 KB
/
IValidatorTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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 "MantidKernel/IValidator.h"
#include <cxxtest/TestSuite.h>
#include <memory>
namespace {
/**
* Implement the validator interface to check that
* it does not copy any data when the check method is called
*
* This is intimately tied to the test implementation
*/
class DataNotCopiedValidator : public Mantid::Kernel::IValidator {
public:
DataNotCopiedValidator() : Mantid::Kernel::IValidator(), m_head(nullptr) {}
Mantid::Kernel::IValidator_sptr clone() const override { return std::make_shared<DataNotCopiedValidator>(); }
/// Return the stored head pointer
const double *head() const { return m_head; }
private:
std::string check(const boost::any &value) const override {
using HeldType = std::vector<double>;
const HeldType *dataPtr = boost::any_cast<const HeldType *>(value);
m_head = dataPtr->data();
return "";
}
/// The pointer to the head of the vector
mutable const double *m_head;
};
} // namespace
class IValidatorTest : public CxxTest::TestSuite {
public:
void test_Values_Are_Not_Copied_When_Passed_To_Concrete_Validators() {
const std::vector<double> testData(10, 1.0);
DataNotCopiedValidator noCopy;
std::string error;
TS_ASSERT_THROWS_NOTHING(error = noCopy.isValid(testData));
TS_ASSERT_EQUALS(error, "");
TS_ASSERT_EQUALS(noCopy.head(), testData.data());
}
};