Skip to content

Commit

Permalink
Added some tests for WorkspaceProperty
Browse files Browse the repository at this point in the history
Refs #7309
  • Loading branch information
arturbekasov committed Jul 25, 2013
1 parent 4484dbd commit 98a17ae
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Code/Mantid/Framework/API/test/WorkspacePropertyTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class WorkspacePropertyTest : public CxxTest::TestSuite
wsp4 = new WorkspaceProperty<Workspace>("workspace4","",Direction::Input, PropertyMode::Optional);
wsp5 = new WorkspaceProperty<WorkspaceTester2>("workspace5","",Direction::Input, PropertyMode::Optional);
wsp6 = new WorkspaceProperty<Workspace>("InvalidNameTest","",Direction::Output);
wsp7 = new WorkspaceProperty<Workspace>("UniqueProperty", "", Direction::Output, UniqueMode::Unique);
}

~WorkspacePropertyTest()
Expand All @@ -56,13 +57,35 @@ class WorkspacePropertyTest : public CxxTest::TestSuite
delete wsp4;
delete wsp5;
delete wsp6;
delete wsp7;
}

void testConstructor()
{
TS_ASSERT_THROWS( WorkspaceProperty<Workspace>("test","",3), std::out_of_range )
}

void testDefaultValues()
{
TS_ASSERT(wsp1->isLocking());
TS_ASSERT(!wsp1->isOptional());
TS_ASSERT(!wsp1->isUnique());
}

void testCopyConstructor()
{
WorkspaceProperty<Workspace>* newWsp = new WorkspaceProperty<Workspace>(*wsp1);

TS_ASSERT_EQUALS(wsp1->name(), newWsp->name());
TS_ASSERT_EQUALS(wsp1->value(), newWsp->value());
TS_ASSERT(wsp1->direction() == newWsp->direction());
TS_ASSERT(wsp1->isLocking() == newWsp->isLocking());
TS_ASSERT(wsp1->isOptional() == newWsp->isOptional());
TS_ASSERT(wsp1->isUnique() == newWsp->isUnique());

delete newWsp;
}

void testValue()
{
TS_ASSERT_EQUALS( wsp1->value(), "ws1" )
Expand Down Expand Up @@ -256,13 +279,27 @@ class WorkspacePropertyTest : public CxxTest::TestSuite

}

void test_unique()
{
Workspace_sptr ws;
TS_ASSERT_THROWS_NOTHING(ws = WorkspaceFactory::Instance().create("WorkspacePropertyTest", 1, 1, 1));
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().addOrReplace("ws1", ws));

// Check that returns an error message if is unique
TS_ASSERT_EQUALS(wsp7->setValue("ws1"), "Workspace with name \"ws1\" already exists");

// Check that passes if is not unique
TS_ASSERT_EQUALS(wsp2->setValue("ws1"), "");
}

private:
WorkspaceProperty<Workspace> *wsp1;
WorkspaceProperty<Workspace> *wsp2;
WorkspaceProperty<WorkspaceTester2> *wsp3;
WorkspaceProperty<Workspace> *wsp4;
WorkspaceProperty<WorkspaceTester2> *wsp5;
WorkspaceProperty<Workspace> *wsp6;
WorkspaceProperty<Workspace> *wsp7;
};

#endif /*WORKSPACEPROPERTYTEST_H_*/

0 comments on commit 98a17ae

Please sign in to comment.