Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | /* |
| 18 | * The tests in this file operate on a higher level than the tests in the other |
| 19 | * files. Here, all tests execute the idmap2 binary and only depend on |
| 20 | * libidmap2 to verify the output of idmap2. |
| 21 | */ |
| 22 | #include <fcntl.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/wait.h> |
| 26 | #include <unistd.h> |
| 27 | |
| 28 | #include <cerrno> |
| 29 | #include <cstdlib> |
| 30 | #include <cstring> // strerror |
| 31 | #include <fstream> |
| 32 | #include <memory> |
| 33 | #include <sstream> |
| 34 | #include <string> |
| 35 | #include <vector> |
| 36 | |
Ryan Mitchell | 52e1f7a | 2019-04-12 12:31:42 -0700 | [diff] [blame] | 37 | #include "TestHelpers.h" |
| 38 | #include "androidfw/PosixUtils.h" |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 39 | #include "gmock/gmock.h" |
| 40 | #include "gtest/gtest.h" |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 41 | #include "idmap2/FileUtils.h" |
| 42 | #include "idmap2/Idmap.h" |
Ryan Mitchell | 52e1f7a | 2019-04-12 12:31:42 -0700 | [diff] [blame] | 43 | #include "private/android_filesystem_config.h" |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 44 | |
| 45 | using ::android::util::ExecuteBinary; |
| 46 | using ::testing::NotNull; |
| 47 | |
Mårten Kongstad | 0eba72a | 2018-11-29 08:23:14 +0100 | [diff] [blame] | 48 | namespace android::idmap2 { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 49 | |
| 50 | class Idmap2BinaryTests : public Idmap2Tests {}; |
| 51 | |
Mårten Kongstad | 744ccfe | 2018-12-20 14:56:14 +0100 | [diff] [blame] | 52 | namespace { |
| 53 | |
| 54 | void AssertIdmap(const Idmap& idmap, const std::string& target_apk_path, |
| 55 | const std::string& overlay_apk_path) { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 56 | // check that the idmap file looks reasonable (IdmapTests is responsible for |
| 57 | // more in-depth verification) |
| 58 | ASSERT_EQ(idmap.GetHeader()->GetMagic(), kIdmapMagic); |
| 59 | ASSERT_EQ(idmap.GetHeader()->GetVersion(), kIdmapCurrentVersion); |
| 60 | ASSERT_EQ(idmap.GetHeader()->GetTargetPath(), target_apk_path); |
| 61 | ASSERT_EQ(idmap.GetHeader()->GetOverlayPath(), overlay_apk_path); |
Mårten Kongstad | b877902 | 2018-11-29 09:53:17 +0100 | [diff] [blame] | 62 | ASSERT_EQ(idmap.GetData().size(), 1U); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | #define ASSERT_IDMAP(idmap_ref, target_apk_path, overlay_apk_path) \ |
| 66 | do { \ |
| 67 | ASSERT_NO_FATAL_FAILURE(AssertIdmap(idmap_ref, target_apk_path, overlay_apk_path)); \ |
| 68 | } while (0) |
| 69 | |
Mårten Kongstad | 1da49dc | 2019-01-14 10:03:53 +0100 | [diff] [blame] | 70 | #ifdef __ANDROID__ |
| 71 | #define SKIP_TEST_IF_CANT_EXEC_IDMAP2 \ |
| 72 | do { \ |
| 73 | const uid_t uid = getuid(); \ |
| 74 | if (uid != AID_ROOT && uid != AID_SYSTEM) { \ |
| 75 | GTEST_SKIP(); \ |
| 76 | } \ |
| 77 | } while (0) |
| 78 | #else |
| 79 | #define SKIP_TEST_IF_CANT_EXEC_IDMAP2 |
| 80 | #endif |
| 81 | |
Mårten Kongstad | 744ccfe | 2018-12-20 14:56:14 +0100 | [diff] [blame] | 82 | } // namespace |
| 83 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 84 | TEST_F(Idmap2BinaryTests, Create) { |
Mårten Kongstad | 1da49dc | 2019-01-14 10:03:53 +0100 | [diff] [blame] | 85 | SKIP_TEST_IF_CANT_EXEC_IDMAP2; |
| 86 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 87 | // clang-format off |
| 88 | auto result = ExecuteBinary({"idmap2", |
| 89 | "create", |
| 90 | "--target-apk-path", GetTargetApkPath(), |
| 91 | "--overlay-apk-path", GetOverlayApkPath(), |
| 92 | "--idmap-path", GetIdmapPath()}); |
| 93 | // clang-format on |
| 94 | ASSERT_THAT(result, NotNull()); |
| 95 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 96 | |
| 97 | struct stat st; |
| 98 | ASSERT_EQ(stat(GetIdmapPath().c_str(), &st), 0); |
| 99 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 100 | std::ifstream fin(GetIdmapPath()); |
Mårten Kongstad | ce42490 | 2019-03-01 08:35:37 +0100 | [diff] [blame] | 101 | const auto idmap = Idmap::FromBinaryStream(fin); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 102 | fin.close(); |
| 103 | |
Mårten Kongstad | ce42490 | 2019-03-01 08:35:37 +0100 | [diff] [blame] | 104 | ASSERT_TRUE(idmap); |
| 105 | ASSERT_IDMAP(**idmap, GetTargetApkPath(), GetOverlayApkPath()); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 106 | |
| 107 | unlink(GetIdmapPath().c_str()); |
| 108 | } |
| 109 | |
| 110 | TEST_F(Idmap2BinaryTests, Dump) { |
Mårten Kongstad | 1da49dc | 2019-01-14 10:03:53 +0100 | [diff] [blame] | 111 | SKIP_TEST_IF_CANT_EXEC_IDMAP2; |
| 112 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 113 | // clang-format off |
| 114 | auto result = ExecuteBinary({"idmap2", |
| 115 | "create", |
| 116 | "--target-apk-path", GetTargetApkPath(), |
| 117 | "--overlay-apk-path", GetOverlayApkPath(), |
| 118 | "--idmap-path", GetIdmapPath()}); |
| 119 | // clang-format on |
| 120 | ASSERT_THAT(result, NotNull()); |
| 121 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 122 | |
| 123 | // clang-format off |
| 124 | result = ExecuteBinary({"idmap2", |
| 125 | "dump", |
| 126 | "--idmap-path", GetIdmapPath()}); |
| 127 | // clang-format on |
| 128 | ASSERT_THAT(result, NotNull()); |
| 129 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 130 | ASSERT_NE(result->stdout.find("0x7f010000 -> 0x7f010000 integer/int1"), std::string::npos); |
Ryan Mitchell | 939df09 | 2019-04-09 17:13:50 -0700 | [diff] [blame^] | 131 | ASSERT_NE(result->stdout.find("0x7f02000c -> 0x7f020000 string/str1"), std::string::npos); |
| 132 | ASSERT_NE(result->stdout.find("0x7f02000e -> 0x7f020001 string/str3"), std::string::npos); |
| 133 | ASSERT_NE(result->stdout.find("0x7f02000f -> 0x7f020002 string/str4"), std::string::npos); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 134 | ASSERT_EQ(result->stdout.find("00000210: 007f target package id"), std::string::npos); |
| 135 | |
| 136 | // clang-format off |
| 137 | result = ExecuteBinary({"idmap2", |
| 138 | "dump", |
| 139 | "--verbose", |
| 140 | "--idmap-path", GetIdmapPath()}); |
| 141 | // clang-format on |
| 142 | ASSERT_THAT(result, NotNull()); |
| 143 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 144 | ASSERT_NE(result->stdout.find("00000000: 504d4449 magic"), std::string::npos); |
| 145 | ASSERT_NE(result->stdout.find("00000210: 007f target package id"), std::string::npos); |
| 146 | |
| 147 | // clang-format off |
| 148 | result = ExecuteBinary({"idmap2", |
| 149 | "dump", |
| 150 | "--verbose", |
| 151 | "--idmap-path", GetTestDataPath() + "/DOES-NOT-EXIST"}); |
| 152 | // clang-format on |
| 153 | ASSERT_THAT(result, NotNull()); |
| 154 | ASSERT_NE(result->status, EXIT_SUCCESS); |
| 155 | |
| 156 | unlink(GetIdmapPath().c_str()); |
| 157 | } |
| 158 | |
| 159 | TEST_F(Idmap2BinaryTests, Scan) { |
Mårten Kongstad | 1da49dc | 2019-01-14 10:03:53 +0100 | [diff] [blame] | 160 | SKIP_TEST_IF_CANT_EXEC_IDMAP2; |
| 161 | |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 162 | const std::string overlay_static_no_name_apk_path = |
| 163 | GetTestDataPath() + "/overlay/overlay-no-name-static.apk"; |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 164 | const std::string overlay_static_1_apk_path = GetTestDataPath() + "/overlay/overlay-static-1.apk"; |
| 165 | const std::string overlay_static_2_apk_path = GetTestDataPath() + "/overlay/overlay-static-2.apk"; |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 166 | const std::string idmap_static_no_name_path = |
| 167 | Idmap::CanonicalIdmapPathFor(GetTempDirPath(), overlay_static_no_name_apk_path); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 168 | const std::string idmap_static_1_path = |
| 169 | Idmap::CanonicalIdmapPathFor(GetTempDirPath(), overlay_static_1_apk_path); |
| 170 | const std::string idmap_static_2_path = |
| 171 | Idmap::CanonicalIdmapPathFor(GetTempDirPath(), overlay_static_2_apk_path); |
| 172 | |
| 173 | // single input directory, recursive |
| 174 | // clang-format off |
| 175 | auto result = ExecuteBinary({"idmap2", |
| 176 | "scan", |
| 177 | "--input-directory", GetTestDataPath(), |
| 178 | "--recursive", |
| 179 | "--target-package-name", "test.target", |
| 180 | "--target-apk-path", GetTargetApkPath(), |
Mårten Kongstad | d10d06d | 2019-01-07 17:26:25 -0800 | [diff] [blame] | 181 | "--output-directory", GetTempDirPath(), |
| 182 | "--override-policy", "public"}); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 183 | // clang-format on |
| 184 | ASSERT_THAT(result, NotNull()); |
| 185 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 186 | std::stringstream expected; |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 187 | expected << idmap_static_no_name_path << std::endl; |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 188 | expected << idmap_static_1_path << std::endl; |
| 189 | expected << idmap_static_2_path << std::endl; |
| 190 | ASSERT_EQ(result->stdout, expected.str()); |
| 191 | |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 192 | auto idmap_static_no_name_raw_string = utils::ReadFile(idmap_static_no_name_path); |
| 193 | auto idmap_static_no_name_raw_stream = std::istringstream(*idmap_static_no_name_raw_string); |
Mårten Kongstad | ce42490 | 2019-03-01 08:35:37 +0100 | [diff] [blame] | 194 | auto idmap_static_no_name = Idmap::FromBinaryStream(idmap_static_no_name_raw_stream); |
| 195 | ASSERT_TRUE(idmap_static_no_name); |
| 196 | ASSERT_IDMAP(**idmap_static_no_name, GetTargetApkPath(), overlay_static_no_name_apk_path); |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 197 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 198 | auto idmap_static_1_raw_string = utils::ReadFile(idmap_static_1_path); |
| 199 | auto idmap_static_1_raw_stream = std::istringstream(*idmap_static_1_raw_string); |
Mårten Kongstad | ce42490 | 2019-03-01 08:35:37 +0100 | [diff] [blame] | 200 | auto idmap_static_1 = Idmap::FromBinaryStream(idmap_static_1_raw_stream); |
| 201 | ASSERT_TRUE(idmap_static_1); |
| 202 | ASSERT_IDMAP(**idmap_static_1, GetTargetApkPath(), overlay_static_1_apk_path); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 203 | |
| 204 | auto idmap_static_2_raw_string = utils::ReadFile(idmap_static_2_path); |
| 205 | auto idmap_static_2_raw_stream = std::istringstream(*idmap_static_2_raw_string); |
Mårten Kongstad | ce42490 | 2019-03-01 08:35:37 +0100 | [diff] [blame] | 206 | auto idmap_static_2 = Idmap::FromBinaryStream(idmap_static_2_raw_stream); |
| 207 | ASSERT_TRUE(idmap_static_2); |
| 208 | ASSERT_IDMAP(**idmap_static_2, GetTargetApkPath(), overlay_static_2_apk_path); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 209 | |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 210 | unlink(idmap_static_no_name_path.c_str()); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 211 | unlink(idmap_static_2_path.c_str()); |
| 212 | unlink(idmap_static_1_path.c_str()); |
| 213 | |
| 214 | // multiple input directories, non-recursive |
| 215 | // clang-format off |
| 216 | result = ExecuteBinary({"idmap2", |
| 217 | "scan", |
| 218 | "--input-directory", GetTestDataPath() + "/target", |
| 219 | "--input-directory", GetTestDataPath() + "/overlay", |
| 220 | "--target-package-name", "test.target", |
| 221 | "--target-apk-path", GetTargetApkPath(), |
Mårten Kongstad | d10d06d | 2019-01-07 17:26:25 -0800 | [diff] [blame] | 222 | "--output-directory", GetTempDirPath(), |
| 223 | "--override-policy", "public"}); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 224 | // clang-format on |
| 225 | ASSERT_THAT(result, NotNull()); |
| 226 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 227 | ASSERT_EQ(result->stdout, expected.str()); |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 228 | unlink(idmap_static_no_name_path.c_str()); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 229 | unlink(idmap_static_2_path.c_str()); |
| 230 | unlink(idmap_static_1_path.c_str()); |
| 231 | |
| 232 | // the same input directory given twice, but no duplicate entries |
| 233 | // clang-format off |
| 234 | result = ExecuteBinary({"idmap2", |
| 235 | "scan", |
| 236 | "--input-directory", GetTestDataPath(), |
| 237 | "--input-directory", GetTestDataPath(), |
| 238 | "--recursive", |
| 239 | "--target-package-name", "test.target", |
| 240 | "--target-apk-path", GetTargetApkPath(), |
Mårten Kongstad | d10d06d | 2019-01-07 17:26:25 -0800 | [diff] [blame] | 241 | "--output-directory", GetTempDirPath(), |
| 242 | "--override-policy", "public"}); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 243 | // clang-format on |
| 244 | ASSERT_THAT(result, NotNull()); |
| 245 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 246 | ASSERT_EQ(result->stdout, expected.str()); |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 247 | unlink(idmap_static_no_name_path.c_str()); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 248 | unlink(idmap_static_2_path.c_str()); |
| 249 | unlink(idmap_static_1_path.c_str()); |
| 250 | |
| 251 | // no APKs in input-directory: ok, but no output |
| 252 | // clang-format off |
| 253 | result = ExecuteBinary({"idmap2", |
| 254 | "scan", |
| 255 | "--input-directory", GetTempDirPath(), |
| 256 | "--target-package-name", "test.target", |
| 257 | "--target-apk-path", GetTargetApkPath(), |
Mårten Kongstad | d10d06d | 2019-01-07 17:26:25 -0800 | [diff] [blame] | 258 | "--output-directory", GetTempDirPath(), |
| 259 | "--override-policy", "public"}); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 260 | // clang-format on |
| 261 | ASSERT_THAT(result, NotNull()); |
| 262 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 263 | ASSERT_EQ(result->stdout, ""); |
Ryan Mitchell | 0503fa5 | 2019-04-12 12:29:36 -0700 | [diff] [blame] | 264 | |
| 265 | // the signature idmap failing to generate should not cause scanning to fail |
| 266 | // clang-format off |
| 267 | result = ExecuteBinary({"idmap2", |
| 268 | "scan", |
| 269 | "--input-directory", GetTestDataPath(), |
| 270 | "--recursive", |
| 271 | "--target-package-name", "test.target", |
| 272 | "--target-apk-path", GetTargetApkPath(), |
| 273 | "--output-directory", GetTempDirPath(), |
| 274 | "--override-policy", "public"}); |
| 275 | // clang-format on |
| 276 | ASSERT_THAT(result, NotNull()); |
| 277 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 278 | ASSERT_EQ(result->stdout, expected.str()); |
| 279 | unlink(idmap_static_no_name_path.c_str()); |
| 280 | unlink(idmap_static_2_path.c_str()); |
| 281 | unlink(idmap_static_1_path.c_str()); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | TEST_F(Idmap2BinaryTests, Lookup) { |
Mårten Kongstad | 1da49dc | 2019-01-14 10:03:53 +0100 | [diff] [blame] | 285 | SKIP_TEST_IF_CANT_EXEC_IDMAP2; |
| 286 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 287 | // clang-format off |
| 288 | auto result = ExecuteBinary({"idmap2", |
| 289 | "create", |
| 290 | "--target-apk-path", GetTargetApkPath(), |
| 291 | "--overlay-apk-path", GetOverlayApkPath(), |
| 292 | "--idmap-path", GetIdmapPath()}); |
| 293 | // clang-format on |
| 294 | ASSERT_THAT(result, NotNull()); |
| 295 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 296 | |
| 297 | // clang-format off |
| 298 | result = ExecuteBinary({"idmap2", |
| 299 | "lookup", |
| 300 | "--idmap-path", GetIdmapPath(), |
| 301 | "--config", "", |
Ryan Mitchell | 939df09 | 2019-04-09 17:13:50 -0700 | [diff] [blame^] | 302 | "--resid", "0x7f02000c"}); // string/str1 |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 303 | // clang-format on |
| 304 | ASSERT_THAT(result, NotNull()); |
| 305 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 306 | ASSERT_NE(result->stdout.find("overlay-1"), std::string::npos); |
| 307 | ASSERT_EQ(result->stdout.find("overlay-1-sv"), std::string::npos); |
| 308 | |
| 309 | // clang-format off |
| 310 | result = ExecuteBinary({"idmap2", |
| 311 | "lookup", |
| 312 | "--idmap-path", GetIdmapPath(), |
| 313 | "--config", "", |
| 314 | "--resid", "test.target:string/str1"}); |
| 315 | // clang-format on |
| 316 | ASSERT_THAT(result, NotNull()); |
| 317 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 318 | ASSERT_NE(result->stdout.find("overlay-1"), std::string::npos); |
| 319 | ASSERT_EQ(result->stdout.find("overlay-1-sv"), std::string::npos); |
| 320 | |
| 321 | // clang-format off |
| 322 | result = ExecuteBinary({"idmap2", |
| 323 | "lookup", |
| 324 | "--idmap-path", GetIdmapPath(), |
| 325 | "--config", "sv", |
| 326 | "--resid", "test.target:string/str1"}); |
| 327 | // clang-format on |
| 328 | ASSERT_THAT(result, NotNull()); |
| 329 | ASSERT_EQ(result->status, EXIT_SUCCESS) << result->stderr; |
| 330 | ASSERT_NE(result->stdout.find("overlay-1-sv"), std::string::npos); |
| 331 | |
| 332 | unlink(GetIdmapPath().c_str()); |
| 333 | } |
| 334 | |
| 335 | TEST_F(Idmap2BinaryTests, InvalidCommandLineOptions) { |
Mårten Kongstad | 1da49dc | 2019-01-14 10:03:53 +0100 | [diff] [blame] | 336 | SKIP_TEST_IF_CANT_EXEC_IDMAP2; |
| 337 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 338 | const std::string invalid_target_apk_path = GetTestDataPath() + "/DOES-NOT-EXIST"; |
| 339 | |
| 340 | // missing mandatory options |
| 341 | // clang-format off |
| 342 | auto result = ExecuteBinary({"idmap2", |
| 343 | "create"}); |
| 344 | // clang-format on |
| 345 | ASSERT_THAT(result, NotNull()); |
| 346 | ASSERT_NE(result->status, EXIT_SUCCESS); |
| 347 | |
| 348 | // missing argument to option |
| 349 | // clang-format off |
| 350 | result = ExecuteBinary({"idmap2", |
| 351 | "create", |
| 352 | "--target-apk-path", GetTargetApkPath(), |
| 353 | "--overlay-apk-path", GetOverlayApkPath(), |
| 354 | "--idmap-path"}); |
| 355 | // clang-format on |
| 356 | ASSERT_THAT(result, NotNull()); |
| 357 | ASSERT_NE(result->status, EXIT_SUCCESS); |
| 358 | |
| 359 | // invalid target apk path |
| 360 | // clang-format off |
| 361 | result = ExecuteBinary({"idmap2", |
| 362 | "create", |
| 363 | "--target-apk-path", invalid_target_apk_path, |
| 364 | "--overlay-apk-path", GetOverlayApkPath(), |
| 365 | "--idmap-path", GetIdmapPath()}); |
| 366 | // clang-format on |
| 367 | ASSERT_THAT(result, NotNull()); |
| 368 | ASSERT_NE(result->status, EXIT_SUCCESS); |
Mårten Kongstad | d10d06d | 2019-01-07 17:26:25 -0800 | [diff] [blame] | 369 | |
| 370 | // unknown policy |
| 371 | // clang-format off |
| 372 | result = ExecuteBinary({"idmap2", |
| 373 | "create", |
| 374 | "--target-apk-path", GetTargetApkPath(), |
| 375 | "--overlay-apk-path", GetOverlayApkPath(), |
| 376 | "--idmap-path", GetIdmapPath(), |
| 377 | "--policy", "this-does-not-exist"}); |
| 378 | // clang-format on |
| 379 | ASSERT_THAT(result, NotNull()); |
| 380 | ASSERT_NE(result->status, EXIT_SUCCESS); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 381 | } |
| 382 | |
Mårten Kongstad | 0eba72a | 2018-11-29 08:23:14 +0100 | [diff] [blame] | 383 | } // namespace android::idmap2 |