libguf/src/test/test.cpp
2025-05-14 17:37:19 +02:00

63 lines
1.7 KiB
C++

#include <vector>
#include <string>
#include <cstdio>
#include <iostream>
#include "test_dbuf.hpp"
#include "test_dict.hpp"
#include "test_utf8.hpp"
#include "test_str.hpp"
#include "test_ckdint.hpp"
extern "C"
{
#include "guf_assert.h"
#include "guf_math.h"
}
static std::vector<std::unique_ptr<Test>> g_tests {};
static void init_tests()
{
g_tests.push_back(std::make_unique<DbufIntTest>("DbufIntTest"));
g_tests.push_back(std::make_unique<DbufCstringTest>("DbufCstringTest"));
g_tests.push_back(std::make_unique<DictSvToIntTest>("DictSvToIntTest"));
g_tests.push_back(std::make_unique<UTF8Test>("UTF8Test"));
g_tests.push_back(std::make_unique<StrTest>("StrTest"));
g_tests.push_back(std::make_unique<CkdIntTest>("CkdIntTest"));
}
int main()
{
init_tests();
std::cout << "Running " << g_tests.size() << " tests...\n";
// std::cout << "max cap 1:" << dict_sv_i32_max_capacity() << "\n";
// std::cout << "max cap 2:" << dict_cstr_int_max_capacity() << "\n";
size_t num_passed = 0;
for (auto &test : g_tests) {
Test *tst = test.get();
GUF_ASSERT_RELEASE(tst);
tst->before_run();
tst->run();
tst->after_run();
std::cout << "- " << *tst << "\n";
if (tst->passed) {
++num_passed;
}
}
const bool passed_all = (num_passed == g_tests.size());
GUF_ASSERT_RELEASE(num_passed <= g_tests.size());
if (passed_all) {
std::cout << "-> SUCCESS: Passed all (" << num_passed << "/" << g_tests.size() << ") tests.\n";
} else {
std::cout << "-> FAILURE: Failed " << (g_tests.size() - num_passed) << "/" << g_tests.size() << " tests.\n";
}
return passed_all ? EXIT_SUCCESS : EXIT_FAILURE;
}