37 lines
989 B
C++
37 lines
989 B
C++
#include <Void/Storage/Storage.hpp>
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <unistd.h>
|
|
|
|
int main()
|
|
{
|
|
if (Void::Storage::crc32c(std::string_view{"123456789"}) != 0xE3069283u) {
|
|
return 1;
|
|
}
|
|
const auto dir = std::filesystem::temp_directory_path() /
|
|
("void-storage-pkg-" + std::to_string(::getpid()));
|
|
std::error_code ec;
|
|
std::filesystem::remove_all(dir, ec);
|
|
|
|
Void::Storage::OpenOptions opts;
|
|
opts.directory = dir;
|
|
auto eng = Void::Storage::Engine::open(opts);
|
|
if (!eng) return 2;
|
|
|
|
Void::Storage::Batch b;
|
|
b.require_absent("hello").put("hello", "world");
|
|
auto wr = eng->write(std::move(b), Void::Storage::Durability::Sync);
|
|
if (!wr) return 3;
|
|
|
|
auto snap = eng->snapshot();
|
|
if (!snap) return 4;
|
|
auto val = eng->get(*snap, "hello");
|
|
const bool ok = val && val->as_string_view() == "world" && val->version == wr->sequence;
|
|
snap->reset();
|
|
const bool closed = eng->close().has_value();
|
|
|
|
std::filesystem::remove_all(dir, ec);
|
|
return (ok && closed) ? 0 : 5;
|
|
}
|