* src/bin/Makefile.am:

* src/bin/evil_suite.c:
	* src/bin/evil_test_dlfcn.c:
	* src/bin/evil_test_dlfcn.h:
	* src/bin/evil_test_environment.c:
	* src/bin/evil_test_environment.h:
	* src/bin/evil_test_gettimeofday.c:
	* src/bin/evil_test_gettimeofday.h:
	* src/bin/evil_test_link.c:
	* src/bin/evil_test_link.h:
	* src/bin/evil_test_mkstemp.c:
	* src/bin/evil_test_mkstemp.h:
	* src/bin/evil_test_realpath.c:
	* src/bin/evil_test_realpath.h:
	various fixes in the test suite.
	add mkstemp() and realpath tests.
	* src/lib/evil_dirent.c:
	fix opendir() when indexation search is not active.
	formatting.
	* src/lib/evil_stdlib.c:
	fir mkstemp() on both platform
	* src/lib/evil_unistd.c:
	remove useless error message.



SVN revision: 38645
This commit is contained in:
Vincent Torri 2009-01-19 17:51:17 +00:00
parent 011bc06ecc
commit 7da4e5839d
18 changed files with 381 additions and 55 deletions

View File

@ -1,3 +1,32 @@
2009-01-19 Vincent Torri <doursse at users dot sf dot net>
* src/bin/Makefile.am:
* src/bin/evil_suite.c:
* src/bin/evil_test_dlfcn.c:
* src/bin/evil_test_dlfcn.h:
* src/bin/evil_test_environment.c:
* src/bin/evil_test_environment.h:
* src/bin/evil_test_gettimeofday.c:
* src/bin/evil_test_gettimeofday.h:
* src/bin/evil_test_link.c:
* src/bin/evil_test_link.h:
* src/bin/evil_test_mkstemp.c:
* src/bin/evil_test_mkstemp.h:
* src/bin/evil_test_realpath.c:
* src/bin/evil_test_realpath.h:
various fixes in the test suite.
add mkstemp() and realpath tests.
* src/lib/evil_dirent.c:
fix opendir() when indexation search is not active.
formatting.
* src/lib/evil_stdlib.c:
fir mkstemp() on both platform
* src/lib/evil_unistd.c:
remove useless error message.
2009-01-12 Vincent Torri <doursse at users dot sf dot net>
* src/lib/evil_dirent.c:

View File

@ -18,7 +18,9 @@ evil_test_dlfcn.c \
evil_test_environment.c \
evil_test_gettimeofday.c \
evil_test_link.c \
evil_test_memcpy.c
evil_test_memcpy.c \
evil_test_mkstemp.c \
evil_test_realpath.c
if EVIL_HAVE_WINCE
@ -46,4 +48,6 @@ evil_suite.h \
evil_test_dlfcn.h \
evil_test_environment.h \
evil_test_link.h \
evil_test_memcpy.h
evil_test_memcpy.h \
evil_test_mkstemp.h \
evil_test_realpath.h

View File

