The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tests: Add tests for m_relation_history_get

authored by

Ryan Pavlik and committed by
Jakob Bornecrantz
4bd0d124 8c04bf12

+90
+7
tests/CMakeLists.txt
··· 28 28 target_link_libraries(tests_json PRIVATE tests_main) 29 29 target_link_libraries(tests_json PRIVATE aux_util) 30 30 add_test(NAME tests_json COMMAND tests_json --success) 31 + 32 + 33 + # history 34 + add_executable(tests_history_buf tests_history_buf.cpp) 35 + target_link_libraries(tests_history_buf PRIVATE tests_main) 36 + target_link_libraries(tests_history_buf PRIVATE aux_util aux_math) 37 + add_test(NAME tests_history_buf COMMAND tests_history_buf --success)
+83
tests/tests_history_buf.cpp
··· 1 + // Copyright 2021, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief HistoryBuffer collection tests. 6 + * @author Ryan Pavlik <ryan.pavlik@collabora.com> 7 + */ 8 + 9 + #include <iostream> 10 + #include <math/m_relation_history.h> 11 + 12 + #include "catch/catch.hpp" 13 + 14 + 15 + 16 + TEST_CASE("m_relation_history") 17 + { 18 + m_relation_history *rh = nullptr; 19 + 20 + m_relation_history_create(&rh); 21 + SECTION("empty buffer") 22 + { 23 + xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO; 24 + CHECK(m_relation_history_get(rh, 0, &out_relation) == M_RELATION_HISTORY_RESULT_INVALID); 25 + CHECK(m_relation_history_get(rh, 1, &out_relation) == M_RELATION_HISTORY_RESULT_INVALID); 26 + } 27 + SECTION("populated buffer") 28 + { 29 + xrt_space_relation relation = XRT_SPACE_RELATION_ZERO; 30 + relation.relation_flags = (xrt_space_relation_flags)( 31 + XRT_SPACE_RELATION_POSITION_TRACKED_BIT | XRT_SPACE_RELATION_POSITION_VALID_BIT | 32 + XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | 33 + XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT); 34 + relation.linear_velocity.x = 1.f; 35 + 36 + // arbitrary value 37 + constexpr auto T0 = 20 * (uint64_t)U_TIME_1S_IN_NS; 38 + // one second after T0 39 + constexpr auto T1 = T0 + (uint64_t)U_TIME_1S_IN_NS; 40 + // two seconds after T0 41 + constexpr auto T2 = T1 + (uint64_t)U_TIME_1S_IN_NS; 42 + 43 + m_relation_history_push(rh, &relation, T0); 44 + relation.pose.position.x = 1.f; 45 + m_relation_history_push(rh, &relation, T1); 46 + relation.pose.position.x = 2.f; 47 + m_relation_history_push(rh, &relation, T2); 48 + 49 + xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO; 50 + CHECK(m_relation_history_get(rh, 0, &out_relation) == M_RELATION_HISTORY_RESULT_INVALID); 51 + 52 + CHECK(m_relation_history_get(rh, T0, &out_relation) == M_RELATION_HISTORY_RESULT_EXACT); 53 + CHECK(out_relation.pose.position.x == 0.f); 54 + 55 + CHECK(m_relation_history_get(rh, T1, &out_relation) == M_RELATION_HISTORY_RESULT_EXACT); 56 + CHECK(out_relation.pose.position.x == 1.f); 57 + 58 + CHECK(m_relation_history_get(rh, T2, &out_relation) == M_RELATION_HISTORY_RESULT_EXACT); 59 + CHECK(out_relation.pose.position.x == 2.f); 60 + 61 + 62 + CHECK(m_relation_history_get(rh, T0 - (uint64_t)U_TIME_1S_IN_NS, &out_relation) == 63 + M_RELATION_HISTORY_RESULT_REVERSE_PREDICTED); 64 + CHECK(out_relation.pose.position.x < 0.f); 65 + 66 + CHECK(m_relation_history_get(rh, (T0 + T1) / 2, &out_relation) == 67 + M_RELATION_HISTORY_RESULT_INTERPOLATED); 68 + CHECK(out_relation.pose.position.x > 0.f); 69 + CHECK(out_relation.pose.position.x < 1.f); 70 + 71 + CHECK(m_relation_history_get(rh, (T1 + T2) / 2, &out_relation) == 72 + M_RELATION_HISTORY_RESULT_INTERPOLATED); 73 + CHECK(out_relation.pose.position.x > 1.f); 74 + CHECK(out_relation.pose.position.x < 2.f); 75 + 76 + CHECK(m_relation_history_get(rh, T2 + (uint64_t)U_TIME_1S_IN_NS, &out_relation) == 77 + M_RELATION_HISTORY_RESULT_PREDICTED); 78 + CHECK(out_relation.pose.position.x > 2.f); 79 + } 80 + 81 + 82 + m_relation_history_destroy(&rh); 83 + }