commit
bba5c8a39a
109 files changed
+14085
No files matched your search
@@ -0,0 +1,15 @@
|
||||
add_executable(test_format_roundtrip roundtrip.cpp)
|
||||
target_link_libraries(test_format_roundtrip PRIVATE voidlibc_format)
|
||||
target_include_directories(test_format_roundtrip
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/voidlink
|
||||
)
|
||||
# Pick up writer/reader sources directly — these are small and tests are
|
||||
# the only consumer outside the voidlink binary.
|
||||
target_sources(test_format_roundtrip PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/voidlink/writer.cpp
|
||||
${CMAKE_SOURCE_DIR}/voidlink/reader.cpp
|
||||
)
|
||||
add_test(NAME format_roundtrip COMMAND test_format_roundtrip)
|
||||
set_tests_properties(format_roundtrip PROPERTIES LABELS "format;unit")
|
||||
@@ -0,0 +1,50 @@
|
||||
#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(); }
|
||||
Reference in new issue
Block a user