Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Gaudi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Frank Winklmeier
Gaudi
Commits
c4062378
Commit
c4062378
authored
1 month ago
by
Frank Winklmeier
Browse files
Options
Downloads
Patches
Plain Diff
DataObjID: add unit test
parent
23df4f1a
No related branches found
No related tags found
No related merge requests found
Pipeline
#10857129
passed with warnings
1 month ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GaudiKernel/CMakeLists.txt
+3
-0
3 additions, 0 deletions
GaudiKernel/CMakeLists.txt
GaudiKernel/tests/src/test_DataObjID.cpp
+122
-0
122 additions, 0 deletions
GaudiKernel/tests/src/test_DataObjID.cpp
with
125 additions
and
0 deletions
GaudiKernel/CMakeLists.txt
+
3
−
0
View file @
c4062378
...
...
@@ -281,6 +281,9 @@ if(BUILD_TESTING)
gaudi_add_executable
(
test_Property SOURCES tests/src/test_Property.cpp
LINK GaudiKernel Boost::unit_test_framework TEST
)
gaudi_add_executable
(
test_DataObjID SOURCES tests/src/test_DataObjID.cpp
LINK GaudiKernel Boost::unit_test_framework TEST
)
gaudi_add_executable
(
test_WeakPropertyRef SOURCES tests/src/test_WeakPropertyRef.cpp
LINK GaudiKernel Boost::unit_test_framework TEST
)
...
...
This diff is collapsed.
Click to expand it.
GaudiKernel/tests/src/test_DataObjID.cpp
0 → 100644
+
122
−
0
View file @
c4062378
/***********************************************************************************\
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
* *
* This software is distributed under the terms of the Apache version 2 licence, *
* copied verbatim in the file "LICENSE". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\***********************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE test_DataObjID
#include
<boost/test/unit_test.hpp>
#include
<Gaudi/Application.h>
#include
<GaudiKernel/ClassID.h>
#include
<GaudiKernel/DataObjID.h>
#include
<GaudiKernel/IClassIDSvc.h>
#include
<GaudiKernel/Service.h>
#include
<map>
/// IClassIDSvc mockup
class
MyClassIDSvc
:
public
extends
<
Service
,
IClassIDSvc
>
{
public:
using
base_class
::
base_class
;
virtual
CLID
nextAvailableID
()
const
override
{
return
m_types
.
size
()
+
1
;
}
virtual
bool
isIDInUse
(
const
CLID
&
id
)
const
override
{
return
m_types
.
contains
(
id
);
}
virtual
bool
isNameInUse
(
const
std
::
string
&
name
)
const
override
{
CLID
id
;
return
getIDOfTypeName
(
name
,
id
).
isSuccess
();
}
virtual
StatusCode
getIDOfTypeName
(
const
std
::
string
&
typeName
,
CLID
&
id
)
const
override
{
for
(
const
auto
&
[
i
,
n
]
:
m_types
)
{
if
(
n
==
typeName
)
{
id
=
i
;
return
StatusCode
::
SUCCESS
;
}
}
return
StatusCode
::
FAILURE
;
}
virtual
StatusCode
getTypeNameOfID
(
const
CLID
&
id
,
std
::
string
&
typeName
)
const
override
{
const
auto
t
=
m_types
.
find
(
id
);
if
(
t
!=
m_types
.
end
()
)
{
typeName
=
t
->
second
;
return
StatusCode
::
SUCCESS
;
}
return
StatusCode
::
FAILURE
;
}
// Not implemented
virtual
StatusCode
getTypeInfoNameOfID
(
const
CLID
&
,
std
::
string
&
)
const
override
{
return
StatusCode
::
FAILURE
;
}
virtual
StatusCode
getIDOfTypeInfoName
(
const
std
::
string
&
,
CLID
&
)
const
override
{
return
StatusCode
::
FAILURE
;
}
virtual
StatusCode
setTypeForID
(
const
CLID
&
,
const
std
::
string
&
,
const
std
::
string
&
)
override
{
return
StatusCode
::
FAILURE
;
}
private
:
inline
static
const
std
::
map
<
CLID
,
std
::
string
>
m_types
=
{
{
1
,
"TFoo"
}
};
};
DECLARE_COMPONENT
(
MyClassIDSvc
)
// Test with bare key and without ClassIDSvc (e.g. LHCb use-case)
BOOST_AUTO_TEST_CASE
(
noClassIDSvc
)
{
auto
check
=
[](
const
DataObjID
&
dobj
)
{
BOOST_CHECK_EQUAL
(
dobj
.
key
(),
"X"
);
BOOST_CHECK_EQUAL
(
dobj
.
fullKey
(),
"X"
);
BOOST_CHECK_EQUAL
(
dobj
.
clid
(),
0
);
BOOST_CHECK
(
dobj
.
className
().
empty
()
);
};
const
DataObjID
dobj
(
"X"
);
check
(
dobj
);
// Copy constructor
const
DataObjID
dobj2
(
dobj
);
BOOST_CHECK
(
dobj
==
dobj2
);
check
(
dobj2
);
// Assignment
DataObjID
dobj3
=
dobj
;
BOOST_CHECK
(
dobj
==
dobj3
);
check
(
dobj3
);
// Change key
dobj3
.
updateKey
(
"Y"
);
BOOST_CHECK_EQUAL
(
dobj3
.
key
(),
"Y"
);
BOOST_CHECK
(
dobj
!=
dobj3
);
}
// Test construction with ClassIDSvc (e.g. ATLAS use-case)
BOOST_AUTO_TEST_CASE
(
withClassIDSvc
)
{
auto
app
=
Gaudi
::
Application
(
{
{
"ApplicationMgr.JobOptionsType"
,
"
\"
NONE
\"
"
},
{
"ApplicationMgr.CreateSvc"
,
"[
\"
MyClassIDSvc/ClassIDSvc
\"
]"
}
}
);
app
.
run
(
[](
SmartIF
<
IStateful
>&
app
)
{
// Lookup CLID via ClassIDSvc
{
const
DataObjID
dobj
(
"TFoo"
,
"Key"
);
BOOST_CHECK_EQUAL
(
dobj
.
key
(),
"Key"
);
BOOST_CHECK_EQUAL
(
dobj
.
fullKey
(),
"TFoo/Key"
);
BOOST_CHECK_EQUAL
(
dobj
.
clid
(),
1
);
BOOST_CHECK_EQUAL
(
dobj
.
className
(),
"TFoo"
);
}
// Lookup class name via ClassIDSvc
{
const
DataObjID
dobj
(
CLID
(
1
),
"Key"
);
BOOST_CHECK_EQUAL
(
dobj
.
key
(),
"Key"
);
BOOST_CHECK_EQUAL
(
dobj
.
fullKey
(),
"TFoo/Key"
);
BOOST_CHECK_EQUAL
(
dobj
.
clid
(),
1
);
BOOST_CHECK_EQUAL
(
dobj
.
className
(),
"TFoo"
);
}
return
0
;
}
);
}
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