51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
#include "format/vlc_format.hpp"
|
|
#include "reader.hpp"
|
|
#include "writer.hpp"
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
|
|
namespace fs = std::filesystem;
|
|
using namespace voidlibc::format;
|
|
using namespace voidlibc::voidlink;
|
|
|
|
namespace {
|
|
|
|
#define EXPECT(cond) do { \
|
|
if (!(cond)) { \
|
|
std::fprintf(stderr, "FAIL: %s (line %d)\n", #cond, \
|
|
__LINE__); \
|
|
std::exit(1); \
|
|
} \
|
|
} while (0)
|
|
|
|
int run() {
|
|
const fs::path tmp = fs::temp_directory_path() / "voidlibc_roundtrip.vlc";
|
|
fs::remove(tmp);
|
|
|
|
{
|
|
const auto w = write_empty(tmp);
|
|
EXPECT(w.ok);
|
|
}
|
|
{
|
|
const auto r = read_container(tmp);
|
|
const auto* container = std::get_if<Container>(&r);
|
|
EXPECT(container != nullptr);
|
|
EXPECT(container->header.magic == kMagic);
|
|
EXPECT(container->header.version_major == kVersionMajor);
|
|
EXPECT(container->header.version_minor == kVersionMinor);
|
|
EXPECT(container->header.arch == TargetArch::X86_64);
|
|
EXPECT(container->header.section_count == 0);
|
|
EXPECT(container->header.file_size == sizeof(FileHeader));
|
|
EXPECT(container->actual_file_size == sizeof(FileHeader));
|
|
}
|
|
fs::remove(tmp);
|
|
std::printf("PASS: format_roundtrip\n");
|
|
return 0;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main() { return run(); }
|