test/paths: use helper functions for result testing

This commit is contained in:
Kacper Michajłow 2024-06-26 18:01:23 +02:00
parent 22fc2e6af3
commit 4a0c0ce92d
1 changed files with 3 additions and 22 deletions

View File

@ -7,35 +7,16 @@
static void test_join(char *file, int line, char *a, char *b, char *c) static void test_join(char *file, int line, char *a, char *b, char *c)
{ {
char *res = mp_path_join(NULL, a, b); char *res = mp_path_join(NULL, a, b);
if (strcmp(res, c) != 0) { assert_string_equal_impl(file, line, res, c);
printf("%s:%d: '%s' + '%s' = '%s', expected '%s'\n", file, line,
a, b, res, c);
fflush(stdout);
abort();
}
talloc_free(res); talloc_free(res);
} }
static void test_abs(char *file, int line, bool abs, char *a)
{
if (mp_path_is_absolute(bstr0(a)) != abs) {
printf("%s:%d: mp_path_is_absolute('%s') => %d, expected %d\n",
file, line, a, !abs, abs);
fflush(stdout);
abort();
}
}
static void test_normalize(char *file, int line, char *expected, char *path) static void test_normalize(char *file, int line, char *expected, char *path)
{ {
void *ctx = talloc_new(NULL); void *ctx = talloc_new(NULL);
char *normalized = mp_normalize_path(ctx, path); char *normalized = mp_normalize_path(ctx, path);
if (strcmp(normalized, expected)) { assert_string_equal_impl(file, line, normalized, expected);
printf("%s:%d: mp_normalize_path('%s') => %s, expected %s\n",
file, line, path, normalized, expected);
fflush(stdout);
abort();
}
talloc_free(ctx); talloc_free(ctx);
} }
@ -43,7 +24,7 @@ static void test_normalize(char *file, int line, char *expected, char *path)
test_join(__FILE__, __LINE__, a, b, c); test_join(__FILE__, __LINE__, a, b, c);
#define TEST_ABS(abs, a) \ #define TEST_ABS(abs, a) \
test_abs(__FILE__, __LINE__, abs, a) assert_int_equal_impl(__FILE__, __LINE__, abs, mp_path_is_absolute(bstr0(a)))
#define TEST_NORMALIZE(expected, path) \ #define TEST_NORMALIZE(expected, path) \
test_normalize(__FILE__, __LINE__, expected, path) test_normalize(__FILE__, __LINE__, expected, path)