import RT-Thread@9217865c without bsp, libcpu and components/net
This commit is contained in:
commit
e2376a3709
1414 changed files with 390370 additions and 0 deletions
66
examples/utest/testcases/posix/unistd_h/functions/chdir_tc.c
Normal file
66
examples/utest/testcases/posix/unistd_h/functions/chdir_tc.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define NEW_CURR_DIR "./chdir_test"
|
||||
|
||||
static int chdir_entry(void)
|
||||
{
|
||||
__attribute__((unused)) long path_max;
|
||||
size_t size;
|
||||
char *buf;
|
||||
char *ptr;
|
||||
|
||||
__attribute__((unused)) char *old_dir;
|
||||
|
||||
size = 1024;
|
||||
|
||||
for (buf = ptr = NULL; ptr == NULL; size *= 2)
|
||||
{
|
||||
if ((buf = realloc(buf, size)) == NULL)
|
||||
{
|
||||
printf("error\n");
|
||||
}
|
||||
ptr = getcwd(buf, size);
|
||||
|
||||
if (ptr == NULL)
|
||||
{
|
||||
printf("error\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ptr %s\n",ptr);
|
||||
printf("old curr dir is %s\n", ptr);
|
||||
}
|
||||
|
||||
mkdir(NEW_CURR_DIR, 0x777);
|
||||
chdir(NEW_CURR_DIR);
|
||||
|
||||
ptr = getcwd(buf, size);
|
||||
if (ptr == NULL)
|
||||
{
|
||||
printf("error\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("new curr dir is %s\n", ptr);
|
||||
}
|
||||
|
||||
}
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_chdir(void)
|
||||
{
|
||||
uassert_int_equal(chdir_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_chdir);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.unistd_h.chdir_tc.c", RT_NULL, RT_NULL, 10);
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue