mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-07 16:00:55 +00:00
Add unit testing framework from libite (-lite)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
847532f935
commit
6a21b7a90b
4 files changed
+94
-2
No files matched your search
+1
-1
@@ -19,7 +19,7 @@ doc_DATA = README.md LICENSE
|
|||||||
EXTRA_DIST = README.md LICENSE AUTHORS ChangeLog.md
|
EXTRA_DIST = README.md LICENSE AUTHORS ChangeLog.md
|
||||||
|
|
||||||
DIST_SUBDIRS = examples
|
DIST_SUBDIRS = examples
|
||||||
SUBDIRS = .
|
SUBDIRS = tests
|
||||||
if ENABLE_EXAMPLES
|
if ENABLE_EXAMPLES
|
||||||
SUBDIRS += examples
|
SUBDIRS += examples
|
||||||
endif
|
endif
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ AM_SILENT_RULES([yes])
|
|||||||
|
|
||||||
AC_CONFIG_SRCDIR(uev.c)
|
AC_CONFIG_SRCDIR(uev.c)
|
||||||
AM_CONFIG_HEADER(config.h)
|
AM_CONFIG_HEADER(config.h)
|
||||||
AC_CONFIG_FILES([Makefile libuev.pc examples/Makefile])
|
AC_CONFIG_FILES([Makefile libuev.pc examples/Makefile tests/Makefile])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
EXTRA_DIST = check.h
|
||||||
|
CLEANFILES = *~ *.trs *.log
|
||||||
|
|
||||||
|
TESTS =
|
||||||
|
|
||||||
|
check_PROGRAMS = $(TESTS)
|
||||||
|
|
||||||
|
# Ignore warnings about unused result, in e.g. write()
|
||||||
|
CFLAGS = -W -Wall -Wextra -Wno-unused-result
|
||||||
|
CPPFLAGS = -D_GNU_SOURCE
|
||||||
|
LDADD = -L../ ../libuev.la
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#ifndef UEV_TESTS_CHECK_H_
|
||||||
|
#define UEV_TESTS_CHECK_H_
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "../uev.h"
|
||||||
|
|
||||||
|
#define UNUSED(arg) arg __attribute__ ((unused))
|
||||||
|
|
||||||
|
#define fail_unless(test) \
|
||||||
|
do { \
|
||||||
|
if (!(test)) { \
|
||||||
|
fprintf(stderr, \
|
||||||
|
"----------------------------------------------\n" \
|
||||||
|
"%s:%d: test FAILED:\nFailed test: %s\n" \
|
||||||
|
"----------------------------------------------\n", \
|
||||||
|
__FILE__, __LINE__, #test); \
|
||||||
|
exit(1); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static inline int test(int result, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buf[80];
|
||||||
|
size_t len;
|
||||||
|
va_list ap;
|
||||||
|
const char success[] = " \033[1m[ OK ]\033[0m\n";
|
||||||
|
const char failure[] = " \033[7m[FAIL]\033[0m\n";
|
||||||
|
const char dots[] = " .....................................................................";
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
write(STDERR_FILENO, buf, len);
|
||||||
|
write(STDERR_FILENO, dots, 60 - len); /* pad with dots. */
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
write(STDERR_FILENO, success, strlen(success));
|
||||||
|
else
|
||||||
|
write(STDERR_FILENO, failure, strlen(failure));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int timespec_newer(const struct timespec *a, const struct timespec *b)
|
||||||
|
{
|
||||||
|
if (a->tv_sec != b->tv_sec)
|
||||||
|
return a->tv_sec > b->tv_sec;
|
||||||
|
|
||||||
|
return a->tv_nsec > b->tv_nsec;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char *timespec2str(struct timespec *ts, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
size_t ret, pos;
|
||||||
|
struct tm t;
|
||||||
|
|
||||||
|
memset(buf, 0, len);
|
||||||
|
|
||||||
|
tzset();
|
||||||
|
if (localtime_r(&(ts->tv_sec), &t) == NULL)
|
||||||
|
return buf;
|
||||||
|
|
||||||
|
ret = strftime(buf, len, "%F %T", &t);
|
||||||
|
if (ret == 0)
|
||||||
|
return buf;
|
||||||
|
len -= ret - 1;
|
||||||
|
|
||||||
|
pos = strlen(buf);
|
||||||
|
len -= pos;
|
||||||
|
snprintf(&buf[pos], len, ".%09ld", ts->tv_nsec);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* UEV_TESTS_CHECK_H_ */
|
||||||
Reference in new issue
Block a user