forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PeakShapeSphericalFactoryTest.h
106 lines (84 loc) · 3.81 KB
/
PeakShapeSphericalFactoryTest.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// 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
#ifdef _MSC_VER
// 'identifier' : class 'type' needs to have dll-interface to be used by clients
// of class 'type2'
#pragma warning(disable : 4251)
// JSON: non- DLL-interface classkey 'identifier' used as base for
// DLL-interface classkey 'identifier'
#pragma warning(disable : 4275)
#endif
#include <cxxtest/TestSuite.h>
#include <gmock/gmock.h>
#include <json/json.h>
#include "MantidDataObjects/PeakShapeSpherical.h"
#include "MantidDataObjects/PeakShapeSphericalFactory.h"
#include "MantidFrameworkTestHelpers/FallbackBoostOptionalIO.h"
#include "MantidJson/Json.h"
#include "MantidKernel/SpecialCoordinateSystem.h"
#include "MantidKernel/VMD.h"
#include "MockObjects.h"
using namespace Mantid::DataObjects;
using namespace Mantid::Kernel;
class PeakShapeSphericalFactoryTest : 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 PeakShapeSphericalFactoryTest *createSuite() { return new PeakShapeSphericalFactoryTest(); }
static void destroySuite(PeakShapeSphericalFactoryTest *suite) { delete suite; }
void test_invalid_json_with_no_successor() {
PeakShapeSphericalFactory factory;
TS_ASSERT_THROWS(factory.create(""), std::invalid_argument &);
}
void test_use_successor_when_different_shape_found() {
using namespace testing;
// We expect it to try to use the deletate factory. If it cannot process the
// json.
MockPeakShapeFactory *delegate = new MockPeakShapeFactory;
EXPECT_CALL(*delegate, create(_)).Times(1);
PeakShapeSphericalFactory factory;
factory.setSuccessor(PeakShapeFactory_const_sptr(delegate));
// Minimal valid JSON for describing the shape.
Json::Value root;
root["shape"] = "square";
const std::string str_json = Mantid::JsonHelpers::jsonToString(root);
factory.create(str_json);
TS_ASSERT(Mock::VerifyAndClearExpectations(delegate));
}
void test_create() {
const double radius = 2;
const SpecialCoordinateSystem frame = SpecialCoordinateSystem::HKL;
const std::string algorithmName = "foo";
const int algorithmVersion = 3;
// Make a source shape
PeakShapeSpherical sourceShape(radius, frame, algorithmName, algorithmVersion);
PeakShapeSphericalFactory factory;
Mantid::Geometry::PeakShape *productShape = factory.create(sourceShape.toJSON());
PeakShapeSpherical *sphericalShapeProduct = dynamic_cast<PeakShapeSpherical *>(productShape);
TS_ASSERT(sphericalShapeProduct);
TS_ASSERT_EQUALS(sourceShape, *sphericalShapeProduct);
delete productShape;
}
void test_create_with_multiple_radii() {
const double radius = 2;
const double backgroundInnerRadius = 3;
const double backgroundOuterRadius = 4;
const SpecialCoordinateSystem frame = SpecialCoordinateSystem::HKL;
const std::string algorithmName = "foo";
const int algorithmVersion = 3;
// Make a source shape with background outer and inner radius
PeakShapeSpherical sourceShape(radius, backgroundInnerRadius, backgroundOuterRadius, frame, algorithmName,
algorithmVersion);
PeakShapeSphericalFactory factory;
Mantid::Geometry::PeakShape *productShape = factory.create(sourceShape.toJSON());
PeakShapeSpherical *sphericalShapeProduct = dynamic_cast<PeakShapeSpherical *>(productShape);
TS_ASSERT(sphericalShapeProduct);
TS_ASSERT_EQUALS(sourceShape, *sphericalShapeProduct);
delete productShape;
}
};