• 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 {
TEST(MetricsFlagsParserTest,ParseOneInstanceMetricsReportInvalidValue)22 TEST(MetricsFlagsParserTest, ParseOneInstanceMetricsReportInvalidValue) {
23   const char* test_string = R""""(
24 {
25     "instances" :
26     [
27         {
28             "metrics": {
29             }
30         }
31     ]
32 }
33   )"""";
34 
35   Json::Value json_configs;
36   std::string json_text(test_string);
37 
38   EXPECT_TRUE(ParseJsonString(json_text, json_configs))
39       << "Invalid Json string";
40   auto serialized_data = LaunchCvdParserTester(json_configs);
41   EXPECT_FALSE(serialized_data.ok()) << serialized_data.error().Trace();
42 }
43 
TEST(MetricsFlagsParserTest,ParseOneInstancesMetricsReportFlagEmptyJson)44 TEST(MetricsFlagsParserTest, ParseOneInstancesMetricsReportFlagEmptyJson) {
45   const char* test_string = R""""(
46 {
47     "instances" :
48     [
49         {
50         }
51     ]
52 }
53   )"""";
54 
55   Json::Value json_configs;
56   std::string json_text(test_string);
57 
58   EXPECT_TRUE(ParseJsonString(json_text, json_configs))
59       << "Invalid Json string";
60   auto serialized_data = LaunchCvdParserTester(json_configs);
61   EXPECT_TRUE(serialized_data.ok()) << serialized_data.error().Trace();
62   EXPECT_TRUE(
63       FindConfig(*serialized_data, R"(--report_anonymous_usage_stats=n)"))
64       << "report_anonymous_usage_stats flag is missing or wrongly formatted";
65 }
66 
TEST(MetricsFlagsParserTest,ParseTwoInstancesMetricsReportFlagEmptyJson)67 TEST(MetricsFlagsParserTest, ParseTwoInstancesMetricsReportFlagEmptyJson) {
68   const char* test_string = R""""(
69 {
70     "instances" :
71     [
72         {
73         },
74         {
75         }
76     ]
77 }
78   )"""";
79 
80   Json::Value json_configs;
81   std::string json_text(test_string);
82 
83   EXPECT_TRUE(ParseJsonString(json_text, json_configs))
84       << "Invalid Json string";
85   auto serialized_data = LaunchCvdParserTester(json_configs);
86   EXPECT_TRUE(serialized_data.ok()) << serialized_data.error().Trace();
87   EXPECT_TRUE(
88       FindConfig(*serialized_data, R"(--report_anonymous_usage_stats=n)"))
89       << "report_anonymous_usage_stats flag is missing or wrongly formatted";
90 }
91 
92 }  // namespace cuttlefish
93