Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
b0c80e58
Commit
b0c80e58
authored
14 years ago
by
Gigg, Martyn Anthony
Browse files
Options
Downloads
Patches
Plain Diff
Forgot to check in changes to Sample test. Re #1416
parent
eb55ac4c
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Mantid/API/test/SampleTest.h
+37
-36
37 additions, 36 deletions
Code/Mantid/API/test/SampleTest.h
with
37 additions
and
36 deletions
Code/Mantid/API/test/SampleTest.h
+
37
−
36
View file @
b0c80e58
...
...
@@ -4,24 +4,19 @@
#include
<cxxtest/TestSuite.h>
#include
"MantidAPI/Sample.h"
#include
"MantidKernel/Property.h"
#include
"MantidKernel/Exception.h"
#include
"MantidGeometry/Objects/ShapeFactory.h"
#include
"Poco/DOM/DOMParser.h"
#include
"Poco/DOM/Document.h"
#include
"Poco/DOM/Element.h"
#include
"Poco/Path.h"
#include
"Poco/File.h"
using
namespace
Mantid
::
Kernel
;
using
namespace
Mantid
::
Geometry
;
using
Mantid
::
API
::
Sample
;
// Helper class
class
ConcreteProperty
:
public
Property
{
public:
ConcreteProperty
()
:
Property
(
"Test"
,
typeid
(
int
)
)
{}
Property
*
clone
()
{
return
new
ConcreteProperty
(
*
this
);
}
bool
isDefault
()
const
{
return
true
;
}
std
::
string
getDefault
()
const
{
return
"getDefault() is not implemented in this class"
;
}
std
::
string
value
()
const
{
return
"Nothing"
;
}
std
::
string
setValue
(
const
std
::
string
&
value
)
{
return
""
;
}
};
class
SampleTest
:
public
CxxTest
::
TestSuite
{
public:
...
...
@@ -32,33 +27,39 @@ public:
TS_ASSERT
(
!
sample
.
getName
().
compare
(
"test"
)
)
}
void
test
AddGetLogData
()
void
test
Shape
()
{
Property
*
p
=
new
ConcreteProperty
();
TS_ASSERT_THROWS_NOTHING
(
sample
.
addLogData
(
p
)
)
Property
*
pp
;
TS_ASSERT_THROWS_NOTHING
(
pp
=
sample
.
getLogData
(
"Test"
)
)
TS_ASSERT_EQUALS
(
p
,
pp
)
TS_ASSERT
(
!
pp
->
name
().
compare
(
"Test"
)
)
TS_ASSERT
(
dynamic_cast
<
ConcreteProperty
*>
(
pp
)
)
TS_ASSERT_THROWS
(
sample
.
getLogData
(
"NotThere"
),
Exception
::
NotFoundError
)
std
::
vector
<
Property
*
>
props
=
sample
.
getLogData
();
TS_ASSERT
(
!
props
.
empty
()
)
TS_ASSERT_EQUALS
(
props
.
size
(),
1
)
TS_ASSERT
(
!
props
[
0
]
->
name
().
compare
(
"Test"
)
)
TS_ASSERT
(
dynamic_cast
<
ConcreteProperty
*>
(
props
[
0
])
)
}
void
testGetSetCharge
()
{
TS_ASSERT_EQUALS
(
sample
.
getProtonCharge
(),
0.0
)
TS_ASSERT_THROWS_NOTHING
(
sample
.
setProtonCharge
(
10.0
)
)
TS_ASSERT_EQUALS
(
sample
.
getProtonCharge
(),
10.0
)
std
::
string
xmlShape
=
"<cylinder id=
\"
shape
\"
> "
;
xmlShape
+=
"<centre-of-bottom-base x=
\"
0.0
\"
y=
\"
0.0
\"
z=
\"
0.0
\"
/> "
;
xmlShape
+=
"<axis x=
\"
0.0
\"
y=
\"
1.0
\"
z=
\"
0
\"
/> "
;
xmlShape
+=
"<radius val=
\"
0.0127
\"
/> "
;
xmlShape
+=
"<height val=
\"
1
\"
/> "
;
xmlShape
+=
"</cylinder>"
;
xmlShape
+=
"<algebra val=
\"
shape
\"
/> "
;
std
::
string
shapeXML
=
"<type name=
\"
userShape
\"
> "
+
xmlShape
+
" </type>"
;
// Set up the DOM parser and parse xml string
Poco
::
XML
::
DOMParser
pParser
;
Poco
::
XML
::
Document
*
pDoc
;
pDoc
=
pParser
.
parseString
(
shapeXML
);
// Get pointer to root element
Poco
::
XML
::
Element
*
pRootElem
=
pDoc
->
documentElement
();
//convert into a Geometry object
ShapeFactory
sFactory
;
boost
::
shared_ptr
<
Object
>
shape_sptr
=
sFactory
.
createShape
(
pRootElem
);
pDoc
->
release
();
TS_ASSERT_THROWS_NOTHING
(
sample
.
setShapeObject
(
*
shape_sptr
))
const
Object
&
sampleShape
=
sample
.
getShapeObject
();
TS_ASSERT_EQUALS
(
shape_sptr
->
getName
(),
sampleShape
.
getName
());
}
private
:
Sample
sample
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment