aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-26 13:06:08 +0200
committerMattias Andrée <maandree@kth.se>2018-08-26 13:06:08 +0200
commit185c5c2f86adacbe2ba6987f2de14b98090bc51a (patch)
treef1906bcb8cbf13c8cfb795439912833a28fd1898
parentFixes, more test, and add minimise_number_string (diff)
downloadlibsimple-185c5c2f86adacbe2ba6987f2de14b98090bc51a.tar.gz
libsimple-185c5c2f86adacbe2ba6987f2de14b98090bc51a.tar.bz2
libsimple-185c5c2f86adacbe2ba6987f2de14b98090bc51a.tar.xz
Add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--Makefile2
-rw-r--r--timespectostr.c26
-rw-r--r--timevaltostr.c26
3 files changed, 54 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 50b8ca9..451a3af 100644
--- a/Makefile
+++ b/Makefile
@@ -78,6 +78,8 @@ TESTS =\
strrcasestr.test\
strrstr.test\
strstarts.test\
+ timespectostr.test\
+ timevaltostr.test\
vasprintf.test\
libsimple.test
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
diff --git a/timevaltostr.c b/timevaltostr.c
index 5daace5..702b46b 100644
--- a/timevaltostr.c
+++ b/timevaltostr.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"
+#ifndef TEST
char *
@@ -37,3 +38,28 @@ libsimple_timevaltostr(char *restrict buf, const struct timeval *restrict tv)
sprintf(buf, "%s%lli.%06li", sign, (long long int)s, us);
return buf;
}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ char buf[1000];
+
+ /* Mostly tested in libsimple.c */
+
+ errno = 0;
+ assert(!libsimple_timevaltostr(buf, &(struct timeval){.tv_sec = 0, .tv_usec = -1}) && errno == EINVAL);
+ errno = 0;
+ assert(!libsimple_timevaltostr(buf, &(struct timeval){.tv_sec = 0, .tv_usec = -2}) && errno == EINVAL);
+ errno = 0;
+ assert(!libsimple_timevaltostr(buf, &(struct timeval){.tv_sec = 0, .tv_usec = 1000000L}) && errno == EINVAL);
+ errno = 0;
+ assert(!libsimple_timevaltostr(buf, &(struct timeval){.tv_sec = 0, .tv_usec = 1000001L}) && errno == EINVAL);
+
+ return 0;
+}
+
+#endif