Newer
Older
#ifndef MANTID_API_PROPERTYNEXUSTEST_H_
#define MANTID_API_PROPERTYNEXUSTEST_H_
Janik Zikovsky
committed
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/PropertyWithValue.h"
Janik Zikovsky
committed
#include "MantidKernel/System.h"
#include "MantidKernel/TimeSeriesProperty.h"
Janik Zikovsky
committed
#include "MantidKernel/Timer.h"
#include "MantidTestHelpers/NexusTestHelper.h"
Janik Zikovsky
committed
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using Mantid::Types::Core::DateAndTime;
Janik Zikovsky
committed
class PropertyNexusTest : public CxxTest::TestSuite {
Janik Zikovsky
committed
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static PropertyNexusTest *createSuite() { return new PropertyNexusTest(); }
static void destroySuite(PropertyNexusTest *suite) { delete suite; }
Janik Zikovsky
committed
/** Compare a property */
template <typename T> void check_prop(Property *prop, T *other) {
T *p = dynamic_cast<T *>(prop);
TSM_ASSERT("Loaded property was not of the expected type", p);
if (!p)
return;
TS_ASSERT_EQUALS(p->value(), other->value());
Janik Zikovsky
committed
}
Janik Zikovsky
committed
NexusTestHelper th(true);
th.createFile("PropertyNexusTest.nxs");
PropertyWithValue<int> pi("int_val", 123);
PropertyWithValue<uint32_t> pu("uint_val", 123);
PropertyWithValue<double> pd("double_val", 456.78);
PropertyWithValue<float> pf("float_val", float(987.56));
PropertyWithValue<std::string> ps("string_val", "supercallifragalistic");
PropertyWithValue<std::vector<double>> pvd("vector_double_val",
std::vector<double>(2, 1.4));
Janik Zikovsky
committed
pi.saveProperty(th.file);
pu.saveProperty(th.file);
pd.saveProperty(th.file);
pf.saveProperty(th.file);
ps.saveProperty(th.file);
pvd.saveProperty(th.file);
Janik Zikovsky
committed
TimeSeriesProperty<int> tspi("int_series");
tspi.addValue(DateAndTime("2011-01-01T00:00:01"), 1234);
tspi.addValue(DateAndTime("2011-01-01T00:01:02"), 4567);
Janik Zikovsky
committed
TimeSeriesProperty<double> tspd("double_series");
tspd.addValue(DateAndTime("2011-01-01T00:00:01"), 1234.5);
tspd.addValue(DateAndTime("2011-01-01T00:01:02"), 4567.8);
Janik Zikovsky
committed
TimeSeriesProperty<bool> tspb("bool_series");
tspb.addValue(DateAndTime("2011-01-01T00:00:01"), true);
tspb.addValue(DateAndTime("2011-01-01T00:01:02"), false);
Janik Zikovsky
committed
TimeSeriesProperty<std::string> tsps("string_series");
tsps.addValue(DateAndTime("2011-01-01T00:00:01"), "help me i");
tsps.addValue(DateAndTime("2011-01-01T00:01:02"), "am stuck in a NXS file");
Janik Zikovsky
committed
tspi.saveProperty(th.file);
tspd.saveProperty(th.file);
tspb.saveProperty(th.file);
tsps.saveProperty(th.file);
Janik Zikovsky
committed
// ---- Now re-load and compare to the original ones
// ----------------------------
Janik Zikovsky
committed
th.reopenFile();
check_prop(PropertyNexus::loadProperty(th.file, "int_val").get(), &pi);
check_prop(PropertyNexus::loadProperty(th.file, "uint_val").get(), &pu);
check_prop(PropertyNexus::loadProperty(th.file, "double_val").get(), &pd);
check_prop(PropertyNexus::loadProperty(th.file, "float_val").get(), &pf);
check_prop(PropertyNexus::loadProperty(th.file, "string_val").get(), &ps);
check_prop(PropertyNexus::loadProperty(th.file, "vector_double_val").get(),
check_prop(PropertyNexus::loadProperty(th.file, "int_series").get(), &tspi);
check_prop(PropertyNexus::loadProperty(th.file, "double_series").get(),
check_prop(PropertyNexus::loadProperty(th.file, "bool_series").get(),
check_prop(PropertyNexus::loadProperty(th.file, "string_series").get(),
Janik Zikovsky
committed
}
};
#endif /* MANTID_API_PROPERTYNEXUSTEST_H_ */