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 | #ifndef IDMAP2_TESTS_TESTHELPERS_H_ |
| 18 | #define IDMAP2_TESTS_TESTHELPERS_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | |
Ryan Mitchell | 52e1f7a | 2019-04-12 12:31:42 -0700 | [diff] [blame] | 22 | #include "gmock/gmock.h" |
| 23 | #include "gtest/gtest.h" |
| 24 | |
Mårten Kongstad | 0eba72a | 2018-11-29 08:23:14 +0100 | [diff] [blame] | 25 | namespace android::idmap2 { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 26 | |
| 27 | const unsigned char idmap_raw_data[] = { |
| 28 | // IDMAP HEADER |
| 29 | // 0x0: magic |
| 30 | 0x49, 0x44, 0x4d, 0x50, |
| 31 | |
| 32 | // 0x4: version |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 33 | 0x02, 0x00, 0x00, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 34 | |
| 35 | // 0x8: target crc |
| 36 | 0x34, 0x12, 0x00, 0x00, |
| 37 | |
| 38 | // 0xc: overlay crc |
| 39 | 0x78, 0x56, 0x00, 0x00, |
| 40 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 41 | // 0x10: target path "targetX.apk" |
| 42 | 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 53 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 54 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 56 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 58 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 59 | // 0x110: overlay path "overlayX.apk" |
| 60 | 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 63 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 65 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 66 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 67 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 69 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 70 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 71 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 72 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 73 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 75 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 76 | |
| 77 | // DATA HEADER |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 78 | // 0x210: target_package_id |
| 79 | 0x7f, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 80 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 81 | // 0x211: overlay_package_id |
| 82 | 0x7f, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 83 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 84 | // 0x212: target_entry_count |
| 85 | 0x03, 0x00, 0x00, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 86 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 87 | // 0x216: overlay_entry_count |
| 88 | 0x03, 0x00, 0x00, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 89 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 90 | // 0x21a: string_pool_offset |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 91 | 0x00, 0x00, 0x00, 0x00, |
| 92 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 93 | // 0x21e: string_pool_byte_length |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 94 | 0x00, 0x00, 0x00, 0x00, |
| 95 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 96 | // TARGET ENTRIES |
| 97 | // 0x222: 0x7f020000 |
| 98 | 0x00, 0x00, 0x02, 0x7f, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 99 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 100 | // 0x226: TYPE_REFERENCE |
| 101 | 0x01, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 102 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 103 | // 0x227: 0x7f020000 |
| 104 | 0x00, 0x00, 0x02, 0x7f, |
| 105 | |
| 106 | // 0x22b: 0x7f030000 |
| 107 | 0x00, 0x00, 0x03, 0x7f, |
| 108 | |
| 109 | // 0x22f: TYPE_REFERENCE |
| 110 | 0x01, |
| 111 | |
| 112 | // 0x230: 0x7f030000 |
| 113 | 0x00, 0x00, 0x03, 0x7f, |
| 114 | |
| 115 | // 0x234: 0x7f030002 |
| 116 | 0x02, 0x00, 0x03, 0x7f, |
| 117 | |
| 118 | // 0x238: TYPE_REFERENCE |
| 119 | 0x01, |
| 120 | |
| 121 | // 0x239: 0x7f030001 |
| 122 | 0x01, 0x00, 0x03, 0x7f, |
| 123 | |
| 124 | // OVERLAY ENTRIES |
| 125 | // 0x23d: 0x7f020000 -> 0x7f020000 |
| 126 | 0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f, |
| 127 | |
| 128 | // 0x245: 0x7f030000 -> 0x7f030000 |
| 129 | 0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f, |
| 130 | |
| 131 | // 0x24d: 0x7f030001 -> 0x7f030002 |
| 132 | 0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f}; |
| 133 | |
| 134 | const unsigned int idmap_raw_data_len = 0x255; |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 135 | |
Mårten Kongstad | b877902 | 2018-11-29 09:53:17 +0100 | [diff] [blame] | 136 | std::string GetTestDataPath(); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 137 | |
| 138 | class Idmap2Tests : public testing::Test { |
| 139 | protected: |
Mårten Kongstad | cb85d9c | 2018-12-21 08:28:40 +0100 | [diff] [blame] | 140 | void SetUp() override { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 141 | #ifdef __ANDROID__ |
| 142 | tmp_dir_path_ = "/data/local/tmp/idmap2-tests-XXXXXX"; |
| 143 | #else |
| 144 | tmp_dir_path_ = "/tmp/idmap2-tests-XXXXXX"; |
| 145 | #endif |
| 146 | EXPECT_NE(mkdtemp(const_cast<char*>(tmp_dir_path_.c_str())), nullptr) |
| 147 | << "Failed to create temporary directory: " << strerror(errno); |
| 148 | target_apk_path_ = GetTestDataPath() + "/target/target.apk"; |
| 149 | overlay_apk_path_ = GetTestDataPath() + "/overlay/overlay.apk"; |
| 150 | idmap_path_ = tmp_dir_path_ + "/a.idmap"; |
| 151 | } |
| 152 | |
Mårten Kongstad | cb85d9c | 2018-12-21 08:28:40 +0100 | [diff] [blame] | 153 | void TearDown() override { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 154 | EXPECT_EQ(rmdir(tmp_dir_path_.c_str()), 0) |
| 155 | << "Failed to remove temporary directory " << tmp_dir_path_ << ": " << strerror(errno); |
| 156 | } |
| 157 | |
| 158 | const std::string& GetTempDirPath() { |
| 159 | return tmp_dir_path_; |
| 160 | } |
| 161 | |
| 162 | const std::string& GetTargetApkPath() { |
| 163 | return target_apk_path_; |
| 164 | } |
| 165 | |
| 166 | const std::string& GetOverlayApkPath() { |
| 167 | return overlay_apk_path_; |
| 168 | } |
| 169 | |
| 170 | const std::string& GetIdmapPath() { |
| 171 | return idmap_path_; |
| 172 | } |
| 173 | |
| 174 | private: |
| 175 | std::string tmp_dir_path_; |
| 176 | std::string target_apk_path_; |
| 177 | std::string overlay_apk_path_; |
| 178 | std::string idmap_path_; |
| 179 | }; |
| 180 | |
Mårten Kongstad | 0eba72a | 2018-11-29 08:23:14 +0100 | [diff] [blame] | 181 | } // namespace android::idmap2 |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 182 | |
| 183 | #endif // IDMAP2_TESTS_TESTHELPERS_H_ |