test_wuf_gquic_be.c revision a74702c6
1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
2#include <assert.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#ifndef WIN32
7#include <sys/time.h>
8#endif
9
10#include "lsquic.h"
11#include "lsquic_types.h"
12#include "lsquic_parse.h"
13
14//static const struct parse_funcs *const pf = select_pf_by_ver(LSQVER_043); // will not work on MSVC
15#define pf ((const struct parse_funcs *const)select_pf_by_ver(LSQVER_043))
16
17
18/* The test is both for generation and parsing: */
19struct wuf_test {
20    unsigned char   buf[0x10];
21    size_t          buf_len;
22    lsquic_stream_id_t        stream_id;
23    uint64_t        offset;
24};
25
26static const struct wuf_test wuf_tests[] = {
27    {
28        .buf            = { 0x04, 0x00, 0x67, 0x45, 0x34, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, },
29        .buf_len        = GQUIC_WUF_SZ,
30        .stream_id      = 0x674534,
31        .offset         = 0x0102030405,
32    },
33
34    {   .buf            = { 0 },    }
35};
36
37
38static void
39run_parse_tests (void)
40{
41    const struct wuf_test *test;
42    for (test = wuf_tests; test->buf[0]; ++test)
43    {
44        lsquic_stream_id_t stream_id = ~0;
45        uint64_t offset = ~0;
46        int sz = pf->pf_parse_window_update_frame(test->buf, test->buf_len, &stream_id, &offset);
47        assert(sz == GQUIC_WUF_SZ);
48        assert(stream_id == test->stream_id);
49        assert(offset == test->offset);
50    }
51}
52
53
54static void
55run_gen_tests (void)
56{
57    const struct wuf_test *test;
58    for (test = wuf_tests; test->buf[0]; ++test)
59    {
60        unsigned char buf[0x100];
61        int sz = pf->pf_gen_window_update_frame(buf, test->buf_len, test->stream_id, test->offset);
62        assert(sz == GQUIC_WUF_SZ);
63        assert(0 == memcmp(buf, test->buf, sz));
64    }
65}
66
67
68int
69main (void)
70{
71    run_parse_tests();
72    run_gen_tests();
73    return 0;
74}
75