@ -12,6 +12,8 @@
#include "evil_test_gettimeofday.h"
#include "evil_test_link.h"
#include "evil_test_memcpy.h"
#include "evil_test_mkstemp.h"
#include "evil_test_realpath.h"
typedef int(*function)(suite *s);
@ -171,10 +173,12 @@ int
main()
{
test tests[] = {
{ "dlfcn ", test_environment },
{ "dlfcn ", test_dlfcn },
{ "environment ", test_environment },
{ "gettimeofday", test_gettimeofday },
{ "link ", test_link },
{ "mkstemp ", test_mkstemp },
{ "realpath ", test_realpath },
/* { "memcpy ", test_memcpy }, */
{ NULL, NULL },
};
@ -193,7 +197,6 @@ main()
for (i = 0; tests[i].name; ++i)
{
suite_test_add(s, tests[i].name, tests[i].fct);
}

View File

@ -2,7 +2,6 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
@ -22,7 +21,7 @@ test_dlfcn_test_dlopen()
if (!handle)
return 0;
if (!dlclose(handle))
if (dlclose(handle))
return 0;
return 1;
@ -53,7 +52,7 @@ test_dlfcn_test_dlsym()
return 0;
}
if (!dlclose(handle))
if (dlclose(handle))
return 0;
return 1;
@ -64,7 +63,7 @@ test_dlfcn_tests_run(suite *s)
{
int res;
res = test_dlfcn_test_dlopen();
res = test_dlfcn_test_dlopen();
res &= test_dlfcn_test_dlsym();
return res;

View File

@ -1,8 +1,8 @@
#ifndef __EVIL_TEST_DLFCN__
#define __EVIL_TEST_DLFCN__
#ifndef __EVIL_TEST_DLFCN_H__
#define __EVIL_TEST_DLFCN_H__
int test_dlfcn(suite *s);
#endif /* __EVIL_TEST_DLFCN__ */
#endif /* __EVIL_TEST_DLFCN_H__ */

View File

@ -1,10 +1,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <string.h>
#include <Evil.h>
@ -12,24 +9,165 @@
#include "evil_suite.h"
static int
test_env_tests_run(suite *s)
test_env_test_setenv_NULL(void)
{
char *val;
int res;
res = setenv("EVIL_TEST_ENV", "val1", 1);
res = setenv("EVIL_TEST_ENV", NULL, 1);
if (res < 0)
return 0;
val = getenv("EVIL_TEST_ENV");
return val ? 0 : 1;
}
static int
test_env_test_setenv_NULL_after_set(void)
{
char *val;
int res;
res = setenv("EVIL_TEST_ENV", "val", 1);
if (res < 0)
return 0;
val = getenv("EVIL_TEST_ENV");
if (!val)
return 0;
if (strcmp(val, "val"))
return 0;
res = setenv("EVIL_TEST_ENV", NULL, 1);
if (res < 0)
return 0;
val = getenv("EVIL_TEST_ENV");
return val ? 0 : 1;
}
static int
test_env_test_getenv_one(void)
{
char *val;
int res;
res = setenv("EVIL_TEST_ENV", "val", 1);
if (res < 0)
return 0;
val = getenv("EVIL_TEST_ENV");
if (!val)
return 0;
if (strcmp(val, "val"))
return 0;
return 1;
}
static int
test_env_test_getenv_two(void)
{
char *val;
int res;
res = setenv("EVIL_TEST_ENV1", "val1", 1);
if (res < 0)
return 0;
res = setenv("EVIL_TEST_ENV2", "val2", 1);
if (res < 0)
return 0;
val = getenv("EVIL_TEST_ENV1");
if (!val)
return 0;
if (strcmp(val, "val1"))
return 0;
val = getenv("EVIL_TEST_ENV2");
if (!val)
return 0;
if (strcmp(val, "val2"))
return 0;
return 1;
}
static int
test_env_test_getenv_two_swapped(void)
{
char *val;
int res;
res = setenv("EVIL_TEST_ENV1", "val1", 1);
if (res < 0)
return 0;
res = setenv("EVIL_TEST_ENV2", "val2", 1);
if (res < 0)
return 0;
val = getenv("EVIL_TEST_ENV2");
if (!val)
return 0;
if (strcmp(val, "val2"))
return 0;
val = getenv("EVIL_TEST_ENV1");
if (!val)
return 0;
if (strcmp(val, "val1"))
return 0;
return 1;
}
static int
test_env_test_unsetenv(void)
{
char *val;
int res;
res = setenv("EVIL_TEST_ENV", "val", 1);
if (res < 0)
return 0;
val = getenv("EVIL_TEST_ENV");
if (!val)
return 0;
if (unsetenv("EVIL_TEST_ENV") != 0)
return 0;
val = getenv("EVIL_TEST_ENV");
if (val)
return 0;
return 1;
}
static int
test_env_tests_run(suite *s)
{
int res;
res = test_env_test_setenv_NULL();
res &= test_env_test_setenv_NULL_after_set();
res &= test_env_test_getenv_one();
res &= test_env_test_getenv_two();
res &= test_env_test_getenv_two_swapped();
res &= test_env_test_unsetenv();
return res;
}
int
test_environment(suite *s)
{

View File

@ -1,8 +1,8 @@
#ifndef __EVIL_TEST_ENVIRONMENT__
#define __EVIL_TEST_ENVIRONMENT__
#ifndef __EVIL_TEST_ENVIRONMENT_H__
#define __EVIL_TEST_ENVIRONMENT_H__
int test_environment(suite *s);
#endif /* __EVIL_TEST_ENVIRONMENT__ */
#endif /* __EVIL_TEST_ENVIRONMENT_H__ */

View File

@ -1,10 +1,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <string.h>
#include <math.h>
@ -13,7 +10,7 @@
#include "evil_suite.h"
static int
test_time_tests_run(suite *s)
test_time_test_gettimeofday(void)
{
struct timeval tp1;
struct timeval tp2;
@ -34,6 +31,16 @@ test_time_tests_run(suite *s)
return 1;
}
static int
test_time_tests_run(suite *s)
{
int res;
res = test_time_test_gettimeofday();
return res;
}
int
test_gettimeofday(suite *s)
{

View File

@ -1,8 +1,8 @@
#ifndef __EVIL_TEST_GETTIMEOFDAY__
#define __EVIL_TEST_GETTIMEOFDAY__
#ifndef __EVIL_TEST_GETTIMEOFDAY_H__
#define __EVIL_TEST_GETTIMEOFDAY_H__
int test_gettimeofday(suite *s);
#endif /* __EVIL_TEST_GETTIMEOFDAY__ */
#endif /* __EVIL_TEST_GETTIMEOFDAY_H__ */

View File

@ -2,7 +2,6 @@
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <string.h>
#include <Evil.h>
@ -144,7 +143,7 @@ test_link_tests_run(suite *s)
{
int res;
res = test_link_test_symlink();
res = test_link_test_symlink();
res &= test_link_test_readlink();
return res;

View File

@ -1,8 +1,8 @@
#ifndef __EVIL_TEST_LINK__
#define __EVIL_TEST_LINK__
#ifndef __EVIL_TEST_LINK_H__
#define __EVIL_TEST_LINK_H__
int test_link(suite *s);
#endif /* __EVIL_TEST_LINK__ */
#endif /* __EVIL_TEST_LINK_H__ */

View File

@ -0,0 +1,48 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include <Evil.h>
#include "evil_suite.h"
int test_mkstemp_test(void)
{
char _template[PATH_MAX];
char cwd[PATH_MAX];
int fd;
#ifdef _WIN32_WCE
if (!getcwd(cwd, PATH_MAX))
return 0;
_snprintf(_template, PATH_MAX, "%s\\%s", cwd, "file_XXXXXX");
#else
_snprintf(_template, PATH_MAX, "%s", "file_XXXXXX");
#endif
fd = mkstemp(_template);
if (fd < 0)
return 0;
return 1;
}
static int
test_mkstemp_run(suite *s)
{
int res;
res = test_mkstemp_test();
return res;
}
int
test_mkstemp(suite *s)
{
return test_mkstemp_run(s);
}

View File

@ -0,0 +1,8 @@
#ifndef __EVIL_TEST_MKSTEMP_H__
#define __EVIL_TEST_MKSTEMP_H__
int test_mkstemp(suite *s);
#endif /* __EVIL_TEST_MKSTEMP_H__ */

View File

@ -0,0 +1,42 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include <Evil.h>
#include "evil_suite.h"
int test_realpath_test(void)
{
char buf[PATH_MAX];
char *filename;
char *result;
filename = "evil_suite.exe";
if (!(result = realpath(filename, buf)))
return 0;
printf ("res : %s\n", buf);
return 1;
}
static int
test_realpath_run(suite *s)
{
int res;
res = test_realpath_test();
return res;
}
int
test_realpath(suite *s)
{
return test_realpath_run(s);
}

View File

@ -0,0 +1,8 @@
#ifndef __EVIL_TEST_REALPATH_H__
#define __EVIL_TEST_REALPATH_H__
int test_realpath(suite *s);
#endif /* __EVIL_TEST_REALPATH_H__ */

View File

@ -47,9 +47,9 @@ DIR *opendir(char const *name)
wname = evil_char_to_wchar(name);
if (!wname)
{
#ifdef HAVE_ERRNO_H
# ifdef HAVE_ERRNO_H
errno = ENOMEM;
#endif
# endif
return NULL;
}
@ -68,8 +68,8 @@ DIR *opendir(char const *name)
free(wname);
#endif
/* directory */
if (attr != FILE_ATTRIBUTE_DIRECTORY)
/* directory */
if (!(attr & FILE_ATTRIBUTE_DIRECTORY))
{
#ifdef HAVE_ERRNO_H
errno = ENOTDIR;
@ -77,8 +77,8 @@ DIR *opendir(char const *name)
return NULL;
}
dir = (DIR *)malloc(sizeof(DIR));
if (!dir)
dir = (DIR *)malloc(sizeof(DIR));
if (!dir)
{
#ifdef HAVE_ERRNO_H
errno = ENOMEM;

View File

@ -176,6 +176,8 @@ setenv(const char *name,
LONG res;
DWORD disposition;
wchar_t *wname;
char *data;
DWORD size;
if (!name || !*name)
return -1;
@ -208,11 +210,31 @@ setenv(const char *name,
return -1;
}
if (value)
{
size = strlen(value);
data = malloc(sizeof(char) * (size + 1));
if (!data)
return -1;
memcpy((void *)data, value, size);
data[size] = '\0';
}
else
{
size = 0;
data = malloc(sizeof(char));
if (!data)
return -1;
data[0] = '\0';
}
if (!data)
return -1;
if ((res = RegSetValueEx(key,
(LPCWSTR)wname,
0, REG_SZ,
(const BYTE *)value,
strlen(value) + 1)) != ERROR_SUCCESS)
(const BYTE *)data,
size + 1)) != ERROR_SUCCESS)
{
free(wname);
_evil_error_display(__FUNCTION__, res);
@ -221,6 +243,7 @@ setenv(const char *name,
return -1;
}
free(data);
free(wname);
if ((res = RegCloseKey (key)) != ERROR_SUCCESS)
@ -251,7 +274,7 @@ unsetenv(const char *name)
*/
int
mkstemp(char *template)
mkstemp(char *__template)
{
const char lookup[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char *suffix;
@ -259,12 +282,12 @@ mkstemp(char *template)
size_t length;
int i;
if (!template)
if (!__template)
return 0;
length = strlen(template);
length = strlen(__template);
if ((length < 6) ||
(strncmp (template + length - 6, "XXXXXX", 6)))
(strncmp (__template + length - 6, "XXXXXX", 6)))
{
#ifdef HAVE_ERRNO_H
errno = EINVAL;
@ -272,7 +295,7 @@ mkstemp(char *template)
return -1;
}
suffix = template + length - 6;
suffix = __template + length - 6;
val = GetTickCount();
val += GetCurrentProcessId();
@ -298,12 +321,17 @@ mkstemp(char *template)
v /= 62;
#if ! ( defined(__CEGCC__) || defined(__MINGW32CE__) )
fd = _open(template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
fd = _open(__template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
#else /* __CEGCC__ || __MINGW32CE__ */
{
FILE *f;
FILE *f;
wchar_t *wtemplate;
f = fopen(template, "rwb");
wtemplate = evil_char_to_wchar(__template);
if (!wtemplate)
return -1;
f = _wfopen(wtemplate, L"rwb");
free(wtemplate);
if (!f)
{
#ifdef HAVE_ERRNO_H
@ -311,7 +339,7 @@ mkstemp(char *template)
#endif /* HAVE_ERRNO_H */
return -1;
}
fd = fileno(f);
fd = _fileno(f);
}
#endif /* __CEGCC__ || __MINGW32CE__ */
if (fd >= 0)
@ -333,13 +361,27 @@ realpath(const char *file_name, char *resolved_name)
#if ! ( defined(__CEGCC__) || defined(__MINGW32CE__) )
return _fullpath(resolved_name, file_name, PATH_MAX);
#else
int length;
char cwd[PATH_MAX];
size_t l1;
size_t l2;
size_t l;
length = strlen(file_name);
if ((length + 1) > PATH_MAX)
length = PATH_MAX - 1;
memcpy(resolved_name, file_name, length);
resolved_name[length] = '\0';
if (!file_name || !resolved_name)
return NULL;
if (!getcwd(cwd, PATH_MAX))
return NULL;
l1 = strlen(cwd);
l2 = strlen(file_name);
l = l1 + l2 + 2;
if (l > PATH_MAX)
l = PATH_MAX - 1;
memcpy(resolved_name, cwd, l1);
resolved_name[l1] = '\\';
memcpy(resolved_name + l1 + 1, file_name, l2);
resolved_name[l] = '\0';
return resolved_name;
#endif /* __CEGCC__ || __MINGW32CE__ */

View File

@ -215,7 +215,6 @@ evil_stat(const char *file_name, struct stat *st)
handle = FindFirstFile(file, &data);
if (handle == INVALID_HANDLE_VALUE)
{
_evil_last_error_display(__FUNCTION__);
free(file);
return -1;
}