-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform_test.c
54 lines (42 loc) · 1.62 KB
/
platform_test.c
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
#include "platform.h"
#include "string.h"
#include "test.h"
#include <stdio.h>
static int expect_join_paths(const char* file, int line, const char* const* paths, const char* expected);
#define EXPECT_JOIN_PATHS(paths, expected) EXPECT_PASS(expect_join_paths(__FILE__, __LINE__, paths, expected))
int test_platform(void)
{
{
printf("## join_paths\n");
EXPECT_JOIN_PATHS(((const char*[]) { NULL }), "");
EXPECT_JOIN_PATHS(((const char*[]) { "", NULL }), "");
EXPECT_JOIN_PATHS(((const char*[]) { "", "", "", "", NULL }), "");
EXPECT_JOIN_PATHS(((const char*[]) { "/", NULL }), "/");
EXPECT_JOIN_PATHS(((const char*[]) { "a", "b", NULL }), "a/b");
EXPECT_JOIN_PATHS(((const char*[]) { "a/", "/b", NULL }), "a/b");
EXPECT_JOIN_PATHS(((const char*[]) { "/a//", "//b/", "/c/", NULL }), "/a/b/c");
}
return EXIT_SUCCESS;
}
static int expect_join_paths(const char* const file, const int line, const char* const* const paths, const char* const expected)
{
const char* const actual = join_paths(paths);
char label[1 << 5] = { 0 };
{
int i = 0;
const char* const* path = paths;
int n = 0;
while (*path) {
if (i != 0) {
n += snprintf(label + n, sizeof(label) - n, ",");
}
n += snprintf(label + n, sizeof(label) - n, "\"%s\"", *path);
i++;
path++;
}
}
const bool passes = str_equals(actual, expected);
report_status_str(file, line, passes, label, actual, expected);
free((void*)actual);
return passes ? EXIT_SUCCESS : EXIT_FAILURE;
}