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