-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathtest_elf_file.cpp
More file actions
67 lines (50 loc) · 2.24 KB
/
test_elf_file.cpp
File metadata and controls
67 lines (50 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "linuxdeploy/core/elf_file.h"
using namespace std;
using namespace linuxdeploy::core;
namespace fs = std::filesystem;
using namespace std;
using namespace linuxdeploy::core::elf_file;
namespace {
typedef std::function<void()> callback_t;
template<typename T>
void expectThrowMessageHasSubstr(const callback_t& callback, const char* message) {
EXPECT_THAT(callback, ::testing::ThrowsMessage<ElfFileParseError>(::testing::HasSubstr(message)));
}
void expectElfFileConstructorThrowMessage(const char* path, const char* message) {
return expectThrowMessageHasSubstr<ElfFileParseError>([=]() { ElfFile{path}; }, message);
}
void expectThrowsElfFileErrorInvalidElfHeader(const char* path) {
expectElfFileConstructorThrowMessage(path, "Invalid magic bytes in file header");
}
void expectThrowsElfFileErrorFileNotFound(const char* path) {
expectElfFileConstructorThrowMessage(path, "No such file or directory: ");
}
}
namespace LinuxDeployTest {
class ElfFileTest : public ::testing::Test {};
TEST_F(ElfFileTest, checkIsDebugSymbolsFile) {
ElfFile debugSymbolsFile(SIMPLE_LIBRARY_DEBUG_PATH);
EXPECT_TRUE(debugSymbolsFile.isDebugSymbolsFile());
ElfFile regularLibraryFile(SIMPLE_LIBRARY_PATH);
EXPECT_FALSE(regularLibraryFile.isDebugSymbolsFile());
}
TEST_F(ElfFileTest, checkIsDynamicallyLinked) {
ElfFile regularLibraryFile(SIMPLE_EXECUTABLE_PATH);
EXPECT_TRUE(regularLibraryFile.isDynamicallyLinked());
ElfFile staticLibraryFile(SIMPLE_EXECUTABLE_STATIC_PATH);
EXPECT_FALSE(staticLibraryFile.isDynamicallyLinked());
}
TEST_F(ElfFileTest, checkInvalidElfHeaderOnEmptyFile) {
expectThrowsElfFileErrorInvalidElfHeader("/dev/null");
}
TEST_F(ElfFileTest, checkInvalidElfHeaderOnRandomFiles) {
expectThrowsElfFileErrorInvalidElfHeader(SIMPLE_DESKTOP_ENTRY_PATH);
expectThrowsElfFileErrorInvalidElfHeader(SIMPLE_ICON_PATH);
expectThrowsElfFileErrorInvalidElfHeader(SIMPLE_FILE_PATH);
}
TEST_F(ElfFileTest, checkFileNotFound) {
expectThrowsElfFileErrorFileNotFound("/abc/def/ghi/jkl/mno/pqr/stu/vwx/yz");
}
}