blob: 45740e2d5a9e86dc41aaaad9142b47ca711caa4a [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
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080027const unsigned char kIdmapRawData[] = {
Mårten Kongstad02751232018-04-27 13:16:32 +020028 // IDMAP HEADER
29 // 0x0: magic
30 0x49, 0x44, 0x4d, 0x50,
31
32 // 0x4: version
Jeremy Meyerbe2b7792022-08-23 17:42:50 +000033 0x09, 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 Mitchell0699f1d2020-12-03 15:41:42 -080047 // 0x18: target path length
48 0x0b, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020049
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080050 // 0x1c: target path "targetX.apk"
51 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020052
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080053 // 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 Mitchell30dc2e02020-12-02 11:43:18 -080059 // 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 Mitchellbf1f45b2020-09-29 17:22:52 -070066 // string length,
67 0x05, 0x00, 0x00, 0x00,
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020068
Ryan Mitchell30dc2e02020-12-02 11:43:18 -080069 // 0x4c string contents "debug\0\0\0" (padded to word alignment)
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020070 0x64, 0x65, 0x62, 0x75, 0x67, 0x00, 0x00, 0x00,
71
Mårten Kongstad02751232018-04-27 13:16:32 +020072 // DATA HEADER
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080073 // 0x54: target_entry_count
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070074 0x03, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020075
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080076 // 0x58: target_inline_entry_count
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070077 0x01, 0x00, 0x00, 0x00,
78
Jeremy Meyerbe2b7792022-08-23 17:42:50 +000079 // 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 Mitchelle753ffe2019-09-23 09:47:02 -070086 0x03, 0x00, 0x00, 0x00,
Mårten Kongstad02751232018-04-27 13:16:32 +020087
Jeremy Meyerbe2b7792022-08-23 17:42:50 +000088 // 0x68: string_pool_offset
Mårten Kongstad02751232018-04-27 13:16:32 +020089 0x00, 0x00, 0x00, 0x00,
90
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070091 // TARGET ENTRIES
Jeremy Meyerbe2b7792022-08-23 17:42:50 +000092 // 0x6c: target id (0x7f020000)
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070093 0x00, 0x00, 0x02, 0x7f,
94
Jeremy Meyerbe2b7792022-08-23 17:42:50 +000095 // 0x70: overlay_id (0x7f020000)
Ryan Mitchella7070132020-05-13 14:17:52 -070096 0x00, 0x00, 0x02, 0x7f,
97
Jeremy Meyerbe2b7792022-08-23 17:42:50 +000098 // 0x74: target id (0x7f030000)
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070099 0x00, 0x00, 0x03, 0x7f,
100
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000101 // 0x78: overlay_id (0x7f030000)
Ryan Mitchella7070132020-05-13 14:17:52 -0700102 0x00, 0x00, 0x03, 0x7f,
103
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000104 // 0x7c: target id (0x7f030002)
Ryan Mitchella7070132020-05-13 14:17:52 -0700105 0x02, 0x00, 0x03, 0x7f,
106
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000107 // 0x80: overlay_id (0x7f030001)
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700108 0x01, 0x00, 0x03, 0x7f,
109
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700110 // INLINE TARGET ENTRIES
111
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000112 // 0x84: target_id
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700113 0x00, 0x00, 0x04, 0x7f,
114
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000115 // 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 Mitchellbf1f45b2020-09-29 17:22:52 -0700127 0x08, 0x00,
128
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000129 // 0x98: Res_value::res0 (value ignored by idmap)
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700130 0x00,
131
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000132 // 0x9c: Res_value::dataType (TYPE_INT_HEX)
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700133 0x11,
134
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000135 // 0xa0: Res_value::data
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700136 0x78, 0x56, 0x34, 0x12,
137
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000138 // 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 Mitchelle753ffe2019-09-23 09:47:02 -0700178 // OVERLAY ENTRIES
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000179 // 0xe4: 0x7f020000 -> 0x7f020000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700180 0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f,
181
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000182 // 0xec: 0x7f030000 -> 0x7f030000
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700183 0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f,
184
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000185 // 0xf4: 0x7f030001 -> 0x7f030002
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700186 0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f,
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700187
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000188 // 0xfc: string pool
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700189 // string length,
190 0x04, 0x00, 0x00, 0x00,
191
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000192 // 0x100 string contents "test"
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700193 0x74, 0x65, 0x73, 0x74};
194
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000195const unsigned int kIdmapRawDataLen = 0x104;
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800196const unsigned int kIdmapRawDataOffset = 0x54;
197const unsigned int kIdmapRawDataTargetCrc = 0x1234;
198const unsigned int kIdmapRawOverlayCrc = 0x5678;
199const unsigned int kIdmapRawDataPolicies = 0x11;
200inline const std::string kIdmapRawTargetPath = "targetX.apk";
201inline const std::string kIdmapRawOverlayPath = "overlayX.apk";
202inline const std::string kIdmapRawOverlayName = "OverlayName";
Mårten Kongstad02751232018-04-27 13:16:32 +0200203
Mårten Kongstadb8779022018-11-29 09:53:17 +0100204std::string GetTestDataPath();
Mårten Kongstad02751232018-04-27 13:16:32 +0200205
206class Idmap2Tests : public testing::Test {
207 protected:
Mårten Kongstadcb85d9c2018-12-21 08:28:40 +0100208 void SetUp() override {
Mårten Kongstad02751232018-04-27 13:16:32 +0200209#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 Kongstadcb85d9c2018-12-21 08:28:40 +0100221 void TearDown() override {
Mårten Kongstad02751232018-04-27 13:16:32 +0200222 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 Kongstad0eba72a2018-11-29 08:23:14 +0100249} // namespace android::idmap2
Mårten Kongstad02751232018-04-27 13:16:32 +0200250
251#endif // IDMAP2_TESTS_TESTHELPERS_H_