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 | |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame] | 27 | const unsigned char kIdmapRawData[] = { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 28 | // IDMAP HEADER |
| 29 | // 0x0: magic |
| 30 | 0x49, 0x44, 0x4d, 0x50, |
| 31 | |
| 32 | // 0x4: version |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 33 | 0x09, 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 | a707013 | 2020-05-13 14:17:52 -0700 | [diff] [blame] | 41 | // 0x10: fulfilled policies |
| 42 | 0x11, 0x00, 0x00, 0x00, |
| 43 | |
| 44 | // 0x14: enforce overlayable |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 45 | 0x01, 0x00, 0x00, 0x00, |
Ryan Mitchell | a707013 | 2020-05-13 14:17:52 -0700 | [diff] [blame] | 46 | |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame] | 47 | // 0x18: target path length |
| 48 | 0x0b, 0x00, 0x00, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 49 | |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame] | 50 | // 0x1c: target path "targetX.apk" |
| 51 | 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 52 | |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame] | 53 | // 0x28: overlay path length |
| 54 | 0x0c, 0x00, 0x00, 0x00, |
| 55 | |
| 56 | // 0x2c: overlay path "overlayX.apk" |
| 57 | 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x58, 0x2e, 0x61, 0x70, 0x6b, |
| 58 | |
Ryan Mitchell | 30dc2e0 | 2020-12-02 11:43:18 -0800 | [diff] [blame] | 59 | // 0x38: overlay name length |
| 60 | 0x0b, 0x00, 0x00, 0x00, |
| 61 | |
| 62 | // 0x3c: overlay name "OverlayName" |
| 63 | 0x4f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6D, 0x65, 0x00, |
| 64 | |
| 65 | // 0x48 -> 4c: debug string |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 66 | // string length, |
| 67 | 0x05, 0x00, 0x00, 0x00, |
Mårten Kongstad | d7e8a53 | 2019-10-11 08:32:04 +0200 | [diff] [blame] | 68 | |
Ryan Mitchell | 30dc2e0 | 2020-12-02 11:43:18 -0800 | [diff] [blame] | 69 | // 0x4c string contents "debug\0\0\0" (padded to word alignment) |
Mårten Kongstad | d7e8a53 | 2019-10-11 08:32:04 +0200 | [diff] [blame] | 70 | 0x64, 0x65, 0x62, 0x75, 0x67, 0x00, 0x00, 0x00, |
| 71 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 72 | // DATA HEADER |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame] | 73 | // 0x54: target_entry_count |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 74 | 0x03, 0x00, 0x00, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 75 | |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame] | 76 | // 0x58: target_inline_entry_count |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 77 | 0x01, 0x00, 0x00, 0x00, |
| 78 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 79 | // 0x5c: target_inline_entry_value_count |
| 80 | 0x01, 0x00, 0x00, 0x00, |
| 81 | |
| 82 | // 0x60: config_count |
| 83 | 0x01, 0x00, 0x00, 0x00, |
| 84 | |
| 85 | // 0x64: overlay_entry_count |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 86 | 0x03, 0x00, 0x00, 0x00, |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 87 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 88 | // 0x68: string_pool_offset |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 89 | 0x00, 0x00, 0x00, 0x00, |
| 90 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 91 | // TARGET ENTRIES |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 92 | // 0x6c: target id (0x7f020000) |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 93 | 0x00, 0x00, 0x02, 0x7f, |
| 94 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 95 | // 0x70: overlay_id (0x7f020000) |
Ryan Mitchell | a707013 | 2020-05-13 14:17:52 -0700 | [diff] [blame] | 96 | 0x00, 0x00, 0x02, 0x7f, |
| 97 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 98 | // 0x74: target id (0x7f030000) |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 99 | 0x00, 0x00, 0x03, 0x7f, |
| 100 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 101 | // 0x78: overlay_id (0x7f030000) |
Ryan Mitchell | a707013 | 2020-05-13 14:17:52 -0700 | [diff] [blame] | 102 | 0x00, 0x00, 0x03, 0x7f, |
| 103 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 104 | // 0x7c: target id (0x7f030002) |
Ryan Mitchell | a707013 | 2020-05-13 14:17:52 -0700 | [diff] [blame] | 105 | 0x02, 0x00, 0x03, 0x7f, |
| 106 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 107 | // 0x80: overlay_id (0x7f030001) |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 108 | 0x01, 0x00, 0x03, 0x7f, |
| 109 | |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 110 | // INLINE TARGET ENTRIES |
| 111 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 112 | // 0x84: target_id |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 113 | 0x00, 0x00, 0x04, 0x7f, |
| 114 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 115 | // 0x88: start value index |
| 116 | 0x00, 0x00, 0x00, 0x00, |
| 117 | |
| 118 | // 0x8c: value count |
| 119 | 0x01, 0x00, 0x00, 0x00, |
| 120 | |
| 121 | // INLINE TARGET ENTRY VALUES |
| 122 | |
| 123 | // 0x90: config index |
| 124 | 0x00, 0x00, 0x00, 0x00, |
| 125 | |
| 126 | // 0x94: Res_value::size (value ignored by idmap) |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 127 | 0x08, 0x00, |
| 128 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 129 | // 0x98: Res_value::res0 (value ignored by idmap) |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 130 | 0x00, |
| 131 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 132 | // 0x9c: Res_value::dataType (TYPE_INT_HEX) |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 133 | 0x11, |
| 134 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 135 | // 0xa0: Res_value::data |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 136 | 0x78, 0x56, 0x34, 0x12, |
| 137 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 138 | // CONFIGURATIONS |
| 139 | |
| 140 | // 0xa4: ConfigDescription |
| 141 | // size |
| 142 | 0x40, 0x00, 0x00, 0x00, |
| 143 | // 0xa8: imsi |
| 144 | 0x00, 0x00, 0x00, 0x00, |
| 145 | // 0xac: locale |
| 146 | 0x00, 0x00, 0x00, 0x00, |
| 147 | // 0xb0: screenType |
| 148 | 0x02, 0x00, 0xe0, 0x01, |
| 149 | // 0xb4: input |
| 150 | 0x00, 0x00, 0x00, 0x00, |
| 151 | // 0xb8: screenSize |
| 152 | 0x00, 0x00, 0x00, 0x00, |
| 153 | // 0xbc: version |
| 154 | 0x07, 0x00, 0x00, 0x00, |
| 155 | // 0xc0: screenConfig |
| 156 | 0x00, 0x00, 0x00, 0x00, |
| 157 | // 0xc4: screenSizeDp |
| 158 | 0x00, 0x00, 0x00, 0x00, |
| 159 | // 0xc8: localeScript |
| 160 | 0x00, 0x00, 0x00, 0x00, |
| 161 | // 0xcc: localVariant(1) |
| 162 | 0x00, 0x00, 0x00, 0x00, |
| 163 | // 0xd0: localVariant(2) |
| 164 | 0x00, 0x00, 0x00, 0x00, |
| 165 | // 0xd4: screenConfig2 |
| 166 | 0x00, 0x00, 0x00, 0x00, |
| 167 | // 0xd8: localeScriptWasComputed |
| 168 | 0x00, |
| 169 | // 0xd9: localeNumberingSystem(1) |
| 170 | 0x00, 0x00, 0x00, 0x00, |
| 171 | // 0xdd: localeNumberingSystem(2) |
| 172 | 0x00, 0x00, 0x00, 0x00, |
| 173 | |
| 174 | // 0xe1: padding |
| 175 | 0x00, 0x00, 0x00, |
| 176 | |
| 177 | |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 178 | // OVERLAY ENTRIES |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 179 | // 0xe4: 0x7f020000 -> 0x7f020000 |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 180 | 0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f, |
| 181 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 182 | // 0xec: 0x7f030000 -> 0x7f030000 |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 183 | 0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f, |
| 184 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 185 | // 0xf4: 0x7f030001 -> 0x7f030002 |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 186 | 0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f, |
Ryan Mitchell | e753ffe | 2019-09-23 09:47:02 -0700 | [diff] [blame] | 187 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 188 | // 0xfc: string pool |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 189 | // string length, |
| 190 | 0x04, 0x00, 0x00, 0x00, |
| 191 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 192 | // 0x100 string contents "test" |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 193 | 0x74, 0x65, 0x73, 0x74}; |
| 194 | |
Jeremy Meyer | be2b779 | 2022-08-23 17:42:50 +0000 | [diff] [blame^] | 195 | const unsigned int kIdmapRawDataLen = 0x104; |
Ryan Mitchell | 30dc2e0 | 2020-12-02 11:43:18 -0800 | [diff] [blame] | 196 | const unsigned int kIdmapRawDataOffset = 0x54; |
| 197 | const unsigned int kIdmapRawDataTargetCrc = 0x1234; |
| 198 | const unsigned int kIdmapRawOverlayCrc = 0x5678; |
| 199 | const unsigned int kIdmapRawDataPolicies = 0x11; |
| 200 | inline const std::string kIdmapRawTargetPath = "targetX.apk"; |
| 201 | inline const std::string kIdmapRawOverlayPath = "overlayX.apk"; |
| 202 | inline const std::string kIdmapRawOverlayName = "OverlayName"; |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 203 | |
Mårten Kongstad | b877902 | 2018-11-29 09:53:17 +0100 | [diff] [blame] | 204 | std::string GetTestDataPath(); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 205 | |
| 206 | class Idmap2Tests : public testing::Test { |
| 207 | protected: |
Mårten Kongstad | cb85d9c | 2018-12-21 08:28:40 +0100 | [diff] [blame] | 208 | void SetUp() override { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 209 | #ifdef __ANDROID__ |
| 210 | tmp_dir_path_ = "/data/local/tmp/idmap2-tests-XXXXXX"; |
| 211 | #else |
| 212 | tmp_dir_path_ = "/tmp/idmap2-tests-XXXXXX"; |
| 213 | #endif |
| 214 | EXPECT_NE(mkdtemp(const_cast<char*>(tmp_dir_path_.c_str())), nullptr) |
| 215 | << "Failed to create temporary directory: " << strerror(errno); |
| 216 | target_apk_path_ = GetTestDataPath() + "/target/target.apk"; |
| 217 | overlay_apk_path_ = GetTestDataPath() + "/overlay/overlay.apk"; |
| 218 | idmap_path_ = tmp_dir_path_ + "/a.idmap"; |
| 219 | } |
| 220 | |
Mårten Kongstad | cb85d9c | 2018-12-21 08:28:40 +0100 | [diff] [blame] | 221 | void TearDown() override { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 222 | EXPECT_EQ(rmdir(tmp_dir_path_.c_str()), 0) |
| 223 | << "Failed to remove temporary directory " << tmp_dir_path_ << ": " << strerror(errno); |
| 224 | } |
| 225 | |
| 226 | const std::string& GetTempDirPath() { |
| 227 | return tmp_dir_path_; |
| 228 | } |
| 229 | |
| 230 | const std::string& GetTargetApkPath() { |
| 231 | return target_apk_path_; |
| 232 | } |
| 233 | |
| 234 | const std::string& GetOverlayApkPath() { |
| 235 | return overlay_apk_path_; |
| 236 | } |
| 237 | |
| 238 | const std::string& GetIdmapPath() { |
| 239 | return idmap_path_; |
| 240 | } |
| 241 | |
| 242 | private: |
| 243 | std::string tmp_dir_path_; |
| 244 | std::string target_apk_path_; |
| 245 | std::string overlay_apk_path_; |
| 246 | std::string idmap_path_; |
| 247 | }; |
| 248 | |
Mårten Kongstad | 0eba72a | 2018-11-29 08:23:14 +0100 | [diff] [blame] | 249 | } // namespace android::idmap2 |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 250 | |
| 251 | #endif // IDMAP2_TESTS_TESTHELPERS_H_ |