File: t_radmsg.c

package info (click to toggle)
radsecproxy 1.11.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,420 kB
  • sloc: ansic: 12,097; sh: 1,963; makefile: 84
file content (52 lines) | stat: -rw-r--r-- 1,169 bytes parent folder | download | duplicates (2)
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
/* Copyright (C) 2023, SWITCH */
/* See LICENSE for licensing information. */

#include "../radmsg.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int numtests = 0;

void test_radlen(uint8_t *buf, int expected, char *msg) {
    int actual = get_checked_rad_length(buf);

    if (actual != expected)
        printf("not ");
    printf("ok %d - radlen %s (expected %d, got %d)\n", ++numtests, msg, expected, actual);
}

int main(int argc, char *argv[]) {
    {
        uint8_t buf[] = {0x0c, 0x00, 0x00, 0x2a};
        test_radlen(buf, 42, "basic length test");
    }

    {
        uint8_t buf[] = {0x0c, 0x00, 0x00, 0x14};
        test_radlen(buf, 20, "lower bound");
    }

    {
        uint8_t buf[] = {0x0c, 0x00, 0x10, 0x00};
        test_radlen(buf, 4096, "upper bound");
    }

    {
        uint8_t buf[] = {0x0c, 0x00, 0x00, 0x13};
        test_radlen(buf, -19, "too small");
    }

    {
        uint8_t buf[] = {0x0c, 0x00, 0x10, 0x01};
        test_radlen(buf, -4097, "too big");
    }

    {
        uint8_t buf[] = {0x0c, 0x00, 0x00, 0x00};
        test_radlen(buf, 0, "zero");
    }

    printf("1..%d\n", numtests);
}