summaryrefslogtreecommitdiff
path: root/tests/test_aichat.c
blob: 4ef1c2c10f1ae9ee42397d34789bb2df9a173979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
}
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com