Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenMesh
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenMesh
OpenMesh
Commits
4e2ae5be
Commit
4e2ae5be
authored
Apr 14, 2016
by
Janis Born
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create unit tests for C++11 PropertyManager features
parent
70d7ae8a
Pipeline
#1258
passed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
1 deletion
+102
-1
src/Unittests/unittests_propertymanager.cc
src/Unittests/unittests_propertymanager.cc
+102
-1
No files found.
src/Unittests/unittests_propertymanager.cc
View file @
4e2ae5be
...
...
@@ -26,7 +26,7 @@ class OpenMeshPropertyManager : public OpenMeshBase {
/*
* ====================================================================
*
Define tests below
*
General Tests
* ====================================================================
*/
...
...
@@ -92,11 +92,112 @@ TEST_F(OpenMeshPropertyManager, set_range_bool) {
ASSERT_TRUE
(
pm_f_bool
[
*
f_it
]);
}
/*
* ====================================================================
* C++11 Specific Tests
* ====================================================================
*/
#if _MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
template
<
typename
PropHandle
,
typename
Mesh
>
bool
has_property
(
const
Mesh
&
_mesh
,
const
std
::
string
&
_name
)
{
auto
dummy_handle
=
PropHandle
{};
return
_mesh
.
get_property_handle
(
dummy_handle
,
_name
);
}
/*
* Temporary property
*/
TEST_F
(
OpenMeshPropertyManager
,
cpp11_temp_property
)
{
using
handle_type
=
OpenMesh
::
VPropHandleT
<
int
>
;
const
auto
prop_name
=
"pm_v_test_property"
;
ASSERT_FALSE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
{
auto
vprop
=
OpenMesh
::
makePropertyManagerFromNew
<
handle_type
>
(
mesh_
,
prop_name
);
static_cast
<
void
>
(
vprop
);
// Unused variable
ASSERT_TRUE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
}
ASSERT_FALSE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
}
/*
* Two temporary properties on a mesh using the same name and type. The second
* (inner) one shadows the first (outer) one instead of aliasing.
*/
TEST_F
(
OpenMeshPropertyManager
,
cpp11_temp_property_shadowing
)
{
auto
vh
=
mesh_
.
add_vertex
({
0
,
0
,
0
});
// Dummy vertex to attach properties to
using
handle_type
=
OpenMesh
::
VPropHandleT
<
int
>
;
const
auto
prop_name
=
"pm_v_test_property"
;
auto
outer_prop
=
OpenMesh
::
makePropertyManagerFromNew
<
handle_type
>
(
mesh_
,
prop_name
);
outer_prop
[
vh
]
=
100
;
ASSERT_EQ
(
100
,
outer_prop
[
vh
]);
{
// inner_prop uses same type and name as outer_prop
auto
inner_prop
=
OpenMesh
::
makePropertyManagerFromNew
<
handle_type
>
(
mesh_
,
prop_name
);
inner_prop
[
vh
]
=
200
;
ASSERT_EQ
(
200
,
inner_prop
[
vh
]);
// End of scope: inner_prop is removed from mesh_
}
// Ensure outer_prop still exists and its data has not been overwritten by inner_prop
ASSERT_TRUE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
ASSERT_EQ
(
100
,
outer_prop
[
vh
]);
}
/*
* In sequence:
* - add a persistent property to a mesh
* - retrieve an existing property of a mesh and modify it
* - obtain a non-owning property handle
* - attempt to obtain a non-owning handle to a non-existing property (throws)
*/
TEST_F
(
OpenMeshPropertyManager
,
cpp11_persistent_and_non_owning_properties
)
{
auto
vh
=
mesh_
.
add_vertex
({
0
,
0
,
0
});
// Dummy vertex to attach properties to
using
handle_type
=
OpenMesh
::
VPropHandleT
<
int
>
;
const
auto
prop_name
=
"pm_v_test_property"
;
ASSERT_FALSE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
{
auto
prop
=
OpenMesh
::
makePropertyManagerFromExistingOrNew
<
handle_type
>
(
mesh_
,
prop_name
);
prop
[
vh
]
=
100
;
// End of scope, property persists
}
ASSERT_TRUE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
{
// Since a property of the same name and type already exists, this refers to the existing property.
auto
prop
=
OpenMesh
::
makePropertyManagerFromExistingOrNew
<
handle_type
>
(
mesh_
,
prop_name
);
ASSERT_EQ
(
100
,
prop
[
vh
]);
prop
[
vh
]
=
200
;
// End of scope, property persists
}
ASSERT_TRUE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
{
// Acquire non-owning handle to the property, knowing it exists
auto
prop
=
OpenMesh
::
makePropertyManagerFromExisting
<
handle_type
>
(
mesh_
,
prop_name
);
ASSERT_EQ
(
200
,
prop
[
vh
]);
}
ASSERT_TRUE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
{
// Attempt to acquire non-owning handle for a non-existing property
ASSERT_THROW
(
OpenMesh
::
makePropertyManagerFromExisting
<
handle_type
>
(
mesh_
,
"wrong_property_name"
),
std
::
runtime_error
);
}
ASSERT_TRUE
(
has_property
<
handle_type
>
(
mesh_
,
prop_name
));
}
#endif
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment