From 185c5c2f86adacbe2ba6987f2de14b98090bc51a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 26 Aug 2018 13:06:08 +0200 Subject: Add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- timespectostr.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'timespectostr.c') diff --git a/timespectostr.c b/timespectostr.c index 05bcaac..bd99fe1 100644 --- a/timespectostr.c +++ b/timespectostr.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "libsimple.h" +#ifndef TEST char * @@ -37,3 +38,28 @@ libsimple_timespectostr(char *restrict buf, const struct timespec *restrict ts) sprintf(buf, "%s%lli.%09li", sign, (long long int)s, ns); return buf; } + + +#else +#include "test.h" + +int +main(void) +{ + char buf[1000]; + + /* Mostly tested in libsimple.c */ + + errno = 0; + assert(!libsimple_timespectostr(buf, &(struct timespec){.tv_sec = 0, .tv_nsec = -1}) && errno == EINVAL); + errno = 0; + assert(!libsimple_timespectostr(buf, &(struct timespec){.tv_sec = 0, .tv_nsec = -2}) && errno == EINVAL); + errno = 0; + assert(!libsimple_timespectostr(buf, &(struct timespec){.tv_sec = 0, .tv_nsec = 1000000000L}) && errno == EINVAL); + errno = 0; + assert(!libsimple_timespectostr(buf, &(struct timespec){.tv_sec = 0, .tv_nsec = 1000000001L}) && errno == EINVAL); + + return 0; +} + +#endif -- cgit v1.2.3-70-g09d2