Skip to content
Snippets Groups Projects
Commit e05d79e2 authored by Julien Maurer's avatar Julien Maurer
Browse files

Merge branch 'unittestRename' into '23.0'

rename algs and tools to avoid collision with standard tutorials that use...

See merge request atlas/athena!66679
parents f3bafcf2 63b38dd8
No related branches found
No related tags found
2 merge requests!666912023-10-24: merge of 23.0 into main,!66679rename algs and tools to avoid collision with standard tutorials that use...
Showing
with 135 additions and 69 deletions
// -*- mode: c++ -*-
//
// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
//
#ifndef ATHASGEXUNITTEST_MYPACKAGETOOL_H
#define ATHASGEXUNITTEST_MYPACKAGETOOL_H 1
#ifndef ATHASGEXUNITTEST_ATHEXUNITTESTTOOL_H
#define ATHASGEXUNITTEST_ATHEXUNITTESTTOOL_H 1
#include "AsgTools/AsgTool.h"
#include "AthAsgExUnittest/IMyPackageTool.h"
#include "AthAsgExUnittest/IAthAsgExUnittestTool.h"
class MyPackageTool: public asg::AsgTool, public virtual IMyPackageTool {
class AthAsgExUnittestTool: public asg::AsgTool, public virtual IAthAsgExUnittestTool {
public:
ASG_TOOL_CLASS( MyPackageTool, IMyPackageTool )
ASG_TOOL_CLASS( AthAsgExUnittestTool, IAthAsgExUnittestTool )
// Add another constructor for non-athena use cases
MyPackageTool( const std::string& name );
AthAsgExUnittestTool( const std::string& name );
// Initialize is required by AsgTool base class
virtual StatusCode initialize() override;
......@@ -28,4 +28,4 @@ private:
};
#endif //> !ATHASGEXUNITTEST_MYPACKAGETOOL_H
#endif //> !ATHASGEXUNITTEST_ATHEXUNITTESTTOOL_H
......@@ -4,15 +4,15 @@
// Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
//
#ifndef ATHASGEXUNITTEST_IMYPACKAGETOOL_H
#define ATHASGEXUNITTEST_IMYPACKAGETOOL_H 1
#ifndef ATHASGEXUNITTEST_IATHASGEXUNITTESTTOOL_H
#define ATHASGEXUNITTEST_IATHASGEXUNITTESTTOOL_H 1
#include "AsgTools/IAsgTool.h"
class IMyPackageTool : public virtual asg::IAsgTool {
class IAthAsgExUnittestTool : public virtual asg::IAsgTool {
public:
ASG_TOOL_INTERFACE( IMyPackageTool )
ASG_TOOL_INTERFACE( IAthAsgExUnittestTool )
//declare enums for properties here too, so that they are accessible through just the interface header
//example of an enum you might end up using for your properties .. please put enums in a class! (not just a namespace)
......@@ -22,4 +22,4 @@ public:
};
#endif //> !ATHASGEXUNITTEST_IMYPACKAGETOOL_H
#endif //> !ATHASGEXUNITTEST_IATHASGEXUNITTESTTOOL_H
......@@ -3,10 +3,10 @@
// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
//
// MyPackage includes
#include "AthAsgExUnittest/MyPackageTool.h"
// AthAsgExUnittest includes
#include "AthAsgExUnittest/AthAsgExUnittestTool.h"
MyPackageTool::MyPackageTool( const std::string& name ) : asg::AsgTool( name ) {
AthAsgExUnittestTool::AthAsgExUnittestTool( const std::string& name ) : asg::AsgTool( name ) {
//example property declarations with default values
declareProperty( "Property", m_nProperty = 3.0,
"Please describe the property here" );
......@@ -14,7 +14,7 @@ MyPackageTool::MyPackageTool( const std::string& name ) : asg::AsgTool( name ) {
"Please define enums inside your classes, not just in namespaces" );
}
StatusCode MyPackageTool::initialize() {
StatusCode AthAsgExUnittestTool::initialize() {
ATH_MSG_INFO( "Initializing " << name() << "..." );
ATH_MSG_INFO( "Property = " << m_nProperty );
//
......@@ -24,6 +24,6 @@ StatusCode MyPackageTool::initialize() {
return StatusCode::SUCCESS;
}
double MyPackageTool::useTheProperty() {
double AthAsgExUnittestTool::useTheProperty() {
return m_nProperty;
}
## Hook for MyPackage genConf module
## Hook for AthAsgExUnittest genConf module
//
// Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
//
// MyPackage includes
#include "MyPackageAlg.h"
// AthAsgExUnittest includes
#include "AthAsgExUnittestAlg.h"
MyPackageAlg::MyPackageAlg( const std::string& name,
AthAsgExUnittestAlg::AthAsgExUnittestAlg( const std::string& name,
ISvcLocator* pSvcLocator ) :
AthAnalysisAlgorithm( name, pSvcLocator ),
m_property( 1 ),
m_tool( "MyPackageTool/MyTool", this ) {
m_tool( "AthAsgExUnittestTool/MyTool", this ) {
addRef(); // workaround until fix in Gaudi
// example property declarations
declareProperty( "MyProperty", m_property );
......@@ -18,22 +18,22 @@ MyPackageAlg::MyPackageAlg( const std::string& name,
}
MyPackageAlg::~MyPackageAlg() {}
AthAsgExUnittestAlg::~AthAsgExUnittestAlg() {}
StatusCode MyPackageAlg::initialize() {
StatusCode AthAsgExUnittestAlg::initialize() {
ATH_MSG_INFO( "Initializing " << name() << "..." );
ATH_MSG_INFO( "MyProperty = " << m_property );
CHECK(m_tool.retrieve());
return StatusCode::SUCCESS;
}
StatusCode MyPackageAlg::finalize() {
StatusCode AthAsgExUnittestAlg::finalize() {
ATH_MSG_INFO( "Finalizing " << name() << "..." );
return StatusCode::SUCCESS;
}
StatusCode MyPackageAlg::execute() {
StatusCode AthAsgExUnittestAlg::execute() {
ATH_MSG_DEBUG( "Executing " << name() << "..." );
setFilterPassed(false); //optional: start with algorithm not passed
......
// -*- mode: c++ -*-
//
// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
//
#ifndef ATHASGEXUNITTEST_MYPACKAGEALG_H
#define ATHASGEXUNITTEST_MYPACKAGEALG_H 1
#ifndef ATHASGEXUNITTEST_ATHASGEXUNITTESTALG_H
#define ATHASGEXUNITTEST_ATHASGEXUNITTESTALG_H 1
#include "AthAnalysisBaseComps/AthAnalysisAlgorithm.h"
......@@ -12,14 +12,14 @@
#include "AsgTools/AnaToolHandle.h" //use asg::AnaToolHandle instead of regular ToolHandles for full dual-use experience!
#endif
#include "AthAsgExUnittest/IMyPackageTool.h"
#include "AthAsgExUnittest/IAthAsgExUnittestTool.h"
class MyPackageAlg: public ::AthAnalysisAlgorithm {
class AthAsgExUnittestAlg: public ::AthAnalysisAlgorithm {
public:
MyPackageAlg( const std::string& name, ISvcLocator* pSvcLocator );
virtual ~MyPackageAlg();
AthAsgExUnittestAlg( const std::string& name, ISvcLocator* pSvcLocator );
virtual ~AthAsgExUnittestAlg();
virtual StatusCode initialize() override;
virtual StatusCode execute() override;
......@@ -28,8 +28,8 @@ public:
private:
int m_property;
ToolHandle<IMyPackageTool> m_tool;
ToolHandle<IAthAsgExUnittestTool> m_tool;
};
#endif //> !ATHASGEXUNITTEST_MYPACKAGEALG_H
#endif //> !ATHASGEXUNITTEST_ATHASGEXUNITTESTALG_H
//
// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
//
#include "AthAsgExUnittest/MyPackageTool.h"
#include "../MyPackageAlg.h"
#include "AthAsgExUnittest/AthAsgExUnittestTool.h"
#include "../AthAsgExUnittestAlg.h"
DECLARE_COMPONENT( MyPackageAlg )
DECLARE_COMPONENT( MyPackageTool )
DECLARE_COMPONENT( AthAsgExUnittestAlg )
DECLARE_COMPONENT( AthAsgExUnittestTool )
......@@ -15,8 +15,8 @@ ATLAS_NO_CHECK_FILE_THREAD_SAFETY;
#include "AsgTools/StandaloneToolHandle.h"
#include "AthAnalysisBaseComps/AthAnalysisHelper.h"
#include "AthAsgExUnittest/IMyPackageTool.h"
#include "AthAsgExUnittest/MyPackageTool.h"
#include "AthAsgExUnittest/IAthAsgExUnittestTool.h"
#include "AthAsgExUnittest/AthAsgExUnittestTool.h"
#include "GaudiKernel/IAlgManager.h"
#include "Gaudi/Algorithm.h"
......@@ -30,19 +30,19 @@ namespace Athena_test {
// Tool test suite:
class MyPackageToolTest : public ::testing::Test {
class AthAsgExUnittestToolTest : public ::testing::Test {
public:
MyPackageToolTest() : myTool( "MyTool" ) {}
~MyPackageToolTest() {}
MyPackageTool myTool;
AthAsgExUnittestToolTest() : myTool( "MyTool" ) {}
~AthAsgExUnittestToolTest() {}
AthAsgExUnittestTool myTool;
};
// cppcheck-suppress syntaxError
TEST_F( MyPackageToolTest, initialise ) {
TEST_F( AthAsgExUnittestToolTest, initialise ) {
EXPECT_TRUE( myTool.initialize().isSuccess() );
}
TEST_F( MyPackageToolTest, property ) {
TEST_F( AthAsgExUnittestToolTest, property ) {
EXPECT_TRUE( myTool.setProperty( "Property", 42.0 ).isSuccess() );
EXPECT_TRUE( myTool.initialize().isSuccess() );
std::string prop;
......@@ -50,48 +50,48 @@ namespace Athena_test {
EXPECT_EQ( std::stod( prop ), 42.0 );
}
TEST_F( MyPackageToolTest, enumProperty ) {
EXPECT_TRUE( myTool.setProperty( "EnumProperty", IMyPackageTool::Val2 ).isSuccess() );
TEST_F( AthAsgExUnittestToolTest, enumProperty ) {
EXPECT_TRUE( myTool.setProperty( "EnumProperty", IAthAsgExUnittestTool::Val2 ).isSuccess() );
EXPECT_TRUE( myTool.initialize().isSuccess() );
std::string prop;
EXPECT_TRUE( myTool.getProperty( "EnumProperty", prop ).isSuccess() );
EXPECT_EQ( std::stoi( prop ), IMyPackageTool::Val2 );
EXPECT_EQ( std::stoi( prop ), IAthAsgExUnittestTool::Val2 );
}
// Algorithm test suite:
class MyPackageAlgTest : public InitGaudiGoogleTest {
class AthAsgExUnittestAlgTest : public InitGaudiGoogleTest {
public:
virtual void SetUp() override {
// Algorithm and Tool properties via service:
// see: Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisHelper.h
EXPECT_TRUE( AthAnalysisHelper::addPropertyToCatalogue( "MyPackageAlg",
EXPECT_TRUE( AthAnalysisHelper::addPropertyToCatalogue( "AthAsgExUnittestAlg",
"MyProperty",
21 ).isSuccess() );
EXPECT_TRUE( AthAnalysisHelper::addPropertyToCatalogue( "MyPackageAlg",
EXPECT_TRUE( AthAnalysisHelper::addPropertyToCatalogue( "AthAsgExUnittestAlg",
"MyTool",
"MyPackageTool/AnotherName" ).isSuccess() );
"AthAsgExUnittestTool/AnotherName" ).isSuccess() );
// Set property on the tool
EXPECT_TRUE( AthAnalysisHelper::addPropertyToCatalogue( "MyPackageAlg.AnotherName",
EXPECT_TRUE( AthAnalysisHelper::addPropertyToCatalogue( "AthAsgExUnittestAlg.AnotherName",
"Property",
42.0 ).isSuccess() );
// Create instance of my algorithm through Gaudi.
IAlgManager* algMgr = svcMgr.as< IAlgManager >();
EXPECT_TRUE( algMgr != nullptr );
IAlgorithm* alg = nullptr;
EXPECT_TRUE( algMgr->createAlgorithm( "MyPackageAlg", "MyPackageAlg",
EXPECT_TRUE( algMgr->createAlgorithm( "AthAsgExUnittestAlg", "AthAsgExUnittestAlg",
alg ).isSuccess() );
EXPECT_TRUE( alg != nullptr );
myAlg = dynamic_cast< Algorithm* >( alg );
EXPECT_TRUE( myAlg != nullptr );
}
MyPackageTool* getMyTool() {
ToolHandle<IMyPackageTool> toolHandle( "", myAlg );
AthAsgExUnittestTool* getMyTool() {
ToolHandle<IAthAsgExUnittestTool> toolHandle( "", myAlg );
toolHandle.setTypeAndName( myAlg->getProperty( "MyTool" ).toString() );
EXPECT_TRUE( toolHandle.retrieve().isSuccess() );
IMyPackageTool* impt= toolHandle.get();
MyPackageTool* mpt= dynamic_cast<MyPackageTool*>( impt );
IAthAsgExUnittestTool* impt= toolHandle.get();
AthAsgExUnittestTool* mpt= dynamic_cast<AthAsgExUnittestTool*>( impt );
return mpt;
}
......@@ -99,11 +99,11 @@ namespace Athena_test {
};
TEST_F( MyPackageAlgTest, initialise ) {
TEST_F( AthAsgExUnittestAlgTest, initialise ) {
EXPECT_TRUE( myAlg->initialize().isSuccess() );
}
TEST_F( MyPackageAlgTest, setProperty ) {
TEST_F( AthAsgExUnittestAlgTest, setProperty ) {
EXPECT_TRUE( myAlg->setProperty( "MyProperty", 5 ).isSuccess() );
EXPECT_TRUE( myAlg->initialize().isSuccess() );
std::string prop;
......@@ -111,17 +111,17 @@ namespace Athena_test {
EXPECT_EQ( prop, "5" );
}
TEST_F( MyPackageAlgTest, sysInitialize ) {
TEST_F( AthAsgExUnittestAlgTest, sysInitialize ) {
EXPECT_TRUE( myAlg->sysInitialize().isSuccess() );
std::string prop;
EXPECT_TRUE( myAlg->getProperty( "MyProperty", prop ).isSuccess() );
EXPECT_EQ( std::stoi( prop ), 21 );
}
TEST_F( MyPackageAlgTest, toolProperty ) {
TEST_F( AthAsgExUnittestAlgTest, toolProperty ) {
// sysInitialize() gets properties then call initialize()
EXPECT_TRUE( myAlg->sysInitialize().isSuccess() );
MyPackageTool* mpt= getMyTool();
AthAsgExUnittestTool* mpt= getMyTool();
std::string prop;
EXPECT_TRUE( mpt->getProperty( "Property", prop ).isSuccess() );
EXPECT_EQ( std::stod( prop ), 42.0 );
......
......@@ -15,7 +15,7 @@ ATLAS_NO_CHECK_FILE_THREAD_SAFETY;
#include "AthenaBaseComps/AthAlgorithm.h"
#include "AthenaBaseComps/AthService.h"
#include "AthAsgExUnittest/IMyPackageTool.h"
#include "AthAsgExUnittest/IAthAsgExUnittestTool.h"
#include <string>
#include <iostream>
......@@ -25,10 +25,10 @@ namespace Athena_test {
// Algorithm test suite:
class MyPackageAlgTest : public InitGaudiGoogleTest {
class AthAsgExUnittestAlgTest : public InitGaudiGoogleTest {
public:
MyPackageAlgTest()
AthAsgExUnittestAlgTest()
// : InitGaudiGoogleTest( MSG::INFO ) // get usual message blurb
: myAlg(nullptr)
{}
......@@ -36,22 +36,22 @@ namespace Athena_test {
virtual void SetUp() override {
ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc( "JobOptionsSvc",
"MyPackageAlgTest" );
joSvc->set( "MyPackageAlg.MyProperty", Gaudi::Utils::toString( 21 ) );
joSvc->set( "MyPackageAlg.MyTool", "MyPackageTool/AnotherName" );
joSvc->set( "MyPackageAlg.AnotherName.Property", Gaudi::Utils::toString( 42.0 ) );
IAlgorithm* ialg= Algorithm::Factory::create( "MyPackageAlg",
"MyPackageAlg",
"AthAsgExUnittestAlgTest" );
joSvc->set( "AthAsgExUnittestAlg.MyProperty", Gaudi::Utils::toString( 21 ) );
joSvc->set( "AthAsgExUnittestAlg.MyTool", "AthAsgExUnittestTool/AnotherName" );
joSvc->set( "AthAsgExUnittestAlg.AnotherName.Property", Gaudi::Utils::toString( 42.0 ) );
IAlgorithm* ialg= Algorithm::Factory::create( "AthAsgExUnittestAlg",
"AthAsgExUnittestAlg",
Gaudi::svcLocator() ).release();
myAlg= dynamic_cast<Gaudi::Algorithm*>( ialg );
}
IMyPackageTool* getMyTool() {
ToolHandle<IMyPackageTool> toolHandle( "", myAlg );
IAthAsgExUnittestTool* getMyTool() {
ToolHandle<IAthAsgExUnittestTool> toolHandle( "", myAlg );
toolHandle.setTypeAndName( myAlg->getProperty( "MyTool" ).toString() );
EXPECT_TRUE( toolHandle.retrieve().isSuccess() );
IMyPackageTool* impt= toolHandle.get();
IAthAsgExUnittestTool* impt= toolHandle.get();
return impt;
}
......@@ -66,32 +66,32 @@ namespace Athena_test {
};
// cppcheck-suppress syntaxError
TEST_F( MyPackageAlgTest, getDefaultPropertyValue ) {
TEST_F( AthAsgExUnittestAlgTest, getDefaultPropertyValue ) {
int prop= getIntProperty( "MyProperty" );
EXPECT_EQ( prop, 1 );
}
TEST_F( MyPackageAlgTest, initialise ) {
TEST_F( AthAsgExUnittestAlgTest, initialise ) {
EXPECT_TRUE( myAlg->initialize().isSuccess() );
}
TEST_F( MyPackageAlgTest, setProperty ) {
TEST_F( AthAsgExUnittestAlgTest, setProperty ) {
EXPECT_TRUE( myAlg->setProperty( "MyProperty", 5 ).isSuccess() );
EXPECT_TRUE( myAlg->initialize().isSuccess() );
int prop= getIntProperty( "MyProperty" );
EXPECT_EQ( prop, 5 );
}
TEST_F( MyPackageAlgTest, getPropertyFromCatalogue ) {
TEST_F( AthAsgExUnittestAlgTest, getPropertyFromCatalogue ) {
EXPECT_TRUE( myAlg->sysInitialize().isSuccess() );
int prop= getIntProperty( "MyProperty" );
EXPECT_EQ( prop, 21 );
}
TEST_F( MyPackageAlgTest, toolProperty ) {
TEST_F( AthAsgExUnittestAlgTest, toolProperty ) {
// sysInitialize() gets properties then calls initialize()
EXPECT_TRUE( myAlg->sysInitialize().isSuccess() );
IMyPackageTool* mpt= getMyTool();
IAthAsgExUnittestTool* mpt= getMyTool();
double prop= mpt->useTheProperty();
EXPECT_EQ( prop, 42.0 );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment