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