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