/**
 * Copyright © 2019 IBM Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>

static ssize_t __read(int fd, void *buf, size_t len);
#define read __read
#include "config.c"
#include "console-socket.c"
#define main __main
#include "console-client.c"
#undef read
#undef main

struct test {
	enum esc_type esc_type;
	union {
		struct ssh_esc_state ssh;
		struct str_esc_state str;
	} esc_state;
	const char *in[4];
	size_t n_in;
	const char *exp_out;
	int exp_rc;
};

struct test_ctx {
	struct console_client client;
	struct test *test;
	uint8_t out[4096];
	size_t cur_in;
	size_t cur_out;
};

struct test tests[] = {
	{
		/* no escape code */
		.esc_type = ESC_TYPE_SSH,
		.in = { "a" },
		.n_in = 1,
		.exp_out = "a",
		.exp_rc = PROCESS_EXIT,
	},
	{
		/* no escape code, multiple reads */
		.esc_type = ESC_TYPE_SSH,
		.in = { "a", "b" },
		.n_in = 2,
		.exp_out = "ab",
		.exp_rc = PROCESS_EXIT,
	},
	{
		/* ssh escape in one read */
		.esc_type = ESC_TYPE_SSH,
		.in = { "a\r~." },
		.n_in = 1,
		.exp_out = "a\r",
		.exp_rc = PROCESS_ESC,
	},
	{
		/* ssh escape, partial ~ is not output. */
		.esc_type = ESC_TYPE_SSH,
		.in = { "a\r~" },
		.n_in = 1,
		.exp_out = "a\r",
		.exp_rc = PROCESS_EXIT,
	},
	{
		/* ssh escape split into individual reads */
		.esc_type = ESC_TYPE_SSH,
		.in = { "a", "\r", "~", "." },
		.n_in = 4,
		.exp_out = "a\r",
		.exp_rc = PROCESS_ESC,
	},
	{
		/* ssh escape, escaped. */
		.esc_type = ESC_TYPE_SSH,
		.in = { "a\r~~." },
		.n_in = 1,
		.exp_out = "a\r~.",
		.exp_rc = PROCESS_EXIT,
	},
	{
		/* ssh escape, escaped ~, and not completed. */
		.esc_type = ESC_TYPE_SSH,
		.in = { "a\r~~" },
		.n_in = 1,
		.exp_out = "a\r~",
		.exp_rc = PROCESS_EXIT,
	},
	{
		/* str escape, no match */
		.esc_type = ESC_TYPE_STR,
		.esc_state = { .str = { .str = (const uint8_t *)"c" } },
		.in = { "ab" },
		.n_in = 1,
		.exp_out = "ab",
		.exp_rc = PROCESS_EXIT,
	},
	{
		/* str escape, one byte, as one read */
		.esc_type = ESC_TYPE_STR,
		.esc_state = { .str = { .str = (const uint8_t *)"b" } },
		.in = { "abc" },
		.n_in = 1,
		.exp_out = "ab",
		.exp_rc = PROCESS_ESC,
	},
	{
		/* str escape, multiple bytes, as one read */
		.esc_type = ESC_TYPE_STR,
		.esc_state = { .str = { .str = (const uint8_t *)"bc" } },
		.in = { "abcd" },
		.n_in = 1,
		.exp_out = "abc",
		.exp_rc = PROCESS_ESC,
	},
	{
		/* str escape, multiple bytes, split over reads */
		.esc_type = ESC_TYPE_STR,
		.esc_state = { .str = { .str = (const uint8_t *)"bc" } },
		.in = { "ab", "cd" },
		.n_in = 2,
		.exp_out = "abc",
		.exp_rc = PROCESS_ESC,
	},
	{
		/* str escape, not matched due to intermediate data */
		.esc_type = ESC_TYPE_STR,
		.esc_state = { .str = { .str = (const uint8_t *)"ab" } },
		.in = { "acb" },
		.n_in = 1,
		.exp_out = "acb",
		.exp_rc = PROCESS_EXIT,
	},
};

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

struct test_ctx ctxs[ARRAY_SIZE(tests)];

int write_buf_to_fd(int fd, const uint8_t *buf, size_t len)
{
	struct test_ctx *ctx = &ctxs[fd];

	assert(ctx->cur_out + len <= sizeof(ctx->out));
	memcpy(ctx->out + ctx->cur_out, buf, len);
	ctx->cur_out += len;

	return 0;
}

static ssize_t __read(int fd, void *buf, size_t len)
{
	struct test_ctx *ctx = &ctxs[fd];
	const char *inbuf;
	size_t inlen;

	if (len > SSIZE_MAX) {
		errno = EINVAL;
		return -1;
	}

	if (ctx->cur_in >= ctx->test->n_in)
		return 0;

	inbuf = ctx->test->in[ctx->cur_in];
	inlen = strlen(inbuf);
	assert(inlen <= len);
	memcpy(buf, inbuf, inlen);
	ctx->cur_in++;
	return (ssize_t)inlen;
}

void run_one_test(size_t idx, struct test *test, struct test_ctx *ctx)
{
	size_t exp_out_len;
	int rc;

	/* we store the index into the context array as a FD, so we
	 * can refer to it through the read & write callbacks.
	 */
	assert(idx < INT_MAX);
	ctx->client.console_sd = (int)idx;
	ctx->client.fd_in = (int)idx;
	ctx->client.esc_type = test->esc_type;
	memcpy(&ctx->client.esc_state, &test->esc_state,
	       sizeof(test->esc_state));
	ctx->test = test;

	for (;;) {
		rc = process_tty(&ctx->client);
		if (rc != PROCESS_OK)
			break;
	}

	exp_out_len = strlen(test->exp_out);

#ifdef DEBUG
	printf("got: rc %d %s(%d), exp: rc %d %s(%ld)\n", rc, ctx->out,
	       ctx->cur_out, test->exp_rc, test->exp_out, exp_out_len);
	fflush(stdout);
#endif
	assert(rc == test->exp_rc);
	assert(exp_out_len == ctx->cur_out);
	assert(!memcmp(ctx->out, test->exp_out, exp_out_len));
}

int main(void)
{
	size_t i;

	for (i = 0; i < ARRAY_SIZE(tests); i++)
		run_one_test(i, &tests[i], &ctxs[i]);

	return EXIT_SUCCESS;
}
