summaryrefslogtreecommitdiff
path: root/test/test_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_io.c')
-rw-r--r--test/test_io.c67
1 files changed, 43 insertions, 24 deletions
diff --git a/test/test_io.c b/test/test_io.c
index 0596dbc..688ac31 100644
--- a/test/test_io.c
+++ b/test/test_io.c
@@ -21,20 +21,20 @@
#include <stdio.h>
#include <string.h>
-#include "minunit.h"
-
#include "io.h"
+#include "minunit.h"
+
extern int tests_run;
-char *test_stream_obj(void) {
+const char *test_stream_obj(void) {
struct stream *s_1 = stream_new(0x10);
struct stream *s_2 = stream_new(0x20);
struct stream *s_3 = stream_new(0x40);
- mu_assert("Incorrect size for stream `s_1`", s_1->len == 0x10);
- mu_assert("Incorrect size for stream `s_2`", s_2->len == 0x20);
- mu_assert("Incorrect size for stream `s_3`", s_3->len == 0x40);
+ mu_assert("[io] test_stream_obj: Incorrect size for stream `s_1`", s_1->len == 0x10);
+ mu_assert("[io] test_stream_obj: Incorrect size for stream `s_2`", s_2->len == 0x20);
+ mu_assert("[io] test_stream_obj: Incorrect size for stream `s_3`", s_3->len == 0x40);
stream_free(s_1);
stream_free(s_2);
stream_free(s_3);
@@ -42,23 +42,27 @@ char *test_stream_obj(void) {
}
-char *test_stream_rw(void) {
+const char *test_stream_rw(void) {
char dest[4];
struct stream *s = stream_new(0x4);
stream_write(s, "\x00\x01\x02\x03", 4);
- mu_assert("Stream write failure", !memcmp(s->_start, "\x00\x01\x02\x03", 4));
- mu_assert("Stream write did not increment cursor", s->_cur - s->_start == 4);
+ mu_assert("[io] test_stream_rw: Stream write failure",
+ !memcmp(s->_start, "\x00\x01\x02\x03", 4));
+ mu_assert("[io] test_stream_rw: Write did not increment cursor",
+ s->_cur - s->_start == 4);
s->_cur = s->_start;
stream_read(dest, s, 4);
- mu_assert("Stream read failure", !memcmp(dest, "\x00\x01\x02\x03", 4));
- mu_assert("Stream read did not increment cursor", s->_cur - s->_start == 4);
+ mu_assert("[io] test_stream_rw: Stream read failure",
+ !memcmp(dest, "\x00\x01\x02\x03", 4));
+ mu_assert("[io] test_stream_rw: Read did not increment cursor",
+ s->_cur - s->_start == 4);
stream_free(s);
return NULL;
}
-char *test_stream_dump(void) {
+const char *test_stream_dump(void) {
char buf[4];
FILE *fp = tmpfile();
struct stream *s = stream_new(0x4);
@@ -67,43 +71,58 @@ char *test_stream_dump(void) {
stream_dump(fp, s, 4);
fseek(fp, 0, SEEK_SET);
fread(buf, 4, 1, fp);
- mu_assert("Stream dump failure", !memcmp(buf, "\x00\x01\x02\x03", 4));
+ mu_assert("[io] test_stream_dump: Stream dump failure",
+ !memcmp(buf, "\x00\x01\x02\x03", 4));
fclose(fp);
return NULL;
}
-char *test_stream_realloc(void) {
+const char *test_stream_realloc(void) {
struct stream *s = stream_new(0x2);
stream_write(s, "\x00\x01\x02\x03", 4);
- mu_assert("Stream realloc did not modify `len`", s->len > 0x2);
+ mu_assert("[io] test_stream_realloc: Stream realloc did not modify `len`",
+ s->len > 0x2);
return NULL;
}
-char *test_stream_xor(void) {
+const char *test_stream_xor(void) {
struct stream *s = stream_new(2);
stream_write(s, "\x01\x01", 2);
stream_xor(s, 1, 0);
- mu_assert("Stream initial key failure", !memcmp(s->_start, "\x00\x01", 2));
+ mu_assert("[io] test_stream_xor: Stream initial key failure",
+ !memcmp(s->_start, "\x00\x01", 2));
+
stream_xor(s, 0, 1);
- mu_assert("Stream primary key failure", !memcmp(s->_start, "\x01\x00", 2));
+ mu_assert("[io] test_stream_xor: Stream primary key failure",
+ !memcmp(s->_start, "\x01\x00", 2));
+
stream_free(s);
return NULL;
}
-char *test_stream_nav(void) {
+const char *test_stream_nav(void) {
struct stream *s = stream_new(2);
- mu_assert("Stream cursor not at beginning", stream_tell(s) == 0);
+ mu_assert("[io] test_stream_nav: Stream cursor not at beginning",
+ stream_tell(s) == 0);
+
stream_seek(s, 2, SEEK_CUR);
- mu_assert("Stream cursor not advanced (SEEK_CUR)", stream_tell(s) == 2);
+ mu_assert("[io] test_stream_nav: Stream cursor not advanced (SEEK_CUR)",
+ stream_tell(s) == 2);
+
stream_seek(s, 2, SEEK_SET);
- mu_assert("Stream cursor not advanced (SEEK_SET)", stream_tell(s) == 2);
+ mu_assert("[io] test_stream_nav: Stream cursor not advanced (SEEK_SET)",
+ stream_tell(s) == 2);
+
stream_seek(s, 0, SEEK_END);
- mu_assert("Stream cursor not advanced (SEEK_END)", stream_tell(s) == 2);
+ mu_assert("[io] test_stream_nav: Stream cursor not advanced (SEEK_END)",
+ stream_tell(s) == 2);
+
stream_rewind(s);
- mu_assert("Stream cursor not rewinded", stream_tell(s) == 0);
+ mu_assert("[io] test_stream_nav: Stream cursor not rewinded",
+ stream_tell(s) == 0);
stream_free(s);
return NULL;
}