Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GeoModel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
GeoModelDev
GeoModel
Commits
4e46b503
Commit
4e46b503
authored
2 months ago
by
Shaun Roe
Committed by
Johannes Junggeburth
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Extend GeoMaterial Test
parent
df04ac83
No related branches found
No related tags found
1 merge request
!435
Extend GeoMaterial Test
Pipeline
#11908587
passed
2 months ago
Stage: step-A
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h
+12
-12
12 additions, 12 deletions
GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h
GeoModelCore/GeoModelKernel/tests/testGeoMaterial.cxx
+54
-4
54 additions, 4 deletions
GeoModelCore/GeoModelKernel/tests/testGeoMaterial.cxx
with
66 additions
and
16 deletions
GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h
+
12
−
12
View file @
4e46b503
...
@@ -6,14 +6,14 @@
...
@@ -6,14 +6,14 @@
* @class RCBase
* @class RCBase
*
*
* @brief This is a base class for objects whose memory is managed
* @brief This is a base class for objects whose memory is managed
*
through reference counting. Reference-counted objects
*
through reference counting. Reference-counted objects
*
should only be created using
*
should only be created using
*
operator new, they should not be created on the stack.
*
operator new, they should not be created on the stack.
*
*
*
The methods ref() and unref() can be called to increase
*
The methods ref() and unref() can be called to increase
*
and decrease the reference count of an object. When
*
and decrease the reference count of an object. When
*
the reference count decreases to zero, the object deletes
*
the reference count decreases to zero, the object deletes
*
itself
*
itself
*/
*/
#ifndef GEOMODELKERNEL_RCBASE_H
#ifndef GEOMODELKERNEL_RCBASE_H
...
@@ -25,20 +25,20 @@ class RCBase {
...
@@ -25,20 +25,20 @@ class RCBase {
public:
public:
RCBase
()
=
default
;
RCBase
()
=
default
;
//
Increase the reference count
//
Increase the reference count
void
ref
()
const
noexcept
{
void
ref
()
const
noexcept
{
++
m_count
;
++
m_count
;
}
}
//
Decreases the reference count. When the reference count
//
Decreases the reference count. When the reference count
//
falls to zero, the object deletes itself.
//
falls to zero, the object deletes itself.
void
unref
()
const
noexcept
{
void
unref
()
const
noexcept
{
if
(
--
m_count
==
0
)
{
if
(
--
m_count
==
0
)
{
delete
this
;
delete
this
;
}
}
}
}
//
Return the reference count.
//
Return the reference count.
unsigned
int
refCount
()
const
noexcept
{
unsigned
int
refCount
()
const
noexcept
{
return
m_count
.
load
();
return
m_count
.
load
();
}
}
...
@@ -51,7 +51,7 @@ class RCBase {
...
@@ -51,7 +51,7 @@ class RCBase {
RCBase
&
operator
=
(
const
RCBase
&
right
)
=
delete
;
RCBase
&
operator
=
(
const
RCBase
&
right
)
=
delete
;
//
The reference count
//
The reference count
mutable
std
::
atomic
<
unsigned
>
m_count
{
0
};
mutable
std
::
atomic
<
unsigned
>
m_count
{
0
};
};
};
...
...
This diff is collapsed.
Click to expand it.
GeoModelCore/GeoModelKernel/tests/testGeoMaterial.cxx
+
54
−
4
View file @
4e46b503
...
@@ -4,18 +4,68 @@
...
@@ -4,18 +4,68 @@
#include
"GeoModelKernel/GeoMaterial.h"
#include
"GeoModelKernel/GeoMaterial.h"
#include
"GeoModelKernel/GeoIntrusivePtr.h"
#include
<gtest/gtest.h>
#include
<gtest/gtest.h>
#include
<stdexcept>
#define GTEST_COUT std::cerr << "[ MESSAGE ] "
using
namespace
GeoModelKernelUnits
;
using
namespace
GeoModelKernelUnits
;
class
SampleMaterial
{
private:
const
std
::
string
m_name
{
"Rhodium"
};
const
double
m_dense
{
13.0
*
gram
/
centimeter3
};
GeoIntrusivePtr
<
GeoMaterial
>
m_ptr
{};
public
:
GeoMaterial
*
ptr
()
const
{
return
m_ptr
.
get
();}
SampleMaterial
()
:
m_ptr
(
make_intrusive
<
GeoMaterial
>
(
m_name
,
m_dense
)){
//
};
};
TEST
(
GeoMaterial
,
CanBeConstructedOnHeap
)
{
TEST
(
GeoMaterial
,
CanBeConstructedOnHeap
)
{
GeoMaterial
*
pG
{};
GeoIntrusivePtr
<
GeoMaterial
>
pG
{};
const
std
::
string
name
{
"Shaun"
};
const
std
::
string
name
{
"Shaun"
};
const
double
dense
{
13.0
*
gram
/
centimeter3
};
const
double
dense
{
13.0
*
gram
/
centimeter3
};
EXPECT_NO_THROW
(
pG
=
new
GeoMaterial
(
name
,
dense
));
//Shaun is dense
EXPECT_NO_THROW
(
pG
=
make_intrusive
<
GeoMaterial
>
(
name
,
dense
));
pG
->
ref
();
}
pG
->
unref
();
//should be destroyed here
TEST
(
GeoMaterial
,
CannotLockAMaterialWithNoElements
)
{
SampleMaterial
s
;
auto
*
pMat
=
s
.
ptr
();
EXPECT_THROW
(
pMat
->
lock
(),
std
::
runtime_error
);
}
TEST
(
GeoMaterial
,
CannotAccessUnlockedMaterialProperties
)
{
SampleMaterial
s
;
auto
*
pMat
=
s
.
ptr
();
EXPECT_THROW
(
pMat
->
getNumElements
(),
std
::
runtime_error
);
EXPECT_THROW
(
pMat
->
getDeDxConstant
(),
std
::
runtime_error
);
EXPECT_THROW
(
pMat
->
getDeDxI0
(),
std
::
runtime_error
);
EXPECT_THROW
(
pMat
->
getDeDxMin
(),
std
::
runtime_error
);
EXPECT_THROW
(
pMat
->
getRadLength
(),
std
::
runtime_error
);
EXPECT_THROW
(
pMat
->
getIntLength
(),
std
::
runtime_error
);
EXPECT_THROW
(
pMat
->
getNumElements
(),
std
::
runtime_error
);
EXPECT_THROW
(
pMat
->
getElement
(
0
),
std
::
runtime_error
);
EXPECT_THROW
(
pMat
->
getFraction
(
0
),
std
::
runtime_error
);
}
}
TEST
(
GeoMaterial
,
CanAccessTrivialUnlockedMaterialProperties
)
{
SampleMaterial
s
;
const
double
expectedDensity
{
13.0
*
gram
/
centimeter3
};
auto
*
pMat
=
s
.
ptr
();
EXPECT_EQ
(
pMat
->
getName
(),
"Rhodium"
);
EXPECT_EQ
(
pMat
->
getDensity
(),
expectedDensity
);
int
id
{};
//id seems to vary run to run
EXPECT_NO_THROW
(
id
=
pMat
->
getID
());
GTEST_COUT
<<
"id is "
<<
id
<<
std
::
endl
;
}
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