Changeset 156:9e42f886e71e in finroc_plugins_data_ports


Ignore:
Timestamp:
28.03.2020 13:48:40 (11 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Parents:
152:fc98e54c5973 (diff), 155:784bc286a24d (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

    r144 r156  
    400400} 
    401401 
     402template <typename T> 
     403void SetBoundsGeneric(T min, T max, tOutOfBoundsAction action) 
     404{ 
     405  common::tAbstractDataPortCreationInfo creation_info; 
     406  creation_info.name = "Bounds Test"; 
     407  creation_info.flags = cDEFAULT_INPUT_PORT_FLAGS; 
     408  creation_info.parent = &core::tRuntimeEnvironment::GetInstance(); 
     409  creation_info.data_type = rrlib::rtti::tDataType<T>(); 
     410 
     411  if (!std::is_arithmetic<T>::value) 
     412  { 
     413    common::tAbstractDataPortCreationInfo::RegisterBoundedPortCreateFunction<T>(); 
     414  } 
     415 
     416  rrlib::rtti::tGenericObjectWrapper<T> min_object(min); 
     417  rrlib::rtti::tGenericObjectWrapper<T> max_object(max); 
     418  creation_info.SetBoundsGeneric(min_object, max_object, action); 
     419 
     420  tGenericPort port(creation_info); 
     421  RRLIB_UNIT_TESTS_ASSERT(typeid(*port.GetWrapped()) == typeid(api::tBoundedPort<T>)); 
     422  api::tBoundedPort<T>& bounded_port = static_cast<api::tBoundedPort<T>&>(*port.GetWrapped()); 
     423  auto bounds = bounded_port.GetBounds(); 
     424  RRLIB_UNIT_TESTS_ASSERT(bounds.GetMin() == min); 
     425  RRLIB_UNIT_TESTS_ASSERT(bounds.GetMax() == max); 
     426  RRLIB_UNIT_TESTS_ASSERT(bounds.GetOutOfBoundsAction() == action); 
     427  port.ManagedDelete(); 
     428} 
     429 
    402430class DataPortsTestCollection : public rrlib::util::tUnitTestSuite 
    403431{ 
     
    431459    TestHijackedPublishing<int>(42); 
    432460    TestGenericPorts<bool>(true, false); 
     461 
     462    SetBoundsGeneric<uint8_t>(4, 9, tOutOfBoundsAction::ADJUST_TO_RANGE); 
     463    SetBoundsGeneric<int16_t>(-12, 900, tOutOfBoundsAction::APPLY_DEFAULT); 
     464    SetBoundsGeneric<int32_t>(-121, 5235623, tOutOfBoundsAction::DISCARD); 
     465    SetBoundsGeneric<int64_t>(-552121, 523511352456623, tOutOfBoundsAction::ADJUST_TO_RANGE); 
     466    SetBoundsGeneric<double>(-552121., 523511352456623, tOutOfBoundsAction::ADJUST_TO_RANGE); 
     467    SetBoundsGeneric<numeric::tNumber>(-552121., 523511352456623, tOutOfBoundsAction::ADJUST_TO_RANGE); 
     468    SetBoundsGeneric<std::pair<int, uint8_t>>(std::pair<int, uint8_t>(-44315, 90), std::pair<int, uint8_t>(-2, 177), tOutOfBoundsAction::APPLY_DEFAULT); 
     469    SetBoundsGeneric<std::array<short, 3>>({ -2, 5, 2}, { 5, -11233, 77 }, tOutOfBoundsAction::APPLY_DEFAULT); 
     470    SetBoundsGeneric<std::tuple<double, short, float>>(std::tuple<double, short, float>(-0.5, 1133, 0.11), std::tuple<double, short, float>(55, -1133, 6436.2), tOutOfBoundsAction::APPLY_DEFAULT); 
    433471  } 
    434472 
Note: See TracChangeset for help on using the changeset viewer.