/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only */
/* Copyright (c) 2023 Brett Sheffield <bacs@librecast.net> */

#include "test.h"
#include "testdata.h"
#include "globals.h"
#include "sync.h"
#include "arg.h"
#include <assert.h>
#include <errno.h>
#include <string.h>

void log_commandline(int argc, char *argv[])
{
	for (int i = 0; i < argc; i++) {
		test_log("%s ", argv[i]);
	}
	test_log("\n");
}

int main(void)
{
	char prog[] = "lcsync";
	char src[] = "0000-0025.src.tmp.XXXXXX";
	char dst[] = "0000-0025.dst.tmp.XXXXXX";
	char **argv;
	char *argv1[] = { prog, "-b", src, dst, NULL };
	const size_t sz_s = 1024 * 10 + 13;
	int argc1 = sizeof argv1 / sizeof argv1[0] - 1;
	int argc, fd;

	test_name("commandline: sync two local files, both exist");

	/* create test files */
	fd = test_data_file(src, sz_s, TEST_TMP | TEST_RND);
	close(fd);
	fd = test_data_file(dst, sz_s, TEST_TMP | TEST_RND);
	close(fd);

	/* sync */
	argc = argc1; argv = argv1;
	log_commandline(argc, argv);
	test_assert(arg_parse(&argc, &argv) == 0, "arg_parse()");
	test_assert(action(&argc, argv) == 0, "action()");

	/* verify */
	test_assert(test_file_match(src, dst) == 0, "test_file_match(): dst matches src");

	return test_status;
}
