blob: d0a8e3db8ecae3444bb427243a98b57dda07c8da [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
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070033 0x05, 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 Mitchella7070132020-05-13 14:17:52 -070041 // 0x10: fulfilled policies
42 0x11, 0x00, 0x00, 0x00,
43
44 // 0x14: enforce overlayable
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070045 0x01, 0x00, 0x00, 0x00,
Ryan Mitchella7070132020-05-13 14:17:52 -070046
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070047 // 0x18: target path "targetX.apk"
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070048 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020049 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070065 // 0x118: overlay path "overlayX.apk"
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070066 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020067 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070083 // 0x218: debug string
84 // string length,
85 0x05, 0x00, 0x00, 0x00,
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020086
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070087 // 0x21c string contents "debug\0\0\0" (padded to word alignment)
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020088 0x64, 0x65, 0x62, 0x75, 0x67, 0x00, 0x00, 0x00,
89
Mårten Kongstad02751232018-04-27 13:16:32 +020090 // DATA HEADER
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070091 // 0x224: target_package_id
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070092 0x7f,
Mårten Kongstad02751232018-04-27 13:16:32 +020093
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070094 // 0x225: overlay_package_id
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070095 0x7f,
Mårten Kongstad02751232018-04-27 13:16:32 +020096
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070097 // 0x226: padding
98 0x00, 0x00,
99
100 // 0x228: target_entry_count
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700101 0x03, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +0200102
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700103 // 0x22c: target_inline_entry_count
104 0x01, 0x00, 0x00, 0x00,
105
106 // 0x230: overlay_entry_count
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700107 0x03, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +0200108
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700109 // 0x234: string_pool_offset
Mårten Kongstad02751232018-04-27 13:16:32 +0200110 0x00, 0x00, 0x00, 0x00,
111
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700112 // TARGET ENTRIES
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700113 // 0x238: target id (0x7f020000)
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700114 0x00, 0x00, 0x02, 0x7f,
115
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700116 // 0x23c: overlay_id (0x7f020000)
Ryan Mitchella7070132020-05-13 14:17:52 -0700117 0x00, 0x00, 0x02, 0x7f,
118
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700119 // 0x240: target id (0x7f030000)
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700120 0x00, 0x00, 0x03, 0x7f,
121
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700122 // 0x244: overlay_id (0x7f030000)
Ryan Mitchella7070132020-05-13 14:17:52 -0700123 0x00, 0x00, 0x03, 0x7f,
124
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700125 // 0x248: target id (0x7f030002)
Ryan Mitchella7070132020-05-13 14:17:52 -0700126 0x02, 0x00, 0x03, 0x7f,
127
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700128 // 0x24c: overlay_id (0x7f030001)
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700129 0x01, 0x00, 0x03, 0x7f,
130
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700131 // INLINE TARGET ENTRIES
132
133 // 0x250: target_id
134 0x00, 0x00, 0x04, 0x7f,
135
136 // 0x254: Res_value::size (value ignored by idmap)
137 0x08, 0x00,
138
139 // 0x256: Res_value::res0 (value ignored by idmap)
140 0x00,
141
142 // 0x257: Res_value::dataType (TYPE_INT_HEX)
143 0x11,
144
145 // 0x258: Res_value::data
146 0x78, 0x56, 0x34, 0x12,
147
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700148 // OVERLAY ENTRIES
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700149 // 0x25c: 0x7f020000 -> 0x7f020000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700150 0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f,
151
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700152 // 0x264: 0x7f030000 -> 0x7f030000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700153 0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f,
154
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700155 // 0x26c: 0x7f030001 -> 0x7f030002
156 0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f,
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700157
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700158 // 0x274: string pool
159 // string length,
160 0x04, 0x00, 0x00, 0x00,
161
162 // 0x278 string contents "test" (padded to word alignment)
163 0x74, 0x65, 0x73, 0x74};
164
165const unsigned int idmap_raw_data_len = 0x27c;
Mårten Kongstad02751232018-04-27 13:16:32 +0200166
Mårten Kongstadb8779022018-11-29 09:53:17 +0100167std::string GetTestDataPath();
Mårten Kongstad02751232018-04-27 13:16:32 +0200168
169class Idmap2Tests : public testing::Test {
170 protected:
Mårten Kongstadcb85d9c2018-12-21 08:28:40 +0100171 void SetUp() override {
Mårten Kongstad02751232018-04-27 13:16:32 +0200172#ifdef __ANDROID__
173 tmp_dir_path_ = "/data/local/tmp/idmap2-tests-XXXXXX";
174#else
175 tmp_dir_path_ = "/tmp/idmap2-tests-XXXXXX";
176#endif
177 EXPECT_NE(mkdtemp(const_cast<char*>(tmp_dir_path_.c_str())), nullptr)
178 << "Failed to create temporary directory: " << strerror(errno);
179 target_apk_path_ = GetTestDataPath() + "/target/target.apk";
180 overlay_apk_path_ = GetTestDataPath() + "/overlay/overlay.apk";
181 idmap_path_ = tmp_dir_path_ + "/a.idmap";
182 }
183
Mårten Kongstadcb85d9c2018-12-21 08:28:40 +0100184 void TearDown() override {
Mårten Kongstad02751232018-04-27 13:16:32 +0200185 EXPECT_EQ(rmdir(tmp_dir_path_.c_str()), 0)
186 << "Failed to remove temporary directory " << tmp_dir_path_ << ": " << strerror(errno);
187 }
188
189 const std::string& GetTempDirPath() {
190 return tmp_dir_path_;
191 }
192
193 const std::string& GetTargetApkPath() {
194 return target_apk_path_;
195 }
196
197 const std::string& GetOverlayApkPath() {
198 return overlay_apk_path_;
199 }
200
201 const std::string& GetIdmapPath() {
202 return idmap_path_;
203 }
204
205 private:
206 std::string tmp_dir_path_;
207 std::string target_apk_path_;
208 std::string overlay_apk_path_;
209 std::string idmap_path_;
210};
211
Mårten Kongstad0eba72a2018-11-29 08:23:14 +0100212} // namespace android::idmap2
Mårten Kongstad02751232018-04-27 13:16:32 +0200213
214#endif // IDMAP2_TESTS_TESTHELPERS_H_