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
149
examples/utest/testcases/posix/stdio_h/Kconfig
Normal file
149
examples/utest/testcases/posix/stdio_h/Kconfig
Normal file
|
@ -0,0 +1,149 @@
|
|||
menuconfig RTT_POSIX_TESTCASE_STDIO_H
|
||||
bool "<stdio.h>"
|
||||
default n
|
||||
|
||||
if RTT_POSIX_TESTCASE_STDIO_H
|
||||
|
||||
config STDIO_H_CLEARERR
|
||||
bool "<stdio.h> -> clearerr"
|
||||
default n
|
||||
|
||||
config STDIO_H_FCLOSE
|
||||
bool "<stdio.h> -> fclose"
|
||||
default n
|
||||
|
||||
config STDIO_H_FDOPEN
|
||||
bool "<stdio.h> -> fdopen"
|
||||
default n
|
||||
|
||||
config STDIO_H_FEOF
|
||||
bool "<stdio.h> -> feof"
|
||||
default n
|
||||
|
||||
config STDIO_H_FERROR
|
||||
bool "<stdio.h> -> ferror"
|
||||
default n
|
||||
|
||||
config STDIO_H_FFLUSH
|
||||
bool "<stdio.h> -> fflush"
|
||||
default n
|
||||
|
||||
config STDIO_H_FGETC
|
||||
bool "<stdio.h> -> fgetc"
|
||||
default n
|
||||
|
||||
config STDIO_H_FGETS
|
||||
bool "<stdio.h> -> fgets"
|
||||
default n
|
||||
|
||||
config STDIO_H_FILENO
|
||||
bool "<stdio.h> -> fileno"
|
||||
default n
|
||||
|
||||
config STDIO_H_FOPEN
|
||||
bool "<stdio.h> -> fopen"
|
||||
default n
|
||||
|
||||
config STDIO_H_FPRINTF
|
||||
bool "<stdio.h> -> fprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_FPUTC
|
||||
bool "<stdio.h> -> fputc"
|
||||
default n
|
||||
|
||||
config STDIO_H_FPUTS
|
||||
bool "<stdio.h> -> fputs"
|
||||
default n
|
||||
|
||||
config STDIO_H_FREAD
|
||||
bool "<stdio.h> -> fread"
|
||||
default n
|
||||
|
||||
config STDIO_H_FSCANF
|
||||
bool "<stdio.h> -> fscanf"
|
||||
default n
|
||||
|
||||
config STDIO_H_FSEEK
|
||||
bool "<stdio.h> -> fseek"
|
||||
default n
|
||||
|
||||
config STDIO_H_FTELL
|
||||
bool "<stdio.h> -> ftell"
|
||||
default n
|
||||
|
||||
config STDIO_H_FWRITE
|
||||
bool "<stdio.h> -> fwrite"
|
||||
default n
|
||||
|
||||
|
||||
|
||||
config STDIO_H_PERROR
|
||||
bool "<stdio.h> -> perror"
|
||||
default n
|
||||
|
||||
config STDIO_H_PRINTF
|
||||
bool "<stdio.h> -> printf"
|
||||
default n
|
||||
|
||||
config STDIO_H_PUTC
|
||||
bool "<stdio.h> -> putc"
|
||||
default n
|
||||
|
||||
config STDIO_H_PUTCHAR
|
||||
bool "<stdio.h> -> putchar"
|
||||
default n
|
||||
|
||||
config STDIO_H_PUTS
|
||||
bool "<stdio.h> -> puts"
|
||||
default n
|
||||
|
||||
config STDIO_H_REMOVE
|
||||
bool "<stdio.h> -> remove"
|
||||
default n
|
||||
|
||||
config STDIO_H_RENAME
|
||||
bool "<stdio.h> -> rename"
|
||||
default n
|
||||
|
||||
config STDIO_H_REWIND
|
||||
bool "<stdio.h> -> rewind"
|
||||
default n
|
||||
|
||||
config STDIO_H_SETBUF
|
||||
bool "<stdio.h> -> setbuf"
|
||||
default n
|
||||
|
||||
config STDIO_H_SETVBUF
|
||||
bool "<stdio.h> -> setvbuf"
|
||||
default n
|
||||
|
||||
config STDIO_H_SNPRINTF
|
||||
bool "<stdio.h> -> snprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_SPRINTF
|
||||
bool "<stdio.h> -> sprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_SSCANF
|
||||
bool "<stdio.h> -> sscanf"
|
||||
default n
|
||||
|
||||
config STDIO_H_VFPRINTF
|
||||
bool "<stdio.h> -> vfprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_VPRINTF
|
||||
bool "<stdio.h> -> vprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_VSNPRINTF
|
||||
bool "<stdio.h> -> vsnprintf"
|
||||
default n
|
||||
|
||||
config STDIO_H_VSPRINTF
|
||||
bool "<stdio.h> -> vsprintf"
|
||||
default n
|
||||
|
||||
endif
|
116
examples/utest/testcases/posix/stdio_h/SConscript
Normal file
116
examples/utest/testcases/posix/stdio_h/SConscript
Normal file
|
@ -0,0 +1,116 @@
|
|||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
path = [cwd]
|
||||
src = []
|
||||
|
||||
if GetDepend('RTT_POSIX_TESTCASE_STDIO_H'):
|
||||
src += Glob('./definitions/*.c')
|
||||
|
||||
|
||||
if GetDepend('STDIO_H_CLEARERR'):
|
||||
src += Glob('./functions/clearerr.c')
|
||||
|
||||
if GetDepend('STDIO_H_FCLOSE'):
|
||||
src += Glob('./functions/fclose.c')
|
||||
|
||||
if GetDepend('STDIO_H_FDOPEN'):
|
||||
src += Glob('./functions/fdopen_tc.c')
|
||||
|
||||
if GetDepend('STDIO_H_FEOF'):
|
||||
src += Glob('./functions/feof.c')
|
||||
|
||||
if GetDepend('STDIO_H_FERROR'):
|
||||
src += Glob('./functions/ferror.c')
|
||||
|
||||
if GetDepend('STDIO_H_FFLUSH'):
|
||||
src += Glob('./functions/fflush.c')
|
||||
|
||||
if GetDepend('STDIO_H_FGETC'):
|
||||
src += Glob('./functions/fgetc.c')
|
||||
|
||||
if GetDepend('STDIO_H_FGETS'):
|
||||
src += Glob('./functions/fgets.c')
|
||||
|
||||
if GetDepend('STDIO_H_FILENO'):
|
||||
src += Glob('./functions/fileno.c')
|
||||
|
||||
if GetDepend('STDIO_H_FOPEN'):
|
||||
src += Glob('./functions/fopen.c')
|
||||
|
||||
if GetDepend('STDIO_H_FPRINTF'):
|
||||
src += Glob('./functions/fprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_FPUTC'):
|
||||
src += Glob('./functions/fputc.c')
|
||||
|
||||
if GetDepend('STDIO_H_FPUTS'):
|
||||
src += Glob('./functions/fputs.c')
|
||||
|
||||
if GetDepend('STDIO_H_FREAD'):
|
||||
src += Glob('./functions/fread.c')
|
||||
|
||||
if GetDepend('STDIO_H_FSCANF'):
|
||||
src += Glob('./functions/fscanf.c')
|
||||
|
||||
if GetDepend('STDIO_H_FSEEK'):
|
||||
src += Glob('./functions/fseek.c')
|
||||
|
||||
if GetDepend('STDIO_H_FTELL'):
|
||||
src += Glob('./functions/ftell.c')
|
||||
|
||||
if GetDepend('STDIO_H_FWRITE'):
|
||||
src += Glob('./functions/fwrite.c')
|
||||
|
||||
|
||||
if GetDepend('STDIO_H_PERROR'):
|
||||
src += Glob('./functions/perror.c')
|
||||
|
||||
if GetDepend('STDIO_H_PRINTF'):
|
||||
src += Glob('./functions/printf.c')
|
||||
|
||||
if GetDepend('STDIO_H_PUTC'):
|
||||
src += Glob('./functions/puts.c')
|
||||
|
||||
if GetDepend('STDIO_H_REMOVE'):
|
||||
src += Glob('./functions/remove.c')
|
||||
|
||||
if GetDepend('STDIO_H_RENAME'):
|
||||
src += Glob('./functions/rename.c')
|
||||
|
||||
if GetDepend('STDIO_H_REWIND'):
|
||||
src += Glob('./functions/rewind.c')
|
||||
|
||||
if GetDepend('STDIO_H_SETBUF'):
|
||||
src += Glob('./functions/setbuf.c')
|
||||
|
||||
if GetDepend('STDIO_H_SETVBUF'):
|
||||
src += Glob('./functions/setvbuf.c')
|
||||
|
||||
if GetDepend('STDIO_H_SNPRINTF'):
|
||||
src += Glob('./functions/snprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_SPRINTF'):
|
||||
src += Glob('./functions/sprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_SSCANF'):
|
||||
src += Glob('./functions/sscanf.c')
|
||||
|
||||
if GetDepend('STDIO_H_VFPRINTF'):
|
||||
src += Glob('./functions/vfprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_VPRINTF'):
|
||||
src += Glob('./functions/vprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_VSNPRINTF'):
|
||||
src += Glob('./functions/vsnprintf.c')
|
||||
|
||||
if GetDepend('STDIO_H_VSPRINTF'):
|
||||
src += Glob('./functions/vsprintf.c')
|
||||
|
||||
group = DefineGroup('rtt_posix_testcase', src, depend = ['RTT_POSIX_TESTCASE_STDIO_H'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
123
examples/utest/testcases/posix/stdio_h/definitions/stdio_h.c
Normal file
123
examples/utest/testcases/posix/stdio_h/definitions/stdio_h.c
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Bull SA. All rights reserved.
|
||||
* Created by: Laurent.Vivier@bull.net
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
*/
|
||||
|
||||
/* test if stdio.h exists and can be included */
|
||||
|
||||
// #define _POSIX_C_SOURCE 2
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void (*test_clearerr)(FILE *);
|
||||
int (*test_fclose)(FILE *);
|
||||
FILE * (*test_fdopen)(int, const char *);
|
||||
int (*test_feof)(FILE *);
|
||||
int (*test_ferror)(FILE *);
|
||||
int (*test_fflush)(FILE *);
|
||||
int (*test_fgetc)(FILE *);
|
||||
char * (*test_fgets)(char *__restrict, int, FILE *__restrict);
|
||||
int (*test_fileno)(FILE *);
|
||||
void (*test_flockfile)(FILE *);
|
||||
FILE * (*test_fopen)(const char *__restrict _name, const char *__restrict _type);
|
||||
int (*test_fprintf)(FILE *__restrict, const char *__restrict, ...);
|
||||
int (*test_fputc)(int, FILE *);
|
||||
int (*test_fputs)(const char *__restrict, FILE *__restrict);
|
||||
size_t (*test_fread)(void *__restrict, size_t _size, size_t _n, FILE *__restrict);
|
||||
FILE * (*test_freopen)(const char *__restrict, const char *__restrict, FILE *__restrict);
|
||||
int (*test_fscanf)(FILE *__restrict, const char *__restrict, ...);
|
||||
int (*test_ftrylockfile)(FILE *);
|
||||
void (*test_funlockfile)(FILE *);
|
||||
size_t (*test_fwrite)(const void *__restrict , size_t _size, size_t _n, FILE *);
|
||||
int (*test_getc)(FILE *);
|
||||
int (*test_getc_unlocked)(FILE *);
|
||||
int (*test_getchar)(void);
|
||||
int (*test_getchar_unlocked)(void);
|
||||
char * (*test_gets)(char *);
|
||||
void (*test_perror)(const char *);
|
||||
int (*test_printf)(const char *__restrict, ...);
|
||||
int (*test_putc)(int, FILE *);
|
||||
int (*test_putc_unlocked)(int, FILE *);
|
||||
int (*test_putchar)(int);
|
||||
int (*test_putchar_unlocked)(int);
|
||||
int (*test_puts)(const char *);
|
||||
int (*test_scanf)(const char *__restrict, ...);
|
||||
void (*test_setbuf)(FILE *__restrict, char *__restrict);
|
||||
int (*test_setvbuf)(FILE *__restrict, char *__restrict, int, size_t);
|
||||
int (*test_snprintf)(char *__restrict, size_t, const char *__restrict, ...);
|
||||
int (*test_sprintf)(char *__restrict, const char *__restrict, ...);
|
||||
int (*test_sscanf)(const char *__restrict, const char *__restrict, ...);
|
||||
int (*test_ungetc)(int, FILE *);
|
||||
|
||||
FILE *test_stderr;
|
||||
FILE *test_stdin;
|
||||
FILE *test_stdout;
|
||||
|
||||
int (*test_vfprintf)(FILE *restrict, const char *restrict, va_list);
|
||||
int (*test_vfscanf)(FILE *restrict, const char *restrict, va_list);
|
||||
int (*test_vprintf)(const char *restrict, va_list);
|
||||
int (*test_vscanf)(const char *restrict, va_list);
|
||||
int (*test_vsnprintf)(char *restrict, size_t, const char *restrict, va_list);
|
||||
int (*test_vsprintf)(char *restrict, const char *restrict, va_list);
|
||||
int (*test_vsscanf)(const char *restrict, const char *restrict, va_list);
|
||||
|
||||
__attribute__((unused)) static int test_defined()
|
||||
{
|
||||
test_clearerr = clearerr;
|
||||
test_fclose = fclose;
|
||||
// test_fdopen = fdopen;
|
||||
test_feof = feof;
|
||||
test_ferror = ferror;
|
||||
test_fflush = fflush;
|
||||
test_fgetc = fgetc;
|
||||
test_fgets = fgets;
|
||||
// test_fileno = fileno;
|
||||
// test_flockfile = flockfile;
|
||||
test_fopen = fopen;
|
||||
test_fprintf = fprintf;
|
||||
test_fputc = fputc;
|
||||
test_fputs = fputs;
|
||||
test_fread = fread;
|
||||
test_freopen = freopen;
|
||||
test_fscanf = fscanf;
|
||||
// test_ftrylockfile = ftrylockfile;
|
||||
// test_funlockfile = funlockfile;
|
||||
test_fwrite = fwrite;
|
||||
test_getc = getc;
|
||||
// test_getc_unlocked = getc_unlocked;
|
||||
test_getchar = getchar;
|
||||
test_gets = gets;
|
||||
test_perror = perror;
|
||||
test_printf = printf;
|
||||
test_putc = putc;
|
||||
// test_putc_unlocked = putc_unlocked;
|
||||
test_putchar = putchar;
|
||||
// test_putchar_unlocked = putchar_unlocked;
|
||||
test_puts = puts;
|
||||
test_scanf = scanf;
|
||||
test_setbuf = setbuf;
|
||||
test_setvbuf = setvbuf;
|
||||
test_snprintf = snprintf;
|
||||
test_sprintf = sprintf;
|
||||
test_sscanf = sscanf;
|
||||
test_ungetc = ungetc;
|
||||
|
||||
test_stderr = stderr;
|
||||
test_stdin = stdin;
|
||||
test_stdout = stdout;
|
||||
|
||||
test_vfprintf = vfprintf;
|
||||
test_vfscanf = vfscanf;
|
||||
test_vprintf = vprintf;
|
||||
test_vscanf = vscanf;
|
||||
test_vsnprintf = vsnprintf;
|
||||
test_vsprintf = vsprintf;
|
||||
test_vsscanf = vsscanf;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int clearerr_entry(void)
|
||||
{
|
||||
putc( 'c', stdin );
|
||||
if( ferror( stdin ) )
|
||||
{
|
||||
perror( "Write error" );
|
||||
clearerr( stdin );
|
||||
}
|
||||
|
||||
if( ferror( stdin ))
|
||||
{
|
||||
perror( "clearerr error" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_clearerr(void)
|
||||
{
|
||||
uassert_int_equal(clearerr_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_clearerr);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.clearerr.c", RT_NULL, RT_NULL, 10);
|
||||
|
34
examples/utest/testcases/posix/stdio_h/functions/fclose_tc.c
Normal file
34
examples/utest/testcases/posix/stdio_h/functions/fclose_tc.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int fclose_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
stream = fopen("fopen_file.txt","a+");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
return -1;
|
||||
}
|
||||
if(fclose(stream) != 0)
|
||||
{
|
||||
perror("fclose fail");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("fclose success \n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fclose(void)
|
||||
{
|
||||
uassert_int_equal(fclose_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fclose);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fclose.c", RT_NULL, RT_NULL, 10);
|
||||
|
39
examples/utest/testcases/posix/stdio_h/functions/fdopen_tc.c
Normal file
39
examples/utest/testcases/posix/stdio_h/functions/fdopen_tc.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
static int fdopen_entry(void)
|
||||
{
|
||||
int fd;
|
||||
FILE *stream;
|
||||
|
||||
fd = open("fdopen_file.txt", O_CREAT | O_RDWR | O_APPEND);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("open fail.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TODO */
|
||||
stream = fdopen(fd, "w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
printf("fdopen fail.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fdopen(void)
|
||||
{
|
||||
uassert_int_equal(fdopen_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fdopen);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fdopen_tc.c", RT_NULL, RT_NULL, 10);
|
||||
|
55
examples/utest/testcases/posix/stdio_h/functions/feof_tc.c
Normal file
55
examples/utest/testcases/posix/stdio_h/functions/feof_tc.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int feof_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char data[] = "test fgetc";
|
||||
char getc[sizeof(data)] = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
int i=0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w+");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
fwrite(data, sizeof(data), 1, stream);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
while(1)
|
||||
{
|
||||
getc[i] = fgetc(stream);
|
||||
i++;
|
||||
if( feof(stream) )
|
||||
{
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(getc, data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
__exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_feof(void)
|
||||
{
|
||||
uassert_int_equal(feof_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_feof);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.feof.c", RT_NULL, RT_NULL, 10);
|
||||
|
28
examples/utest/testcases/posix/stdio_h/functions/ferror_tc.c
Normal file
28
examples/utest/testcases/posix/stdio_h/functions/ferror_tc.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int ferror_entry(void)
|
||||
{
|
||||
int c;
|
||||
putc( 'c', stdin );
|
||||
if( ferror( stdin ) )
|
||||
{
|
||||
clearerr( stdin );
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_ferror(void)
|
||||
{
|
||||
uassert_int_equal(ferror_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_ferror);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.ferror.c", RT_NULL, RT_NULL, 10);
|
||||
|
29
examples/utest/testcases/posix/stdio_h/functions/fflush_tc.c
Normal file
29
examples/utest/testcases/posix/stdio_h/functions/fflush_tc.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int fflush_entry(void)
|
||||
{
|
||||
fflush(stdout);
|
||||
printf("test fflush\n");
|
||||
|
||||
printf("t");
|
||||
printf("e");
|
||||
printf("s");
|
||||
printf("t");
|
||||
fflush(stdout);
|
||||
printf(" fflush");
|
||||
fflush(stdout);
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fflush(void)
|
||||
{
|
||||
uassert_int_equal(fflush_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fflush);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fflush.c", RT_NULL, RT_NULL, 10);
|
||||
|
54
examples/utest/testcases/posix/stdio_h/functions/fgetc_tc.c
Normal file
54
examples/utest/testcases/posix/stdio_h/functions/fgetc_tc.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int fgetc_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char data[] = "test fgetc";
|
||||
char getc[sizeof(data)] = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
int i=0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w+");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
fwrite(data, sizeof(data), 1, stream);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
while(1)
|
||||
{
|
||||
getc[i] = fgetc(stream);
|
||||
i++;
|
||||
if( feof(stream) )
|
||||
{
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(getc, data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
fclose(stream);
|
||||
__exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fgetc(void)
|
||||
{
|
||||
uassert_int_equal(fgetc_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fgetc);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fgetc.c", RT_NULL, RT_NULL, 10);
|
||||
|
50
examples/utest/testcases/posix/stdio_h/functions/fgets_tc.c
Normal file
50
examples/utest/testcases/posix/stdio_h/functions/fgets_tc.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int fgets_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char data[] = "test fgets";
|
||||
char gets[sizeof(data)] = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
fwrite(data, sizeof(data), 1, stream);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
fgets(gets, sizeof(gets), stream);
|
||||
|
||||
if(strcmp(gets, data))
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
fclose(stream);
|
||||
|
||||
__exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fgets(void)
|
||||
{
|
||||
uassert_int_equal(fgets_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fgets);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fgets.c", RT_NULL, RT_NULL, 10);
|
||||
|
26
examples/utest/testcases/posix/stdio_h/functions/fileno_tc.c
Normal file
26
examples/utest/testcases/posix/stdio_h/functions/fileno_tc.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int fdopen_entry(void)
|
||||
{
|
||||
int stdin_no = fileno(stdin);
|
||||
int stdout_no = fileno(stdout);
|
||||
int stderr_no = fileno(stderr);
|
||||
|
||||
if((stdin_no == 0) && (stdout_no == 1) && (stderr_no == 2))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fdopen(void)
|
||||
{
|
||||
uassert_int_equal(fdopen_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fdopen);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fileno.c", RT_NULL, RT_NULL, 10);
|
||||
|
28
examples/utest/testcases/posix/stdio_h/functions/fopen_tc.c
Normal file
28
examples/utest/testcases/posix/stdio_h/functions/fopen_tc.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int fopen_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
/* TODO: other mode fopen */
|
||||
stream = fopen("fopen_file.txt","a+");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fopen(void)
|
||||
{
|
||||
uassert_int_equal(fopen_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fopen);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fopen.c", RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int fdopen_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char test_data[] = "1a2bxx";
|
||||
char gets[sizeof(test_data)] = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
fprintf(stream, "%d%c%d%c%s",1,'a',2,'b',"xx");
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
fgets(gets, sizeof(gets), stream);
|
||||
|
||||
if(strcmp(test_data, gets))
|
||||
{
|
||||
printf("%s\n",gets);
|
||||
ret = -1;
|
||||
}
|
||||
__exit:
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fdopen(void)
|
||||
{
|
||||
uassert_int_equal(fdopen_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fdopen);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fprintf.c", RT_NULL, RT_NULL, 10);
|
||||
|
44
examples/utest/testcases/posix/stdio_h/functions/fputc_tc.c
Normal file
44
examples/utest/testcases/posix/stdio_h/functions/fputc_tc.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int fputc_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
int ch = 'a';
|
||||
int getc = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
fputc(ch, stream);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
getc = fgetc(stream);
|
||||
|
||||
if(getc != ch)
|
||||
{
|
||||
perror("fputc");
|
||||
ret = -1;
|
||||
}
|
||||
__exit:
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fputc(void)
|
||||
{
|
||||
uassert_int_equal(fputc_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fputc);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
45
examples/utest/testcases/posix/stdio_h/functions/fputs_tc.c
Normal file
45
examples/utest/testcases/posix/stdio_h/functions/fputs_tc.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int fputs_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char test_data[] = "1a2bxx";
|
||||
char gets[sizeof(test_data)] = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
fputs(test_data, stream);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
fgets(gets, sizeof(gets), stream);
|
||||
|
||||
if(strcmp(test_data, gets))
|
||||
{
|
||||
printf("%s\n",gets);
|
||||
ret = -1;
|
||||
}
|
||||
__exit:
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fputs(void)
|
||||
{
|
||||
uassert_int_equal(fputs_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fputs);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
44
examples/utest/testcases/posix/stdio_h/functions/fread_tc.c
Normal file
44
examples/utest/testcases/posix/stdio_h/functions/fread_tc.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static int fread_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char data[] = "test fread";
|
||||
char gets[sizeof(data)] = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
fwrite(data, sizeof(data), 1, stream);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
fread(gets, sizeof(gets), 1, stream);
|
||||
if(strcmp(gets, data))
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
__exit:
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fread(void)
|
||||
{
|
||||
uassert_int_equal(fread_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fread);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
44
examples/utest/testcases/posix/stdio_h/functions/fscanf_tc.c
Normal file
44
examples/utest/testcases/posix/stdio_h/functions/fscanf_tc.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int fscanf_entry(void)
|
||||
{
|
||||
long l;
|
||||
char s[81] = {0};
|
||||
char c;
|
||||
int ret = 0;
|
||||
FILE* stream = fopen("fopen_file.txt","w+");
|
||||
if(stream == NULL)
|
||||
{
|
||||
ret = -1;
|
||||
perror("fopen");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stream,"%s %d %c","a_string",6500,'x');
|
||||
fseek(stream,0L,SEEK_SET);
|
||||
fscanf(stream,"%s",s);
|
||||
fscanf(stream,"%ld",&l);
|
||||
fscanf(stream," %c",&c);
|
||||
|
||||
if((strcmp(s,"a_string") != 0) || (l != 6500) || (c != 'x'))
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fscanf(void)
|
||||
{
|
||||
uassert_int_equal(fscanf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fscanf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.fscanf.c", RT_NULL, RT_NULL, 10);
|
||||
|
44
examples/utest/testcases/posix/stdio_h/functions/fseek_tc.c
Normal file
44
examples/utest/testcases/posix/stdio_h/functions/fseek_tc.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int fdopen_entry(void)
|
||||
{
|
||||
long l;
|
||||
char s[81] = {0};
|
||||
char c;
|
||||
int ret = 0;
|
||||
FILE* stream = fopen("fopen_file.txt","w+");
|
||||
if(stream == NULL)
|
||||
{
|
||||
ret = -1;
|
||||
perror("fopen");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stream,"%s %d %c","a_string",6500,'x');
|
||||
fseek(stream,0L,SEEK_SET);
|
||||
fscanf(stream,"%s",s);
|
||||
fscanf(stream,"%ld",&l);
|
||||
fscanf(stream," %c",&c);
|
||||
|
||||
if((strcmp(s,"a_string") != 0) || (l != 6500) || (c != 'x'))
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fdopen(void)
|
||||
{
|
||||
uassert_int_equal(fdopen_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fdopen);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
38
examples/utest/testcases/posix/stdio_h/functions/ftell_tc.c
Normal file
38
examples/utest/testcases/posix/stdio_h/functions/ftell_tc.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int ftell_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char str[] = "123456789";
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen");
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stream, "%s",str);
|
||||
if(ftell(stream) != strlen(str))
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
fclose(stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_ftell(void)
|
||||
{
|
||||
uassert_int_equal(ftell_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_ftell);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
45
examples/utest/testcases/posix/stdio_h/functions/fwrite_tc.c
Normal file
45
examples/utest/testcases/posix/stdio_h/functions/fwrite_tc.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int fwrite_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char test_data[] = "1a2bxx";
|
||||
char gets[sizeof(test_data)] = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
fwrite(test_data, sizeof(test_data), 1,stream);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
fgets(gets, sizeof(gets), stream);
|
||||
|
||||
if(strcmp(test_data, gets))
|
||||
{
|
||||
printf("%s\n",gets);
|
||||
ret = -1;
|
||||
}
|
||||
__exit:
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_fwrite(void)
|
||||
{
|
||||
uassert_int_equal(fwrite_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_fwrite);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
27
examples/utest/testcases/posix/stdio_h/functions/perror_tc.c
Normal file
27
examples/utest/testcases/posix/stdio_h/functions/perror_tc.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int perror_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
stream = fopen( "nulltest.txt", "r" );
|
||||
if(stream == NULL)
|
||||
{
|
||||
printf("perror test:");
|
||||
perror("nulltest.txt");
|
||||
return -1;
|
||||
}
|
||||
fclose(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_perror(void)
|
||||
{
|
||||
uassert_int_equal(perror_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_perror);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
19
examples/utest/testcases/posix/stdio_h/functions/printf_tc.c
Normal file
19
examples/utest/testcases/posix/stdio_h/functions/printf_tc.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int printf_entry(void)
|
||||
{
|
||||
printf("printf test:%s-%d-%c %f 0x%x","2021" ,8 ,'1' ,3.14 ,0xff);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_printf(void)
|
||||
{
|
||||
uassert_int_equal(printf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_printf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
44
examples/utest/testcases/posix/stdio_h/functions/putc_tc.c
Normal file
44
examples/utest/testcases/posix/stdio_h/functions/putc_tc.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int putc_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
int ch = 'a';
|
||||
int getc = {0};
|
||||
size_t size = 0;
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
putc(ch, stream);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
getc = fgetc(stream);
|
||||
|
||||
if(getc != ch)
|
||||
{
|
||||
printf("fputc test:getc %c",getc);
|
||||
ret = -1;
|
||||
}
|
||||
__exit:
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_putc(void)
|
||||
{
|
||||
uassert_int_equal(putc_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_putc);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int putchar_entry(void)
|
||||
{
|
||||
char data[] = "putchar testcase\n";
|
||||
int i = 0;
|
||||
for(;i < sizeof(data);i++)
|
||||
{
|
||||
putchar(data[i]);
|
||||
}
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_putchar(void)
|
||||
{
|
||||
uassert_int_equal(putchar_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_putchar);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
22
examples/utest/testcases/posix/stdio_h/functions/puts_tc.c
Normal file
22
examples/utest/testcases/posix/stdio_h/functions/puts_tc.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int puts_entry(void)
|
||||
{
|
||||
char data[] = "puts testcase\n";
|
||||
printf("puts testcase:");
|
||||
puts(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_puts(void)
|
||||
{
|
||||
uassert_int_equal(puts_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_puts);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.puts.c", RT_NULL, RT_NULL, 10);
|
||||
|
35
examples/utest/testcases/posix/stdio_h/functions/remove_tc.c
Normal file
35
examples/utest/testcases/posix/stdio_h/functions/remove_tc.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int remove_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if(stream)
|
||||
{
|
||||
fclose(stream);
|
||||
remove("fopen_file.txt");
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
if(stream)
|
||||
{
|
||||
fclose(stream);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_remove(void)
|
||||
{
|
||||
uassert_int_equal(remove_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_remove);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
37
examples/utest/testcases/posix/stdio_h/functions/rename_tc.c
Normal file
37
examples/utest/testcases/posix/stdio_h/functions/rename_tc.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static int rename_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
if(stream == NULL)
|
||||
{
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if(stream == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
fclose(stream);
|
||||
|
||||
rename("fopen_file.txt", "rename_test.txt");
|
||||
stream = fopen("rename_test.txt","r");
|
||||
if(stream == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
fclose(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_rename(void)
|
||||
{
|
||||
uassert_int_equal(rename_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_rename);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.rename.c", RT_NULL, RT_NULL, 10);
|
||||
|
44
examples/utest/testcases/posix/stdio_h/functions/rewind_tc.c
Normal file
44
examples/utest/testcases/posix/stdio_h/functions/rewind_tc.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int rewind_entry(void)
|
||||
{
|
||||
long l;
|
||||
char s[81] = {0};
|
||||
char c;
|
||||
int ret = 0;
|
||||
FILE* stream = fopen("fopen_file.txt","w+");
|
||||
if(stream == NULL)
|
||||
{
|
||||
ret = -1;
|
||||
perror("fopen");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stream,"%s %d %c","a_string",6500,'x');
|
||||
rewind(stream);
|
||||
fscanf(stream,"%s",s);
|
||||
fscanf(stream,"%ld",&l);
|
||||
fscanf(stream," %c",&c);
|
||||
|
||||
if((strcmp(s,"a_string") != 0) || (l != 6500) || (c != 'x'))
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_rewind(void)
|
||||
{
|
||||
uassert_int_equal(rewind_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_rewind);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.rewind.c", RT_NULL, RT_NULL, 10);
|
||||
|
41
examples/utest/testcases/posix/stdio_h/functions/setbuf_tc.c
Normal file
41
examples/utest/testcases/posix/stdio_h/functions/setbuf_tc.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char outbuf[BUFSIZ];
|
||||
static int setbuf_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char test_data[] = "test setbuf";
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
setbuf(stream, outbuf);
|
||||
fwrite(test_data, sizeof(test_data), 1,stream);
|
||||
|
||||
if(strcmp(test_data, outbuf))
|
||||
{
|
||||
printf("setbuf test:%s\n",test_data);
|
||||
ret = -1;
|
||||
}
|
||||
fclose(stream);
|
||||
__exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_setbuf(void)
|
||||
{
|
||||
uassert_int_equal(setbuf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_setbuf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.setbuf.c", RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char outbuf[BUFSIZ];
|
||||
static int setvbuf_entry(void)
|
||||
{
|
||||
FILE *stream;
|
||||
char test_data[] = "test setbuf";
|
||||
int ret = 0;
|
||||
|
||||
stream = fopen("fopen_file.txt","w");
|
||||
if (stream == NULL)
|
||||
{
|
||||
perror("fopen fail");
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
setvbuf(stream, outbuf, _IOLBF, BUFSIZ);
|
||||
fwrite(test_data, sizeof(test_data), 1,stream);
|
||||
|
||||
if(strcmp(test_data, outbuf))
|
||||
{
|
||||
printf("setvbuf test:%s\n",test_data);
|
||||
ret = -1;
|
||||
}
|
||||
__exit:
|
||||
fclose(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_setvbuf(void)
|
||||
{
|
||||
uassert_int_equal(setvbuf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_setvbuf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.setvbuf.c", RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int snprintf_entry(void)
|
||||
{
|
||||
char buf[64] = {0};
|
||||
char test_data[] = "snprintf test:2021-8-";
|
||||
snprintf(buf, 22,"snprintf test:%s-%d-%c %.02f 0x%x","2021" ,8 ,'1' ,3.14 ,0xff);
|
||||
|
||||
if(strcmp(buf, test_data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_snprintf(void)
|
||||
{
|
||||
uassert_int_equal(snprintf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_snprintf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.snprintf.c", RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int sprintf_entry(void)
|
||||
{
|
||||
char buf[64] = {0};
|
||||
char test_data[] = "sprintf test:2021-8-1 3.14 0xff";
|
||||
sprintf(buf, "sprintf test:%s-%d-%c %.02f 0x%x","2021" ,8 ,'1' ,3.14 ,0xff);
|
||||
|
||||
if(strcmp(buf, test_data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_sprintf(void)
|
||||
{
|
||||
uassert_int_equal(sprintf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_sprintf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.sprintf.c", RT_NULL, RT_NULL, 10);
|
||||
|
30
examples/utest/testcases/posix/stdio_h/functions/sscanf_tc.c
Normal file
30
examples/utest/testcases/posix/stdio_h/functions/sscanf_tc.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int sscanf_entry(void)
|
||||
{
|
||||
int day, year;
|
||||
char weekday[20], month[20], dtm[100];
|
||||
|
||||
strcpy( dtm, "Friday January 1 2021" );
|
||||
sscanf( dtm, "%s %s %d %d", weekday, month, &day, &year );
|
||||
|
||||
if(strcmp(month,"January") || strcmp(weekday,"Friday")
|
||||
|| (year != 2021) ||(day != 1))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_sscanf(void)
|
||||
{
|
||||
uassert_int_equal(sscanf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_sscanf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.sscanf.c", RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
static void WriteFrmtd(FILE *stream ,char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vfprintf(stream, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static int vfprintf_entry(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[64] = {0};
|
||||
char test_data[] = "vfprintf test:2021-8-1 3.14 0xff";
|
||||
FILE *stream = fopen("fopen_file.txt", "w");
|
||||
if(stream)
|
||||
{
|
||||
WriteFrmtd(stream, "vfprintf test:%s-%d-%c %.02f 0x%x","2021" ,8 ,'1' ,3.14 ,0xff);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("fopen_file.txt","r");
|
||||
fread(buf, 1, sizeof(test_data), stream);
|
||||
if(strcmp(buf, test_data))
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
fclose(stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_vfprintf(void)
|
||||
{
|
||||
uassert_int_equal(vfprintf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_vfprintf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
static void WriteFrmtd(char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static int vprintf_entry(void)
|
||||
{
|
||||
WriteFrmtd("vprintf test:%s-%d-%c %.02f 0x%x\n","2021" ,8 ,'1' ,3.14 ,0xff);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_vprintf(void)
|
||||
{
|
||||
uassert_int_equal(vprintf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_vprintf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdio_h.vprintf.c", RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
static char buf[64] = {0};
|
||||
static void WriteFrmtd(char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vsnprintf(buf, 22, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static int vsnprintf_entry(void)
|
||||
{
|
||||
char buf[64] = {0};
|
||||
char test_data[] = "vsnprintf test:2021-8";
|
||||
snprintf(buf, 22,"vsnprintf test:%s-%d-%c %.02f 0x%x","2021" ,8 ,'1' ,3.14 ,0xff);
|
||||
|
||||
if(strcmp(buf, test_data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_vsnprintf(void)
|
||||
{
|
||||
uassert_int_equal(vsnprintf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_vsnprintf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
static char buf[64] = {0};
|
||||
static void WriteFrmtd(char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vsprintf(buf, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static int vsprintf_entry(void)
|
||||
{
|
||||
char buf[64] = {0};
|
||||
char test_data[] = "vsprintf test:2021-8-1 3.14 0xff";
|
||||
sprintf(buf, "vsprintf test:%s-%d-%c %.02f 0x%x","2021" ,8 ,'1' ,3.14 ,0xff);
|
||||
|
||||
if(strcmp(buf, test_data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <utest.h>
|
||||
static void test_vsprintf(void)
|
||||
{
|
||||
uassert_int_equal(vsprintf_entry(), 0);
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_vsprintf);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "rtt_posix_testcase.stdio_h."__FILE__, RT_NULL, RT_NULL, 10);
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue