Newer
Older
#ifndef PROPERTYTEST_H_
#define PROPERTYTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidKernel/PropertyHistory.h"
using namespace Mantid::Kernel;
// Helper class
class PropertyHelper : public Property
{
public:
PropertyHelper() : Property( "Test", typeid( int ) ) {}
PropertyHelper* clone() const { return new PropertyHelper(*this); }
std::string value() const { return "Nothing"; }
std::string setValue( const std::string&) { return ""; }
std::string setValueFromProperty( const Property& ) { return ""; }
std::string setDataItem( const boost::shared_ptr<DataItem> ) { return ""; }
Steve Williams
committed
bool isDefault() const { return true; }
std::string getDefault() const { return "Is not implemented in this class, should be overriden"; }
Property& operator+=( Property const * ) { return *this; }
};
class PropertyTest : public CxxTest::TestSuite
{
public:
Russell Taylor
committed
static PropertyTest *createSuite() { return new PropertyTest(); }
static void destroySuite(PropertyTest *suite) { delete suite; }
PropertyTest()
{
p = new PropertyHelper;
}
Russell Taylor
committed
Russell Taylor
committed
~PropertyTest()
{
delete p;
}
Janik Zikovsky
committed
TS_ASSERT( ! p->name().compare("Test") );
void testDocumentation()
{
Property *pp = new PropertyHelper;
TS_ASSERT( pp->documentation().empty() );
TS_ASSERT( pp->briefDocumentation().empty() );
Janik Zikovsky
committed
TS_ASSERT( typeid( int ) == *p->type_info() );
TS_ASSERT( ! p->type().compare("number") );
Steve Williams
committed
void testisValid()
Janik Zikovsky
committed
TS_ASSERT_EQUALS( p->isValid(), "" );
Janik Zikovsky
committed
TS_ASSERT( p->isDefault() );
const std::string str("Doc comment. This property does something.");
TS_ASSERT_EQUALS( p->documentation(), str );
TS_ASSERT_EQUALS( p->briefDocumentation(), "Doc comment");
const std::string str2("A string with no period to be seen");
// Brief documentation not changed if it's not empty
p->setDocumentation(str2);
TS_ASSERT_EQUALS( p->documentation(), str2 );
TS_ASSERT_EQUALS( p->briefDocumentation(), "Doc comment");
// Make it empty and see that it will now be changed via setDocumentation()
p->setBriefDocumentation("");
TS_ASSERT( p->briefDocumentation().empty() );
p->setDocumentation(str2);
TS_ASSERT_EQUALS( p->documentation(), str2 );
TS_ASSERT_EQUALS( p->briefDocumentation(), str2 );
// Set just the brief documentation
p->setBriefDocumentation("Brief");
TS_ASSERT_EQUALS( p->documentation(), str2 );
TS_ASSERT_EQUALS( p->briefDocumentation(), "Brief" );
Janik Zikovsky
committed
TS_ASSERT( p->allowedValues().empty() );
Russell Taylor
committed
void testCreateHistory()
{
PropertyHistory history = p->createHistory();
Janik Zikovsky
committed
TS_ASSERT_EQUALS( history.name(), "Test" );
TS_ASSERT_EQUALS( history.value(), "Nothing" );
TS_ASSERT( history.isDefault() );
TS_ASSERT_EQUALS( history.type(), p->type() );
TS_ASSERT_EQUALS( history.direction(), 0 );
Russell Taylor
committed
}
Janik Zikovsky
committed
void testUnits()
{
Property * p2 = new PropertyHelper;
Janik Zikovsky
committed
//No unit at first
TS_ASSERT_EQUALS(p2->units(), "");
p2->setUnits("furlongs/fortnight");
TS_ASSERT_EQUALS(p2->units(), "furlongs/fortnight");
Janik Zikovsky
committed
}
Property * p3 = new PropertyHelper;
TS_ASSERT(p3->remember());
p3->setRemember(false);
TS_ASSERT(!p3->remember());
p3->setRemember(true);
TS_ASSERT(p3->remember());
delete p3;
private:
Property *p;
Russell Taylor
committed
};
#endif /*PROPERTYTEST_H_*/