• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2023 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 #include <iostream>
17 #include <optional>
18 #include <string>
19 
20 #include <gtest/gtest.h>
21 
22 #include "host/commands/cvd/frontline_parser.h"
23 
24 namespace std {
25 
26 template <typename T>
operator <<(std::ostream & out,const std::vector<T> & v)27 static std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
28   if (v.empty()) {
29     out << "{}";
30     return out;
31   }
32   if (v.size() == 1) {
33     out << "{" << v.front() << "}";
34     return out;
35   }
36   out << "{";
37   for (size_t i = 0; i != v.size() - 1; i++) {
38     out << v.at(i) << ", ";
39   }
40   out << v.back() << "}";
41   return out;
42 }
43 
44 }  // namespace std
45 
46 namespace cuttlefish {
47 
TEST(FrontlineParserTest,CvdOnly)48 TEST(FrontlineParserTest, CvdOnly) {
49   cvd_common::Args input{"cvd"};
50   FlagCollection empty_flags;
51   FrontlineParser::ParserParam parser_param{.server_supported_subcmds = {},
52                                             .internal_cmds = {},
53                                             .all_args = {"cvd"},
54                                             .cvd_flags = empty_flags};
55 
56   auto result = FrontlineParser::Parse(parser_param);
57 
58   ASSERT_TRUE(result.ok()) << result.error().Trace();
59   auto& parser_ptr = *result;
60   ASSERT_TRUE(parser_ptr);
61   ASSERT_EQ("cvd", parser_ptr->ProgPath());
62   ASSERT_EQ(std::nullopt, parser_ptr->SubCmd())
63       << (parser_ptr->SubCmd() ? std::string("nullopt")
64                                : *parser_ptr->SubCmd());
65   ASSERT_EQ(cvd_common::Args{}, parser_ptr->SubCmdArgs());
66   ASSERT_EQ(cvd_common::Args{}, parser_ptr->CvdArgs());
67 }
68 
69 }  // namespace cuttlefish
70