aboutsummaryrefslogtreecommitdiff
path: root/tests/test_fs_mkdirs.c
blob: 453b517c6654849a814025641d20ee96d287e613 (plain) (blame)
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
#include "spm.h"
#include "framework.h"

const char *testFmt = "returned '%d', expected '%d'\n";
struct TestCase testCase[] = {
        {.arg[0].str = "one", .truthValue.signed_int = 0},
        {.arg[0].str = "one/two", .truthValue.signed_int = 0},
        {.arg[0].str = "one/two/three", .truthValue.signed_int = 0},
        {.arg[0].str = "one/two/three/four", .truthValue.signed_int = 0},
        {.arg[0].str = "one/two/three/four/five", .truthValue.signed_int = 0},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);

int main(int argc, char *argv[]) {
    for (size_t i = 0; i < numCases; i++) {
        int present = 0;
        int result = 0;
        char path_root[PATH_MAX] = {"test_fs_mkdirs_XXXXXX"};
        char *path = NULL;

        if (mkdtemp(path_root) == NULL) {
            perror("mkdtemp failed to create temporary directory");
            exit(errno);
        }

        path = join((char *[]){path_root, testCase[i].caseValue.str, NULL}, DIRSEPS);

        if ((result = mkdirs(path, 0755)) < 0) {
            perror(path);
            exit(1);
        }
        present = access(path, X_OK);

        myassert(result == 0, testFmt, result, testCase[i].truthValue.signed_int);
        myassert(present == 0, testFmt, result, testCase[i].truthValue.signed_int);

        rmdirs(path);

        present = access(path, X_OK);
        myassert(present != 0, testFmt, result, testCase[i].truthValue.signed_int);
    }
    return 0;
}