blob: e899589c7e61035116f6b4435b4a0f4953c5cffe [file] [log] [blame]
Mårten Kongstad02751232018-04-27 13:16:32 +02001/*
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 Mitchell52e1f7a2019-04-12 12:31:42 -070022#include "gmock/gmock.h"
23#include "gtest/gtest.h"
24
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010025namespace android::idmap2 {
Mårten Kongstad02751232018-04-27 13:16:32 +020026
27const unsigned char idmap_raw_data[] = {
28 // IDMAP HEADER
29 // 0x0: magic
30 0x49, 0x44, 0x4d, 0x50,
31
32 // 0x4: version
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020033 0x03, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020034
35 // 0x8: target crc
36 0x34, 0x12, 0x00, 0x00,
37
38 // 0xc: overlay crc
39 0x78, 0x56, 0x00, 0x00,
40
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070041 // 0x10: target path "targetX.apk"
42 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020043 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 Mitchelle753ffe2019-09-23 09:47:02 -070059 // 0x110: overlay path "overlayX.apk"
60 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020061 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
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020077 // 0x210: debug string
78 // string length, including terminating null
79 0x08, 0x00, 0x00, 0x00,
80
81 // string contents "debug\0\0\0" (padded to word alignment)
82 0x64, 0x65, 0x62, 0x75, 0x67, 0x00, 0x00, 0x00,
83
Mårten Kongstad02751232018-04-27 13:16:32 +020084 // DATA HEADER
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020085 // 0x21c: target_package_id
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070086 0x7f,
Mårten Kongstad02751232018-04-27 13:16:32 +020087
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020088 // 0x21d: overlay_package_id
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070089 0x7f,
Mårten Kongstad02751232018-04-27 13:16:32 +020090
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020091 // 0x21e: target_entry_count
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070092 0x03, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020093
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020094 // 0x222: overlay_entry_count
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070095 0x03, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020096
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020097 // 0x226: string_pool_offset
Mårten Kongstad02751232018-04-27 13:16:32 +020098 0x00, 0x00, 0x00, 0x00,
99
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200100 // 0x22a: string_pool_byte_length
Mårten Kongstad02751232018-04-27 13:16:32 +0200101 0x00, 0x00, 0x00, 0x00,
102
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700103 // TARGET ENTRIES
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200104 // 0x22e: 0x7f020000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700105 0x00, 0x00, 0x02, 0x7f,
Mårten Kongstad02751232018-04-27 13:16:32 +0200106
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200107 // 0x232: TYPE_REFERENCE
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700108 0x01,
Mårten Kongstad02751232018-04-27 13:16:32 +0200109
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200110 // 0x233: 0x7f020000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700111 0x00, 0x00, 0x02, 0x7f,
112
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200113 // 0x237: 0x7f030000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700114 0x00, 0x00, 0x03, 0x7f,
115
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200116 // 0x23b: TYPE_REFERENCE
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700117 0x01,
118
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200119 // 0x23c: 0x7f030000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700120 0x00, 0x00, 0x03, 0x7f,
121
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200122 // 0x240: 0x7f030002
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700123 0x02, 0x00, 0x03, 0x7f,
124
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200125 // 0x244: TYPE_REFERENCE
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700126 0x01,
127
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200128 // 0x245: 0x7f030001
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700129 0x01, 0x00, 0x03, 0x7f,
130
131 // OVERLAY ENTRIES
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200132 // 0x249: 0x7f020000 -> 0x7f020000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700133 0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f,
134
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200135 // 0x251: 0x7f030000 -> 0x7f030000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700136 0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f,
137
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200138 // 0x259: 0x7f030001 -> 0x7f030002
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700139 0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f};
140
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200141const unsigned int idmap_raw_data_len = 0x261;
Mårten Kongstad02751232018-04-27 13:16:32 +0200142
Mårten Kongstadb8779022018-11-29 09:53:17 +0100143std::string GetTestDataPath();
Mårten Kongstad02751232018-04-27 13:16:32 +0200144
145class Idmap2Tests : public testing::Test {
146 protected:
Mårten Kongstadcb85d9c2018-12-21 08:28:40 +0100147 void SetUp() override {
Mårten Kongstad02751232018-04-27 13:16:32 +0200148#ifdef __ANDROID__
149 tmp_dir_path_ = "/data/local/tmp/idmap2-tests-XXXXXX";
150#else
151 tmp_dir_path_ = "/tmp/idmap2-tests-XXXXXX";
152#endif
153 EXPECT_NE(mkdtemp(const_cast<char*>(tmp_dir_path_.c_str())), nullptr)
154 << "Failed to create temporary directory: " << strerror(errno);
155 target_apk_path_ = GetTestDataPath() + "/target/target.apk";
156 overlay_apk_path_ = GetTestDataPath() + "/overlay/overlay.apk";
157 idmap_path_ = tmp_dir_path_ + "/a.idmap";
158 }
159
Mårten Kongstadcb85d9c2018-12-21 08:28:40 +0100160 void TearDown() override {
Mårten Kongstad02751232018-04-27 13:16:32 +0200161 EXPECT_EQ(rmdir(tmp_dir_path_.c_str()), 0)
162 << "Failed to remove temporary directory " << tmp_dir_path_ << ": " << strerror(errno);
163 }
164
165 const std::string& GetTempDirPath() {
166 return tmp_dir_path_;
167 }
168
169 const std::string& GetTargetApkPath() {
170 return target_apk_path_;
171 }
172
173 const std::string& GetOverlayApkPath() {
174 return overlay_apk_path_;
175 }
176
177 const std::string& GetIdmapPath() {
178 return idmap_path_;
179 }
180
181 private:
182 std::string tmp_dir_path_;
183 std::string target_apk_path_;
184 std::string overlay_apk_path_;
185 std::string idmap_path_;
186};
187
Mårten Kongstad0eba72a2018-11-29 08:23:14 +0100188} // namespace android::idmap2
Mårten Kongstad02751232018-04-27 13:16:32 +0200189
190#endif // IDMAP2_TESTS_TESTHELPERS_H_