#ifndef PARSE_TEST_FILE_H
#define PARSE_TEST_FILE_H
#include <stdint.h>
#include <stdio.h>
#include "bytestring.h"
#if defined(__cplusplus)
extern "C" {
#endif
struct parse;
enum line {
LINE_STRING_MATCH,
LINE_HEX,
};
struct line_spec {
int state;
enum line type;
const char *name;
const char *label;
const char *match;
};
struct test_parse {
const struct line_spec *states;
size_t num_states;
const struct line_spec *instructions;
size_t num_instructions;
int (*init)(void *ctx, void *parse_ctx);
void (*finish)(void *ctx);
int (*run_test_case)(void *ctx);
};
int parse_test_file(const char *fn, const struct test_parse *lctx, void *ctx);
int parse_get_int(struct parse *p, size_t idx, int *out);
int parse_get_cbs(struct parse *p, size_t idx, CBS *out);
int parse_instruction_get_int(struct parse *p, size_t idx, int *out);
int parse_instruction_get_cbs(struct parse *p, size_t idx, CBS *out);
int parse_length_equal(struct parse *p, const char *descr, size_t want, size_t got);
int parse_data_equal(struct parse *p, const char *descr, CBS *want,
const uint8_t *got, size_t len);
void parse_info(struct parse *ctx, const char *fmt, ...)
__attribute__((__format__ (printf, 2, 3)))
__attribute__((__nonnull__ (2)));
void parse_errx(struct parse *ctx, const char *fmt, ...)
__attribute__((__format__ (printf, 2, 3)))
__attribute__((__nonnull__ (2)))
__attribute__((__noreturn__));
#ifdef __cplusplus
}
#endif
#endif