1#include <assert.h> 2#include <stdlib.h> 3#include <string.h> 4#include <sys/queue.h> 5 6#include "lsqpack.h" 7#include "lsqpack-test.h" 8 9 10struct str_test 11{ 12 int strt_lineno; 13 unsigned strt_prefix_bits; 14 const unsigned char *strt_in_str; 15 unsigned strt_in_len; 16 const unsigned char *strt_out_buf; 17 int strt_retval; 18}; 19 20 21static const struct str_test tests[] = 22{ 23 24 { 25 __LINE__, 26 3, 27 (unsigned char *) "", 28 0, 29 (unsigned char *) "\x00", 30 1, 31 }, 32 33 { 34 __LINE__, 35 3, 36 (unsigned char *) "a", 37 1, 38 (unsigned char *) "\x01" "a", 39 2, 40 }, 41 42 { 43 __LINE__, 44 3, 45 (unsigned char *) "aa", 46 2, 47 (unsigned char *) "\x02" "aa", 48 3, 49 }, 50 51 { 52 __LINE__, 53 3, 54 (unsigned char *) "aaa", 55 3, 56 (unsigned char *) "\x0A\x18\xc7", 57 3, 58 }, 59 60 { 61 __LINE__, 62 3, 63 (unsigned char *) "aaaaaaaaa", 64 9, 65 (unsigned char *) "\x0E\x18\xc6\x31\x8c\x63\x1f", 66 7, 67 }, 68 69 { 70 __LINE__, 71 3, 72 (unsigned char *) "aaaaaaaaaa", 73 10, 74 (unsigned char *) "\x0F\x00\x18\xc6\x31\x8c\x63\x18\xff", 75 9, 76 }, 77 78 { 79 __LINE__, 80 3, 81 (unsigned char *) "aaaaaaaaaabbb", 82 13, 83 (unsigned char *) "\x0F\x02\x18\xc6\x31\x8c\x63\x18\xe3\x8e\x3f", 84 11, 85 }, 86 87 { 88 __LINE__, 89 3, 90 (unsigned char *) "\x80\x90\xA0\xBA", 91 4, 92 (unsigned char *) "\x04\x80\x90\xA0\xBA", 93 5, 94 }, 95 96 { 97 __LINE__, 98 3, 99 (unsigned char *) "\x80\x90\xA0\xBA\x80\x90\xA0", 100 7, 101 (unsigned char *) "\x07\x00\x80\x90\xA0\xBA\x80\x90\xA0", 102 9, 103 }, 104 105 { 106 __LINE__, 107 3, 108 (unsigned char *) "\x80\x90\xA0\xBA\x80\x90\xA0" "foo", 109 10, 110 (unsigned char *) "\x07\x03\x80\x90\xA0\xBA\x80\x90\xA0" "foo", 111 12, 112 }, 113 114}; 115 116 117int 118main (void) 119{ 120 const struct str_test *test; 121 int r; 122 unsigned char *out= malloc(0x1000); 123 124 if (!out) 125 return 1; 126 127 for (test = tests; test < tests + sizeof(tests) / sizeof(tests[0]); ++test) 128 { 129 out[0] = 0; 130 r = lsqpack_enc_enc_str(test->strt_prefix_bits, out, 0x1000, 131 test->strt_in_str, test->strt_in_len); 132 assert(r == test->strt_retval); 133 if (r > 0) 134 assert(0 == memcmp(test->strt_out_buf, out, r)); 135 } 136 137 free(out); 138 return 0; 139} 140