aoc-2025/libguf/test/test_dbuf.hpp
2025-12-23 21:13:41 +01:00

70 lines
1.7 KiB
C++
Executable File

#pragma once
#include <vector>
#include "test.hpp"
extern "C"
{
#include "guf_alloc_libc.h"
#include "impls/dbuf_impl.h"
}
struct DbufIntTest : public Test
{
DbufIntTest(const std::string& nm) : Test(nm)
{
allocator_ctx.zero_init = false;
guf_alloc_tracker_init(&allocator_ctx.tracker, 1, "DbufIntTest_allocator", NULL, NULL);
guf_libc_allocator_init(&allocator, &allocator_ctx);
}
void run() override;
private:
guf_allocator allocator;
guf_libc_alloc_ctx allocator_ctx;
std::vector<int> dbuf_to_vec(dbuf_int *dbuf);
void test_push(dbuf_int *dbuf, int n);
void test_insert_remove(int n);
};
struct DbufCstringTest : public Test
{
DbufCstringTest(std::string nm) : Test(nm)
{
allocator_ctx.zero_init = false;
guf_alloc_tracker_init(&allocator_ctx.tracker, 2, "DbufCstringTest_allocator", NULL, NULL);
guf_libc_allocator_init(&allocator, &allocator_ctx);
}
void run() override;
private:
guf_allocator allocator;
guf_libc_alloc_ctx allocator_ctx;
void test_iter(std::vector<std::string>& str_vec, dbuf_heap_cstr *str_dbuf, int step = 1);
void test_push_insert_erase(int n, ptrdiff_t start_cap = 0);
void test_find(int n = 32);
};
struct DbufStrTest : public Test
{
DbufStrTest(std::string nm) : Test(nm)
{
allocator_ctx.zero_init = false;
guf_alloc_tracker_init(&allocator_ctx.tracker, 3, "DbufStrTest_allocator", NULL, NULL);
guf_libc_allocator_init(&allocator, &allocator_ctx);
}
void run() override;
private:
guf_allocator allocator;
guf_libc_alloc_ctx allocator_ctx;
void test_push_insert_erase(size_t n, ptrdiff_t start_cap = 0);
};