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
dd1edb99
Commit
dd1edb99
authored
2 months ago
by
Shaun Roe
Committed by
Johannes Junggeburth
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Refine and document RCBaseTests
parent
4be29757
No related branches found
No related tags found
1 merge request
!427
Refine and document RCBaseTests
Pipeline
#11783400
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
+1
-0
1 addition, 0 deletions
GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h
GeoModelCore/GeoModelKernel/tests/testRCBase.cxx
+25
-12
25 additions, 12 deletions
GeoModelCore/GeoModelKernel/tests/testRCBase.cxx
with
26 additions
and
12 deletions
GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h
+
1
−
0
View file @
dd1edb99
...
@@ -49,6 +49,7 @@ class RCBase {
...
@@ -49,6 +49,7 @@ class RCBase {
private
:
private
:
RCBase
(
const
RCBase
&
right
)
=
delete
;
RCBase
(
const
RCBase
&
right
)
=
delete
;
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/testRCBase.cxx
+
25
−
12
View file @
dd1edb99
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include
"GeoModelKernel/RCBase.h"
#include
"GeoModelKernel/RCBase.h"
#include
<exception>
#include
<gtest/gtest.h>
#include
<gtest/gtest.h>
#include
<limits>
#include
<limits>
...
@@ -13,7 +14,10 @@ class Stub:public RCBase{
...
@@ -13,7 +14,10 @@ class Stub:public RCBase{
virtual
~
Stub
()
=
default
;
virtual
~
Stub
()
=
default
;
};
};
TEST
(
GeoModelKernel
,
RCBaseStub_CanBeConstructedOnStack
)
{
//Making the destructor of RCBase private would cause all the defaulted destructors
//of derived classes (e.g the 'Stub' above, and many others) no longer compile.
//However, keeping it protected results in this undesirable behaviour:
TEST
(
RCBase
,
StubCanBeConstructedOnStack
)
{
EXPECT_NO_THROW
([[
maybe_unused
]]
Stub
stub
);
EXPECT_NO_THROW
([[
maybe_unused
]]
Stub
stub
);
//Stub stub1; (unused here if the following are commented out)
//Stub stub1; (unused here if the following are commented out)
//none of the following compile (correctly so)
//none of the following compile (correctly so)
...
@@ -23,14 +27,14 @@ TEST(GeoModelKernel, RCBaseStub_CanBeConstructedOnStack) {
...
@@ -23,14 +27,14 @@ TEST(GeoModelKernel, RCBaseStub_CanBeConstructedOnStack) {
//Stub stub5 = std::move(stub3);
//Stub stub5 = std::move(stub3);
}
}
TEST
(
GeoModelKernel
,
RCBase
_
CanBeConstructedOnHeap
)
{
TEST
(
RCBase
,
CanBeConstructedOnHeap
)
{
RCBase
*
p
{};
RCBase
*
p
{};
EXPECT_NO_THROW
(
p
=
new
RCBase
);
EXPECT_NO_THROW
(
p
=
new
RCBase
);
EXPECT_NE
(
p
,
nullptr
);
EXPECT_NE
(
p
,
nullptr
);
//deliberate leak here, RCBase d'tor is protected, so cannot delete
//deliberate leak here, RCBase d'tor is protected, so cannot delete
}
}
TEST
(
GeoModelKernel
,
RCBaseStub
_
CanBeConstructedOnHeap
)
{
TEST
(
RCBase
,
StubCanBeConstructedOnHeap
)
{
Stub
*
p
{};
Stub
*
p
{};
EXPECT_NO_THROW
(
p
=
new
Stub
);
EXPECT_NO_THROW
(
p
=
new
Stub
);
EXPECT_NE
(
p
,
nullptr
);
EXPECT_NE
(
p
,
nullptr
);
...
@@ -38,20 +42,29 @@ TEST(GeoModelKernel, RCBaseStub_CanBeConstructedOnHeap) {
...
@@ -38,20 +42,29 @@ TEST(GeoModelKernel, RCBaseStub_CanBeConstructedOnHeap) {
EXPECT_NO_THROW
(
delete
p
);
EXPECT_NO_THROW
(
delete
p
);
}
}
TEST
(
GeoModelKernel
,
RCBaseStub_
Reference
CountOk
){
TEST
(
RCBase
,
CanIncrementAndDecrement
Reference
){
//do on heap, as is supposed to be
//do on heap, as is supposed to be
Stub
*
pStub
=
new
Stub
;
Stub
*
pStub
=
new
Stub
;
EXPECT_EQ
(
pStub
->
refCount
(),
0
);
EXPECT_EQ
(
pStub
->
refCount
(),
0
);
EXPECT_NO_THROW
(
pStub
->
ref
());
EXPECT_NO_THROW
(
pStub
->
ref
());
EXPECT_EQ
(
pStub
->
refCount
(),
1
);
EXPECT_EQ
(
pStub
->
refCount
(),
1
);
EXPECT_NO_THROW
(
pStub
->
unref
());
EXPECT_NO_THROW
(
pStub
->
unref
());
//now, where is the object? The pointer has not been set to zero.. so...
}
//the following line would execute (not crash) and return a nonsense value,
//undesirable behaviours
//EXPECT_EQ(pStub->refCount(), 0); //returns 2043 on my machine
TEST
(
RCBase
,
DISABLED_CannotDecrementReferenceBelowZero
){
//segfault : delete pStub;
Stub
*
pStub
=
new
Stub
;
Stub
*
pStub2
=
new
Stub
;
pStub
->
unref
();
//should this throw?
EXPECT_NO_THROW
(
pStub2
->
unref
());
EXPECT_EQ
(
pStub
->
refCount
(),
0
);
//fails
EXPECT_EQ
(
pStub2
->
refCount
(),
std
::
numeric_limits
<
unsigned
int
>::
max
());
//now it's cursed, so euthanise it
//now it's cursed, so euthanise it
delete
pStub2
;
delete
pStub
;
}
TEST
(
RCBase
,
DISABLED_CannotBeUsedAfterRefCountBecomesZero
){
Stub
*
pStub
=
new
Stub
;
EXPECT_NO_THROW
(
pStub
->
ref
());
EXPECT_NO_THROW
(
pStub
->
unref
());
//object destroyed, but pointer still valid
EXPECT_THROW
(
pStub
->
ref
(),
std
::
exception
);
//compiles, doesn't throw
//now the refcount is some random value (returns 2043 on my machine)
//deleting would cause segfault
//delete pStub;
}
}
\ No newline at end of file
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