tst_assert.c 1.9 KB
Newer Older
M
m00302376 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
 * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
 * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
 */
#include <stdio.h>
#define TST_NO_DEFAULT_MAIN
#include "tst_assert.h"
#include "tst_test.h"

void tst_assert_int(const char *file, const int lineno, const char *path, int val)
{
	int sys_val;

	safe_file_scanf(file, lineno, NULL, path, "%d", &sys_val);

	if (val == sys_val) {
		tst_res_(file, lineno, TPASS, "%s = %d", path, val);
		return;
	}

	tst_res_(file, lineno, TFAIL, "%s != %d got %d", path, val, sys_val);
}

void tst_assert_file_int(const char *file, const int lineno, const char *path, const char *prefix, int val)
{
	int sys_val;
	char fmt[1024];

	snprintf(fmt, sizeof(fmt), "%s%%d", prefix);
	file_lines_scanf(file, lineno, NULL, 1, path, fmt, &sys_val);

	if (val == sys_val) {
		tst_res_(file, lineno, TPASS, "%s %s = %d", path, prefix, sys_val);
		return;
	}

	tst_res_(file, lineno, TFAIL, "%s %s != %d got %d", path, prefix, val, sys_val);
}

void tst_assert_str(const char *file, const int lineno, const char *path, const char *val)
{
	char sys_val[1024];

	safe_file_scanf(file, lineno, NULL, path, "%1024s", sys_val);
	if (!strcmp(val, sys_val)) {
		tst_res_(file, lineno, TPASS, "%s = '%s'", path, val);
		return;
	}

	tst_res_(file, lineno, TFAIL, "%s != '%s' got '%s'", path, val, sys_val);
}

void tst_assert_file_str(const char *file, const int lineno, const char *path, const char *prefix, const char *val)
{
	char sys_val[1024];
	char fmt[2048];

	snprintf(fmt, sizeof(fmt), "%s: %%1024s", prefix);
	file_lines_scanf(file, lineno, NULL, 1, path, fmt, sys_val);

	if (!strcmp(val, sys_val)) {
		tst_res_(file, lineno, TPASS, "%s %s = '%s'", path, prefix, sys_val);
		return;
	}

	tst_res_(file, lineno, TFAIL, "%s %s != '%s' got '%s'", path, prefix, val, sys_val);
}