• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 <algorithm>
18 
19 #include <fstream>
20 #include <iostream>
21 
22 #include "host/commands/cvd/parser/cf_flags_validator.h"
23 #include "host/commands/cvd/parser/launch_cvd_parser.h"
24 #include "host/commands/cvd/unittests/parser/test_common.h"
25 
26 namespace cuttlefish {
27 
ParseJsonString(std::string & json_text,Json::Value & root)28 bool ParseJsonString(std::string& json_text, Json::Value& root) {
29   Json::Reader reader;  //  Reader
30   return reader.parse(json_text, root);
31 }
32 
FindConfig(const std::vector<std::string> & vec,const std::string & element)33 bool FindConfig(const std::vector<std::string>& vec,
34                 const std::string& element) {
35   auto it = find(vec.begin(), vec.end(), element);
36   return it != vec.end();
37 }
FindConfigIgnoreSpaces(const std::vector<std::string> & vec,const std::string & str)38 bool FindConfigIgnoreSpaces(const std::vector<std::string>& vec,
39                             const std::string& str) {
40   std::string target = str;
41   target.erase(std::remove(target.begin(), target.end(), ' '), target.end());
42   target.erase(std::remove(target.begin(), target.end(), '\t'), target.end());
43 
44   for (const auto& s : vec) {
45     std::string current = s;
46     current.erase(std::remove(current.begin(), current.end(), ' '),
47                   current.end());
48     current.erase(std::remove(current.begin(), current.end(), '\t'),
49                   target.end());
50     if (current == target) {
51       return true;
52     }
53   }
54   return false;
55 }
56 
LaunchCvdParserTester(Json::Value & root)57 Result<std::vector<std::string>> LaunchCvdParserTester(Json::Value& root) {
58   CF_EXPECT(ValidateCfConfigs(root), "Loaded Json validation failed");
59   return ParseLaunchCvdConfigs(root);
60 }
61 
62 }  // namespace cuttlefish