test_blocked_gquic_be.c revision 9a690580
1/* Copyright (c) 2017 - 2020 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 14static const struct parse_funcs *const pf = select_pf_by_ver(LSQVER_043); 15 16 17/* The test is both for generation and parsing: */ 18struct wuf_test { 19 unsigned char buf[0x10]; 20 size_t buf_len; 21 lsquic_stream_id_t stream_id; 22}; 23 24static const struct wuf_test wuf_tests[] = { 25 { 26 .buf = { 0x05, 0x00, 0x67, 0x45, 0x34, }, 27 .buf_len = GQUIC_BLOCKED_FRAME_SZ, 28 .stream_id = 0x674534, 29 }, 30 31 { .buf = { 0 }, } 32}; 33 34 35static void 36run_parse_tests (void) 37{ 38 const struct wuf_test *test; 39 for (test = wuf_tests; test->buf[0]; ++test) 40 { 41 lsquic_stream_id_t stream_id = ~0; 42 int sz = pf->pf_parse_blocked_frame(test->buf, test->buf_len, &stream_id); 43 assert(sz == GQUIC_BLOCKED_FRAME_SZ); 44 assert(stream_id == test->stream_id); 45 } 46} 47 48 49static void 50run_gen_tests (void) 51{ 52 const struct wuf_test *test; 53 for (test = wuf_tests; test->buf[0]; ++test) 54 { 55 unsigned char buf[0x100]; 56 int sz = pf->pf_gen_blocked_frame(buf, test->buf_len, test->stream_id); 57 assert(sz == GQUIC_BLOCKED_FRAME_SZ); 58 assert(0 == memcmp(buf, test->buf, sz)); 59 } 60} 61 62 63int 64main (void) 65{ 66 run_parse_tests(); 67 run_gen_tests(); 68 return 0; 69} 70