Commit 05816491 authored by Russell Taylor's avatar Russell Taylor
Browse files

Re #7854. Move NexusTestHelper to TestHelpers.

parent 096aea1b
......@@ -4,7 +4,10 @@ if ( CXXTEST_FOUND )
include_directories ( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build these helper classes into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp ../../TestHelpers/src/BoxControllerDummyIO.cpp)
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/BoxControllerDummyIO.cpp
../../TestHelpers/src/NexusTestHelper.cpp
)
if ( GMOCK_FOUND AND GTEST_FOUND )
cxxtest_add_test ( APITest ${TEST_FILES} ${GMOCK_TEST_FILES})
......
......@@ -8,12 +8,11 @@
#include "MantidGeometry/Instrument/DetectorGroup.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/NexusTestHelper.h"
#include "MantidKernel/SingletonHolder.h"
#include "MantidKernel/Matrix.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
#include <cxxtest/TestSuite.h>
#include <boost/regex.hpp>
......@@ -26,7 +25,6 @@
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
using Mantid::Kernel::NexusTestHelper;
class FakeChopper : public Mantid::API::ChopperModel
{
......
......@@ -8,13 +8,12 @@
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/V3D.h"
#include <cxxtest/TestSuite.h>
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
#include "MantidGeometry/Instrument/Goniometer.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using Mantid::Kernel::NexusTestHelper;
// Helper class
namespace
......
......@@ -8,11 +8,11 @@
#include "MantidAPI/SpectrumDetectorMapping.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/NexusTestHelper.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/VMD.h"
#include "MantidTestHelpers/FakeGmockObjects.h"
#include "MantidTestHelpers/FakeObjects.h"
#include "MantidTestHelpers/NexusTestHelper.h"
#include <cxxtest/TestSuite.h>
#include <boost/make_shared.hpp>
......
......@@ -7,7 +7,7 @@
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
#include "MantidKernel/PropertyWithValue.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/DateAndTime.h"
......@@ -15,7 +15,6 @@
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using Mantid::Kernel::NexusTestHelper;
class PropertyNexusTest : public CxxTest::TestSuite
{
......
......@@ -8,13 +8,12 @@
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/V3D.h"
#include <cxxtest/TestSuite.h>
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
#include "MantidGeometry/Instrument/Goniometer.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using Mantid::Kernel::NexusTestHelper;
// Helper class
namespace
......
......@@ -9,14 +9,13 @@
#include "MantidGeometry/Objects/ShapeFactory.h"
#include "MantidKernel/Exception.h"
#include <cxxtest/TestSuite.h>
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
using namespace Mantid;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
using Mantid::API::Sample;
using Mantid::API::SampleEnvironment;
using Mantid::Kernel::NexusTestHelper;
class SampleTest : public CxxTest::TestSuite
{
......
......@@ -8,12 +8,11 @@
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/FileFinder.h"
#include "MantidKernel/Property.h"
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
#include "Poco/File.h"
using namespace Mantid::API;
using namespace Mantid::Kernel;
using Mantid::Kernel::NexusTestHelper;
class WorkspaceHistoryTest : public CxxTest::TestSuite
{
......
......@@ -4,7 +4,10 @@ if ( CXXTEST_FOUND )
include_directories ( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build this helper class into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp ../../TestHelpers/src/WorkspaceCreationHelper.cpp )
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/WorkspaceCreationHelper.cpp
../../TestHelpers/src/NexusTestHelper.cpp
)
cxxtest_add_test ( DataObjectsTest ${TEST_FILES} )
target_link_libraries( DataObjectsTest DataObjects )
# Specify implicit dependency, but don't link to it
......
......@@ -14,7 +14,7 @@
#include "MantidKernel/V3D.h"
#include "MantidKernel/Strings.h"
#include "MantidKernel/PhysicalConstants.h"
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/FrameworkManager.h"
......
......@@ -6,8 +6,9 @@ if ( CXXTEST_FOUND )
include_directories( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build this helper class into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/ScopedFileHelper.cpp
set ( TESTHELPER_SRCS ../../TestHelpers/src/ComponentCreationHelper.cpp
../../TestHelpers/src/NexusTestHelper.cpp
../../TestHelpers/src/ScopedFileHelper.cpp
)
if ( GMOCK_FOUND AND GTEST_FOUND )
......
......@@ -7,12 +7,12 @@
#include <stdexcept>
#include <string>
#include "MantidKernel/Quat.h"
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
using namespace Mantid::Geometry;
using Mantid::Kernel::V3D;
using Mantid::Kernel::Quat;
using Mantid::Kernel::DblMatrix;
using Mantid::Kernel::NexusTestHelper;
class GoniometerTest : public CxxTest::TestSuite
{
......
......@@ -4,15 +4,14 @@
#include <cxxtest/TestSuite.h>
#include <iostream>
#include <iomanip>
#include <MantidKernel/Matrix.h>
#include <MantidGeometry/Crystal/OrientedLattice.h>
#include "MantidKernel/NexusTestHelper.h"
#include "MantidKernel/Matrix.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidTestHelpers/NexusTestHelper.h"
using namespace Mantid::Geometry;
using Mantid::Kernel::V3D;
using Mantid::Kernel::DblMatrix;
using Mantid::Kernel::Matrix;
using Mantid::Kernel::NexusTestHelper;
class OrientedLatticeTest : public CxxTest::TestSuite
{
......
......@@ -55,7 +55,6 @@ set ( SRC_FILES
src/NDRandomNumberGenerator.cpp
src/NeutronAtom.cpp
src/NexusDescriptor.cpp
src/NexusTestHelper.cpp
src/ParaViewVersion.cpp
src/ProgressBase.cpp
src/ProgressText.cpp
......@@ -181,7 +180,6 @@ set ( INC_FILES
inc/MantidKernel/NDRandomNumberGenerator.h
inc/MantidKernel/NeutronAtom.h
inc/MantidKernel/NexusDescriptor.h
inc/MantidKernel/NexusTestHelper.h
inc/MantidKernel/NullValidator.h
inc/MantidKernel/ParaViewVersion.h
inc/MantidKernel/PhysicalConstants.h
......
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/System.h"
#include "MantidKernel/NexusTestHelper.h"
#include <Poco/File.h>
namespace Mantid
{
namespace Kernel
{
//----------------------------------------------------------------------------------------------
/** Constructor.
* */
NexusTestHelper::NexusTestHelper(bool deleteFile)
: file(NULL), deleteFile(deleteFile)
{
}
//----------------------------------------------------------------------------------------------
/** Destructor.
* Close the NXS file and delete it.
*/
NexusTestHelper::~NexusTestHelper()
{
if (!file) return;
file->close();
delete file;
if (deleteFile)
{
if (Poco::File(filename).exists())
Poco::File(filename).remove();
}
}
//----------------------------------------------------------------------------------------------
/** Creates a NXS file with an entry, for use in a test
* @param barefilename :: simple filename (no path) to save to.
* */
void NexusTestHelper::createFile(std::string barefilename)
{
filename = (Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory") + barefilename);
if (Poco::File(filename).exists())
Poco::File(filename).remove();
file = new ::NeXus::File(filename, NXACC_CREATE5);
file->makeGroup("test_entry", "NXentry", 1);
}
//----------------------------------------------------------------------------------------------
/** Close the newly created file and re-open it for reading back. */
void NexusTestHelper::reopenFile()
{
if (!file)
throw std::runtime_error("NexusTestHelper: you must call createFile() before reopenFile().");
file->close();
delete file;
file = new ::NeXus::File(filename, NXACC_READ);
file->openGroup("test_entry", "NXentry");
}
} // namespace Mantid
} // namespace Kernel
if ( CXXTEST_FOUND )
include_directories ( SYSTEM ${CXXTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} ../../TestHelpers/inc )
# This is required to pick up NexusTestHelper
include_directories( ../../TestHelpers/inc )
# This variable is used within the cxxtest_add_test macro to build this helper class into the test executable.
# It will go out of scope at the end of this file so doesn't need un-setting
set ( TESTHELPER_SRCS ../../TestHelpers/src/NexusTestHelper.cpp )
cxxtest_add_test ( KernelTest ${TEST_FILES} )
target_link_libraries( KernelTest Kernel ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} )
add_dependencies ( FrameworkTests KernelTest )
......
......@@ -7,10 +7,9 @@
#include "MantidKernel/Material.h"
#include "MantidKernel/NeutronAtom.h"
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
using Mantid::Kernel::Material;
using Mantid::Kernel::NexusTestHelper;
class MaterialTest: public CxxTest::TestSuite
{
......
......@@ -8,10 +8,9 @@
#include <vector>
#include "MantidKernel/V3D.h"
#include "MantidKernel/NexusTestHelper.h"
#include "MantidTestHelpers/NexusTestHelper.h"
using Mantid::Kernel::V3D;
using Mantid::Kernel::NexusTestHelper;
class V3DTest : public CxxTest::TestSuite
{
......
/*********************************************************************************
* PLEASE READ THIS!!!!!!!
*
* This file MAY NOT be modified to use anything from a package other than Kernel.
*********************************************************************************/
#ifndef MANTID_NEXUSCPP_NEXUSTESTHELPER_H_
#define MANTID_NEXUSCPP_NEXUSTESTHELPER_H_
#include "MantidKernel/System.h"
#include <nexus/NeXusFile.hpp>
/** A Helper class for easily writing nexus saving/loading tests.
namespace Mantid
{
namespace Kernel
{
/** A Helper class for easily writing nexus saving/loading tests.
@author Janik Zikovsky
@date 2011-09-07
......@@ -35,27 +33,23 @@ namespace Kernel
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport NexusTestHelper
{
public:
NexusTestHelper(bool deleteFile = true);
virtual ~NexusTestHelper();
void createFile(std::string barefilename);
void reopenFile();
/// Nexus file handle
::NeXus::File * file;
class NexusTestHelper
{
public:
NexusTestHelper(bool deleteFile = true);
virtual ~NexusTestHelper();
/// Created filename (full path)
std::string filename;
void createFile(std::string barefilename);
void reopenFile();
/// Do you delete when finished?
bool deleteFile;
};
/// Nexus file handle
::NeXus::File * file;
/// Created filename (full path)
std::string filename;
} // namespace Kernel
} // namespace Mantid
/// Do you delete when finished?
bool deleteFile;
};
#endif /* MANTID_NEXUSCPP_NEXUSTESTHELPER_H_ */
/*********************************************************************************
* PLEASE READ THIS!!!!!!!
*
* This file MAY NOT be modified to use anything from a package other than Kernel.
*********************************************************************************/
#include "MantidKernel/ConfigService.h"
#include "MantidTestHelpers/NexusTestHelper.h"
#include <Poco/File.h>
//----------------------------------------------------------------------------------------------
/** Constructor.
* */
NexusTestHelper::NexusTestHelper(bool deleteFile)
: file(NULL), deleteFile(deleteFile)
{
}
//----------------------------------------------------------------------------------------------
/** Destructor.
* Close the NXS file and delete it.
*/
NexusTestHelper::~NexusTestHelper()
{
if (!file) return;
file->close();
delete file;
if (deleteFile)
{
if (Poco::File(filename).exists())
Poco::File(filename).remove();
}
}
//----------------------------------------------------------------------------------------------
/** Creates a NXS file with an entry, for use in a test
* @param barefilename :: simple filename (no path) to save to.
* */
void NexusTestHelper::createFile(std::string barefilename)
{
filename = (Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory") + barefilename);
if (Poco::File(filename).exists())
Poco::File(filename).remove();
file = new ::NeXus::File(filename, NXACC_CREATE5);
file->makeGroup("test_entry", "NXentry", 1);
}
//----------------------------------------------------------------------------------------------
/** Close the newly created file and re-open it for reading back. */
void NexusTestHelper::reopenFile()
{
if (!file)
throw std::runtime_error("NexusTestHelper: you must call createFile() before reopenFile().");
file->close();
delete file;
file = new ::NeXus::File(filename, NXACC_READ);
file->openGroup("test_entry", "NXentry");
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment