• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015-2022 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 "host/commands/cvd/parser/launch_cvd_parser.h"
19 #include "host/commands/cvd/unittests/parser/test_common.h"
20 
21 namespace cuttlefish {
22 
TEST(BootFlagsParserTest,ParseTwoInstancesDisplaysFlagEmptyJson)23 TEST(BootFlagsParserTest, ParseTwoInstancesDisplaysFlagEmptyJson) {
24   const char* test_string = R""""(
25 {
26     "instances" :
27     [
28         {
29         },
30         {
31         }
32     ]
33 }
34 )"""";
35 
36   const char* expected_string =
37       R""""(--displays_binproto=Cg0KCwjQBRCAChjAAiA8Cg0KCwjQBRCAChjAAiA8)"""";
38 
39   Json::Value json_configs;
40   std::string json_text(test_string);
41 
42   EXPECT_TRUE(ParseJsonString(json_text, json_configs))
43       << "Invalid Json string";
44   auto serialized_data = LaunchCvdParserTester(json_configs);
45   EXPECT_TRUE(serialized_data.ok()) << serialized_data.error().Trace();
46   EXPECT_TRUE(FindConfig(*serialized_data, expected_string))
47       << "extra_bootconfig_args flag is missing or wrongly formatted";
48 }
49 
TEST(BootFlagsParserTest,ParseTwoInstancesDisplaysFlagEmptyGraphics)50 TEST(BootFlagsParserTest, ParseTwoInstancesDisplaysFlagEmptyGraphics) {
51   const char* test_string = R""""(
52 {
53     "instances" :
54     [
55         {
56             "graphics": {
57             }
58         },
59         {
60             "graphics": {
61             }
62         }
63     ]
64 }
65   )"""";
66 
67   const char* expected_string =
68       R""""(--displays_binproto=Cg0KCwjQBRCAChjAAiA8Cg0KCwjQBRCAChjAAiA8)"""";
69 
70   Json::Value json_configs;
71   std::string json_text(test_string);
72 
73   EXPECT_TRUE(ParseJsonString(json_text, json_configs))
74       << "Invalid Json string";
75   auto serialized_data = LaunchCvdParserTester(json_configs);
76   EXPECT_TRUE(serialized_data.ok()) << serialized_data.error().Trace();
77   EXPECT_TRUE(FindConfig(*serialized_data, expected_string))
78       << "extra_bootconfig_args flag is missing or wrongly formatted";
79 }
80 
TEST(BootFlagsParserTest,ParseTwoInstancesDisplaysFlagEmptyDisplays)81 TEST(BootFlagsParserTest, ParseTwoInstancesDisplaysFlagEmptyDisplays) {
82   const char* test_string = R""""(
83 {
84     "instances" :
85     [
86         {
87             "graphics":{
88                 "displays":[
89                     {
90                     }
91                 ]
92                 }
93         },
94         {
95             "graphics":{
96                 "displays":[
97                     {
98                     },
99                     {
100                     }
101                 ]
102                 }
103         }
104     ]
105 }
106 )"""";
107 
108   const char* expected_string =
109       R""""(--displays_binproto=Cg0KCwjQBRCAChjAAiA8ChoKCwjQBRCAChjAAiA8CgsI0AUQgAoYwAIgPA==)"""";
110 
111   Json::Value json_configs;
112   std::string json_text(test_string);
113 
114   EXPECT_TRUE(ParseJsonString(json_text, json_configs))
115       << "Invalid Json string";
116   auto serialized_data = LaunchCvdParserTester(json_configs);
117   EXPECT_TRUE(serialized_data.ok()) << serialized_data.error().Trace();
118   EXPECT_TRUE(FindConfig(*serialized_data, expected_string))
119       << "extra_bootconfig_args flag is missing or wrongly formatted";
120 }
121 
TEST(BootFlagsParserTest,ParseTwoInstancesAutoTabletDisplaysFlag)122 TEST(BootFlagsParserTest, ParseTwoInstancesAutoTabletDisplaysFlag) {
123   const char* test_string = R""""(
124 {
125     "instances" :
126     [
127         {
128             "graphics":{
129                 "displays":[
130                     {
131                         "width": 1080,
132                         "height": 600,
133                         "dpi": 120,
134                         "refresh_rate_hertz": 60
135                     },
136                     {
137                         "width": 400,
138                         "height": 600,
139                         "dpi": 120,
140                         "refresh_rate_hertz": 60
141                     }
142                 ]
143                 }
144         },
145         {
146             "graphics":{
147                 "displays":[
148                     {
149                         "width": 2560,
150                         "height": 1800,
151                         "dpi": 320,
152                         "refresh_rate_hertz": 60
153                     }
154                 ]
155                 }
156         }
157     ]
158 }
159   )"""";
160 
161   const char* expected_string =
162       R""""(--displays_binproto=ChgKCgi4CBDYBBh4IDwKCgiQAxDYBBh4IDwKDQoLCIAUEIgOGMACIDw=)"""";
163 
164   Json::Value json_configs;
165   std::string json_text(test_string);
166 
167   EXPECT_TRUE(ParseJsonString(json_text, json_configs))
168       << "Invalid Json string";
169   auto serialized_data = LaunchCvdParserTester(json_configs);
170   EXPECT_TRUE(serialized_data.ok()) << serialized_data.error().Trace();
171   EXPECT_TRUE(FindConfig(*serialized_data, expected_string))
172       << "extra_bootconfig_args flag is missing or wrongly formatted";
173 }
174 
175 }  // namespace cuttlefish
176