| 1 |
//===-- ZipFileResolverTest.cpp -------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "lldb/Host/common/ZipFileResolver.h" |
| 10 |
#include "TestingSupport/SubsystemRAII.h" |
| 11 |
#include "TestingSupport/TestUtilities.h" |
| 12 |
#include "gtest/gtest.h" |
| 13 |
|
| 14 |
using namespace lldb_private; |
| 15 |
using namespace llvm; |
| 16 |
|
| 17 |
namespace { |
| 18 |
class ZipFileResolverTest : public ::testing::Test { |
| 19 |
SubsystemRAII<FileSystem> subsystems; |
| 20 |
}; |
| 21 |
|
| 22 |
std::string TestZipPath() { |
| 23 |
FileSpec zip_spec(GetInputFilePath("zip-test.zip")); |
| 24 |
FileSystem::Instance().Resolve(zip_spec); |
| 25 |
return zip_spec.GetPath(); |
| 26 |
} |
| 27 |
} // namespace |
| 28 |
|
| 29 |
TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithNormalFile) { |
| 30 |
const FileSpec file_spec("/system/lib64/libtest.so"); |
| 31 |
|
| 32 |
ZipFileResolver::FileKind file_kind; |
| 33 |
std::string file_path; |
| 34 |
lldb::offset_t file_offset; |
| 35 |
lldb::offset_t file_size; |
| 36 |
ASSERT_TRUE(ZipFileResolver::ResolveSharedLibraryPath( |
| 37 |
file_spec, file_kind, file_path, file_offset, file_size)); |
| 38 |
|
| 39 |
EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindNormal); |
| 40 |
EXPECT_EQ(file_path, file_spec.GetPath()); |
| 41 |
EXPECT_EQ(file_offset, 0UL); |
| 42 |
EXPECT_EQ(file_size, 0UL); |
| 43 |
} |
| 44 |
|
| 45 |
TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithZipMissing) { |
| 46 |
const std::string zip_path = TestZipPath(); |
| 47 |
const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libmissing.so"); |
| 48 |
|
| 49 |
ZipFileResolver::FileKind file_kind; |
| 50 |
std::string file_path; |
| 51 |
lldb::offset_t file_offset; |
| 52 |
lldb::offset_t file_size; |
| 53 |
ASSERT_FALSE(ZipFileResolver::ResolveSharedLibraryPath( |
| 54 |
file_spec, file_kind, file_path, file_offset, file_size)); |
| 55 |
} |
| 56 |
|
| 57 |
TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithZipExisting) { |
| 58 |
const std::string zip_path = TestZipPath(); |
| 59 |
const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libzip-test.so"); |
| 60 |
|
| 61 |
ZipFileResolver::FileKind file_kind; |
| 62 |
std::string file_path; |
| 63 |
lldb::offset_t file_offset; |
| 64 |
lldb::offset_t file_size; |
| 65 |
ASSERT_TRUE(ZipFileResolver::ResolveSharedLibraryPath( |
| 66 |
file_spec, file_kind, file_path, file_offset, file_size)); |
| 67 |
|
| 68 |
EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindZip); |
| 69 |
EXPECT_EQ(file_path, zip_path); |
| 70 |
EXPECT_EQ(file_offset, 4096UL); |
| 71 |
EXPECT_EQ(file_size, 3600UL); |
| 72 |
} |