test_blocked_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}; 24 25static const struct wuf_test wuf_tests[] = { 26 { 27 .buf = { 0x05, 0x00, 0x67, 0x45, 0x34, }, 28 .buf_len = GQUIC_BLOCKED_FRAME_SZ, 29 .stream_id = 0x674534, 30 }, 31 32 { .buf = { 0 }, } 33}; 34 35 36static void 37run_parse_tests (void) 38{ 39 const struct wuf_test *test; 40 for (test = wuf_tests; test->buf[0]; ++test) 41 { 42 lsquic_stream_id_t stream_id = ~0; 43 int sz = pf->pf_parse_blocked_frame(test->buf, test->buf_len, &stream_id); 44 assert(sz == GQUIC_BLOCKED_FRAME_SZ); 45 assert(stream_id == test->stream_id); 46 } 47} 48 49 50static void 51run_gen_tests (void) 52{ 53 const struct wuf_test *test; 54 for (test = wuf_tests; test->buf[0]; ++test) 55 { 56 unsigned char buf[0x100]; 57 int sz = pf->pf_gen_blocked_frame(buf, test->buf_len, test->stream_id); 58 assert(sz == GQUIC_BLOCKED_FRAME_SZ); 59 assert(0 == memcmp(buf, test->buf, sz)); 60 } 61} 62 63 64int 65main (void) 66{ 67 run_parse_tests(); 68 run_gen_tests(); 69 return 0; 70} 71