Changeset 113:938e71ac0af4 in finroc_plugins_data_ports


Ignore:
Timestamp:
17.05.2017 20:29:14 (7 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Parents:
111:9fa05a16eed9 (diff), 112:4756cdcbb205 (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
  • tests/test_collection.cpp

    r103 r113  
    4444#include "plugins/data_ports/tProxyPort.h" 
    4545#include "plugins/data_ports/tThreadLocalBufferManagement.h" 
     46#include "plugins/data_ports/tPortPack.h" 
    4647 
    4748//---------------------------------------------------------------------- 
     
    368369  RRLIB_UNIT_TESTS_BEGIN_SUITE(DataPortsTestCollection); 
    369370  RRLIB_UNIT_TESTS_ADD_TEST(Test); 
     371  RRLIB_UNIT_TESTS_ADD_TEST(PortPack); 
    370372  RRLIB_UNIT_TESTS_END_SUITE; 
    371373 
     
    394396    TestGenericPorts<bool>(true, false); 
    395397  } 
     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    } 
     420  } 
    396421}; 
    397422 
  • tests/test_collection.cpp

    r112 r113  
    239239} 
    240240 
     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 
    241367class DataPortsTestCollection : public rrlib::util::tUnitTestSuite 
    242368{ 
     
    253379    TestPortListeners<int>(1); 
    254380    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"); 
    255388 
    256389    tThreadLocalBufferManagement local_buffers; 
     
    258391    TestPortQueues<int>(1, 2, 3); 
    259392    TestPortListeners<int>(1); 
     393    TestNetworkConnectionLoss<int>(4, 7); 
     394    TestOutOfBoundsPublish(); 
     395    TestHijackedPublishing<int>(42); 
     396    TestGenericPorts<bool>(true, false); 
    260397  } 
    261398 
Note: See TracChangeset for help on using the changeset viewer.