mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-16 03:45:24 +00:00
tests: Add tests for m_relation_history_get
This commit is contained in:
parent
8c04bf1274
commit
4bd0d12462
|
@ -28,3 +28,10 @@ add_executable(tests_json tests_json.cpp)
|
|||
target_link_libraries(tests_json PRIVATE tests_main)
|
||||
target_link_libraries(tests_json PRIVATE aux_util)
|
||||
add_test(NAME tests_json COMMAND tests_json --success)
|
||||
|
||||
|
||||
# history
|
||||
add_executable(tests_history_buf tests_history_buf.cpp)
|
||||
target_link_libraries(tests_history_buf PRIVATE tests_main)
|
||||
target_link_libraries(tests_history_buf PRIVATE aux_util aux_math)
|
||||
add_test(NAME tests_history_buf COMMAND tests_history_buf --success)
|
||||
|
|
83
tests/tests_history_buf.cpp
Normal file
83
tests/tests_history_buf.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
// Copyright 2021, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief HistoryBuffer collection tests.
|
||||
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <math/m_relation_history.h>
|
||||
|
||||
#include "catch/catch.hpp"
|
||||
|
||||
|
||||
|
||||
TEST_CASE("m_relation_history")
|
||||
{
|
||||
m_relation_history *rh = nullptr;
|
||||
|
||||
m_relation_history_create(&rh);
|
||||
SECTION("empty buffer")
|
||||
{
|
||||
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
||||
CHECK(m_relation_history_get(rh, 0, &out_relation) == M_RELATION_HISTORY_RESULT_INVALID);
|
||||
CHECK(m_relation_history_get(rh, 1, &out_relation) == M_RELATION_HISTORY_RESULT_INVALID);
|
||||
}
|
||||
SECTION("populated buffer")
|
||||
{
|
||||
xrt_space_relation relation = XRT_SPACE_RELATION_ZERO;
|
||||
relation.relation_flags = (xrt_space_relation_flags)(
|
||||
XRT_SPACE_RELATION_POSITION_TRACKED_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT |
|
||||
XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | XRT_SPACE_RELATION_ORIENTATION_VALID_BIT |
|
||||
XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT);
|
||||
relation.linear_velocity.x = 1.f;
|
||||
|
||||
// arbitrary value
|
||||
constexpr auto T0 = 20 * (uint64_t)U_TIME_1S_IN_NS;
|
||||
// one second after T0
|
||||
constexpr auto T1 = T0 + (uint64_t)U_TIME_1S_IN_NS;
|
||||
// two seconds after T0
|
||||
constexpr auto T2 = T1 + (uint64_t)U_TIME_1S_IN_NS;
|
||||
|
||||
m_relation_history_push(rh, &relation, T0);
|
||||
relation.pose.position.x = 1.f;
|
||||
m_relation_history_push(rh, &relation, T1);
|
||||
relation.pose.position.x = 2.f;
|
||||
m_relation_history_push(rh, &relation, T2);
|
||||
|
||||
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
||||
CHECK(m_relation_history_get(rh, 0, &out_relation) == M_RELATION_HISTORY_RESULT_INVALID);
|
||||
|
||||
CHECK(m_relation_history_get(rh, T0, &out_relation) == M_RELATION_HISTORY_RESULT_EXACT);
|
||||
CHECK(out_relation.pose.position.x == 0.f);
|
||||
|
||||
CHECK(m_relation_history_get(rh, T1, &out_relation) == M_RELATION_HISTORY_RESULT_EXACT);
|
||||
CHECK(out_relation.pose.position.x == 1.f);
|
||||
|
||||
CHECK(m_relation_history_get(rh, T2, &out_relation) == M_RELATION_HISTORY_RESULT_EXACT);
|
||||
CHECK(out_relation.pose.position.x == 2.f);
|
||||
|
||||
|
||||
CHECK(m_relation_history_get(rh, T0 - (uint64_t)U_TIME_1S_IN_NS, &out_relation) ==
|
||||
M_RELATION_HISTORY_RESULT_REVERSE_PREDICTED);
|
||||
CHECK(out_relation.pose.position.x < 0.f);
|
||||
|
||||
CHECK(m_relation_history_get(rh, (T0 + T1) / 2, &out_relation) ==
|
||||
M_RELATION_HISTORY_RESULT_INTERPOLATED);
|
||||
CHECK(out_relation.pose.position.x > 0.f);
|
||||
CHECK(out_relation.pose.position.x < 1.f);
|
||||
|
||||
CHECK(m_relation_history_get(rh, (T1 + T2) / 2, &out_relation) ==
|
||||
M_RELATION_HISTORY_RESULT_INTERPOLATED);
|
||||
CHECK(out_relation.pose.position.x > 1.f);
|
||||
CHECK(out_relation.pose.position.x < 2.f);
|
||||
|
||||
CHECK(m_relation_history_get(rh, T2 + (uint64_t)U_TIME_1S_IN_NS, &out_relation) ==
|
||||
M_RELATION_HISTORY_RESULT_PREDICTED);
|
||||
CHECK(out_relation.pose.position.x > 2.f);
|
||||
}
|
||||
|
||||
|
||||
m_relation_history_destroy(&rh);
|
||||
}
|
Loading…
Reference in a new issue