blob: ecf27f5fb3dbf5b7a9464716f30e1ee4887312d0 [file] [log] [blame]
Ytai Ben-Tsvicbee7d42021-06-15 00:39:31 -07001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include "ScreenHeadFusion.h"
20#include "TestUtil.h"
21
22using Eigen::Quaternionf;
23using Eigen::Vector3f;
24
25namespace android {
26namespace media {
27namespace {
28
29TEST(ScreenHeadFusion, Init) {
30 ScreenHeadFusion fusion;
31 EXPECT_FALSE(fusion.calculate().has_value());
32}
33
34TEST(ScreenHeadFusion, Calculate_NoHead) {
35 ScreenHeadFusion fusion;
36 fusion.setWorldToScreenPose(0, Pose3f());
37 EXPECT_FALSE(fusion.calculate().has_value());
38}
39
40TEST(ScreenHeadFusion, Calculate_NoScreen) {
41 ScreenHeadFusion fusion;
42 fusion.setWorldToHeadPose(0, Pose3f());
43 EXPECT_FALSE(fusion.calculate().has_value());
44}
45
46TEST(ScreenHeadFusion, Calculate) {
47 Pose3f worldToScreen1({1, 2, 3}, Quaternionf::UnitRandom());
48 Pose3f worldToHead1({4, 5, 6}, Quaternionf::UnitRandom());
49 Pose3f worldToScreen2({11, 12, 13}, Quaternionf::UnitRandom());
50 Pose3f worldToHead2({14, 15, 16}, Quaternionf::UnitRandom());
51
52 ScreenHeadFusion fusion;
53 fusion.setWorldToHeadPose(123, worldToHead1);
54 fusion.setWorldToScreenPose(456, worldToScreen1);
55 auto result = fusion.calculate();
56 ASSERT_TRUE(result.has_value());
57 EXPECT_EQ(123, result->timestamp);
58 EXPECT_EQ(worldToScreen1.inverse() * worldToHead1, result->pose);
59
60 fusion.setWorldToHeadPose(567, worldToHead2);
61 result = fusion.calculate();
62 ASSERT_TRUE(result.has_value());
63 EXPECT_EQ(456, result->timestamp);
64 EXPECT_EQ(worldToScreen1.inverse() * worldToHead2, result->pose);
65
66 fusion.setWorldToScreenPose(678, worldToScreen2);
67 result = fusion.calculate();
68 ASSERT_TRUE(result.has_value());
69 EXPECT_EQ(567, result->timestamp);
70 EXPECT_EQ(worldToScreen2.inverse() * worldToHead2, result->pose);
71}
72
73} // namespace
74} // namespace media
75} // namespace android