#include "hybbx/aichat.h" #include "hybbx/config.h" #include #include #include 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; }