Changeset 180:7d8de25a4af2 in finroc_plugins_data_ports


Ignore:
Timestamp:
13.05.2021 20:42:07 (5 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Parents:
172:92474d0c642c (diff), 179:34ddda735cf1 (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
Tags:
tip
Message:

Merge with 17.03

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/test_collection.cpp

    r156 r180  
    4545#include "plugins/data_ports/tThreadLocalBufferManagement.h" 
    4646#include "plugins/data_ports/tPortPack.h" 
     47#include "plugins/data_ports/tMetadata.h" 
    4748 
    4849#include "plugins/structure/tModule.h" 
     
    428429} 
    429430 
     431template <typename T> 
     432void TestMetadata(const T& value_to_publish_1, const T& value_to_publish_2) 
     433{ 
     434  core::tFrameworkElement* parent = new core::tFrameworkElement(&core::tRuntimeEnvironment::GetInstance(), "TestMetadata"); 
     435 
     436  tOutputPort<T> output_port("Output Port", parent); 
     437  tInputPort<T> input_port("Input Port", parent); 
     438  tInputPort<std::pair<T, tMetadata>> input_port_with_meta_data("Input Port With Meta Data", parent); 
     439  tInputPort<tMetadata> input_port_meta_data("Input Port Meta Data", parent); 
     440  tInputPort<numeric::tNumber> input_port_meta_data_number("Input Port Meta Data Number", parent); 
     441  output_port.ConnectTo(input_port); 
     442  output_port.ConnectTo(input_port_with_meta_data, cAPPEND_META_DATA_OPERATION); 
     443  output_port.ConnectTo(input_port_meta_data, cCAPTURE_META_DATA_OPERATION); 
     444  output_port.ConnectTo(input_port_meta_data_number, cCAPTURE_META_DATA_OPERATION); 
     445  parent->Init(); 
     446 
     447  numeric::tNumber number1(42), number2(-0.445); 
     448  rrlib::time::tTimestamp now = rrlib::time::Now(); 
     449  data_ports::tEvent event; 
     450  { 
     451    rrlib::time::tDuration duration = std::chrono::milliseconds(12378); 
     452    float f = -3.551; 
     453 
     454    tScopedMetadata scoped_meta_data(duration, f); 
     455    output_port.Publish(value_to_publish_1, tMetadata::Tie(number1, event, number2)); 
     456 
     457    RRLIB_UNIT_TESTS_EQUALITY(value_to_publish_1, *input_port.GetPointer()); 
     458    RRLIB_UNIT_TESTS_EQUALITY(value_to_publish_1, input_port_with_meta_data.GetPointer()->first); 
     459    RRLIB_UNIT_TESTS_ASSERT(tMetadata::Tie(duration, f, number1, event, number2) == input_port_with_meta_data.GetPointer()->second); 
     460    RRLIB_UNIT_TESTS_ASSERT(tMetadata::Tie(duration, f, number1, event, number2) == *input_port_meta_data.GetPointer()); 
     461    RRLIB_UNIT_TESTS_ASSERT(duration == *input_port_meta_data.GetPointer()->Get<rrlib::time::tDuration>()); 
     462    RRLIB_UNIT_TESTS_EQUALITY(number1, input_port_meta_data_number.Get()); 
     463 
     464    output_port.Publish(value_to_publish_2); 
     465 
     466    RRLIB_UNIT_TESTS_EQUALITY(value_to_publish_2, *input_port.GetPointer()); 
     467    RRLIB_UNIT_TESTS_EQUALITY(value_to_publish_2, input_port_with_meta_data.GetPointer()->first); 
     468    RRLIB_UNIT_TESTS_ASSERT(tMetadata::Tie(duration, f) == input_port_with_meta_data.GetPointer()->second); 
     469    RRLIB_UNIT_TESTS_ASSERT(tMetadata::Tie(duration, f) == *input_port_meta_data.GetPointer()); 
     470    RRLIB_UNIT_TESTS_ASSERT(duration == *input_port_meta_data.GetPointer()->Get<rrlib::time::tDuration>()); 
     471  } 
     472 
     473  output_port.Publish(value_to_publish_1, now, tMetadata::Tie(number2, event, number1)); 
     474 
     475  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish_1, *input_port.GetPointer()); 
     476  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish_1, input_port_with_meta_data.GetPointer()->first); 
     477  RRLIB_UNIT_TESTS_ASSERT(tMetadata::Tie(number2, event, number1) == input_port_with_meta_data.GetPointer()->second); 
     478  RRLIB_UNIT_TESTS_ASSERT(tMetadata::Tie(number2, event, number1) == *input_port_meta_data.GetPointer()); 
     479  RRLIB_UNIT_TESTS_ASSERT(input_port_meta_data.GetPointer()->Get<rrlib::time::tDuration>() == nullptr); 
     480  RRLIB_UNIT_TESTS_EQUALITY(number2, *input_port_meta_data.GetPointer()->Get<numeric::tNumber>()); 
     481  RRLIB_UNIT_TESTS_EQUALITY(number2, input_port_meta_data_number.Get()); 
     482 
     483  output_port.Publish(value_to_publish_2, now); 
     484  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish_2, *input_port.GetPointer()); 
     485  RRLIB_UNIT_TESTS_EQUALITY(value_to_publish_2, input_port_with_meta_data.GetPointer()->first); 
     486  RRLIB_UNIT_TESTS_EQUALITY(true, input_port_with_meta_data.GetPointer()->second.Empty()); 
     487  RRLIB_UNIT_TESTS_ASSERT(tMetadata::Tie() == *input_port_meta_data.GetPointer()); 
     488  RRLIB_UNIT_TESTS_ASSERT(input_port_meta_data.GetPointer()->Get<numeric::tNumber>() == nullptr); 
     489 
     490  parent->ManagedDelete(); 
     491} 
     492 
    430493class DataPortsTestCollection : public rrlib::util::tUnitTestSuite 
    431494{ 
     
    434497  RRLIB_UNIT_TESTS_ADD_TEST(PortPack); 
    435498  RRLIB_UNIT_TESTS_ADD_TEST(PortPackLegacy); 
     499  RRLIB_UNIT_TESTS_ADD_TEST(TestMetadata); 
    436500  RRLIB_UNIT_TESTS_END_SUITE; 
    437501 
     
    504568    } 
    505569  } 
     570 
     571  void TestMetadata() 
     572  { 
     573    data_ports::TestMetadata<double>(7, -3.5); 
     574    data_ports::TestMetadata<std::string>("testing", "meta data"); 
     575  } 
    506576}; 
    507577 
Note: See TracChangeset for help on using the changeset viewer.