Skip to content

Commit

Permalink
Refs #11053 Fix unit test for rhel6
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonPiccardoSelg committed Mar 12, 2015
1 parent 38e4071 commit de65fb8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 41 deletions.
Expand Up @@ -17,28 +17,29 @@
#include "MantidDataObjects/PeakShapeEllipsoid.h"
#include "MantidDataObjects/NoShape.h"
#include "MantidKernel/V3D.h"

#include "MockObjects.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <cxxtest/TestSuite.h>

#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkFieldData.h>
#include <vtkFloatArray.h>
#include <vtkUnsignedCharArray.h>
#include <vtkUnstructuredGrid.h>

#include <boost\shared_ptr.hpp>


using namespace Mantid::MDEvents;
using namespace Mantid::VATES;
using namespace ::testing;

class MockPeakFilter : public Mantid::DataObjects::Peak
{
public:
MockPeakFilter& operator=(const MockPeakFilter& other) {
return *this;
}
MOCK_CONST_METHOD0(getHKL, Mantid::Kernel::V3D (void));
MOCK_CONST_METHOD0(getQLabFrame, Mantid::Kernel::V3D (void));
MOCK_CONST_METHOD0(getQSampleFrame, Mantid::Kernel::V3D (void));
Expand All @@ -47,7 +48,6 @@ class MockPeakFilter : public Mantid::DataObjects::Peak
class MockPeaksWorkspaceFilter : public Mantid::DataObjects::PeaksWorkspace
{
public:
MOCK_CONST_METHOD0(getSpecialCoordinateSystem, Mantid::Kernel::SpecialCoordinateSystem());
MOCK_CONST_METHOD0(getNumberPeaks, int());
MOCK_METHOD1(getPeak, Mantid::DataObjects::Peak & (int peakNum));
MOCK_CONST_METHOD1(getPeak, const Mantid::DataObjects::Peak & (int peakNum));
Expand Down Expand Up @@ -133,26 +133,26 @@ class vtkDataSetToPeaksFilteredDataSetTest : public CxxTest::TestSuite
TSM_ASSERT("The number of elements inside the sphere should be the same for input and output.", insideSphereInput == insideSphereOutput);
}

void do_test_execute(vtkDataSetToPeaksFilteredDataSet peaksFilter, std::vector<std::pair<MockPeakFilter&, Mantid::Kernel::V3D>> peakWsData, Mantid::Kernel::SpecialCoordinateSystem coordinateSystem) {
void do_test_execute(vtkDataSetToPeaksFilteredDataSet peaksFilter, std::vector<std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>> peakWsData, Mantid::Kernel::SpecialCoordinateSystem coordinateSystem) {
std::vector<Mantid::API::IPeaksWorkspace_sptr> peaksContainer;
for (std::vector<std::pair<MockPeakFilter&, Mantid::Kernel::V3D>>::iterator it = peakWsData.begin(); it != peakWsData.end(); ++it) {
for (std::vector<std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>>::iterator it = peakWsData.begin(); it != peakWsData.end(); ++it) {
// Set up the peak
switch(coordinateSystem)
{
case(Mantid::Kernel::SpecialCoordinateSystem::QLab):
EXPECT_CALL(it->first, getQLabFrame()).WillOnce(Return(it->second));
EXPECT_CALL(it->first, getHKL()).Times(0);
EXPECT_CALL(it->first, getQSampleFrame()).Times(0);
EXPECT_CALL(*(it->first), getQLabFrame()).WillOnce(Return(it->second));
EXPECT_CALL(*(it->first), getHKL()).Times(0);
EXPECT_CALL(*(it->first), getQSampleFrame()).Times(0);
break;
case(Mantid::Kernel::SpecialCoordinateSystem::HKL):
EXPECT_CALL(it->first, getQLabFrame()).Times(0);
EXPECT_CALL(it->first, getHKL()).WillOnce(Return(it->second));
EXPECT_CALL(it->first, getQSampleFrame()).Times(0);
EXPECT_CALL(*(it->first), getQLabFrame()).Times(0);
EXPECT_CALL(*(it->first), getHKL()).WillOnce(Return(it->second));
EXPECT_CALL(*(it->first), getQSampleFrame()).Times(0);
break;
case(Mantid::Kernel::SpecialCoordinateSystem::QSample):
EXPECT_CALL(it->first, getQLabFrame()).Times(0);
EXPECT_CALL(it->first, getHKL()).Times(0);
EXPECT_CALL(it->first, getQSampleFrame()).WillOnce(Return(it->second));
EXPECT_CALL(*(it->first), getQLabFrame()).Times(0);
EXPECT_CALL(*(it->first), getHKL()).Times(0);
EXPECT_CALL(*(it->first), getQSampleFrame()).WillOnce(Return(it->second));
break;
default:
break;
Expand All @@ -163,8 +163,7 @@ class vtkDataSetToPeaksFilteredDataSetTest : public CxxTest::TestSuite
MockPeaksWorkspaceFilter & pw = *pw_ptr;

EXPECT_CALL(pw, getNumberPeaks()).Times(1).WillRepeatedly(Return(1));
EXPECT_CALL(pw, getPeak(_)).WillOnce(ReturnRef(it->first));
EXPECT_CALL(pw, getSpecialCoordinateSystem()).WillOnce(Return(coordinateSystem));
EXPECT_CALL(pw, getPeak(_)).WillOnce(ReturnRef(*(it->first)));
peaksContainer.push_back(pw_ptr);
}

Expand Down Expand Up @@ -209,11 +208,11 @@ class vtkDataSetToPeaksFilteredDataSetTest : public CxxTest::TestSuite
double peakRadius = 5;
Mantid::Kernel::SpecialCoordinateSystem coordinateSystem = Mantid::Kernel::SpecialCoordinateSystem::QSample;
Mantid::Geometry::PeakShape_sptr shape(new Mantid::DataObjects::PeakShapeSpherical(peakRadius, coordinateSystem, "test", 1));
MockPeakFilter peak;
peak.setPeakShape(shape);
boost::shared_ptr<MockPeakFilter> peak(new MockPeakFilter());
peak->setPeakShape(shape);

std::vector<std::pair<MockPeakFilter&, Mantid::Kernel::V3D>> fakeSinglePeakPeakWorkspaces;
fakeSinglePeakPeakWorkspaces.push_back(std::pair<MockPeakFilter&, Mantid::Kernel::V3D>(peak, coordinate));
std::vector<std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>> fakeSinglePeakPeakWorkspaces;
fakeSinglePeakPeakWorkspaces.push_back(std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>(peak, coordinate));

std::vector<PeaksFilterDataContainer> peakData;
PeaksFilterDataContainer data1;
Expand Down Expand Up @@ -253,11 +252,11 @@ class vtkDataSetToPeaksFilteredDataSetTest : public CxxTest::TestSuite

Mantid::Kernel::SpecialCoordinateSystem coordinateSystem = Mantid::Kernel::SpecialCoordinateSystem::QSample;
Mantid::Geometry::PeakShape_sptr shape(new Mantid::DataObjects::PeakShapeEllipsoid(directions, radii, radii, radii , coordinateSystem, "test", 1));
MockPeakFilter peak;
peak.setPeakShape(shape);
boost::shared_ptr<MockPeakFilter> peak(new MockPeakFilter());
peak->setPeakShape(shape);

std::vector<std::pair<MockPeakFilter&, Mantid::Kernel::V3D>> fakeSinglePeakPeakWorkspaces;
fakeSinglePeakPeakWorkspaces.push_back(std::pair<MockPeakFilter&, Mantid::Kernel::V3D>(peak, coordinate));
std::vector<std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>> fakeSinglePeakPeakWorkspaces;
fakeSinglePeakPeakWorkspaces.push_back(std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>(peak, coordinate));

std::vector<PeaksFilterDataContainer> peakData;
PeaksFilterDataContainer data1;
Expand Down Expand Up @@ -288,11 +287,11 @@ class vtkDataSetToPeaksFilteredDataSetTest : public CxxTest::TestSuite
Mantid::Kernel::SpecialCoordinateSystem coordinateSystem = Mantid::Kernel::SpecialCoordinateSystem::QSample;
double radius = peaksFilter.getRadiusNoShape();
Mantid::Geometry::PeakShape_sptr shape(new Mantid::DataObjects::NoShape());
MockPeakFilter peak;
peak.setPeakShape(shape);
boost::shared_ptr<MockPeakFilter> peak(new MockPeakFilter());
peak->setPeakShape(shape);

std::vector<std::pair<MockPeakFilter&, Mantid::Kernel::V3D>> fakeSinglePeakPeakWorkspaces;
fakeSinglePeakPeakWorkspaces.push_back(std::pair<MockPeakFilter&, Mantid::Kernel::V3D>(peak, coordinate));
std::vector<std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>> fakeSinglePeakPeakWorkspaces;
fakeSinglePeakPeakWorkspaces.push_back(std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>(peak, coordinate));

std::vector<PeaksFilterDataContainer> peakData;
PeaksFilterDataContainer data1;
Expand Down Expand Up @@ -322,16 +321,15 @@ class vtkDataSetToPeaksFilteredDataSetTest : public CxxTest::TestSuite
double peakRadius = 5;
Mantid::Kernel::SpecialCoordinateSystem coordinateSystem = Mantid::Kernel::SpecialCoordinateSystem::QSample;
Mantid::Geometry::PeakShape_sptr shape(new Mantid::DataObjects::PeakShapeSpherical(peakRadius, coordinateSystem, "test", 1));
MockPeakFilter peak;
peak.setPeakShape(shape);
boost::shared_ptr<MockPeakFilter> peak(new MockPeakFilter());
peak->setPeakShape(shape);

// Peak 2
Mantid::Kernel::V3D coordinate2(12,0,0);
double peakRadius2 = 5;
Mantid::Geometry::PeakShape_sptr shape2(new Mantid::DataObjects::PeakShapeSpherical(peakRadius2, coordinateSystem, "test", 1));
MockPeakFilter peak2;
peak2.setPeakShape(shape2);

boost::shared_ptr<MockPeakFilter> peak2(new MockPeakFilter());
peak2->setPeakShape(shape2);

std::vector<PeaksFilterDataContainer> peakData;
PeaksFilterDataContainer data1;
Expand All @@ -346,9 +344,9 @@ class vtkDataSetToPeaksFilteredDataSetTest : public CxxTest::TestSuite
peakData.push_back(data1);
peakData.push_back(data2);

std::vector<std::pair<MockPeakFilter&, Mantid::Kernel::V3D>> fakeSinglePeakPeakWorkspaces;
fakeSinglePeakPeakWorkspaces.push_back(std::pair<MockPeakFilter&, Mantid::Kernel::V3D>(peak, coordinate));
fakeSinglePeakPeakWorkspaces.push_back(std::pair<MockPeakFilter&, Mantid::Kernel::V3D>(peak2, coordinate2));
std::vector<std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>> fakeSinglePeakPeakWorkspaces;
fakeSinglePeakPeakWorkspaces.push_back(std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>(peak, coordinate));
fakeSinglePeakPeakWorkspaces.push_back(std::pair<boost::shared_ptr<MockPeakFilter>, Mantid::Kernel::V3D>(peak2, coordinate2));

// Act
do_test_execute(peaksFilter, fakeSinglePeakPeakWorkspaces, coordinateSystem);
Expand Down
3 changes: 0 additions & 3 deletions Code/Mantid/Vates/VatesAPI/test/vtkPeakMarkerFactoryTest.h
Expand Up @@ -68,9 +68,6 @@ class vtkPeakMarkerFactoryTest: public CxxTest::TestSuite

TS_ASSERT(set);
TS_ASSERT_EQUALS(set->GetNumberOfPoints(), 30);
//TS_ASSERT_EQUALS(set->GetPoint(0)[0], 1.0);
//TS_ASSERT_EQUALS(set->GetPoint(0)[1], 2.0);
//TS_ASSERT_EQUALS(set->GetPoint(0)[2], 3.0);

TS_ASSERT(testing::Mock::VerifyAndClearExpectations(&pw));
TS_ASSERT(testing::Mock::VerifyAndClearExpectations(&peak1));
Expand Down

0 comments on commit de65fb8

Please sign in to comment.