2021-01-06 14:00:05 +00:00
|
|
|
/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc. See LICENSE. */
|
2017-09-22 21:00:03 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2018-03-12 22:25:01 +00:00
|
|
|
#ifndef WIN32
|
2017-09-22 21:00:03 +00:00
|
|
|
#include <sys/time.h>
|
2018-03-12 22:25:01 +00:00
|
|
|
#endif
|
2017-09-22 21:00:03 +00:00
|
|
|
|
|
|
|
#include "lsquic.h"
|
|
|
|
#include "lsquic_types.h"
|
|
|
|
#include "lsquic_parse.h"
|
|
|
|
|
2020-01-20 14:41:37 +00:00
|
|
|
static const struct parse_funcs *const pf = select_pf_by_ver(LSQVER_043);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* The test is both for generation and parsing: */
|
|
|
|
struct wuf_test {
|
|
|
|
unsigned char buf[0x20];
|
|
|
|
size_t buf_len;
|
2019-09-11 15:27:58 +00:00
|
|
|
lsquic_stream_id_t stream_id;
|
2017-09-22 21:00:03 +00:00
|
|
|
uint64_t offset;
|
2019-09-11 15:27:58 +00:00
|
|
|
uint64_t error_code;
|
2017-09-22 21:00:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct wuf_test wuf_tests[] = {
|
|
|
|
{
|
|
|
|
.buf = { 0x01, 0x00, 0x67, 0x45, 0x34, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00, 0x00, 0x00, 0x03, },
|
2019-09-11 15:27:58 +00:00
|
|
|
.buf_len = GQUIC_RST_STREAM_SZ,
|
2017-09-22 21:00:03 +00:00
|
|
|
.stream_id = 0x674534,
|
|
|
|
.offset = 0x0102030405,
|
|
|
|
.error_code = 0x03,
|
|
|
|
},
|
|
|
|
|
|
|
|
{ .buf = { 0 }, }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_parse_tests (void)
|
|
|
|
{
|
|
|
|
const struct wuf_test *test;
|
|
|
|
for (test = wuf_tests; test->buf[0]; ++test)
|
|
|
|
{
|
2019-09-11 15:27:58 +00:00
|
|
|
lsquic_stream_id_t stream_id = ~0;
|
|
|
|
uint64_t offset = ~0, error_code = ~0;
|
2017-09-22 21:00:03 +00:00
|
|
|
int sz = pf->pf_parse_rst_frame(test->buf, test->buf_len, &stream_id, &offset, &error_code);
|
2019-09-11 15:27:58 +00:00
|
|
|
assert(sz == GQUIC_RST_STREAM_SZ);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(stream_id == test->stream_id);
|
|
|
|
assert(offset == test->offset);
|
|
|
|
assert(error_code == test->error_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_gen_tests (void)
|
|
|
|
{
|
|
|
|
const struct wuf_test *test;
|
|
|
|
for (test = wuf_tests; test->buf[0]; ++test)
|
|
|
|
{
|
|
|
|
unsigned char buf[0x100];
|
|
|
|
int sz = pf->pf_gen_rst_frame(buf, test->buf_len, test->stream_id, test->offset, test->error_code);
|
2019-09-11 15:27:58 +00:00
|
|
|
assert(sz == GQUIC_RST_STREAM_SZ);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(0 == memcmp(buf, test->buf, sz));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
run_parse_tests();
|
|
|
|
run_gen_tests();
|
|
|
|
return 0;
|
|
|
|
}
|