Changeset 124:ca459cc011c8 in finroc_plugins_data_ports


Ignore:
Timestamp:
07.09.2017 10:57:23 (23 months ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Parents:
113:938e71ac0af4 (diff), 116:a842f5afb76b (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 14.08

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tPortPack.h

    r116 r124  
    7777{ 
    7878 
     79  template <bool value, typename> 
     80  using CheckIterators = std::integral_constant<bool, value>; 
     81 
    7982//---------------------------------------------------------------------- 
    8083// Public methods and typedefs 
     
    8992  } 
    9093 
    91   template <typename TIterator> 
     94  template <typename TIterator, typename std::enable_if<CheckIterators<(Tsize> 1), TIterator>::value, int>::type = 0 > 
     95      inline tPortPack(core::tFrameworkElement *parent, TIterator names_begin, TIterator names_end) : 
     96        tPortPack < TPort, TTypeList, Tsize - 1 > (parent, names_begin, names_end - 1), 
     97        port(*(names_end - 1), parent) 
     98  { 
     99    this->port.Init(); 
     100  } 
     101 
     102  template <typename TIterator, typename std::enable_if<CheckIterators<(Tsize == 1), TIterator>::value, int>::type = 0> 
    92103  inline tPortPack(core::tFrameworkElement *parent, TIterator names_begin, TIterator names_end) : 
    93     tPortPack < TPort, TTypeList, Tsize - 1 > (parent, names_begin, names_end - 1), 
    94     port(names_end - 1, parent) 
     104    tPortPack < TPort, TTypeList, Tsize - 1 > (parent, *names_begin), 
     105    port(*names_begin, parent) 
    95106  { 
    96107    this->port.Init(); 
     
    134145  inline tPortPack(core::tFrameworkElement *parent, const std::string &name_prefix) 
    135146  {} 
     147 
     148  template <typename TIterator> 
     149  inline tPortPack(core::tFrameworkElement *parent, TIterator names_begin, TIterator names_end) 
     150  {} 
     151 
    136152  inline core::tPortWrapperBase &GetPort(size_t index) 
    137153  { 
  • tests/test_collection.cpp

    r116 r124  
    4444#include "plugins/data_ports/tProxyPort.h" 
    4545#include "plugins/data_ports/tThreadLocalBufferManagement.h" 
     46#include "plugins/data_ports/tPortPack.h" 
    4647 
    4748//---------------------------------------------------------------------- 
     
    238239} 
    239240 
     241template <typename T> 
     242void TestNetworkConnectionLoss(const T& default_value, const T& publish_value) 
     243{ 
     244  core::tFrameworkElement* parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestNetworkConnectionLoss"); 
     245 
     246  tOutputPort<T> output_port("Output Port", parent); 
     247  tInputPort<T> input_port_no_explicit_default("Input Port No Explicit Default", parent, core::tFrameworkElement::tFlag::DEFAULT_ON_DISCONNECT); 
     248  tInputPort<T> input_port_explicit_default("Input Port Explicit Default", parent, core::tFrameworkElement::tFlag::DEFAULT_ON_DISCONNECT, default_value); 
     249  tInputPort<T> input_port_deferred_default("Input Port Deferred Default", parent, core::tFrameworkElement::tFlag::DEFAULT_ON_DISCONNECT); 
     250  input_port_deferred_default.SetDefault(default_value); 
     251  output_port.ConnectTo(input_port_no_explicit_default); 
     252  output_port.ConnectTo(input_port_explicit_default); 
     253  output_port.ConnectTo(input_port_deferred_default); 
     254  parent->Init(); 
     255 
     256  output_port.Publish(publish_value); 
     257  RRLIB_UNIT_TESTS_EQUALITY(publish_value, *input_port_no_explicit_default.GetPointer()); 
     258  RRLIB_UNIT_TESTS_EQUALITY(publish_value, *input_port_explicit_default.GetPointer()); 
     259  RRLIB_UNIT_TESTS_EQUALITY(publish_value, *input_port_deferred_default.GetPointer()); 
     260  input_port_no_explicit_default.GetWrapped()->NotifyOfNetworkConnectionLoss(); 
     261  input_port_explicit_default.GetWrapped()->NotifyOfNetworkConnectionLoss(); 
     262  input_port_deferred_default.GetWrapped()->NotifyOfNetworkConnectionLoss(); 
     263  RRLIB_UNIT_TESTS_EQUALITY(T(), *input_port_no_explicit_default.GetPointer()); 
     264  RRLIB_UNIT_TESTS_EQUALITY(default_value, *input_port_explicit_default.GetPointer()); 
     265  RRLIB_UNIT_TESTS_EQUALITY(default_value, *input_port_deferred_default.GetPointer()); 
     266  output_port.Publish(publish_value); 
     267  RRLIB_UNIT_TESTS_EQUALITY(publish_value, *input_port_no_explicit_default.GetPointer()); 
     268  RRLIB_UNIT_TESTS_EQUALITY(publish_value, *input_port_explicit_default.GetPointer()); 
     269  RRLIB_UNIT_TESTS_EQUALITY(publish_value, *input_port_deferred_default.GetPointer()); 
     270  output_port.DisconnectAll(); 
     271  RRLIB_UNIT_TESTS_EQUALITY(T(), *input_port_no_explicit_default.GetPointer()); 
     272  RRLIB_UNIT_TESTS_EQUALITY(default_value, *input_port_explicit_default.GetPointer()); 
     273  RRLIB_UNIT_TESTS_EQUALITY(default_value, *input_port_deferred_default.GetPointer()); 
     274 
     275  parent->ManagedDelete(); 
     276} 
     277 
     278void TestOutOfBoundsPublish() 
     279{ 
     280  core::tFrameworkElement* parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestOutOfBoundsPublish"); 
     281 
     282  tOutputPort<int> output_port("Output Port", parent, tBounds<int>(0, 2, tOutOfBoundsAction::DISCARD)); 
     283  tInputPort<int> input_port("Input Port", parent, tBounds<int>(0, 1)); 
     284  output_port.ConnectTo(input_port); 
     285  parent->Init(); 
     286 
     287  output_port.Publish(3); 
     288  RRLIB_UNIT_TESTS_EQUALITY(0, input_port.Get()); 
     289  output_port.Publish(2); 
     290  RRLIB_UNIT_TESTS_EQUALITY(1, input_port.Get()); 
     291 
     292  parent->ManagedDelete(); 
     293} 
     294 
     295template <typename T> 
     296void TestHijackedPublishing(const T& value_to_publish) 
     297{ 
     298  core::tFrameworkElement* parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestHijackedPublishing"); 
     299  T default_value = T(); 
     300 
     301  tOutputPort<T> output_port("Output Port", parent); 
     302  tProxyPort<T, true> proxy_port("Proxy Port", parent, core::tFrameworkElementFlag::PUSH_STRATEGY); 
     303  tInputPort<T> input_port("Input Port", parent); 
     304  output_port.ConnectTo(proxy_port); 
     305  proxy_port.ConnectTo(input_port); 
     306  parent->Init(); 
     307 
     308  output_port.Publish(value_to_publish); 
     309  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *proxy_port.GetPointer()); 
     310  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *input_port.GetPointer()); 
     311  input_port.GetWrapped()->SetHijacked(true); 
     312  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *proxy_port.GetPointer()); 
     313  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *input_port.GetPointer()); 
     314  output_port.Publish(default_value); 
     315  RRLIB_UNIT_TESTS_EQUALITY(default_value, *proxy_port.GetPointer()); 
     316  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *input_port.GetPointer()); 
     317  proxy_port.GetWrapped()->SetHijacked(true); 
     318  input_port.GetWrapped()->SetHijacked(false); 
     319  output_port.Publish(value_to_publish); 
     320  RRLIB_UNIT_TESTS_EQUALITY(default_value, *proxy_port.GetPointer()); 
     321  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, *input_port.GetPointer()); 
     322  output_port.GetWrapped()->SetHijacked(true); 
     323  output_port.Publish(value_to_publish); 
     324 
     325  parent->ManagedDelete(); 
     326} 
     327 
     328template <typename T> 
     329void TestGenericPorts(T value_to_publish, T another_value) 
     330{ 
     331  core::tFrameworkElement* parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestGenericPorts"); 
     332  T default_value = T(); 
     333  rrlib::rtti::tGenericObjectWrapper<T> default_buffer(default_value); 
     334  rrlib::rtti::tGenericObjectWrapper<T> value_buffer(value_to_publish); 
     335  rrlib::rtti::tGenericObjectWrapper<T> another_value_buffer(another_value); 
     336 
     337  tGenericPort output_port("Output Port", rrlib::rtti::tDataType<T>(), parent, core::tFrameworkElement::tFlag::EMITS_DATA | core::tFrameworkElement::tFlag::OUTPUT_PORT); 
     338  tGenericPort proxy_port("Proxy Port", rrlib::rtti::tDataType<T>(), parent, core::tFrameworkElement::tFlag::ACCEPTS_DATA | core::tFrameworkElement::tFlag::PUSH_STRATEGY | core::tFrameworkElement::tFlag::EMITS_DATA); 
     339  tGenericPort input_port("Input Port", rrlib::rtti::tDataType<T>(), parent, core::tFrameworkElement::tFlag::ACCEPTS_DATA | core::tFrameworkElement::tFlag::PUSH_STRATEGY); 
     340  output_port.ConnectTo(proxy_port); 
     341  proxy_port.ConnectTo(input_port); 
     342  parent->Init(); 
     343 
     344  // Publish by value 
     345  T get_value = T(); 
     346  rrlib::rtti::tGenericObjectWrapper<T> get_buffer(get_value); 
     347  input_port.Get(get_buffer); 
     348  RRLIB_UNIT_TESTS_EQUALITY(default_value, get_value); 
     349  output_port.Publish(value_buffer); 
     350  proxy_port.Get(get_buffer); 
     351  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, get_value); 
     352  input_port.Get(get_buffer); 
     353  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish, get_value); 
     354 
     355  // Publish via buffer 
     356  auto unused_buffer = output_port.GetUnusedBuffer(); 
     357  unused_buffer->GetData<T>() = another_value; 
     358  output_port.Publish(unused_buffer); 
     359  proxy_port.Get(get_buffer); 
     360  RRLIB_UNIT_TESTS_EQUALITY(another_value, get_value); 
     361  input_port.Get(get_buffer); 
     362  RRLIB_UNIT_TESTS_EQUALITY(another_value, get_value); 
     363 
     364  parent->ManagedDelete(); 
     365} 
     366 
    240367class DataPortsTestCollection : public rrlib::util::tUnitTestSuite 
    241368{ 
    242369  RRLIB_UNIT_TESTS_BEGIN_SUITE(DataPortsTestCollection); 
    243370  RRLIB_UNIT_TESTS_ADD_TEST(Test); 
     371  RRLIB_UNIT_TESTS_ADD_TEST(PortPack); 
    244372  RRLIB_UNIT_TESTS_END_SUITE; 
    245373 
     
    251379    TestPortListeners<int>(1); 
    252380    TestPortListeners<std::string>("test"); 
     381    TestNetworkConnectionLoss<int>(4, 7); 
     382    TestNetworkConnectionLoss<std::string>("default_value", "published_value"); 
     383    TestOutOfBoundsPublish(); 
     384    TestHijackedPublishing<int>(42); 
     385    TestHijackedPublishing<std::string>("test"); 
     386    TestGenericPorts<bool>(true, false); 
     387    TestGenericPorts<std::string>("123", "45"); 
    253388 
    254389    tThreadLocalBufferManagement local_buffers; 
     
    256391    TestPortQueues<int>(1, 2, 3); 
    257392    TestPortListeners<int>(1); 
     393    TestNetworkConnectionLoss<int>(4, 7); 
     394    TestOutOfBoundsPublish(); 
     395    TestHijackedPublishing<int>(42); 
     396    TestGenericPorts<bool>(true, false); 
     397  } 
     398 
     399  void PortPack() 
     400  { 
     401    auto parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestPortPack"); 
     402 
     403    using tTypeList = rrlib::util::tTypeList<int, double, std::string, bool>; 
     404    data_ports::tPortPack<tInputPort, tTypeList> ports(parent, "X"); 
     405 
     406    RRLIB_UNIT_TESTS_EQUALITY(tTypeList::cSIZE, ports.NumberOfPorts()); 
     407 
     408    for (size_t i = 0; i < tTypeList::cSIZE; ++i) 
     409    { 
     410      RRLIB_UNIT_TESTS_EQUALITY("X" + std::to_string(i + 1), ports.GetPort(i).GetName()); 
     411    } 
     412 
     413    std::array<std::string, tTypeList::cSIZE> names {"foo", "bar", "baz", "fnord"}; 
     414    data_ports::tPortPack<tInputPort, tTypeList> named_ports(parent, names.begin(), names.end()); 
     415 
     416    for (size_t i = 0; i < tTypeList::cSIZE; ++i) 
     417    { 
     418      RRLIB_UNIT_TESTS_EQUALITY(names[i], named_ports.GetPort(i).GetName()); 
     419    } 
    258420  } 
    259421}; 
Note: See TracChangeset for help on using the changeset viewer.