diff options
| author | info@mode42.com <info@mode42.com> | 2026-08-09 14:56:03 +0000 |
|---|---|---|
| committer | info@mode42.com <info@mode42.com> | 2026-08-09 14:56:03 +0000 |
| commit | 12c15060e7266bf53d5879a9e6f7f581de8e808e (patch) | |
| tree | 4b338b00a0fd060cbe890de1fe3fc161600ffc57 /tests/test_aichat.c | |
| parent | 7815183927ecb914de430a5d64f9df27a48f49ae (diff) | |
Diffstat (limited to 'tests/test_aichat.c')
| -rw-r--r-- | tests/test_aichat.c | 74 |
1 files changed, 74 insertions, 0 deletions
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; +} |
