Skip to content
Snippets Groups Projects
Commit 928ebf2f authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Add helper class for C++ test side

parent 0cc1f621
No related branches found
No related tags found
1 merge request!325Add to/fromAron() for one-sided optional and test utilities for C++/Python conversion
......@@ -2,3 +2,4 @@ add_subdirectory(core)
add_subdirectory(converter)
add_subdirectory(codegeneration)
add_subdirectory(common)
add_subdirectory(test)
/**
* 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::aron_cpp_to_python_conv_test
* @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
* @date 2023
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "AronConversionTester.h"
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
namespace armarx::aron::test
{
AronConversionTester::AronConversionTester(dti::AronConversionTestInterfacePrx python) : interface(python)
{
ARMARX_CHECK(python);
}
} // namespace armarx::aron::test
/**
* 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::aron_cpp_to_python_conv_test
* @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
* @date 2023
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <RobotAPI/interface/aron/test/AronConversionTestInterface.h>
namespace armarx::aron::test
{
/**
* @brief Helper class for implementing distributed ARON conversion tests
* based on the `dti::AronConversionTestInterfacePrx`.
*
* Example usage:
*
* @code
*
* armarx::aron::test::dti::AronConversionTestInterfacePrx pythonComponent = ...;
*
* auto myAronClassProbeFn = []()
* {
* my::arondto::MyAronClass probe;
* probe.data = "42";
* return probe,
* };
*
* armarx::aron::test::AronConversionTester tester(pythonComponent);
*
* tester.test<my::arondto::MyAronClass>(myAronClassProbeFn, "MyAronClass");
*
* @endcode
*
* Note that the `pythonComponent` must point to a corresponding
* implementation of the `AronConversionTestInterfacePrx`.
*/
class AronConversionTester
{
public:
template <class AronClassT>
using ProbeFn = std::function<AronClassT()>;
public:
AronConversionTester(dti::AronConversionTestInterfacePrx interface);
/**
* @brief Test the conversion of a specific ARON class.
*
* @param probeFn A factory function creating a test instance of the
* ARON class.
* @param aronClassName The name of the ARON class. Can be used by the
* other component to decide which class to convert to.
*/
template <class AronClassT>
void
test(ProbeFn<AronClassT> probeFn, const std::string& aronClassName)
{
const AronClassT probe = probeFn();
dto::TestAronConversionRequest req;
req.aronClassName = aronClassName;
req.probe = probe.toAronDTO();
dto::TestAronConversionResponse res = interface->testAronConversion(req);
if (res.success)
{
const AronClassT probeOut = AronClassT::FromAron(res.probe);
ARMARX_CHECK(probeOut == probe);
ARMARX_IMPORTANT << "Test successful.";
}
else
{
ARMARX_WARNING << "Conversion in Python component failed: \n" << res.errorMessage;
}
}
public:
dti::AronConversionTestInterfacePrx interface;
};
} // namespace armarx::aron::test
set(LIB_NAME arontest)
armarx_component_set_name("${LIB_NAME}")
armarx_set_target("Library: ${LIB_NAME}")
armarx_add_library(
LIBS
# ArmarXCore
ArmarXCore
# RobotAPI
RobotAPICore
RobotAPIInterfaces
aron
HEADERS
AronConversionTester.h
SOURCES
AronConversionTester.cpp
)
add_library(aron::test ALIAS arontest)
add_library(${PROJECT_NAME}::Aron::test ALIAS arontest)
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