| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef IDMAP2_TESTS_TESTHELPERS_H_ |
| 18 |
#define IDMAP2_TESTS_TESTHELPERS_H_ |
| 19 |
|
| 20 |
#include <string> |
| 21 |
|
| 22 |
#include "gmock/gmock.h" |
| 23 |
#include "gtest/gtest.h" |
| 24 |
|
| 25 |
namespace android::idmap2 { |
| 26 |
|
| 27 |
const unsigned char kIdmapRawData[] = { |
| 28 |
|
| 29 |
|
| 30 |
0x49, 0x44, 0x4d, 0x50, |
| 31 |
|
| 32 |
|
| 33 |
0x08, 0x00, 0x00, 0x00, |
| 34 |
|
| 35 |
|
| 36 |
0x34, 0x12, 0x00, 0x00, |
| 37 |
|
| 38 |
|
| 39 |
0x78, 0x56, 0x00, 0x00, |
| 40 |
|
| 41 |
|
| 42 |
0x11, 0x00, 0x00, 0x00, |
| 43 |
|
| 44 |
|
| 45 |
0x01, 0x00, 0x00, 0x00, |
| 46 |
|
| 47 |
|
| 48 |
0x0b, 0x00, 0x00, 0x00, |
| 49 |
|
| 50 |
|
| 51 |
0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, |
| 52 |
|
| 53 |
|
| 54 |
0x0c, 0x00, 0x00, 0x00, |
| 55 |
|
| 56 |
|
| 57 |
0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x58, 0x2e, 0x61, 0x70, 0x6b, |
| 58 |
|
| 59 |
|
| 60 |
0x0b, 0x00, 0x00, 0x00, |
| 61 |
|
| 62 |
|
| 63 |
0x4f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6D, 0x65, 0x00, |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
0x05, 0x00, 0x00, 0x00, |
| 68 |
|
| 69 |
|
| 70 |
0x64, 0x65, 0x62, 0x75, 0x67, 0x00, 0x00, 0x00, |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
0x03, 0x00, 0x00, 0x00, |
| 75 |
|
| 76 |
|
| 77 |
0x01, 0x00, 0x00, 0x00, |
| 78 |
|
| 79 |
|
| 80 |
0x03, 0x00, 0x00, 0x00, |
| 81 |
|
| 82 |
|
| 83 |
0x00, 0x00, 0x00, 0x00, |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
0x00, 0x00, 0x02, 0x7f, |
| 88 |
|
| 89 |
|
| 90 |
0x00, 0x00, 0x02, 0x7f, |
| 91 |
|
| 92 |
|
| 93 |
0x00, 0x00, 0x03, 0x7f, |
| 94 |
|
| 95 |
|
| 96 |
0x00, 0x00, 0x03, 0x7f, |
| 97 |
|
| 98 |
|
| 99 |
0x02, 0x00, 0x03, 0x7f, |
| 100 |
|
| 101 |
|
| 102 |
0x01, 0x00, 0x03, 0x7f, |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
0x00, 0x00, 0x04, 0x7f, |
| 108 |
|
| 109 |
|
| 110 |
0x08, 0x00, |
| 111 |
|
| 112 |
|
| 113 |
0x00, |
| 114 |
|
| 115 |
|
| 116 |
0x11, |
| 117 |
|
| 118 |
|
| 119 |
0x78, 0x56, 0x34, 0x12, |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f, |
| 124 |
|
| 125 |
|
| 126 |
0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f, |
| 127 |
|
| 128 |
|
| 129 |
0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f, |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
0x04, 0x00, 0x00, 0x00, |
| 134 |
|
| 135 |
|
| 136 |
0x74, 0x65, 0x73, 0x74}; |
| 137 |
|
| 138 |
const unsigned int kIdmapRawDataLen = 0xa8; |
| 139 |
const unsigned int kIdmapRawDataOffset = 0x54; |
| 140 |
const unsigned int kIdmapRawDataTargetCrc = 0x1234; |
| 141 |
const unsigned int kIdmapRawOverlayCrc = 0x5678; |
| 142 |
const unsigned int kIdmapRawDataPolicies = 0x11; |
| 143 |
inline const std::string kIdmapRawTargetPath = "targetX.apk"; |
| 144 |
inline const std::string kIdmapRawOverlayPath = "overlayX.apk"; |
| 145 |
inline const std::string kIdmapRawOverlayName = "OverlayName"; |
| 146 |
|
| 147 |
std::string GetTestDataPath(); |
| 148 |
|
| 149 |
class Idmap2Tests : public testing::Test { |
| 150 |
protected: |
| 151 |
void SetUp() override { |
| 152 |
#ifdef __ANDROID__ |
| 153 |
tmp_dir_path_ = "/data/local/tmp/idmap2-tests-XXXXXX"; |
| 154 |
#else |
| 155 |
tmp_dir_path_ = "/tmp/idmap2-tests-XXXXXX"; |
| 156 |
#endif |
| 157 |
EXPECT_NE(mkdtemp(const_cast<char*>(tmp_dir_path_.c_str())), nullptr) |
| 158 |
<< "Failed to create temporary directory: " << strerror(errno); |
| 159 |
target_apk_path_ = GetTestDataPath() + "/target/target.apk"; |
| 160 |
overlay_apk_path_ = GetTestDataPath() + "/overlay/overlay.apk"; |
| 161 |
idmap_path_ = tmp_dir_path_ + "/a.idmap"; |
| 162 |
} |
| 163 |
|
| 164 |
void TearDown() override { |
| 165 |
EXPECT_EQ(rmdir(tmp_dir_path_.c_str()), 0) |
| 166 |
<< "Failed to remove temporary directory " << tmp_dir_path_ << ": " << strerror(errno); |
| 167 |
} |
| 168 |
|
| 169 |
const std::string& GetTempDirPath() { |
| 170 |
return tmp_dir_path_; |
| 171 |
} |
| 172 |
|
| 173 |
const std::string& GetTargetApkPath() { |
| 174 |
return target_apk_path_; |
| 175 |
} |
| 176 |
|
| 177 |
const std::string& GetOverlayApkPath() { |
| 178 |
return overlay_apk_path_; |
| 179 |
} |
| 180 |
|
| 181 |
const std::string& GetIdmapPath() { |
| 182 |
return idmap_path_; |
| 183 |
} |
| 184 |
|
| 185 |
private: |
| 186 |
std::string tmp_dir_path_; |
| 187 |
std::string target_apk_path_; |
| 188 |
std::string overlay_apk_path_; |
| 189 |
std::string idmap_path_; |
| 190 |
}; |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
#endif |