forked from Lephenixnoir/FxLibcTest
unistd, sys/stat: stat(), mkdir() and rmdir()
This commit is contained in:
parent
6383d9ba0f
commit
25c67e6e10
|
@ -57,7 +57,8 @@ set(SOURCES
|
|||
src/fcntl/open.c
|
||||
# unistd
|
||||
src/unistd/files.c
|
||||
|
||||
# sys/stat
|
||||
src/sysstat/stat.c
|
||||
)
|
||||
# fx-9860G-only assets and fx-CG-50-only assets
|
||||
set(ASSETS_fx
|
||||
|
|
|
@ -68,4 +68,7 @@ extern ft_test ft_unistd_simple_read;
|
|||
extern ft_test ft_unistd_seek_patterns;
|
||||
extern ft_test ft_unistd_folders;
|
||||
|
||||
/* sys/stat */
|
||||
extern ft_test ft_sysstat_stat;
|
||||
|
||||
#endif /* _FT_ALL_TESTS_H_ */
|
||||
|
|
|
@ -97,6 +97,10 @@ ft_list headers_posix[] = {
|
|||
&ft_unistd_folders,
|
||||
NULL,
|
||||
}},
|
||||
{ "<sys/stat.h>", (ft_test*[]){
|
||||
&ft_sysstat_stat,
|
||||
NULL,
|
||||
}},
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#include <ft/test.h>
|
||||
#include <ft/all-tests.h>
|
||||
#include <ft/util.h>
|
||||
|
||||
#include <gint/gint.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static void _ft_sysstat_stat_switch(ft_test *t)
|
||||
{
|
||||
struct stat st;
|
||||
int rc;
|
||||
|
||||
DO_E(rc, stat("@MainMem", &st), t, "%d");
|
||||
ft_assert(t, rc == 0 && S_ISDIR(st.st_mode));
|
||||
|
||||
#ifdef FX9860G
|
||||
DO_E(rc, stat("FxLibcT.g1a", &st), t, "%d");
|
||||
#else
|
||||
DO_E(rc, stat("FxLibcT.g3a", &st), t, "%d");
|
||||
#endif
|
||||
ft_assert(t, rc == 0 && S_ISREG(st.st_mode));
|
||||
}
|
||||
|
||||
static void _ft_sysstat_stat(ft_test *t)
|
||||
{
|
||||
gint_world_switch(GINT_CALL(_ft_sysstat_stat_switch, (void *)t));
|
||||
}
|
||||
|
||||
ft_test ft_sysstat_stat = {
|
||||
.name = "stat() function",
|
||||
.function = _ft_sysstat_stat,
|
||||
};
|
|
@ -308,17 +308,9 @@ static void _ft_unistd_folders_switch(ft_test *t)
|
|||
{
|
||||
int rc, fd, type, size;
|
||||
|
||||
/* Create a directory (don't fail if we already ran the test before) */
|
||||
/* Create a directory */
|
||||
DO_E(rc, mkdir("ft_test", 0755), t, "%d");
|
||||
ft_assert(t, rc == 0 || (rc == -1 && errno == EEXIST));
|
||||
ft_log(t, "note: this folder might already exist\n");
|
||||
|
||||
/* Remove that directory */
|
||||
DO_E(rc, rmdir("ft_test"), t, "%d");
|
||||
ft_assert(t, rc == 0);
|
||||
|
||||
/* Create it anew (and empty) */
|
||||
DO_E(rc, mkdir("ft_test", 0755), t, "%d");
|
||||
ft_assert(t, rc == 0);
|
||||
DO_E(rc, mkdir("ft_test", 0755), t, "%d");
|
||||
ft_assert(t, rc == -1 && errno == EEXIST);
|
||||
|
@ -352,6 +344,20 @@ static void _ft_unistd_folders_switch(ft_test *t)
|
|||
&type, &size);
|
||||
ft_log(t, "BFile_Ext_Stat()=%d (type=%d, size=%d)\n", rc, type, size);
|
||||
ft_assert(t, rc == 0 && type == BFile_Type_File && size == 28);
|
||||
|
||||
/* Clean up everything */
|
||||
DO_E(rc, rmdir("ft_test/subfolder"), t, "%d");
|
||||
ft_assert(t, rc == -1 && errno == ENOTEMPTY);
|
||||
DO_E(rc, unlink("ft_test/subfolder"), t, "%d");
|
||||
ft_assert(t, rc == -1 && errno == ENOTDIR);
|
||||
DO_E(rc, unlink("ft_test/subfolder/file.txt"), t, "%d");
|
||||
ft_assert(t, rc == 0);
|
||||
DO_E(rc, rmdir("ft_test/subfolder"), t, "%d");
|
||||
ft_assert(t, rc == 0);
|
||||
DO_E(rc, unlink("ft_test/file.txt"), t, "%d");
|
||||
ft_assert(t, rc == 0);
|
||||
DO_E(rc, rmdir("ft_test"), t, "%d");
|
||||
ft_assert(t, rc == 0);
|
||||
}
|
||||
|
||||
static void _ft_unistd_folders(ft_test *t)
|
||||
|
|
Loading…
Reference in New Issue