#include "t.h" #include "p.h" static int parse_has_error(const uint8_t *b, size_t n) { tobi_parse_result r; (void)tobi_parse(b, n, 0, &r); int has = tobi_diag_has_error(&r.diag); tobi_parse_result_free(&r); return has; } static int strict_fails(const uint8_t *b, size_t n) { tobi_parse_result r; int ok = tobi_parse(b, n, 1, &r); int has = tobi_diag_has_error(&r.diag); tobi_parse_result_free(&r); return !ok && has; } int t_bad(void) { uint8_t trunc_pkg[] = {0x14,0x20,'M','T'}; T_CHECK(parse_has_error(trunc_pkg, sizeof(trunc_pkg))); uint8_t invalid_pkg[] = {0x14,0x80,0x00}; T_CHECK(parse_has_error(invalid_pkg, sizeof(invalid_pkg))); uint8_t unterm_str[] = {0x0d,'a','b'}; T_CHECK(parse_has_error(unterm_str, sizeof(unterm_str))); uint8_t trunc_name[] = {0x08,'A'}; T_CHECK(parse_has_error(trunc_name, sizeof(trunc_name))); uint8_t bad_table[40] = {'D','S','D','T',1,0,0,0}; T_CHECK(parse_has_error(bad_table, sizeof(bad_table))); uint8_t bad_sum[40] = {'S','S','D','T',40,0,0,0}; T_CHECK(strict_fails(bad_sum, sizeof(bad_sum))); uint8_t rnd[128]; for (size_t i = 0; i < sizeof(rnd); i++) { rnd[i] = (uint8_t)(i * 37u + 11u); } tobi_parse_result r; T_CHECK(tobi_parse(rnd, sizeof(rnd), 0, &r)); tobi_parse_result_free(&r); uint8_t deep[160]; for (size_t i = 0; i < sizeof(deep); i += 2) { deep[i] = 0x10; deep[i + 1] = 0x7f; } T_CHECK(parse_has_error(deep, sizeof(deep))); return 0; }