summaryrefslogtreecommitdiff
path: root/examples/utest/testcases/posix/unistd_h/functions/access_tc.c
blob: 696d1bc4b6e24736697b600b56ed363bca691b0d (plain)
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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>

#define ACCESS_DIR "./access_dir"

#include <utest.h>
static int access_entry(void)
{
    int i = 0;

    /* file/dir that not exist*/
    char *files[] =
    {
        "/usr/local/nginx/conf/nginx.conf",
        "./a.out",
        "/usr/include/libgen.h",
        "/ff/last",
        NULL
    };

    for (i = 0; files[i] != NULL; i++)
    {
        /* mode=0: file/dir exist or not */
        uassert_int_not_equal(access(files[i], 0), 0);
    }

    mkdir(ACCESS_DIR, 0x777);
    uassert_int_equal(access(ACCESS_DIR, 0), 0);
    return 0;
}

static void test_access(void)
{
    uassert_int_equal(access_entry(), 0);
}

static void testcase(void)
{
    UTEST_UNIT_RUN(test_access);
}
UTEST_TC_EXPORT(testcase, "posix.unistd_h.access_tc.c", RT_NULL, RT_NULL, 10);