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
9e5fea39
Commit
9e5fea39
authored
10 years ago
by
Federico Montesino Pouzols
Browse files
Options
Downloads
Patches
Plain Diff
use shared_ptr to prevent leaks, re #11467
parent
fdef668c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Mantid/Framework/Kernel/test/ComputeResourceInfoTest.h
+15
-20
15 additions, 20 deletions
Code/Mantid/Framework/Kernel/test/ComputeResourceInfoTest.h
with
15 additions
and
20 deletions
Code/Mantid/Framework/Kernel/test/ComputeResourceInfoTest.h
+
15
−
20
View file @
9e5fea39
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include
"MantidKernel/Exception.h"
#include
"MantidKernel/Exception.h"
#include
"MantidKernel/FacilityInfo.h"
#include
"MantidKernel/FacilityInfo.h"
#include
<boost/make_shared.hpp>
#include
<Poco/DOM/AutoPtr.h>
#include
<Poco/DOM/AutoPtr.h>
#include
<Poco/DOM/Document.h>
#include
<Poco/DOM/Document.h>
#include
<Poco/DOM/DOMParser.h>
#include
<Poco/DOM/DOMParser.h>
...
@@ -14,7 +15,7 @@ using namespace Mantid::Kernel;
...
@@ -14,7 +15,7 @@ using namespace Mantid::Kernel;
class
ComputeResourceInfoTest
:
public
CxxTest
::
TestSuite
{
class
ComputeResourceInfoTest
:
public
CxxTest
::
TestSuite
{
public:
public:
void
test_allMissing
()
{
void
test_allMissing
()
{
FacilityInfo
*
fac
=
NULL
;
boost
::
shared_ptr
<
FacilityInfo
>
fac
;
TS_ASSERT_THROWS_NOTHING
(
fac
=
TS_ASSERT_THROWS_NOTHING
(
fac
=
createCRInfoInMinimalFacility
(
simpleInstStr
));
createCRInfoInMinimalFacility
(
simpleInstStr
));
TS_ASSERT
(
fac
);
TS_ASSERT
(
fac
);
...
@@ -22,13 +23,11 @@ public:
...
@@ -22,13 +23,11 @@ public:
TS_ASSERT_THROWS_NOTHING
(
cri
=
fac
->
computeResInfos
());
TS_ASSERT_THROWS_NOTHING
(
cri
=
fac
->
computeResInfos
());
TS_ASSERT_EQUALS
(
cri
.
size
(),
0
);
TS_ASSERT_EQUALS
(
cri
.
size
(),
0
);
delete
fac
;
fac
=
NULL
;
fac
=
NULL
;
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
"<computeResource fooAtt=
\"
barVal
\"
/>"
),
"<computeResource fooAtt=
\"
barVal
\"
/>"
),
std
::
runtime_error
);
std
::
runtime_error
);
TS_ASSERT
(
!
fac
);
TS_ASSERT
(
!
fac
);
delete
fac
;
}
}
void
test_noURLTag
()
{
void
test_noURLTag
()
{
...
@@ -36,11 +35,10 @@ public:
...
@@ -36,11 +35,10 @@ public:
"<u>"
+
"<u>"
+
fermiURL
+
"</u>"
fermiURL
+
"</u>"
"</computeResource>"
;
"</computeResource>"
;
FacilityInfo
*
fac
=
NULL
;
boost
::
shared_ptr
<
FacilityInfo
>
fac
;
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
crTxt
),
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
crTxt
),
std
::
runtime_error
);
std
::
runtime_error
);
TS_ASSERT
(
!
fac
);
TS_ASSERT
(
!
fac
);
delete
fac
;
}
}
void
test_wrongXML
()
{
void
test_wrongXML
()
{
...
@@ -48,11 +46,10 @@ public:
...
@@ -48,11 +46,10 @@ public:
"<u_foo>"
+
"<u_foo>"
+
fermiURL
+
"</u_bar>"
fermiURL
+
"</u_bar>"
"</compResource>"
;
"</compResource>"
;
FacilityInfo
*
fac
=
NULL
;
boost
::
shared_ptr
<
FacilityInfo
>
fac
;
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
crTxt
),
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
crTxt
),
Poco
::
XML
::
XMLException
);
Poco
::
XML
::
XMLException
);
TS_ASSERT
(
!
fac
);
TS_ASSERT
(
!
fac
);
delete
fac
;
}
}
void
test_normalFermi
()
{
void
test_normalFermi
()
{
...
@@ -62,7 +59,7 @@ public:
...
@@ -62,7 +59,7 @@ public:
fermiURL
+
"</baseURL>"
fermiURL
+
"</baseURL>"
"</computeResource>"
;
"</computeResource>"
;
FacilityInfo
*
fac
=
NULL
;
boost
::
shared_ptr
<
FacilityInfo
>
fac
;
TS_ASSERT_THROWS_NOTHING
(
fac
=
createCRInfoInMinimalFacility
(
fermi
));
TS_ASSERT_THROWS_NOTHING
(
fac
=
createCRInfoInMinimalFacility
(
fermi
));
TS_ASSERT
(
fac
);
TS_ASSERT
(
fac
);
TS_ASSERT_EQUALS
(
fac
->
name
(),
this
->
testFacilityName
);
TS_ASSERT_EQUALS
(
fac
->
name
(),
this
->
testFacilityName
);
...
@@ -95,12 +92,11 @@ public:
...
@@ -95,12 +92,11 @@ public:
fermiURL
+
"</URL>"
fermiURL
+
"</URL>"
"</computeResource>"
;
"</computeResource>"
;
FacilityInfo
*
fac
=
NULL
;
boost
::
shared_ptr
<
FacilityInfo
>
fac
;
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
fermi
),
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
fermi
),
std
::
runtime_error
);
std
::
runtime_error
);
TS_ASSERT
(
!
fac
);
TS_ASSERT
(
!
fac
);
delete
fac
;
}
}
void
test_normalSCARF
()
{
void
test_normalSCARF
()
{
...
@@ -110,7 +106,7 @@ public:
...
@@ -110,7 +106,7 @@ public:
scarfURL
+
"</baseURL>"
scarfURL
+
"</baseURL>"
"</computeResource>"
;
"</computeResource>"
;
FacilityInfo
*
fac
=
NULL
;
boost
::
shared_ptr
<
FacilityInfo
>
fac
;
TS_ASSERT_THROWS_NOTHING
(
fac
=
createCRInfoInMinimalFacility
(
scarf
));
TS_ASSERT_THROWS_NOTHING
(
fac
=
createCRInfoInMinimalFacility
(
scarf
));
TS_ASSERT
(
fac
);
TS_ASSERT
(
fac
);
TS_ASSERT_EQUALS
(
fac
->
name
(),
this
->
testFacilityName
);
TS_ASSERT_EQUALS
(
fac
->
name
(),
this
->
testFacilityName
);
...
@@ -119,7 +115,8 @@ public:
...
@@ -119,7 +115,8 @@ public:
TS_ASSERT_EQUALS
(
cri
.
size
(),
1
);
TS_ASSERT_EQUALS
(
cri
.
size
(),
1
);
ComputeResourceInfo
cr
=
fac
->
computeResInfos
().
front
();
ComputeResourceInfo
cr
=
fac
->
computeResInfos
().
front
();
TS_ASSERT_THROWS
(
ComputeResourceInfo
fail
=
fac
->
computeResource
(
"inexistent!"
),
TS_ASSERT_THROWS
(
ComputeResourceInfo
fail
=
fac
->
computeResource
(
"inexistent!"
),
Mantid
::
Kernel
::
Exception
::
NotFoundError
);
Mantid
::
Kernel
::
Exception
::
NotFoundError
);
ComputeResourceInfo
cr2
=
fac
->
computeResource
(
scarfName
);
ComputeResourceInfo
cr2
=
fac
->
computeResource
(
scarfName
);
TS_ASSERT_EQUALS
(
cr
,
cr2
);
TS_ASSERT_EQUALS
(
cr
,
cr2
);
...
@@ -133,7 +130,6 @@ public:
...
@@ -133,7 +130,6 @@ public:
TS_ASSERT_EQUALS
(
scarfType
,
cr2
.
remoteJobManagerType
());
TS_ASSERT_EQUALS
(
scarfType
,
cr2
.
remoteJobManagerType
());
TS_ASSERT_EQUALS
(
fac
->
name
(),
cr
.
facility
().
name
());
TS_ASSERT_EQUALS
(
fac
->
name
(),
cr
.
facility
().
name
());
TS_ASSERT_EQUALS
(
fac
->
name
(),
cr2
.
facility
().
name
());
TS_ASSERT_EQUALS
(
fac
->
name
(),
cr2
.
facility
().
name
());
delete
fac
;
}
}
void
test_brokenSCARF
()
{
void
test_brokenSCARF
()
{
...
@@ -143,11 +139,10 @@ public:
...
@@ -143,11 +139,10 @@ public:
"<URL>"
+
"<URL>"
+
scarfURL
+
"</URL>"
scarfURL
+
"</URL>"
"</computeResource>"
;
"</computeResource>"
;
FacilityInfo
*
fac
=
NULL
;
boost
::
shared_ptr
<
FacilityInfo
>
fac
;
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
err
),
TS_ASSERT_THROWS
(
fac
=
createCRInfoInMinimalFacility
(
err
),
std
::
runtime_error
);
std
::
runtime_error
);
TS_ASSERT
(
!
fac
);
TS_ASSERT
(
!
fac
);
delete
fac
;
}
}
void
test_equals
()
{
void
test_equals
()
{
...
@@ -178,7 +173,7 @@ public:
...
@@ -178,7 +173,7 @@ public:
fermiURL
+
"</baseURL>"
fermiURL
+
"</baseURL>"
"</computeResource>"
;
"</computeResource>"
;
FacilityInfo
*
fac
=
NULL
;
boost
::
shared_ptr
<
FacilityInfo
>
fac
;
TS_ASSERT_THROWS_NOTHING
(
fac
=
createCRInfoInMinimalFacility
(
rep
));
TS_ASSERT_THROWS_NOTHING
(
fac
=
createCRInfoInMinimalFacility
(
rep
));
TS_ASSERT
(
fac
);
TS_ASSERT
(
fac
);
TS_ASSERT_EQUALS
(
fac
->
computeResources
().
size
(),
3
);
TS_ASSERT_EQUALS
(
fac
->
computeResources
().
size
(),
3
);
...
@@ -205,13 +200,13 @@ public:
...
@@ -205,13 +200,13 @@ public:
!
(
fac
->
computeResource
(
fermiName
)
==
fac
->
computeResource
(
thirdName
)));
!
(
fac
->
computeResource
(
fermiName
)
==
fac
->
computeResource
(
thirdName
)));
TS_ASSERT
(
TS_ASSERT
(
!
(
fac
->
computeResource
(
otherName
)
==
fac
->
computeResource
(
thirdName
)));
!
(
fac
->
computeResource
(
otherName
)
==
fac
->
computeResource
(
thirdName
)));
delete
fac
;
}
}
private
:
private
:
/// make a minimal facilities file/xml string includin the compute resource
/// make a minimal facilities file/xml string includin the compute resource
/// passed
/// passed
FacilityInfo
*
createCRInfoInMinimalFacility
(
const
std
::
string
&
crStr
)
{
boost
::
shared_ptr
<
FacilityInfo
>
createCRInfoInMinimalFacility
(
const
std
::
string
&
crStr
)
{
const
std
::
string
xmlStr
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>"
const
std
::
string
xmlStr
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>"
"<facilities>"
"<facilities>"
" <facility name=
\"
"
+
" <facility name=
\"
"
+
...
@@ -223,13 +218,13 @@ private:
...
@@ -223,13 +218,13 @@ private:
return
createFacility
(
xmlStr
);
return
createFacility
(
xmlStr
);
}
}
FacilityInfo
*
createFacility
(
const
std
::
string
&
xml
)
{
boost
::
shared_ptr
<
FacilityInfo
>
createFacility
(
const
std
::
string
&
xml
)
{
Poco
::
XML
::
DOMParser
parser
;
Poco
::
XML
::
DOMParser
parser
;
Poco
::
AutoPtr
<
Poco
::
XML
::
Document
>
pDoc
=
parser
.
parseString
(
xml
);
Poco
::
AutoPtr
<
Poco
::
XML
::
Document
>
pDoc
=
parser
.
parseString
(
xml
);
Poco
::
XML
::
Element
*
pRootElem
=
pDoc
->
documentElement
();
Poco
::
XML
::
Element
*
pRootElem
=
pDoc
->
documentElement
();
Poco
::
XML
::
Element
*
elem
=
pRootElem
->
getChildElement
(
"facility"
);
Poco
::
XML
::
Element
*
elem
=
pRootElem
->
getChildElement
(
"facility"
);
return
new
FacilityInfo
(
elem
);
return
boost
::
make_shared
<
FacilityInfo
>
(
elem
);
}
}
private
:
private
:
...
...
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