#include "elf.h" #include "minicc.h" #include #include "gmock/gmock.h" #include "gtest/gtest.h" #include #include #include #include #include #include #include #include #include using namespace std::string_literals; namespace fs = std::filesystem; class ElfTest: public ::testing::Test { protected: ElfTest() { //debug = true; } ~ElfTest() { } fs::path TempFilename(){return "tempfile.txt";} void SetUp(){ std::error_code ec; fs::remove(TempFilename(), ec); } void TearDown(){ std::error_code ec; //fs::remove(TempFilename(), ec); } }; #if 0 TEST_F(ElfTest, read) { } #endif TEST_F(ElfTest, write) { Elf::Write(TempFilename(), { 0x48, 0xc7, 0xc0, 0x3c, 0x00, 0x00, 0x00, // mov $0x3c,%rax # syscall 60 0x48, 0x31, 0xff, // xor %rdi,%rdi # exit code 0 0x0f, 0x05, // syscall }); ASSERT_TRUE(fs::exists(TempFilename())); ASSERT_GT(fs::file_size(TempFilename()), 0); }