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 | |
| 22 | namespace android { |
| 23 | namespace idmap2 { |
| 24 | |
| 25 | const unsigned char idmap_raw_data[] = { |
| 26 | // IDMAP HEADER |
| 27 | // 0x0: magic |
| 28 | 0x49, 0x44, 0x4d, 0x50, |
| 29 | |
| 30 | // 0x4: version |
| 31 | 0x01, 0x00, 0x00, 0x00, |
| 32 | |
| 33 | // 0x8: target crc |
| 34 | 0x34, 0x12, 0x00, 0x00, |
| 35 | |
| 36 | // 0xc: overlay crc |
| 37 | 0x78, 0x56, 0x00, 0x00, |
| 38 | |
| 39 | // 0x10: target path "target.apk" |
| 40 | 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 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 | |
| 57 | // 0x110: overlay path "overlay.apk" |
| 58 | 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 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 | |
| 75 | // DATA HEADER |
| 76 | // 0x210: target package id |
| 77 | 0x7f, 0x00, |
| 78 | |
| 79 | // 0x212: types count |
| 80 | 0x02, 0x00, |
| 81 | |
| 82 | // DATA BLOCK |
| 83 | // 0x214: target type |
| 84 | 0x02, 0x00, |
| 85 | |
| 86 | // 0x216: overlay type |
| 87 | 0x02, 0x00, |
| 88 | |
| 89 | // 0x218: entry count |
| 90 | 0x01, 0x00, |
| 91 | |
| 92 | // 0x21a: entry offset |
| 93 | 0x00, 0x00, |
| 94 | |
| 95 | // 0x21c: entries |
| 96 | 0x00, 0x00, 0x00, 0x00, |
| 97 | |
| 98 | // DATA BLOCK |
| 99 | // 0x220: target type |
| 100 | 0x03, 0x00, |
| 101 | |
| 102 | // 0x222: overlay type |
| 103 | 0x03, 0x00, |
| 104 | |
| 105 | // 0x224: entry count |
| 106 | 0x03, 0x00, |
| 107 | |
| 108 | // 0x226: entry offset |
| 109 | 0x03, 0x00, |
| 110 | |
| 111 | // 0x228, 0x22c, 0x230: entries |
| 112 | 0x00, 0x00, 0x00, 0x00, |
| 113 | |
| 114 | 0xff, 0xff, 0xff, 0xff, |
| 115 | |
| 116 | 0x01, 0x00, 0x00, 0x00}; |
| 117 | |
| 118 | const unsigned int idmap_raw_data_len = 565; |
| 119 | |
| 120 | const std::string GetTestDataPath(); |
| 121 | |
| 122 | class Idmap2Tests : public testing::Test { |
| 123 | protected: |
| 124 | virtual void SetUp() { |
| 125 | #ifdef __ANDROID__ |
| 126 | tmp_dir_path_ = "/data/local/tmp/idmap2-tests-XXXXXX"; |
| 127 | #else |
| 128 | tmp_dir_path_ = "/tmp/idmap2-tests-XXXXXX"; |
| 129 | #endif |
| 130 | EXPECT_NE(mkdtemp(const_cast<char*>(tmp_dir_path_.c_str())), nullptr) |
| 131 | << "Failed to create temporary directory: " << strerror(errno); |
| 132 | target_apk_path_ = GetTestDataPath() + "/target/target.apk"; |
| 133 | overlay_apk_path_ = GetTestDataPath() + "/overlay/overlay.apk"; |
| 134 | idmap_path_ = tmp_dir_path_ + "/a.idmap"; |
| 135 | } |
| 136 | |
| 137 | virtual void TearDown() { |
| 138 | EXPECT_EQ(rmdir(tmp_dir_path_.c_str()), 0) |
| 139 | << "Failed to remove temporary directory " << tmp_dir_path_ << ": " << strerror(errno); |
| 140 | } |
| 141 | |
| 142 | const std::string& GetTempDirPath() { |
| 143 | return tmp_dir_path_; |
| 144 | } |
| 145 | |
| 146 | const std::string& GetTargetApkPath() { |
| 147 | return target_apk_path_; |
| 148 | } |
| 149 | |
| 150 | const std::string& GetOverlayApkPath() { |
| 151 | return overlay_apk_path_; |
| 152 | } |
| 153 | |
| 154 | const std::string& GetIdmapPath() { |
| 155 | return idmap_path_; |
| 156 | } |
| 157 | |
| 158 | private: |
| 159 | std::string tmp_dir_path_; |
| 160 | std::string target_apk_path_; |
| 161 | std::string overlay_apk_path_; |
| 162 | std::string idmap_path_; |
| 163 | }; |
| 164 | |
| 165 | } // namespace idmap2 |
| 166 | } // namespace android |
| 167 | |
| 168 | #endif // IDMAP2_TESTS_TESTHELPERS_H_ |