aboutsummaryrefslogtreecommitdiffstats
path: root/libsimple.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-26 21:55:19 +0200
committerMattias Andrée <maandree@kth.se>2018-08-26 21:55:19 +0200
commit923109ac7005d2d9ae3be9b8c0ffbda0a83a6871 (patch)
treeea33b31354c9f369ea4c41c06fd81a5d5389970b /libsimple.c
parentm (diff)
downloadlibsimple-923109ac7005d2d9ae3be9b8c0ffbda0a83a6871.tar.gz
libsimple-923109ac7005d2d9ae3be9b8c0ffbda0a83a6871.tar.bz2
libsimple-923109ac7005d2d9ae3be9b8c0ffbda0a83a6871.tar.xz
m + add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libsimple.c233
1 files changed, 232 insertions, 1 deletions
diff --git a/libsimple.c b/libsimple.c
index df01ea1..b27f3bb 100644
--- a/libsimple.c
+++ b/libsimple.c
@@ -96,7 +96,8 @@ test_timeval(double d, time_t sec, long int usec, double rd, const char *s, cons
int
main(void)
{
- struct timespec ts;
+ struct timespec ts, ts1, ts2;
+ struct timeval tv1, tv2;
const char *cs;
char buf[1024], *s;
int intarray[10];
@@ -780,6 +781,236 @@ main(void)
assert(ts.tv_sec == -10);
assert(ts.tv_nsec == 1000L);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 999999999L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 999999999L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = 0, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = 0, ts1.tv_nsec = 1L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = -1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 1L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 1L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 0, ts1.tv_nsec = 0L;
+ ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+ ts1.tv_sec = TIME_MAX, ts1.tv_nsec = 0L;
+ ts2.tv_sec = TIME_MAX, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 0);
+ ts1.tv_sec = 1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = -1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == 1);
+ ts1.tv_sec = -1, ts1.tv_nsec = 0L;
+ ts2.tv_sec = 1, ts2.tv_nsec = 0L;
+ assert(libsimple_cmptimespec(&ts1, &ts2) == -1);
+
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 999999L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 0, tv1.tv_usec = 999999L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 999999L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 999999L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 999999L;
+ tv2.tv_sec = 0, tv2.tv_usec = 999999L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = 1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = -1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = -1, tv1.tv_usec = 1L;
+ tv2.tv_sec = 0, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = 0, tv1.tv_usec = 1L;
+ tv2.tv_sec = -1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = -1, tv1.tv_usec = 1L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = -1, tv1.tv_usec = 1L;
+ tv2.tv_sec = -1, tv2.tv_usec = 1L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 0, tv1.tv_usec = 0L;
+ tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+ tv1.tv_sec = TIME_MAX, tv1.tv_usec = 0L;
+ tv2.tv_sec = TIME_MAX, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 0);
+ tv1.tv_sec = 1, tv1.tv_usec = 0L;
+ tv2.tv_sec = -1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == 1);
+ tv1.tv_sec = -1, tv1.tv_usec = 0L;
+ tv2.tv_sec = 1, tv2.tv_usec = 0L;
+ assert(libsimple_cmptimeval(&tv1, &tv2) == -1);
+
return 0;
}