|
| 1 | +/* |
| 2 | + * Copyright 2025 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 | +#include <input/DisplayTopologyGraph.h> |
| 19 | + |
| 20 | +#include <string> |
| 21 | +#include <string_view> |
| 22 | +#include <tuple> |
| 23 | + |
| 24 | +namespace android { |
| 25 | + |
| 26 | +namespace { |
| 27 | + |
| 28 | +constexpr ui::LogicalDisplayId DISPLAY_ID_1{1}; |
| 29 | +constexpr ui::LogicalDisplayId DISPLAY_ID_2{2}; |
| 30 | +constexpr int DENSITY_MEDIUM = 160; |
| 31 | + |
| 32 | +} // namespace |
| 33 | + |
| 34 | +using DisplayTopologyGraphTestFixtureParam = |
| 35 | + std::tuple<std::string_view /*name*/, DisplayTopologyGraph, bool /*isValid*/>; |
| 36 | + |
| 37 | +class DisplayTopologyGraphTestFixture |
| 38 | + : public testing::Test, |
| 39 | + public testing::WithParamInterface<DisplayTopologyGraphTestFixtureParam> {}; |
| 40 | + |
| 41 | +TEST_P(DisplayTopologyGraphTestFixture, DisplayTopologyGraphTest) { |
| 42 | + const auto& [_, displayTopology, isValid] = GetParam(); |
| 43 | + EXPECT_EQ(isValid, displayTopology.isValid()); |
| 44 | +} |
| 45 | + |
| 46 | +INSTANTIATE_TEST_SUITE_P( |
| 47 | + DisplayTopologyGraphTest, DisplayTopologyGraphTestFixture, |
| 48 | + testing::Values( |
| 49 | + std::make_tuple( |
| 50 | + "InvalidPrimaryDisplay", |
| 51 | + DisplayTopologyGraph{.primaryDisplayId = ui::LogicalDisplayId::INVALID, |
| 52 | + .graph = {}, |
| 53 | + .displaysDensity = {}}, |
| 54 | + false), |
| 55 | + std::make_tuple("PrimaryDisplayNotInGraph", |
| 56 | + DisplayTopologyGraph{.primaryDisplayId = DISPLAY_ID_1, |
| 57 | + .graph = {}, |
| 58 | + .displaysDensity = {}}, |
| 59 | + false), |
| 60 | + std::make_tuple("DisplayDensityMissing", |
| 61 | + DisplayTopologyGraph{.primaryDisplayId = DISPLAY_ID_1, |
| 62 | + .graph = {{DISPLAY_ID_1, {}}}, |
| 63 | + .displaysDensity = {}}, |
| 64 | + false), |
| 65 | + std::make_tuple("ValidSingleDisplayTopology", |
| 66 | + DisplayTopologyGraph{.primaryDisplayId = DISPLAY_ID_1, |
| 67 | + .graph = {{DISPLAY_ID_1, {}}}, |
| 68 | + .displaysDensity = {{DISPLAY_ID_1, |
| 69 | + DENSITY_MEDIUM}}}, |
| 70 | + true), |
| 71 | + std::make_tuple( |
| 72 | + "MissingReverseEdge", |
| 73 | + DisplayTopologyGraph{.primaryDisplayId = DISPLAY_ID_1, |
| 74 | + .graph = {{DISPLAY_ID_1, |
| 75 | + {{DISPLAY_ID_2, |
| 76 | + DisplayTopologyPosition::TOP, 0}}}}, |
| 77 | + .displaysDensity = {{DISPLAY_ID_1, DENSITY_MEDIUM}, |
| 78 | + {DISPLAY_ID_2, DENSITY_MEDIUM}}}, |
| 79 | + false), |
| 80 | + std::make_tuple( |
| 81 | + "IncorrectReverseEdgeDirection", |
| 82 | + DisplayTopologyGraph{.primaryDisplayId = DISPLAY_ID_1, |
| 83 | + .graph = {{DISPLAY_ID_1, |
| 84 | + {{DISPLAY_ID_2, |
| 85 | + DisplayTopologyPosition::TOP, 0}}}, |
| 86 | + {DISPLAY_ID_2, |
| 87 | + {{DISPLAY_ID_1, |
| 88 | + DisplayTopologyPosition::TOP, 0}}}}, |
| 89 | + .displaysDensity = {{DISPLAY_ID_1, DENSITY_MEDIUM}, |
| 90 | + {DISPLAY_ID_2, DENSITY_MEDIUM}}}, |
| 91 | + false), |
| 92 | + std::make_tuple( |
| 93 | + "IncorrectReverseEdgeOffset", |
| 94 | + DisplayTopologyGraph{.primaryDisplayId = DISPLAY_ID_1, |
| 95 | + .graph = {{DISPLAY_ID_1, |
| 96 | + {{DISPLAY_ID_2, |
| 97 | + DisplayTopologyPosition::TOP, 10}}}, |
| 98 | + {DISPLAY_ID_2, |
| 99 | + {{DISPLAY_ID_1, |
| 100 | + DisplayTopologyPosition::BOTTOM, 20}}}}, |
| 101 | + .displaysDensity = {{DISPLAY_ID_1, DENSITY_MEDIUM}, |
| 102 | + {DISPLAY_ID_2, DENSITY_MEDIUM}}}, |
| 103 | + false), |
| 104 | + std::make_tuple( |
| 105 | + "ValidMultiDisplayTopology", |
| 106 | + DisplayTopologyGraph{.primaryDisplayId = DISPLAY_ID_1, |
| 107 | + .graph = {{DISPLAY_ID_1, |
| 108 | + {{DISPLAY_ID_2, |
| 109 | + DisplayTopologyPosition::TOP, 10}}}, |
| 110 | + {DISPLAY_ID_2, |
| 111 | + {{DISPLAY_ID_1, |
| 112 | + DisplayTopologyPosition::BOTTOM, -10}}}}, |
| 113 | + .displaysDensity = {{DISPLAY_ID_1, DENSITY_MEDIUM}, |
| 114 | + {DISPLAY_ID_2, DENSITY_MEDIUM}}}, |
| 115 | + true)), |
| 116 | + [](const testing::TestParamInfo<DisplayTopologyGraphTestFixtureParam>& p) { |
| 117 | + return std::string{std::get<0>(p.param)}; |
| 118 | + }); |
| 119 | + |
| 120 | +} // namespace android |
0 commit comments