File: Command_test.cpp

package info (click to toggle)
android-platform-frameworks-base 1%3A10.0.0%2Br36-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 321,788 kB
  • sloc: java: 962,234; cpp: 274,314; xml: 242,770; python: 5,060; sh: 1,432; ansic: 494; makefile: 47; sed: 19
file content (97 lines) | stat: -rw-r--r-- 3,802 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Command.h"

#include "test/Test.h"

using ::testing::Eq;

namespace aapt {

class TestCommand : public Command {
 public:
  explicit TestCommand() : Command("command") {}
  int Action(const std::vector<std::string>& args) override {
    args_ = args;
    return 0;
  }

  std::vector<std::string> args_;
};

#ifdef _WIN32
TEST(CommandTest, LongFullyQualifiedPathWindows) {
  TestCommand command;
  std::string required_flag;
  command.AddRequiredFlag("--rflag", "", &required_flag, Command::kPath);
  Maybe<std::string> optional_flag;
  command.AddOptionalFlag("--oflag", "", &optional_flag, Command::kPath);
  std::vector<std::string> required_flag_list;
  command.AddRequiredFlagList("--rlflag", "", &required_flag_list, Command::kPath);
  std::vector<std::string> optional_flag_list;
  command.AddOptionalFlagList("--olflag", "", &optional_flag_list, Command::kPath);
  std::string non_path_flag;
  command.AddRequiredFlag("--nflag", "", &non_path_flag);

  const std::string kLongPath =
      "C:\\Users\\jedo\\_bazel_jedo\\vcmdctjv\\execroot\\__main__\\_tmp"
      "\\6767b4778f8798efc0f784ee74fa70ee\\tests\\testApksAr8c7560a9a65"
      "\\1346ee7c014a089fb55d8c46cf3d9\\project\\baseModule\\build"
      "\\intermediates\\processed_res\\minified\\processMinifiedResources"
      "\\1346ee7c014a089fb55d8c46cf3d9\\project\\baseModule\\build"
      "\\intermediates\\processed_res\\minified\\processMinifiedResources"
      "\\out\\resources-minified.ap_";

  const std::string kExpected =
      "\\\\?\\C:\\Users\\jedo\\_bazel_jedo\\vcmdctjv\\execroot\\__main__\\_tmp"
      "\\6767b4778f8798efc0f784ee74fa70ee\\tests\\testApksAr8c7560a9a65"
      "\\1346ee7c014a089fb55d8c46cf3d9\\project\\baseModule\\build"
      "\\intermediates\\processed_res\\minified\\processMinifiedResources"
      "\\1346ee7c014a089fb55d8c46cf3d9\\project\\baseModule\\build"
      "\\intermediates\\processed_res\\minified\\processMinifiedResources"
      "\\out\\resources-minified.ap_";


  ASSERT_THAT(command.Execute({"--rflag", kLongPath,
                               "--oflag", kLongPath,
                               "--rlflag", kLongPath,
                               "--rlflag", kLongPath,
                               "--olflag", kLongPath,
                               "--olflag", kLongPath,
                               "--nflag", kLongPath,
                               kLongPath, kLongPath}, &std::cerr), Eq(0));

  ASSERT_THAT(required_flag, Eq(kExpected));
  ASSERT_THAT(optional_flag, Eq(kExpected));
  ASSERT_THAT(required_flag_list.size(), Eq(2));
  ASSERT_THAT(required_flag_list[0], Eq(kExpected));
  ASSERT_THAT(required_flag_list[1], Eq(kExpected));
  ASSERT_THAT(optional_flag_list.size(), Eq(2));
  ASSERT_THAT(optional_flag_list[0], Eq(kExpected));
  ASSERT_THAT(optional_flag_list[1], Eq(kExpected));

  // File arguments should also be converted to use the long path prefix
  ASSERT_THAT(command.args_.size(), Eq(2));
  ASSERT_THAT(command.args_[0], Eq(kExpected));
  ASSERT_THAT(command.args_[1], Eq(kExpected));

  // Do not convert flags that are not marged as paths
  ASSERT_THAT(non_path_flag, Eq(kLongPath));
}
#endif

}  // namespace aapt