Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RobotAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software
ArmarX
RobotAPI
Commits
4429ab3c
Commit
4429ab3c
authored
3 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Add ArMemGetFindTest
parent
c3a0d6c0
No related branches found
No related tags found
3 merge requests
!192
Fix bugs in ArMem and make disk loading and storing nicer
,
!190
ArMem: Revice get/find interface
,
!188
ArMem Updates
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/RobotAPI/libraries/armem/test/ArMemGetFindTest.cpp
+347
-0
347 additions, 0 deletions
source/RobotAPI/libraries/armem/test/ArMemGetFindTest.cpp
source/RobotAPI/libraries/armem/test/CMakeLists.txt
+4
-3
4 additions, 3 deletions
source/RobotAPI/libraries/armem/test/CMakeLists.txt
with
351 additions
and
3 deletions
source/RobotAPI/libraries/armem/test/ArMemGetFindTest.cpp
0 → 100644
+
347
−
0
View file @
4429ab3c
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::ArmarXObjects::armem
* @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu )
* @date 2020
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#define BOOST_TEST_MODULE RobotAPI::ArmarXLibraries::armem
#define ARMARX_BOOST_TEST
#include
<RobotAPI/libraries/armem/core/wm/memory_definitions.h>
#include
<RobotAPI/libraries/armem/core/error.h>
#include
<RobotAPI/libraries/armem/core/operations.h>
#include
<RobotAPI/Test.h>
#include
<iostream>
namespace
armem
=
armarx
::
armem
;
namespace
wm
=
armarx
::
armem
::
wm
;
namespace
aron
=
armarx
::
aron
;
namespace
ArMemGetFindTest
{
struct
Fixture
{
wm
::
EntitySnapshot
snapshot
;
wm
::
Entity
entity
;
wm
::
ProviderSegment
provSeg
;
wm
::
CoreSegment
coreSeg
;
wm
::
Memory
memory
;
armem
::
MemoryID
instanceID
;
armem
::
MemoryID
snapshotID
;
armem
::
MemoryID
entityID
;
armem
::
MemoryID
provSegID
;
armem
::
MemoryID
coreSegID
;
armem
::
MemoryID
memoryID
;
Fixture
()
{
{
snapshot
.
time
()
=
armem
::
Time
::
microSeconds
(
1000
);
snapshot
.
addInstance
();
}
{
entity
.
name
()
=
"entity"
;
entity
.
addSnapshot
(
snapshot
);
}
{
provSeg
.
name
()
=
"provider segment"
;
provSeg
.
addEntity
(
entity
);
}
{
coreSeg
.
name
()
=
"core segment"
;
coreSeg
.
addProviderSegment
(
provSeg
);
}
{
memory
.
name
()
=
"memory"
;
memory
.
addCoreSegment
(
coreSeg
);
}
memoryID
=
memory
.
id
();
coreSegID
=
memoryID
.
withCoreSegmentName
(
coreSeg
.
name
());
provSegID
=
coreSegID
.
withProviderSegmentName
(
provSeg
.
name
());
entityID
=
provSegID
.
withEntityName
(
entity
.
name
());
snapshotID
=
entityID
.
withTimestamp
(
snapshot
.
time
());
instanceID
=
snapshotID
.
withInstanceIndex
(
0
);
}
~
Fixture
()
{
}
template
<
class
ParentT
>
void
test_get_find_instance_by_id
(
ParentT
&&
parent
)
{
_test_get_find_instance_by_id
(
const_cast
<
const
ParentT
&>
(
parent
));
_test_get_find_instance_by_id
(
const_cast
<
ParentT
&>
(
parent
));
}
template
<
class
ParentT
>
void
_test_get_find_instance_by_id
(
ParentT
&&
parent
)
{
BOOST_TEST_CONTEXT
(
"Parent: "
<<
armem
::
print
(
parent
))
{
BOOST_CHECK_EQUAL
(
parent
.
hasInstance
(
snapshotID
.
withInstanceIndex
(
0
)),
true
);
BOOST_CHECK_EQUAL
(
parent
.
hasInstance
(
snapshotID
.
withInstanceIndex
(
1
)),
false
);
BOOST_CHECK_NE
(
parent
.
findInstance
(
snapshotID
.
withInstanceIndex
(
0
)),
nullptr
);
BOOST_CHECK_EQUAL
(
parent
.
findInstance
(
snapshotID
.
withInstanceIndex
(
1
)),
nullptr
);
BOOST_CHECK_NO_THROW
(
parent
.
getInstance
(
snapshotID
.
withInstanceIndex
(
0
)));
BOOST_CHECK_THROW
(
parent
.
getInstance
(
snapshotID
.
withInstanceIndex
(
1
)),
armem
::
error
::
MissingEntry
);
}
}
template
<
class
ParentT
>
void
test_get_find_snapshot_by_id
(
ParentT
&&
parent
)
{
_test_get_find_snapshot_by_id
(
const_cast
<
const
ParentT
&>
(
parent
));
_test_get_find_snapshot_by_id
(
const_cast
<
ParentT
&>
(
parent
));
}
template
<
class
ParentT
>
void
_test_get_find_snapshot_by_id
(
ParentT
&&
parent
)
{
BOOST_TEST_CONTEXT
(
"Parent: "
<<
armem
::
print
(
parent
))
{
BOOST_CHECK_EQUAL
(
parent
.
hasSnapshot
(
entityID
.
withTimestamp
(
armem
::
Time
::
microSeconds
(
1000
))),
true
);
BOOST_CHECK_EQUAL
(
parent
.
hasSnapshot
(
entityID
.
withTimestamp
(
armem
::
Time
::
microSeconds
(
2000
))),
false
);
BOOST_CHECK_NE
(
parent
.
findSnapshot
(
entityID
.
withTimestamp
(
armem
::
Time
::
microSeconds
(
1000
))),
nullptr
);
BOOST_CHECK_EQUAL
(
parent
.
findSnapshot
(
entityID
.
withTimestamp
(
armem
::
Time
::
microSeconds
(
2000
))),
nullptr
);
BOOST_CHECK_NO_THROW
(
parent
.
getSnapshot
(
entityID
.
withTimestamp
(
armem
::
Time
::
microSeconds
(
1000
))));
BOOST_CHECK_THROW
(
parent
.
getSnapshot
(
entityID
.
withTimestamp
(
armem
::
Time
::
microSeconds
(
2000
))),
armem
::
error
::
MissingEntry
);
}
}
template
<
class
ParentT
>
void
test_get_find_entity_by_id
(
ParentT
&&
parent
)
{
_test_get_find_entity_by_id
(
const_cast
<
const
ParentT
&>
(
parent
));
_test_get_find_entity_by_id
(
const_cast
<
ParentT
&>
(
parent
));
}
template
<
class
ParentT
>
void
_test_get_find_entity_by_id
(
ParentT
&&
parent
)
{
BOOST_TEST_CONTEXT
(
"Parent: "
<<
armem
::
print
(
parent
))
{
BOOST_CHECK_EQUAL
(
parent
.
hasEntity
(
provSegID
.
withEntityName
(
"entity"
)),
true
);
BOOST_CHECK_EQUAL
(
parent
.
hasEntity
(
provSegID
.
withEntityName
(
"other entity"
)),
false
);
BOOST_CHECK_NE
(
parent
.
findEntity
(
provSegID
.
withEntityName
(
"entity"
)),
nullptr
);
BOOST_CHECK_EQUAL
(
parent
.
findEntity
(
provSegID
.
withEntityName
(
"other entity"
)),
nullptr
);
BOOST_CHECK_NO_THROW
(
parent
.
getEntity
(
provSegID
.
withEntityName
(
"entity"
)));
BOOST_CHECK_THROW
(
parent
.
getEntity
(
provSegID
.
withEntityName
(
"other entity"
)),
armem
::
error
::
MissingEntry
);
}
}
template
<
class
ParentT
>
void
test_get_find_provider_segment_by_id
(
ParentT
&&
parent
)
{
_test_get_find_provider_segment_by_id
(
const_cast
<
const
ParentT
&>
(
parent
));
_test_get_find_provider_segment_by_id
(
const_cast
<
ParentT
&>
(
parent
));
}
template
<
class
ParentT
>
void
_test_get_find_provider_segment_by_id
(
ParentT
&&
parent
)
{
BOOST_TEST_CONTEXT
(
"Parent: "
<<
armem
::
print
(
parent
))
{
BOOST_CHECK_EQUAL
(
parent
.
hasProviderSegment
(
provSegID
.
withProviderSegmentName
(
"provider segment"
)),
true
);
BOOST_CHECK_EQUAL
(
parent
.
hasProviderSegment
(
provSegID
.
withProviderSegmentName
(
"other provider segment"
)),
false
);
BOOST_CHECK_NE
(
parent
.
findProviderSegment
(
provSegID
.
withProviderSegmentName
(
"provider segment"
)),
nullptr
);
BOOST_CHECK_EQUAL
(
parent
.
findProviderSegment
(
provSegID
.
withProviderSegmentName
(
"other provider segment"
)),
nullptr
);
BOOST_CHECK_NO_THROW
(
parent
.
getProviderSegment
(
provSegID
.
withProviderSegmentName
(
"provider segment"
)));
BOOST_CHECK_THROW
(
parent
.
getProviderSegment
(
provSegID
.
withProviderSegmentName
(
"other provider segment"
)),
armem
::
error
::
MissingEntry
);
}
}
template
<
class
ParentT
>
void
test_get_find_core_segment_by_id
(
ParentT
&&
parent
)
{
_test_get_find_core_segment_by_id
(
const_cast
<
const
ParentT
&>
(
parent
));
_test_get_find_core_segment_by_id
(
const_cast
<
ParentT
&>
(
parent
));
}
template
<
class
ParentT
>
void
_test_get_find_core_segment_by_id
(
ParentT
&&
parent
)
{
BOOST_TEST_CONTEXT
(
"Parent: "
<<
armem
::
print
(
parent
))
{
BOOST_CHECK_EQUAL
(
parent
.
hasCoreSegment
(
provSegID
.
withCoreSegmentName
(
"core segment"
)),
true
);
BOOST_CHECK_EQUAL
(
parent
.
hasCoreSegment
(
provSegID
.
withCoreSegmentName
(
"other core segment"
)),
false
);
BOOST_CHECK_NE
(
parent
.
findCoreSegment
(
provSegID
.
withCoreSegmentName
(
"core segment"
)),
nullptr
);
BOOST_CHECK_EQUAL
(
parent
.
findCoreSegment
(
provSegID
.
withCoreSegmentName
(
"other core segment"
)),
nullptr
);
BOOST_CHECK_NO_THROW
(
parent
.
getCoreSegment
(
provSegID
.
withCoreSegmentName
(
"core segment"
)));
BOOST_CHECK_THROW
(
parent
.
getCoreSegment
(
provSegID
.
withCoreSegmentName
(
"other core segment"
)),
armem
::
error
::
MissingEntry
);
}
}
};
}
BOOST_FIXTURE_TEST_SUITE
(
ArMemGetFindTest
,
Fixture
)
BOOST_AUTO_TEST_CASE
(
test_snapshot_get_find_instance_by_key
)
{
BOOST_CHECK_EQUAL
(
snapshot
.
hasInstance
(
0
),
true
);
BOOST_CHECK_EQUAL
(
snapshot
.
hasInstance
(
1
),
false
);
BOOST_CHECK_NE
(
snapshot
.
findInstance
(
0
),
nullptr
);
BOOST_CHECK_EQUAL
(
snapshot
.
findInstance
(
1
),
nullptr
);
BOOST_CHECK_NO_THROW
(
snapshot
.
getInstance
(
0
));
BOOST_CHECK_THROW
(
snapshot
.
getInstance
(
1
),
armem
::
error
::
MissingEntry
);
}
BOOST_AUTO_TEST_CASE
(
test_entity_get_find_snapshot_by_key
)
{
BOOST_CHECK_EQUAL
(
entity
.
hasSnapshot
(
armem
::
Time
::
microSeconds
(
1000
)),
true
);
BOOST_CHECK_EQUAL
(
entity
.
hasSnapshot
(
armem
::
Time
::
microSeconds
(
2000
)),
false
);
BOOST_CHECK_NE
(
entity
.
findSnapshot
(
armem
::
Time
::
microSeconds
(
1000
)),
nullptr
);
BOOST_CHECK_EQUAL
(
entity
.
findSnapshot
(
armem
::
Time
::
microSeconds
(
2000
)),
nullptr
);
BOOST_CHECK_NO_THROW
(
entity
.
getSnapshot
(
armem
::
Time
::
microSeconds
(
1000
)));
BOOST_CHECK_THROW
(
entity
.
getSnapshot
(
armem
::
Time
::
microSeconds
(
2000
)),
armem
::
error
::
MissingEntry
);
}
BOOST_AUTO_TEST_CASE
(
test_provider_segment_get_find_entity_by_key
)
{
BOOST_CHECK_EQUAL
(
provSeg
.
hasEntity
(
"entity"
),
true
);
BOOST_CHECK_EQUAL
(
provSeg
.
hasEntity
(
"other entity"
),
false
);
BOOST_CHECK_NE
(
provSeg
.
findEntity
(
"entity"
),
nullptr
);
BOOST_CHECK_EQUAL
(
provSeg
.
findEntity
(
"other entity"
),
nullptr
);
BOOST_CHECK_NO_THROW
(
provSeg
.
getEntity
(
"entity"
));
BOOST_CHECK_THROW
(
provSeg
.
getEntity
(
"other entity"
),
armem
::
error
::
MissingEntry
);
}
BOOST_AUTO_TEST_CASE
(
test_core_segment_get_find_provider_segment_by_key
)
{
BOOST_CHECK_EQUAL
(
coreSeg
.
hasProviderSegment
(
"provider segment"
),
true
);
BOOST_CHECK_EQUAL
(
coreSeg
.
hasProviderSegment
(
"other provider segment"
),
false
);
BOOST_CHECK_NE
(
coreSeg
.
findProviderSegment
(
"provider segment"
),
nullptr
);
BOOST_CHECK_EQUAL
(
coreSeg
.
findProviderSegment
(
"other provider segment"
),
nullptr
);
BOOST_CHECK_NO_THROW
(
coreSeg
.
getProviderSegment
(
"provider segment"
));
BOOST_CHECK_THROW
(
coreSeg
.
getProviderSegment
(
"other provider segment"
),
armem
::
error
::
MissingEntry
);
}
BOOST_AUTO_TEST_CASE
(
test_memory_get_find_core_segment_by_key
)
{
BOOST_CHECK_EQUAL
(
memory
.
hasCoreSegment
(
"core segment"
),
true
);
BOOST_CHECK_EQUAL
(
memory
.
hasCoreSegment
(
"other core segment"
),
false
);
BOOST_CHECK_NE
(
memory
.
findCoreSegment
(
"core segment"
),
nullptr
);
BOOST_CHECK_EQUAL
(
memory
.
findCoreSegment
(
"other core segment"
),
nullptr
);
BOOST_CHECK_NO_THROW
(
memory
.
getCoreSegment
(
"core segment"
));
BOOST_CHECK_THROW
(
memory
.
getCoreSegment
(
"other core segment"
),
armem
::
error
::
MissingEntry
);
}
BOOST_AUTO_TEST_CASE
(
test_snapshot_get_find_instance_by_id
)
{
test_get_find_instance_by_id
(
snapshot
);
}
BOOST_AUTO_TEST_CASE
(
test_entity_get_find_instance_by_id
)
{
test_get_find_instance_by_id
(
entity
);
}
BOOST_AUTO_TEST_CASE
(
test_provider_segment_get_find_instance_by_id
)
{
test_get_find_instance_by_id
(
provSeg
);
}
BOOST_AUTO_TEST_CASE
(
test_core_segment_get_find_instance_by_id
)
{
test_get_find_instance_by_id
(
coreSeg
);
}
BOOST_AUTO_TEST_CASE
(
test_memory_get_find_instance_by_id
)
{
test_get_find_instance_by_id
(
memory
);
}
BOOST_AUTO_TEST_CASE
(
test_entity_get_find_snapshot_by_id
)
{
test_get_find_snapshot_by_id
(
entity
);
}
BOOST_AUTO_TEST_CASE
(
test_provider_segment_get_find_snapshot_by_id
)
{
test_get_find_snapshot_by_id
(
provSeg
);
}
BOOST_AUTO_TEST_CASE
(
test_core_segment_get_find_snapshot_by_id
)
{
test_get_find_snapshot_by_id
(
coreSeg
);
}
BOOST_AUTO_TEST_CASE
(
test_memory_get_find_snapshot_by_id
)
{
test_get_find_snapshot_by_id
(
memory
);
}
BOOST_AUTO_TEST_CASE
(
test_provider_segment_get_find_entity_by_id
)
{
test_get_find_entity_by_id
(
provSeg
);
}
BOOST_AUTO_TEST_CASE
(
test_core_segment_get_find_entity_by_id
)
{
test_get_find_entity_by_id
(
coreSeg
);
}
BOOST_AUTO_TEST_CASE
(
test_memory_get_find_entity_by_id
)
{
test_get_find_entity_by_id
(
memory
);
}
BOOST_AUTO_TEST_CASE
(
test_core_segment_get_find_provider_segment_by_id
)
{
test_get_find_provider_segment_by_id
(
coreSeg
);
}
BOOST_AUTO_TEST_CASE
(
test_memory_get_find_provider_segment_by_id
)
{
test_get_find_provider_segment_by_id
(
memory
);
}
BOOST_AUTO_TEST_CASE
(
test_memory_get_find_core_segment_by_id
)
{
test_get_find_core_segment_by_id
(
memory
);
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
source/RobotAPI/libraries/armem/test/CMakeLists.txt
+
4
−
3
View file @
4429ab3c
...
...
@@ -2,10 +2,11 @@
# Libs required for the tests
SET
(
LIBS
${
LIBS
}
ArmarXCore
${
LIB_NAME
}
)
armarx_add_test
(
ArMemForEachTest ArMemForEachTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMemGetFindTest ArMemGetFindTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMemIceConversionsTest ArMemIceConversionsTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMemLTMTest ArMemLTMTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMemMemoryTest ArMemMemoryTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMemMemoryIDTest ArMemMemoryIDTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMemQueryTest ArMemQueryTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMemLTMTest ArMemLTMTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMemQueryBuilderTest ArMemQueryBuilderTest.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMem
ForEach
Test ArMem
ForEach
Test.cpp
"
${
LIBS
}
"
)
armarx_add_test
(
ArMem
Query
Test ArMem
Query
Test.cpp
"
${
LIBS
}
"
)
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