test_wuf_gquic_be.c revision 06b2a236
1/* Copyright (c) 2017 - 2021 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 uint64_t offset; 23}; 24 25static const struct wuf_test wuf_tests[] = { 26 { 27 .buf = { 0x04, 0x00, 0x67, 0x45, 0x34, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, }, 28 .buf_len = GQUIC_WUF_SZ, 29 .stream_id = 0x674534, 30 .offset = 0x0102030405, 31 }, 32 33 { .buf = { 0 }, } 34}; 35 36 37static void 38run_parse_tests (void) 39{ 40 const struct wuf_test *test; 41 for (test = wuf_tests; test->buf[0]; ++test) 42 { 43 lsquic_stream_id_t stream_id = ~0; 44 uint64_t offset = ~0; 45 int sz = pf->pf_parse_window_update_frame(test->buf, test->buf_len, &stream_id, &offset); 46 assert(sz == GQUIC_WUF_SZ); 47 assert(stream_id == test->stream_id); 48 assert(offset == test->offset); 49 } 50} 51 52 53static void 54run_gen_tests (void) 55{ 56 const struct wuf_test *test; 57 for (test = wuf_tests; test->buf[0]; ++test) 58 { 59 unsigned char buf[0x100]; 60 int sz = pf->pf_gen_window_update_frame(buf, test->buf_len, test->stream_id, test->offset); 61 assert(sz == GQUIC_WUF_SZ); 62 assert(0 == memcmp(buf, test->buf, sz)); 63 } 64} 65 66 67int 68main (void) 69{ 70 run_parse_tests(); 71 run_gen_tests(); 72 return 0; 73} 74