~donmcc/ood

ref: 1182412fd4ece0cb55c4b3ebefee78b22c8c15bd ood/src/libood/ood/sockaddr_in_test.c -rw-r--r-- 937 bytes
1182412fDon McCaughey Add `ood_halt()` function. 7 months ago
                                                                                
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
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "ood.h"


static void
test_sockaddr_in_alloc_formatted(void)
{
    struct sockaddr_in address = {
            .sin_family = AF_INET,
            .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
            .sin_port = htons(80),
    };
    char *formatted = ood_sockaddr_in_alloc_formatted(&address);
    assert(0 == strcmp("127.0.0.1:80", formatted));
    free(formatted);
}


static void
test_sockaddr_in_init(void)
{
    struct sockaddr_in address = {
            .sin_family = AF_UNSPEC,
    };
    struct sockaddr_in *result = ood_sockaddr_in_init(&address, INADDR_LOOPBACK, 443);

    assert(result == &address);
    assert(AF_INET == address.sin_family);
    assert(htonl(INADDR_LOOPBACK) == address.sin_addr.s_addr);
    assert(htons(443) == address.sin_port);
}


void
sockaddr_in_test(void)
{
    test_sockaddr_in_alloc_formatted();
    test_sockaddr_in_init();
}