summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_cli.c32
-rw-r--r--test/test_cli.h22
-rw-r--r--test/test_encoding.c34
-rw-r--r--test/test_encoding.h22
-rw-r--r--test/test_header.c4
-rw-r--r--test/test_io.c46
-rw-r--r--test/test_io.h1
-rw-r--r--test/test_run.c5
-rw-r--r--test/test_table.c34
-rw-r--r--test/test_table.h1
10 files changed, 181 insertions, 20 deletions
diff --git a/test/test_cli.c b/test/test_cli.c
new file mode 100644
index 0000000..f52ae0d
--- /dev/null
+++ b/test/test_cli.c
@@ -0,0 +1,32 @@
+/* test_cli.c -- MinUnit test cases for cli.c
+
+ Copyright (C) 2017 Jakob Tsar-Fox, All Rights Reserved.
+
+ This file is part of Nekopack.
+
+ Nekopack is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at
+ your option) any later version.
+
+ Nekopack is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <string.h>
+
+#include "minunit.h"
+
+#include "cli.h"
+
+
+char *test_out_path(void) {
+ char *argv[4] = {"nekopack", "-o", "/tmp", "a.xp3"};
+ struct params p = parse_args(3, argv);
+ mu_assert("Trailing slash not appended to path", !strcmp(p.out, "/tmp/"));
+ return NULL;
+}
diff --git a/test/test_cli.h b/test/test_cli.h
new file mode 100644
index 0000000..b42bb4d
--- /dev/null
+++ b/test/test_cli.h
@@ -0,0 +1,22 @@
+/* test_cli.h -- MinUnit test cases for cli.c
+
+ Copyright (C) 2017 Jakob Tsar-Fox, All Rights Reserved.
+
+ This file is part of Nekopack.
+
+ Nekopack is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at
+ your option) any later version.
+
+ Nekopack is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
+
+#pragma once
+
+char *test_out_path(void);
diff --git a/test/test_encoding.c b/test/test_encoding.c
new file mode 100644
index 0000000..f5c91c2
--- /dev/null
+++ b/test/test_encoding.c
@@ -0,0 +1,34 @@
+/* test_encoding.c -- MinUnit test cases for encoding.c
+
+ Copyright (C) 2017 Jakob Tsar-Fox, All Rights Reserved.
+
+ This file is part of Nekopack.
+
+ Nekopack is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at
+ your option) any later version.
+
+ Nekopack is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "minunit.h"
+
+#include "encoding.h"
+
+
+char *test_decode_utf16le(void) {
+ char *in = "\x41\x00\x00\x00", *out = malloc(4);
+ utf16le_decode(in, out, 4);
+ mu_assert("UTF16-LE decoding failure", !strcmp(out, "A"));
+ free(out);
+ return NULL;
+}
diff --git a/test/test_encoding.h b/test/test_encoding.h
new file mode 100644
index 0000000..6531382
--- /dev/null
+++ b/test/test_encoding.h
@@ -0,0 +1,22 @@
+/* test_encoding.h -- MinUnit test cases for encoding.c
+
+ Copyright (C) 2017 Jakob Tsar-Fox, All Rights Reserved.
+
+ This file is part of Nekopack.
+
+ Nekopack is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at
+ your option) any later version.
+
+ Nekopack is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
+
+#pragma once
+
+char *test_decode_utf16le(void);
diff --git a/test/test_header.c b/test/test_header.c
index 15aa18c..908d889 100644
--- a/test/test_header.c
+++ b/test/test_header.c
@@ -30,8 +30,8 @@ extern int tests_run;
char *test_header_read(void) {
struct stream *s = stream_new(sizeof(struct xp3_header));
-
memset(s->_start, '\x00', sizeof(struct xp3_header));
+
struct xp3_header *h = read_header(s);
mu_assert("Header assertions failed", h == NULL);
@@ -40,7 +40,7 @@ char *test_header_read(void) {
"\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x80\x00\x00\x00\x00\x00"
"\x00\x00\x00\xd1\xfe\x56\x0b\x00\x00\x00\x00", 42);
h = read_header(s);
- mu_assert("Header read as invalid", h != NULL);
+ mu_assert("Header parsing failure", h != NULL);
stream_free(s);
return NULL;
diff --git a/test/test_io.c b/test/test_io.c
index f295182..99e84db 100644
--- a/test/test_io.c
+++ b/test/test_io.c
@@ -18,6 +18,7 @@
along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
#include <stdint.h>
+#include <stdio.h>
#include <string.h>
#include "minunit.h"
@@ -31,9 +32,9 @@ 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 `s_1`", s_1->len == 0x10);
- mu_assert("Incorrect size for `s_2`", s_2->len == 0x20);
- mu_assert("Incorrect size for `s_3`", s_3->len == 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);
stream_free(s_1);
stream_free(s_2);
stream_free(s_3);
@@ -45,22 +46,37 @@ char *test_stream_rw(void) {
char dest[4];
struct stream *s = stream_new(0x4);
stream_write(s, "\x00\x01\x02\x03", 4);
- mu_assert("Write failure", !memcmp(s->_start, "\x00\x01\x02\x03", 4));
- mu_assert("Cursor not incremented", s->_cur - s->_start == 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);
s->_cur = s->_start;
stream_read(dest, s, 4);
- mu_assert("Read failure", !memcmp(dest, "\x00\x01\x02\x03", 4));
- mu_assert("Cursor not incremented", s->_cur - s->_start == 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);
stream_free(s);
return NULL;
}
+char *test_stream_dump(void) {
+ char buf[4];
+ FILE *fp = tmpfile();
+ struct stream *s = stream_new(0x4);
+ stream_write(s, "\x00\x01\x02\x03", 4);
+ stream_rewind(s);
+ 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));
+ fclose(fp);
+ return NULL;
+}
+
+
char *test_stream_realloc(void) {
struct stream *s = stream_new(0x2);
stream_write(s, "\x00\x01\x02\x03", 4);
- mu_assert("`len` not modified", s->len > 0x2);
+ mu_assert("Stream realloc did not modify `len`", s->len > 0x2);
return NULL;
}
@@ -69,9 +85,9 @@ char *test_stream_xor(void) {
struct stream *s = stream_new(2);
stream_write(s, "\x01\x01", 2);
stream_xor(s, 1, 0);
- mu_assert("Initial key failure", !memcmp(s->_start, "\x00\x01", 2));
+ mu_assert("Stream initial key failure", !memcmp(s->_start, "\x00\x01", 2));
stream_xor(s, 0, 1);
- mu_assert("Primary key failure", !memcmp(s->_start, "\x01\x00", 2));
+ mu_assert("Stream primary key failure", !memcmp(s->_start, "\x01\x00", 2));
stream_free(s);
return NULL;
}
@@ -79,15 +95,15 @@ char *test_stream_xor(void) {
char *test_stream_nav(void) {
struct stream *s = stream_new(2);
- mu_assert("Cursor not at beginning", stream_tell(s) == 0);
+ mu_assert("Stream cursor not at beginning", stream_tell(s) == 0);
stream_seek(s, 2, SEEK_CUR);
- mu_assert("Cursor not advanced (SEEK_CUR)", stream_tell(s) == 2);
+ mu_assert("Stream cursor not advanced (SEEK_CUR)", stream_tell(s) == 2);
stream_seek(s, 2, SEEK_SET);
- mu_assert("Cursor not advanced (SEEK_SET)", stream_tell(s) == 2);
+ mu_assert("Stream cursor not advanced (SEEK_SET)", stream_tell(s) == 2);
stream_seek(s, 0, SEEK_END);
- mu_assert("Cursor not advanced (SEEK_END)", stream_tell(s) == 2);
+ mu_assert("Stream cursor not advanced (SEEK_END)", stream_tell(s) == 2);
stream_rewind(s);
- mu_assert("Cursor not rewinded", stream_tell(s) == 0);
+ mu_assert("Stream cursor not rewinded", stream_tell(s) == 0);
stream_free(s);
return NULL;
}
diff --git a/test/test_io.h b/test/test_io.h
index ab3547f..1889e8e 100644
--- a/test/test_io.h
+++ b/test/test_io.h
@@ -21,6 +21,7 @@
char *test_stream_obj(void);
char *test_stream_rw(void);
+char *test_stream_dump(void);
char *test_stream_realloc(void);
char *test_stream_xor(void);
char *test_stream_nav(void);
diff --git a/test/test_run.c b/test/test_run.c
index c6930dc..f1bf07e 100644
--- a/test/test_run.c
+++ b/test/test_run.c
@@ -21,6 +21,7 @@
#include "minunit.h"
+#include "test_encoding.h"
#include "test_header.h"
#include "test_io.h"
#include "test_table.h"
@@ -29,14 +30,18 @@ int tests_run = 0;
static char *run_all_tests(void) {
+ mu_run_test(test_out_path);
mu_run_test(test_stream_obj);
mu_run_test(test_stream_rw);
+ mu_run_test(test_stream_dump);
mu_run_test(test_stream_realloc);
mu_run_test(test_stream_xor);
mu_run_test(test_stream_nav);
mu_run_test(test_header_read);
mu_run_test(test_table_list);
mu_run_test(test_table_elif);
+ mu_run_test(test_table_file);
+ mu_run_test(test_decode_utf16le);
return NULL;
}
diff --git a/test/test_table.c b/test/test_table.c
index e6c18b0..d459de0 100644
--- a/test/test_table.c
+++ b/test/test_table.c
@@ -31,7 +31,7 @@ char *test_table_list(void) {
struct table_entry *next = calloc(sizeof(struct table_entry), 1);
next->key = 0xffffffff;
entry_append(root, next);
- mu_assert("Entry not inserted", root->next->key == 0xffffffff);
+ mu_assert("Table entry not inserted", root->next->key == 0xffffffff);
entry_free(root);
return NULL;
}
@@ -43,9 +43,37 @@ char *test_table_elif(void) {
stream_write(s, "\xff\xff\xff\xff\x01\x00\x41\x00\x00\x00", 10);
stream_rewind(s);
read_elif(s, root);
- mu_assert("Entry not inserted", root->next != NULL);
- mu_assert("Filename handling failed", !strcmp(root->next->filename, "A"));
+ mu_assert("Table entry not inserted (eliF)", root->next != NULL);
+ mu_assert("Filename handling failure", !strcmp(root->next->filename, "A"));
+ free(root->next->filename);
+ root->next->filename = NULL;
+ stream_rewind(s);
+ read_elif(s, root);
+ mu_assert("Existing entry ignored (eliF)", root->next->next == NULL);
entry_free(root);
stream_free(s);
return NULL;
}
+
+
+char *test_table_file(void) {
+ struct stream *s = stream_new(0x100);
+ struct table_entry *root = calloc(sizeof(struct table_entry), 1);
+ stream_write(s, "\x61\x64\x6c\x72\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff"
+ "\xff\xff\x73\x65\x67\x6d\x1c\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x69\x6e\x66"
+ "\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x74\x69\x6d\x65\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x00", 113);
+ stream_rewind(s);
+ read_file(s, root);
+ mu_assert("Table entry not inserted (eliF)", root->next != NULL);
+ mu_assert("Key read failure", root->next->key == 0xffffffff);
+ root->next->ctime = 420;
+ stream_rewind(s);
+ read_file(s, root);
+ mu_assert("Existing entry ignored (eliF)", root->next->ctime == 0);
+ return NULL;
+}
diff --git a/test/test_table.h b/test/test_table.h
index 899c2ab..bd3efa8 100644
--- a/test/test_table.h
+++ b/test/test_table.h
@@ -21,3 +21,4 @@
char *test_table_list(void);
char *test_table_elif(void);
+char *test_table_file(void);