• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020, 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 <getopt.h>
18 #include <gtest/gtest.h>
19 #include <iostream>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <teeui/example/teeui.h>
23 #include <unistd.h>
24 
25 #include "teeui_device_config.h"
26 #include <teeui/test/teeui_render_test.h>
27 
28 #define TeeuiRenderTest_DO_LOG_DEBUG
29 
30 namespace teeui {
31 
32 namespace test {
33 
initRenderTest(int argc,char ** argv)34 void initRenderTest(int argc, char** argv) {
35     ::teeui::test::TeeuiRenderTest::Instance()->initFromOptions(argc, argv);
36 }
37 
runRenderTest(const char * language,bool magnified)38 int runRenderTest(const char* language, bool magnified) {
39     DeviceInfo* device_info_ptr = &TeeuiRenderTest::Instance()->device_info;
40     selectLanguage(language);
41     setDeviceInfo(*device_info_ptr, magnified);
42     uint32_t w = device_info_ptr->width_;
43     uint32_t h = device_info_ptr->height_;
44     uint32_t linestride = w;
45     uint32_t buffer_size = h * linestride;
46     std::vector<uint32_t> buffer(buffer_size);
47     int error = renderUIIntoBuffer(0, 0, w, h, linestride, buffer.data(), buffer_size);
48     return error;
49 }
50 
51 /*
52  * Configures device with test parameters
53  * widthPx, heightPx : pixel dimension of devices
54  * dp2px : density pixel to pixel
55  * mm2px : millimeter to pixel
56  * powerButtonTopMm : location of the top of the power button in mm
57  * powerButtonBottomMm : location of the bottom of the power button in mm
58  * volUpButtonTopMm : location of the top of the up volume button in mm
59  * volUpButtonBottomMm : location of the bottom of the up power button in mm
60  */
createDevice(int widthPx,int heightPx,double dp2px,double mm2px,double powerButtonTopMm,double powerButtonBottomMm,double volUpButtonTopMm,double volUpButtonBottomMm)61 void TeeuiRenderTest::createDevice(int widthPx, int heightPx, double dp2px, double mm2px,
62                                    double powerButtonTopMm, double powerButtonBottomMm,
63                                    double volUpButtonTopMm, double volUpButtonBottomMm) {
64     DeviceInfo* device_info_ptr = &TeeuiRenderTest::Instance()->device_info;
65     device_info_ptr->width_ = widthPx;
66     device_info_ptr->height_ = heightPx;
67     device_info_ptr->dp2px_ = dp2px;
68     device_info_ptr->mm2px_ = mm2px;
69     device_info_ptr->powerButtonTopMm_ = powerButtonTopMm;
70     device_info_ptr->powerButtonBottomMm_ = powerButtonBottomMm;
71     device_info_ptr->volUpButtonTopMm_ = volUpButtonTopMm;
72     device_info_ptr->volUpButtonBottomMm_ = volUpButtonBottomMm;
73 }
74 
initFromOptions(int argc,char ** argv)75 void TeeuiRenderTest::initFromOptions(int argc, char** argv) {
76 
77     uint width = 0, height = 0;
78     double dp2px = 0, mm2px = 0;
79     double powerBottonTopMm = 0, powerButtonBottomMm = 0;
80     double volUpButtonTopMm = 0, volUpButtonBottomMm = 0;
81 
82     int option_index = 0;
83     static struct option options[] = {{"width", required_argument, 0, 'w'},
84                                       {"height", required_argument, 0, 'l'},
85                                       {"dp2px", required_argument, 0, 'd'},
86                                       {"mm2px", required_argument, 0, 'm'},
87                                       {"powerButtonTop", required_argument, 0, 't'},
88                                       {"powerButtonBottom", required_argument, 0, 'b'},
89                                       {"volUpButtonTop", required_argument, 0, 'u'},
90                                       {"volUpButtonBottom", required_argument, 0, 'v'},
91                                       {"help", 0, 0, 'h'},
92                                       {"?", 0, 0, '?'},
93                                       {0, 0, 0, 0}};
94     while (true) {
95         int c = getopt_long(argc, argv, "w:l:d:m:t:b:u:v:h?", options, &option_index);
96         if (c == -1) break;
97         double numeric_value = 0;
98         switch (c) {
99         case 'w':
100             width = atoi(optarg);
101             break;
102         case 'l':
103             height = atoi(optarg);
104             break;
105         case 'd':
106             numeric_value = strtod(optarg, NULL);
107             dp2px = numeric_value;
108             break;
109         case 'm':
110             numeric_value = strtod(optarg, NULL);
111             mm2px = numeric_value;
112             break;
113         case 't':
114             numeric_value = strtod(optarg, NULL);
115             powerBottonTopMm = numeric_value;
116             break;
117         case 'b':
118             numeric_value = strtod(optarg, NULL);
119             powerButtonBottomMm = numeric_value;
120             break;
121         case 'u':
122             numeric_value = strtod(optarg, NULL);
123             volUpButtonTopMm = numeric_value;
124             break;
125         case 'v':
126             numeric_value = strtod(optarg, NULL);
127             volUpButtonBottomMm = numeric_value;
128             break;
129         case '?':
130         case 'h':
131             std::cout << "Options:" << std::endl;
132             std::cout << "--width=<device width in pixels>" << std::endl;
133             std::cout << "--height=<device height in pixels>" << std::endl;
134             std::cout << "--dp2px=<pixel per density independent pixel (px/dp) ratio of the "
135                          "device. Typically <width in pixels>/412 >"
136                       << std::endl;
137             std::cout << "--mm2px=<pixel per millimeter (px/mm) ratio>" << std::endl;
138             std::cout << "--powerButtonTop=<distance from the top of the power button to the top "
139                          "of the screen in mm>"
140                       << std::endl;
141             std::cout << "--powerButtonBottom=<distance from the bottom of the power button to the "
142                          "top of the screen in mm>"
143                       << std::endl;
144             std::cout << "--volUpButtonTop=<distance from the top of the UP volume button to the "
145                          "top of the screen in mm>"
146                       << std::endl;
147             std::cout << "--volUpButtonBottom=<distance from the bottom of the UP power button to "
148                          "the top of the screen in mm>"
149                       << std::endl;
150             exit(0);
151         }
152     }
153     createDevice(width, height, dp2px, mm2px, powerBottonTopMm, powerButtonBottomMm,
154                  volUpButtonTopMm, volUpButtonBottomMm);
155 }
156 
157 }  // namespace test
158 
159 }  // namespace teeui
160