

#include "writer/console/test.h"

/*
 * O.K.
 * Empty string, for each log level
 */
ParameterizedTestParameters(writer_console, test_write_log_console0) {
	return cr_make_param_array(struct param_set_color, ll_and_colors, 8);
}

ParameterizedTest(
	struct param_set_color *p,
	writer_console,
	test_write_log_console0)
{
	cr_assert_eq(YALL_SUCCESS, write_log_console(p->ll, ""));

    #ifdef __linux__
	char output[32] = { 0 };
	snprintf(output, 32, "\033[%dm\033[0m", p->code);

	cr_assert_stderr_eq_str(output);
    #else
    cr_assert(1);
    #endif
}

/*
 * O.K.
 * Non-empty string, for each log level
 */
ParameterizedTestParameters(writer_console, test_write_log_console1) {
	return cr_make_param_array(struct param_set_color, ll_and_colors, 8);
}

ParameterizedTest(
	struct param_set_color *p,
	writer_console,
	test_write_log_console1)
{
	cr_assert_eq(write_log_console(p->ll, "sentence"), YALL_SUCCESS);
	fflush(stderr);

	char output[32] = { 0 };
#ifdef __linux__
	snprintf(output, 32, "\033[%dmsentence\033[0m", p->code);
#elif _WIN32
	snprintf(output, 32, "sentence");
#endif
	cr_assert_stderr_eq_str(output);
}

/*
 * Failing fprintf
 */
Test(writer_console,
	test_write_log_console2)
{
    #ifdef __linux__
	disable_fprintf();
	cr_assert_eq(write_log_console(yall_debug, "nope"), YALL_CONSOLE_WRITE_ERR);
	enable_fprintf();
    #else
    cr_assert(1);
    #endif
}
