aboutsummaryrefslogtreecommitdiffstats
path: root/libsimple.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-28 14:18:41 +0200
committerMattias Andrée <maandree@kth.se>2018-08-28 14:18:41 +0200
commitbad369a06217cd1588c289a75b6a1c17d44119b3 (patch)
tree626b3847268037f2621157a25bfbabb874bb88dc /libsimple.c
parentMake it possible to force all memory allocation functions to fail in tests (diff)
downloadlibsimple-bad369a06217cd1588c289a75b6a1c17d44119b3.tar.gz
libsimple-bad369a06217cd1588c289a75b6a1c17d44119b3.tar.bz2
libsimple-bad369a06217cd1588c289a75b6a1c17d44119b3.tar.xz
Replace exit and fprintf
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libsimple.c')
-rw-r--r--libsimple.c61
1 files changed, 20 insertions, 41 deletions
diff --git a/libsimple.c b/libsimple.c
index b27f3bb..731396d 100644
--- a/libsimple.c
+++ b/libsimple.c
@@ -17,36 +17,25 @@ test_timespec(double d, time_t sec, long int nsec, double rd, const char *s, con
double dt;
libsimple_doubletotimespec(&t, d);
- if (t.tv_sec != sec)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (t.tv_nsec != nsec)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(t.tv_sec == sec);
+ subassert(t.tv_nsec == nsec);
dt = libsimple_timespectodouble(&t);
- if (dt < rd - 0.0000000001)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (dt > rd + 0.0000000001)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(dt >= rd - 0.0000000001);
+ subassert(dt <= rd + 0.0000000001);
str = libsimple_timespectostr(buf, &t);
- if (str != buf)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (strcmp(str, s))
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(str == buf);
+ subassert(!strcmp(str, s));
- str = libsimple_timespectostr(NULL, &t);
- if (!str)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (strcmp(str, s))
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert((str = libsimple_timespectostr(NULL, &t)));
+ subassert(!strcmp(str, s));
strcpy(buf, str);
free(str);
str = libsimple_minimise_number_string(buf);
- if (str != buf)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (strcmp(str, ss))
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(str == buf);
+ subassert(!strcmp(str, ss));
return 1;
}
@@ -59,36 +48,26 @@ test_timeval(double d, time_t sec, long int usec, double rd, const char *s, cons
double dt;
libsimple_doubletotimeval(&t, d);
- if (t.tv_sec != sec)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (t.tv_usec != usec)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(t.tv_sec == sec);
+ subassert(t.tv_usec == usec);
dt = libsimple_timevaltodouble(&t);
- if (dt < rd - 0.0000001)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (dt > rd + 0.0000001)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(dt >= rd - 0.0000001);
+ subassert(dt <= rd + 0.0000001);
str = libsimple_timevaltostr(buf, &t);
- if (str != buf)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (strcmp(str, s))
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(str == buf);
+ subassert(!strcmp(str, s));
str = libsimple_timevaltostr(NULL, &t);
- if (!str)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (strcmp(str, s))
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(str);
+ subassert(!strcmp(str, s));
strcpy(buf, str);
free(str);
str = libsimple_minimise_number_string(buf);
- if (str != buf)
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
- if (strcmp(str, ss))
- return fprintf(stderr, "Failed at %s:%i\n", __FILE__, __LINE__ - 1), 0;
+ subassert(str == buf);
+ subassert(!strcmp(str, ss));
return 1;
}