diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | tests/test_aichat.c | 74 |
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 882aa94..bb0ce56 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,8 +26,12 @@ hybbx_add_instance_test(hybbx_test_instance_secondary hybbx_add_instance_test(hybbx_test_instance_proxy ${CMAKE_SOURCE_DIR}/src/instance_role_proxy.c) +add_executable(hybbx_test_aichat test_aichat.c) +target_link_libraries(hybbx_test_aichat PRIVATE hybbx_core hybbx_plugin_mains_proxy hybbx_plugin_packet_radio) + add_test(NAME util COMMAND hybbx_test_util) add_test(NAME config COMMAND hybbx_test_config) +add_test(NAME aichat COMMAND hybbx_test_aichat) add_test(NAME mains_proxy COMMAND hybbx_test_mains_proxy) add_test(NAME mains_proxy_e2e COMMAND hybbx_test_mains_proxy_e2e $<TARGET_FILE:hybbxd>) add_test(NAME storage_smoke COMMAND hybbx_test_storage_smoke) diff --git a/tests/test_aichat.c b/tests/test_aichat.c new file mode 100644 index 0000000..4ef1c2c --- /dev/null +++ b/tests/test_aichat.c @@ -0,0 +1,74 @@ +#include "hybbx/aichat.h" +#include "hybbx/config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static unsigned g_failures; + +static void check_str(const char *label, const char *got, const char *want) +{ + if (got == NULL || want == NULL || strcmp(got, want) != 0) { + fprintf(stderr, "FAIL %s: got '%s' want '%s'\n", + label, got != NULL ? got : "(null)", want); + g_failures++; + } +} + +static void check_int(const char *label, int got, int want) +{ + if (got != want) { + fprintf(stderr, "FAIL %s: got %d want %d\n", label, got, want); + g_failures++; + } +} + +int main(void) +{ + hybbx_config_t cfg; + hybbx_aichat_config_t ai_cfg; + const char *path = "hybbx_test_aichat.ini"; + FILE *fp; + + fp = fopen(path, "w"); + if (fp == NULL) { + fprintf(stderr, "FAIL fopen\n"); + return 1; + } + + fputs("[aichat]\n", fp); + fputs("enabled = yes\n", fp); + fputs("provider = openrouter\n", fp); + fputs("api_key = test_key_12345\n", fp); + fputs("model = meta-llama/llama-3.2-11b-vision-instruct:free\n", fp); + fputs("max_tokens = 250\n", fp); + fputs("rate_limit_per_user_hour = 10\n", fp); + fclose(fp); + + if (hybbx_config_load(&cfg, path) != HYBBX_OK) { + fprintf(stderr, "FAIL config load\n"); + remove(path); + return 1; + } + + hybbx_aichat_config_init(&ai_cfg, &cfg); + + check_int("aichat.enabled", ai_cfg.enabled, 1); + check_str("aichat.provider", ai_cfg.provider, "openrouter"); + check_str("aichat.api_key", ai_cfg.api_key, "test_key_12345"); + check_str("aichat.model", ai_cfg.model, "meta-llama/llama-3.2-11b-vision-instruct:free"); + check_int("aichat.max_tokens", (int)ai_cfg.max_tokens, 250); + check_int("aichat.rate_limit_per_user_hour", (int)ai_cfg.rate_limit_per_user_hour, 10); + + hybbx_config_free(&cfg); + remove(path); + + if (g_failures != 0) { + fprintf(stderr, "%u failure(s)\n", g_failures); + return 1; + } + + puts("test_aichat: ok"); + return 0; +} |
