forked from enlightenment/efl
* src/bin/Makefile.am:
* src/bin/evil_test_dlfcn.c: * src/bin/evil_test_dlfcn.h: add dflcn unit test * src/bin/evil_suite.c: show result of the unit tests and add dlfcn unit test * src/bin/evil_test_environment.c: remove debug * src/bin/evil_test_gettimeofday.c: debug, not working yet :/ * src/bin/evil_test_link.c: * src/lib/evil_link_ce.c: fix link support on Windows CE SVN revision: 38126
This commit is contained in:
parent
643624fe59
commit
826fd4ce79
|
@ -1,3 +1,23 @@
|
|||
2008-12-13 Vincent Torri <doursse at users dot sf dot net>
|
||||
|
||||
* src/bin/Makefile.am:
|
||||
* src/bin/evil_test_dlfcn.c:
|
||||
* src/bin/evil_test_dlfcn.h:
|
||||
add dflcn unit test
|
||||
|
||||
* src/bin/evil_suite.c:
|
||||
show result of the unit tests and add dlfcn unit test
|
||||
|
||||
* src/bin/evil_test_environment.c:
|
||||
remove debug
|
||||
|
||||
* src/bin/evil_test_gettimeofday.c:
|
||||
debug, not working yet :/
|
||||
|
||||
* src/bin/evil_test_link.c:
|
||||
* src/lib/evil_link_ce.c:
|
||||
fix link support on Windows CE
|
||||
|
||||
2008-12-10 Vincent Torri <doursse at users dot sf dot net>
|
||||
|
||||
* src/lib/Evil.h:
|
||||
|
|
|
@ -14,6 +14,7 @@ bin_PROGRAMS = evil_suite test_dlfcn test_pipe test_evil
|
|||
|
||||
evil_suite_SOURCES = \
|
||||
evil_suite.c \
|
||||
evil_test_dlfcn.c \
|
||||
evil_test_environment.c \
|
||||
evil_test_gettimeofday.c \
|
||||
evil_test_link.c \
|
||||
|
@ -29,7 +30,7 @@ evil_suite_SOURCES += memcpy_glibc_arm.S
|
|||
|
||||
endif
|
||||
|
||||
evil_suite_LDADD = $(top_builddir)/src/lib/libevil.la
|
||||
evil_suite_LDADD = $(top_builddir)/src/lib/libevil.la $(top_builddir)/src/lib/dlfcn/libdl.la
|
||||
evil_suite_LDFLAGS = -Wl,--enable-auto-import
|
||||
|
||||
test_dlfcn_SOURCES = test_dlfcn.c
|
||||
|
@ -46,6 +47,7 @@ test_evil_LDFLAGS = -Wl,--enable-auto-import
|
|||
|
||||
EXTRA_DIST = \
|
||||
evil_suite.h \
|
||||
evil_test_dlfcn.h \
|
||||
evil_test_environment.h \
|
||||
evil_test_link.h \
|
||||
evil_test_memcpy.h
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "Evil.h"
|
||||
#include "evil_suite.h"
|
||||
#include "evil_test_dlfcn.h"
|
||||
#include "evil_test_environment.h"
|
||||
#include "evil_test_gettimeofday.h"
|
||||
#include "evil_test_link.h"
|
||||
|
@ -36,10 +37,13 @@ struct suite
|
|||
|
||||
list *first;
|
||||
list *l;
|
||||
|
||||
int tests_count;
|
||||
int tests_success;
|
||||
};
|
||||
|
||||
|
||||
suite *
|
||||
static suite *
|
||||
suite_new(void)
|
||||
{
|
||||
suite *s;
|
||||
|
@ -56,10 +60,13 @@ suite_new(void)
|
|||
s->first = NULL;
|
||||
s->l = NULL;
|
||||
|
||||
s->tests_count = 0;
|
||||
s->tests_success = 0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
suite_del(suite *s)
|
||||
{
|
||||
list *l;
|
||||
|
@ -97,7 +104,7 @@ suite_time_get(suite *s)
|
|||
return (double)(s->end.QuadPart - s->start.QuadPart) / (double)s->freq.QuadPart;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
suite_test_add(suite *s, const char *name, function fct)
|
||||
{
|
||||
test *t;
|
||||
|
@ -131,7 +138,7 @@ suite_test_add(suite *s, const char *name, function fct)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
suite_run(suite *s)
|
||||
{
|
||||
list *l;
|
||||
|
@ -145,21 +152,34 @@ suite_run(suite *s)
|
|||
l->succeed = t->fct(s);
|
||||
printf("%s test: %s\n", t->name, l->succeed ? "success" : "failure");
|
||||
l = l->next;
|
||||
s->tests_count++;
|
||||
if (l->succeed)
|
||||
s->tests_success++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
suite_show(suite *s)
|
||||
{
|
||||
printf ("%d/%d tests passed (%d%%)\n",
|
||||
s->tests_success,
|
||||
s->tests_count,
|
||||
(100 * s->tests_success) / s->tests_count);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test tests[] = {
|
||||
{ "dlfcn ", test_environment },
|
||||
{ "environment ", test_environment },
|
||||
{ "gettimeofday", test_gettimeofday },
|
||||
{ "link ", test_link },
|
||||
{ "memcpy ", test_memcpy },
|
||||
/* { "memcpy ", test_memcpy }, */
|
||||
{ NULL, NULL },
|
||||
};
|
||||
suite *s;
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (!evil_init())
|
||||
return EXIT_FAILURE;
|
||||
|
@ -179,6 +199,8 @@ main()
|
|||
|
||||
suite_run(s);
|
||||
|
||||
suite_show(s);
|
||||
|
||||
suite_del(s);
|
||||
evil_shutdown();
|
||||
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <Evil.h>
|
||||
|
||||
#include "evil_suite.h"
|
||||
|
||||
typedef int (*_evil_init)();
|
||||
typedef int (*_evil_shutdwon)();
|
||||
|
||||
static int
|
||||
test_dlfcn_test_dlopen()
|
||||
{
|
||||
void *handle;
|
||||
|
||||
handle = dlopen("libevil-0.dll", 0);
|
||||
if (!handle)
|
||||
return 0;
|
||||
|
||||
if (!dlclose(handle))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
test_dlfcn_test_dlsym()
|
||||
{
|
||||
void *handle;
|
||||
_evil_init sym_init;
|
||||
_evil_shutdwon sym_shutdown;
|
||||
|
||||
handle = dlopen("libevil-0.dll", 0);
|
||||
if (!handle)
|
||||
return 0;
|
||||
|
||||
sym_init = dlsym(handle, "evil_init");
|
||||
if (!sym_init)
|
||||
{
|
||||
dlclose(handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sym_shutdown = dlsym(handle, "evil_shutdown");
|
||||
if (!sym_shutdown)
|
||||
{
|
||||
dlclose(handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dlclose(handle))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
test_dlfcn_tests_run(suite *s)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = test_dlfcn_test_dlopen();
|
||||
res &= test_dlfcn_test_dlsym();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
test_dlfcn(suite *s)
|
||||
{
|
||||
|
||||
return test_dlfcn_tests_run(s);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef __EVIL_TEST_DLFCN__
|
||||
#define __EVIL_TEST_DLFCN__
|
||||
|
||||
|
||||
int test_dlfcn(suite *s);
|
||||
|
||||
|
||||
#endif /* __EVIL_TEST_DLFCN__ */
|
|
@ -22,7 +22,6 @@ test_env_tests_run(suite *s)
|
|||
return 0;
|
||||
|
||||
val = getenv("EVIL_TEST_ENV");
|
||||
printf ("val : %s\n", val);
|
||||
if (strcmp(val, "val1"))
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -16,16 +16,20 @@ test_time_tests_run(suite *s)
|
|||
{
|
||||
struct timeval tp1;
|
||||
struct timeval tp2;
|
||||
double delta;
|
||||
|
||||
gettimeofday (&tp1, NULL);
|
||||
|
||||
Sleep(20);
|
||||
Sleep(997);
|
||||
|
||||
gettimeofday (&tp2, NULL);
|
||||
|
||||
printf ("time : %ld %ld\n", tp1.tv_sec, tp1.tv_usec);
|
||||
printf ("time : %ld %ld\n", tp2.tv_sec, tp2.tv_usec);
|
||||
printf ("time : %f\n", (double)tp2.tv_sec - tp1.tv_sec + (tp2.tv_usec - tp1.tv_usec) / 1000000.0);
|
||||
delta = (double)tp2.tv_sec - tp1.tv_sec + (tp2.tv_usec - tp1.tv_usec) / 1000000.0;
|
||||
if (delta > 0.005)
|
||||
{
|
||||
printf (" * %f\n", delta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
@ -38,23 +36,31 @@ test_link_test_file_create(const char *name, const char *data)
|
|||
static int
|
||||
test_link_test_symlink(void)
|
||||
{
|
||||
if (!test_link_test_file_create("evil_test_link.dat",
|
||||
#ifdef _WIN32_WCE
|
||||
const char *old_name = "\\efl\\evil_test_link.dat";
|
||||
const char *new_name = "\\efl\\evil_test_link.lnk";
|
||||
#else
|
||||
const char *old_name = "evil_test_link.dat";
|
||||
const char *new_name = "evil_test_link.lnk";
|
||||
#endif
|
||||
|
||||
if (!test_link_test_file_create(old_name,
|
||||
"evil_test_link symlink data\n"))
|
||||
return 0;
|
||||
|
||||
if (symlink("evil_test_link.dat", "evil_test_link.lnk") < 0)
|
||||
if (symlink(old_name, new_name) < 0)
|
||||
{
|
||||
unlink("evil_test_link.dat");
|
||||
unlink(old_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (unlink("evil_test_link.lnk") < 0)
|
||||
if (unlink(new_name) < 0)
|
||||
{
|
||||
unlink("evil_test_link.dat");
|
||||
unlink(old_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (unlink("evil_test_link.dat") < 0)
|
||||
if (unlink(old_name) < 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
@ -63,25 +69,30 @@ test_link_test_symlink(void)
|
|||
static int
|
||||
test_link_test_readlink(void)
|
||||
{
|
||||
char buf[1024];
|
||||
char *data;
|
||||
FILE *f;
|
||||
ssize_t s1;
|
||||
size_t s2;
|
||||
int l;
|
||||
char buf[1024];
|
||||
#ifdef _WIN32_WCE
|
||||
const char *old_name = "\\efl\\evil_test_link.dat";
|
||||
const char *new_name = "\\efl\\evil_test_link.lnk";
|
||||
#else
|
||||
const char *old_name = "evil_test_link.dat";
|
||||
const char *new_name = "evil_test_link.lnk";
|
||||
#endif
|
||||
const char *data = "evil_test_link symlink data\n";
|
||||
FILE *f;
|
||||
ssize_t s1;
|
||||
size_t s2;
|
||||
int l;
|
||||
|
||||
data = "evil_test_link symlink data\n";
|
||||
|
||||
if (!test_link_test_file_create("evil_test_link.dat", data))
|
||||
if (!test_link_test_file_create(old_name, data))
|
||||
return 0;
|
||||
|
||||
if (symlink("evil_test_link.dat", "evil_test_link.lnk") < 0)
|
||||
if (symlink(old_name, new_name) < 0)
|
||||
return 0;
|
||||
|
||||
if ((s1 = readlink("evil_test_link.lnk", buf, 1023)) < 0)
|
||||
if ((s1 = readlink(new_name, buf, 1023)) < 0)
|
||||
{
|
||||
unlink("evil_test_link.dat");
|
||||
unlink("evil_test_link.lnk");
|
||||
unlink(old_name);
|
||||
unlink(new_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -90,8 +101,8 @@ test_link_test_readlink(void)
|
|||
f = fopen(buf, "rb");
|
||||
if (!f)
|
||||
{
|
||||
unlink("evil_test_link.dat");
|
||||
unlink("evil_test_link.lnk");
|
||||
unlink(old_name);
|
||||
unlink(new_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -101,28 +112,28 @@ test_link_test_readlink(void)
|
|||
if ((int)s2 != (l + 1))
|
||||
{
|
||||
fclose(f);
|
||||
unlink("evil_test_link.dat");
|
||||
unlink("evil_test_link.lnk");
|
||||
unlink(old_name);
|
||||
unlink(new_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(buf, data))
|
||||
{
|
||||
fclose(f);
|
||||
unlink("evil_test_link.dat");
|
||||
unlink("evil_test_link.lnk");
|
||||
unlink(old_name);
|
||||
unlink(new_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
if (unlink("evil_test_link.lnk") < 0)
|
||||
if (unlink(new_name) < 0)
|
||||
{
|
||||
unlink("evil_test_link.dat");
|
||||
unlink(old_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (unlink("evil_test_link.dat") < 0)
|
||||
if (unlink(old_name) < 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -40,7 +40,7 @@ symlink(const char *oldpath, const char *newpath)
|
|||
return -1;
|
||||
}
|
||||
|
||||
res = SHCreateShortcutEx(w_newpath, w_oldpath, NULL, NULL);
|
||||
res = SHCreateShortcut(w_newpath, w_oldpath);
|
||||
if (!res)
|
||||
_evil_last_error_display(__FUNCTION__);
|
||||
|
||||
|
@ -54,7 +54,7 @@ ssize_t
|
|||
readlink(const char *path, char *buf, size_t bufsiz)
|
||||
{
|
||||
wchar_t *w_path;
|
||||
wchar_t w_newpath[MB_CUR_MAX];
|
||||
wchar_t w_newpath[1024];
|
||||
char *newpath;
|
||||
size_t length;
|
||||
BOOL res;
|
||||
|
@ -63,7 +63,9 @@ readlink(const char *path, char *buf, size_t bufsiz)
|
|||
if (!w_path)
|
||||
return -1;
|
||||
|
||||
res = SHGetShortcutTarget(w_path, w_newpath, MB_CUR_MAX);
|
||||
res = SHGetShortcutTarget(w_path, w_newpath, 1024);
|
||||
if (!res)
|
||||
_evil_last_error_display(__FUNCTION__);
|
||||
|
||||
free(w_path);
|
||||
|
||||
|
@ -74,11 +76,12 @@ readlink(const char *path, char *buf, size_t bufsiz)
|
|||
if (!newpath)
|
||||
return -1;
|
||||
|
||||
length = strlen(newpath);
|
||||
/* That stupid SHGetShortcutTarget add " around the file name... */
|
||||
length = strlen(newpath) - 2;
|
||||
if (length > bufsiz)
|
||||
length = bufsiz;
|
||||
|
||||
memcpy(buf, newpath, length);
|
||||
memcpy(buf, newpath + 1, length);
|
||||
|
||||
free(newpath);
|
||||
|
||||
|
|
Loading…
Reference in New Issue