Changeset 139:b80094f9fac6 in finroc_plugins_data_ports for tests/test_collection.cpp


Ignore:
Timestamp:
18.02.2019 07:37:31 (10 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Parents:
124:ca459cc011c8 (diff), 138:b4ec8fe1d2ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merge with 17.03

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/test_collection.cpp

    r124 r139  
    4545#include "plugins/data_ports/tThreadLocalBufferManagement.h" 
    4646#include "plugins/data_ports/tPortPack.h" 
     47 
     48#include "plugins/structure/tModule.h" 
    4749 
    4850//---------------------------------------------------------------------- 
     
    196198    void OnPortChange(const rrlib::rtti::tGenericObject& value, tChangeContext& change_context) 
    197199    { 
    198       FINROC_LOG_PRINT(DEBUG_VERBOSE_1, "  Port Changed Generic: ", value); 
     200      rrlib::serialization::tStringOutputStream stream; 
     201      value.Serialize(stream); 
     202      FINROC_LOG_PRINT(DEBUG_VERBOSE_1, "  Port Changed Generic: ", stream.ToString()); 
    199203      this->calls++; 
    200204    } 
    201205    void OnPortChange(tPortDataPointer<const rrlib::rtti::tGenericObject>& value, tChangeContext& change_context) 
    202206    { 
    203       FINROC_LOG_PRINT(DEBUG_VERBOSE_1, "  Port Changed Generic (tPortDataPointer): ", *value); 
     207      rrlib::serialization::tStringOutputStream stream; 
     208      value->Serialize(stream); 
     209      FINROC_LOG_PRINT(DEBUG_VERBOSE_1, "  Port Changed Generic (tPortDataPointer): ", stream.ToString()); 
    204210      this->calls++; 
    205211    } 
     
    365371} 
    366372 
     373struct mTestModule : structure::tModule 
     374{ 
     375  using tModule::tModule; 
     376  void Update() override {} 
     377}; 
     378 
     379template <typename ... T, typename NAMES> 
     380void PortPackTestHelper(core::tFrameworkElement *parent, const std::initializer_list<NAMES> &names_initializer) 
     381{ 
     382  data_ports::tPortPack<mTestModule::tInput, T...> ports(parent, "X"); 
     383 
     384  RRLIB_UNIT_TESTS_EQUALITY(sizeof...(T), ports.NumberOfPorts()); 
     385  for (size_t i = 0; i < sizeof...(T); ++i) 
     386  { 
     387    RRLIB_UNIT_TESTS_EQUALITY("X" + std::to_string(i), ports.GetPort(i).GetName()); 
     388  } 
     389 
     390  std::array<NAMES, sizeof...(T)> names; 
     391  assert(names_initializer.size() == names.size()); 
     392  std::copy(names_initializer.begin(), names_initializer.end(), names.begin()); 
     393  data_ports::tPortPack<tInputPort, T...> named_ports(parent, names.begin(), names.end()); 
     394 
     395  RRLIB_UNIT_TESTS_EQUALITY(sizeof...(T), named_ports.NumberOfPorts()); 
     396  for (size_t i = 0; i < sizeof...(T); ++i) 
     397  { 
     398    RRLIB_UNIT_TESTS_EQUALITY(std::string(names[i]), named_ports.GetPort(i).GetName()); 
     399  } 
     400} 
     401 
    367402class DataPortsTestCollection : public rrlib::util::tUnitTestSuite 
    368403{ 
     
    370405  RRLIB_UNIT_TESTS_ADD_TEST(Test); 
    371406  RRLIB_UNIT_TESTS_ADD_TEST(PortPack); 
     407  RRLIB_UNIT_TESTS_ADD_TEST(PortPackLegacy); 
    372408  RRLIB_UNIT_TESTS_END_SUITE; 
    373409 
     
    399435  void PortPack() 
    400436  { 
    401     auto parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestPortPack"); 
     437    auto parent = new mTestModule(&core::tRuntimeEnvironment::GetInstance(), "TestModule"); 
     438 
     439    PortPackTestHelper<int, double, std::string, bool>(parent, {"foo", "bar", "baz", "fnord"}); 
     440 
     441    std::array<std::string, 0> empty_names; 
     442    RRLIB_UNIT_TESTS_EQUALITY(size_t(0), data_ports::tPortPack<mTestModule::tInput>(parent, "X").NumberOfPorts()); 
     443    RRLIB_UNIT_TESTS_EQUALITY(size_t(0), data_ports::tPortPack<mTestModule::tInput>(parent, empty_names.begin(), empty_names.end()).NumberOfPorts()); 
     444  } 
     445 
     446  void PortPackLegacy() 
     447  { 
     448    auto parent = new mTestModule(&core::tRuntimeEnvironment::GetInstance(), "TestModule"); 
    402449 
    403450    using tTypeList = rrlib::util::tTypeList<int, double, std::string, bool>; 
    404     data_ports::tPortPack<tInputPort, tTypeList> ports(parent, "X"); 
     451    data_ports::tPortPack<mTestModule::tInput, tTypeList> ports(parent, "X"); 
    405452 
    406453    RRLIB_UNIT_TESTS_EQUALITY(tTypeList::cSIZE, ports.NumberOfPorts()); 
     
    412459 
    413460    std::array<std::string, tTypeList::cSIZE> names {"foo", "bar", "baz", "fnord"}; 
    414     data_ports::tPortPack<tInputPort, tTypeList> named_ports(parent, names.begin(), names.end()); 
     461    data_ports::tPortPack<mTestModule::tInput, tTypeList> named_ports(parent, names.begin(), names.end()); 
    415462 
    416463    for (size_t i = 0; i < tTypeList::cSIZE; ++i) 
Note: See TracChangeset for help on using the changeset viewer.