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