Skip to content
Snippets Groups Projects
Commit 6fc6337f authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

added gtest for generic factory

parent 4054acd4
No related branches found
No related tags found
1 merge request!441Removed loading of packages from Problem
Pipeline #9475 failed
......@@ -34,6 +34,7 @@ target_link_libraries(gtest_example ${PLUGIN_NAME}) #
set(SRC_DUMMY
dummy/processor_tracker_feature_dummy.cpp
dummy/processor_tracker_landmark_dummy.cpp
dummy/dummy_object_derived.cpp
)
add_library(dummy SHARED ${SRC_DUMMY})
target_link_libraries(dummy ${PLUGIN_NAME})
......@@ -64,6 +65,10 @@ target_link_libraries(gtest_factor_base ${PLUGIN_NAME})
wolf_add_gtest(gtest_factor_autodiff gtest_factor_autodiff.cpp)
target_link_libraries(gtest_factor_autodiff ${PLUGIN_NAME})
# Factory test
wolf_add_gtest(gtest_factory gtest_factory.cpp)
target_link_libraries(gtest_factory ${PLUGIN_NAME} dummy)
# FactoryStateBlock factory test
wolf_add_gtest(gtest_factory_state_block gtest_factory_state_block.cpp)
target_link_libraries(gtest_factory_state_block ${PLUGIN_NAME})
......
//--------LICENSE_START--------
//
// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
// Authors: Joan Solà Ortega (jsola@iri.upc.edu)
// All rights reserved.
//
// This file is part of WOLF
// WOLF is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//--------LICENSE_END--------
#ifndef WOLF_DUMMY_OBJECT_H_
#define WOLF_DUMMY_OBJECT_H_
/**************************
* WOLF includes *
**************************/
#include "core/common/wolf.h"
#include <core/utils/params_server.h>
#include "factory_dummy_object.h"
namespace wolf {
WOLF_PTR_TYPEDEFS(DummyObject);
/*
* Macro for defining Autoconf DummyObject creator for WOLF's high level API.
*
* Place a call to this macro inside your class declaration (in the DummyObject_class.h file),
* preferably just after the constructors.
*
* In order to use this macro, the derived DummyObject class, DummyObjectClass,
* must have a constructor available with the API:
*
* DummyObjectClass(const std::string& _unique_name,
* const ParamsServer& _server);
*/
#define WOLF_DUMMY_OBJECT_CREATE(DummyObjectClass) \
static DummyObjectPtr create(const std::string& _unique_name, \
const ParamsServer& _server) \
{ \
DummyObjectPtr sub = std::make_shared<DummyObjectClass>(_unique_name, _server); \
return sub; \
} \
class DummyObject
{
protected:
//wolf
std::string prefix_;
std::string name_;
std::string topic_;
public:
DummyObject(const std::string& _unique_name,
const ParamsServer& _server) :
prefix_("ROS DummyObject/" + _unique_name),
name_(_unique_name)
{
//topic_ = _server.getParam<std::string>(prefix_ + "/topic");
}
virtual ~DummyObject(){};
//std::string getTopic() const;
std::string getName() const;
virtual void print() const = 0;
protected:
template<typename T>
T getParamWithDefault(const ParamsServer &_server,
const std::string &_param_name,
const T _default_value) const;
};
// inline std::string DummyObject::getTopic() const
// {
// return topic_;
// }
inline std::string DummyObject::getName() const
{
return name_;
}
// template<typename T>
// inline T DummyObject::getParamWithDefault(const ParamsServer &_server,
// const std::string &_param_name,
// const T _default_value) const
// {
// try
// {
// return _server.getParam<T>(_param_name);
// }
// catch (...)
// {
// WOLF_INFO("DummyObject: Parameter ", _param_name, " is missing. Taking default value: ", _default_value);
// return _default_value;
// }
// }
}
#endif
//--------LICENSE_START--------
//
// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
// Authors: Joan Solà Ortega (jsola@iri.upc.edu)
// All rights reserved.
//
// This file is part of WOLF
// WOLF is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//--------LICENSE_END--------
#include "dummy_object_derived.h"
namespace wolf
{
DummyObjectDerived::DummyObjectDerived(const std::string& _unique_name,
const ParamsServer& _server) ://,
DummyObject(_unique_name, _server)
{
}
void DummyObjectDerived::print() const
{
WOLF_INFO("DummyObjectDerived::print()");
}
}
\ No newline at end of file
//--------LICENSE_START--------
//
// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
// Authors: Joan Solà Ortega (jsola@iri.upc.edu)
// All rights reserved.
//
// This file is part of WOLF
// WOLF is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//--------LICENSE_END--------
#ifndef DUMMY_OBJECT_DERIVED_H_
#define DUMMY_OBJECT_DERIVED_H_
/**************************
* WOLF includes *
**************************/
#include "core/common/wolf.h"
#include "dummy_object.h"
namespace wolf {
class DummyObjectDerived : public DummyObject
{
public:
DummyObjectDerived(const std::string& _unique_name,
const ParamsServer& _server);
WOLF_DUMMY_OBJECT_CREATE(DummyObjectDerived);
void print() const override;
virtual ~DummyObjectDerived(){};
};
WOLF_REGISTER_DUMMY_OBJECT(DummyObjectDerived)
}
#endif
\ No newline at end of file
//--------LICENSE_START--------
//
// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
// Authors: Joan Solà Ortega (jsola@iri.upc.edu)
// All rights reserved.
//
// This file is part of WOLF
// WOLF is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//--------LICENSE_END--------
#ifndef FACTORY_DUMMY_OBJECT_H_
#define FACTORY_DUMMY_OBJECT_H_
// wolf
#include <core/common/factory.h>
#include <core/utils/params_server.h>
namespace wolf
{
class DummyObject;
typedef Factory<DummyObject,
const std::string&,
const ParamsServer&> FactoryDummyObject;
template<>
inline std::string FactoryDummyObject::getClass() const
{
return "FactoryDummyObject";
}
#define WOLF_REGISTER_DUMMY_OBJECT(DummyObjectType) \
namespace{ const bool WOLF_UNUSED DummyObjectType##Registered = \
wolf::FactoryDummyObject::registerCreator(#DummyObjectType, DummyObjectType::create); } \
} /* namespace wolf */
#endif /* FACTORY_DUMMY_OBJECT_H_ */
//--------LICENSE_START--------
//
// Copyright (C) 2020,2021,2022 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
// Authors: Joan Solà Ortega (jsola@iri.upc.edu)
// All rights reserved.
//
// This file is part of WOLF
// WOLF is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//--------LICENSE_END--------
#include "core/utils/utils_gtest.h"
#include "dummy/factory_dummy_object.h"
#include "dummy/dummy_object.h"
#include "dummy/dummy_object_derived.h"
#include "core/yaml/parser_yaml.h"
#include "core/utils/params_server.h"
using namespace wolf;
std::string wolf_root = _WOLF_ROOT_DIR;
TEST(TestFactory, DummyObjectFactory)
{
ParserYaml parser = ParserYaml("test/yaml/params_basic.yaml", wolf_root);
ParamsServer server = ParamsServer(parser.getParams());
auto object = FactoryDummyObject::create("DummyObjectDerived","ACoolDummyObject", server);
object->getName();
object->print();
// FORCE LOADING
DummyObjectDerived obj_derived = DummyObjectDerived("AnotherCoolDummyObject", server);
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
//::testing::GTEST_FLAG(filter) = "TestTest.DummyTestExample"; // Test only this one
//::testing::GTEST_FLAG(filter) = "TestTest.*"; // Test only the tests in this group
return RUN_ALL_TESTS();
}
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