#include "t.h" #include "js.h" #include "p.h" int t_js(void) { uint8_t data[] = {0x08,'S','T','R','0',0x0d,'a','"','b','\\','c',0x00,0xfe}; tobi_parse_result r; T_CHECK(tobi_parse(data, sizeof(data), 0, &r)); char *s = tobi_js_emit(&r); T_STR(s, "\"kind\":\"root\""); T_STR(s, "\"checksum_sum\":0"); T_STR(s, "\"checksum_valid\":false"); T_STR(s, "\"namespace\":["); T_STR(s, "\"path\":\"\\\\STR0\""); T_STR(s, "\"kind\":\"name\""); T_STR(s, "a\\\"b\\\\c"); T_STR(s, "\"raw_opcode\":254"); T_CHECK(strstr(s, ",}") == NULL); T_CHECK(strstr(s, ",]") == NULL); free(s); tobi_parse_result_free(&r); uint8_t res[] = {0x11,0x05,0x0a,0x02,0x79,0x00}; T_CHECK(tobi_parse(res, sizeof(res), 0, &r)); s = tobi_js_emit(&r); T_STR(s, "\"kind\":\"resource\""); T_STR(s, "\"name\":\"EndTag\""); T_STR(s, "\"string\":\"checksum=0x0\""); T_CHECK(strstr(s, ",}") == NULL); T_CHECK(strstr(s, ",]") == NULL); free(s); tobi_parse_result_free(&r); uint8_t fld[] = {0x5b,0x80,'R','E','G','0',0x01,0x0a,0x10,0x0a,0x04,0x5b,0x81,0x0b,'R','E','G','0',0x00,'F','L','D','0',0x08}; T_CHECK(tobi_parse(fld, sizeof(fld), 0, &r)); s = tobi_js_emit(&r); T_STR(s, "\"target\":\"\\\\REG0\""); T_STR(s, "\"bit_offset\":0"); T_STR(s, "\"bit_length\":8"); T_STR(s, "\"access_type\":0"); T_CHECK(strstr(s, ",}") == NULL); T_CHECK(strstr(s, ",]") == NULL); free(s); tobi_parse_result_free(&r); return 0; }