• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "aemu/base/LayoutResolver.h"
16 
17 #include <gtest/gtest.h>
18 
19 #include "aemu/base/ArraySize.h"
20 
21 namespace android {
22 namespace base {
23 
24 typedef struct testDisplayInput {
25     uint32_t id;
26     uint32_t width;
27     uint32_t height;
28 } testDisplayInput;
29 
30 typedef struct testDisplayOutput {
31     uint32_t id;
32     uint32_t x;
33     uint32_t y;
34 } testDisplayOutput;
35 
TEST(LayoutResolver,twoIdenticalDisplays)36 TEST(LayoutResolver, twoIdenticalDisplays) {
37     const std::pair<testDisplayInput, testDisplayOutput> kData[] = {
38             std::make_pair(testDisplayInput{0, 1080, 1960},
39                            testDisplayOutput{0, 0, 0}),
40             std::make_pair(testDisplayInput{1, 1080, 1960},
41                            testDisplayOutput{1, 1080, 0})};
42     const size_t kDataSize = ARRAY_SIZE(kData);
43     const double kMonitorAspectRatio = 16.0 / 9.0;
44     std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> displays;
45     for (size_t i = 0; i < kDataSize; i++) {
46         const auto& input = kData[i].first;
47         displays[input.id] = std::make_pair(input.width, input.height);
48     }
49 
50     const auto layout = resolveLayout(displays, kMonitorAspectRatio);
51     for (size_t i = 0; i < kDataSize; i++) {
52         const auto& expectedOutput = kData[i].second;
53         const auto& actualOutput = layout.find(expectedOutput.id);
54         EXPECT_NE(actualOutput, layout.end());
55         EXPECT_EQ(actualOutput->second.first, expectedOutput.x);
56         EXPECT_EQ(actualOutput->second.second, expectedOutput.y);
57     }
58 }
59 
TEST(LayoutResolver,FourDifferentDisplays)60 TEST(LayoutResolver, FourDifferentDisplays) {
61     const std::pair<testDisplayInput, testDisplayOutput> kData[] = {
62             std::make_pair(testDisplayInput{0, 1080, 1960},
63                            testDisplayOutput{0, 0, 1860}),
64             std::make_pair(testDisplayInput{1, 1080, 1860},
65                            testDisplayOutput{1, 0, 0}),
66             std::make_pair(testDisplayInput{2, 1200, 1300},
67                            testDisplayOutput{2, 1080, 1860}),
68             std::make_pair(testDisplayInput{3, 1200, 1400},
69                            testDisplayOutput{3, 1080, 0})};
70     const size_t kDataSize = ARRAY_SIZE(kData);
71     const double kMonitorAspectRatio = 16.0 / 9.0;
72     std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> displays;
73     for (size_t i = 0; i < kDataSize; i++) {
74         const auto& input = kData[i].first;
75         displays[input.id] = std::make_pair(input.width, input.height);
76     }
77 
78     const auto layout = resolveLayout(displays, kMonitorAspectRatio);
79     for (size_t i = 0; i < kDataSize; i++) {
80         const auto& expectedOutput = kData[i].second;
81         const auto& actualOutput = layout.find(expectedOutput.id);
82         EXPECT_NE(actualOutput, layout.end());
83         EXPECT_EQ(actualOutput->second.first, expectedOutput.x);
84         EXPECT_EQ(actualOutput->second.second, expectedOutput.y);
85     }
86 }
87 
88 }  // namespace base
89 }  // namespace android
90