-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
86 lines (70 loc) · 1.78 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "du.h"
#define EXPECT_EQ_STR(l,r) \
do { strcmp(l,r) ? printf("\t* error "#r"\n") : printf("\tsuccess "#r"\n"); } while (0)
#define EXPECT_EQ_NUM(l,r) \
do { (l == r) ? printf("\tsuccess "#r"\n") : printf("\t* error"#r"\n"); } while (0)
int expect_eq_str(char* l, char* r) {
return !strcmp(l, r);
}
static void t_path_is_invalid(void) {
printf("[%s]\n", __func__);
const char *pattern = "*";
const char *path = "./jfalsjh";
DirUtil* du = du_init();
if (!du) return;
char** list = du->get(path, pattern);
EXPECT_EQ_NUM(NULL, list);
du->close();
}
static void t_path_is_null(void) {
printf("[%s]\n", __func__);
const char *pattern = "*";
const char *path = NULL;
DirUtil* du = du_init();
if (!du) return;
char** list = du->get(path, pattern);
EXPECT_EQ_NUM(list, NULL);
du->close();
}
static void t_pattern_match(const char* pattern, const char* path) {
printf("[%s]\n", __func__);
DirUtil* du = du_init();
if (!du) return;
char** list = du->get(path, pattern);
if (list) {
unsigned int i = 0;
while (list[i] != NULL) {
printf("\t[%d:%s]\n", i, list[i]);
i++;
}
}
du->close();
}
static void t_print_dir(const char* path) {
printf("[%s]\n", __func__);
const char *pattern = "*";
DirUtil* du = du_init();
if (!du) return;
char** list = du->get(path, pattern);
if (list) {
unsigned int i = 0;
while (list[i] != NULL) {
printf("\t[%d:%s]\n",i, list[i]);
i++;
}
}
du->close();
}
int main() {
printf("[test begin]\n");
t_print_dir("./");
t_path_is_null();
t_path_is_invalid();
t_pattern_match("*.c", "./");
t_pattern_match("d*", "./");
printf("[test end]\n");
return 0;
}