#include "libptouch_protocol.h"

#include <stdio.h>
#include <stdlib.h>

static int expect_int(const char *name, int got, int want)
{
	if (got == want)
		return 0;
	fprintf(stderr, "%s mismatch: got=%d want=%d\n", name, got, want);
	return 1;
}

int main(void)
{
	int fail = 0;

	fail |= expect_int("line_payload_128", (int)ptouch_line_payload_bytes(128u), 16);
	fail |= expect_int("line_payload_560", (int)ptouch_line_payload_bytes(560u), 70);

	uint8_t gf[3];
	ptouch_fill_gf_header(gf, 16u);
	fail |= expect_int("gf16_cmd", gf[0], 0x47);
	fail |= expect_int("gf16_n1", gf[1], 0x10);
	fail |= expect_int("gf16_n2", gf[2], 0x00);

	ptouch_fill_gf_header(gf, 70u);
	fail |= expect_int("gf70_cmd", gf[0], 0x47);
	fail |= expect_int("gf70_n1", gf[1], 0x46);
	fail |= expect_int("gf70_n2", gf[2], 0x00);

	uint8_t iz[13];
	ptouch_fill_esc_iz(iz, 0x01u, 0x0Cu, 70u);
	fail |= expect_int("iz_cmd_0", iz[0], 0x1B);
	fail |= expect_int("iz_cmd_1", iz[1], 0x69);
	fail |= expect_int("iz_cmd_2", iz[2], 0x7A);
	fail |= expect_int("iz_n1_flags", iz[3], 0x8E);
	fail |= expect_int("iz_media_kind_passthrough", iz[4], 0x01);
	fail |= expect_int("iz_media_width", iz[5], 0x0C);
	fail |= expect_int("iz_lines_lsb", iz[7], 70);
	fail |= expect_int("iz_page_index", iz[11], 0x00);
	fail |= expect_int("iz_last_fixed", iz[12], 0x00);

	/* ESC i K mode byte: 128-dot vs 560-dot families */
	fail |= expect_int("esc_ik_128", ptouch_esc_ik_value(128u), 0x08);
	fail |= expect_int("esc_ik_560", ptouch_esc_ik_value(560u), 0x0C);

	return fail ? EXIT_FAILURE : EXIT_SUCCESS;
}
