summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-12-28 20:43:30 +1300
committerDavid Phillips <david@sighup.nz>2017-12-28 20:43:30 +1300
commitb6a3052c3ebde6114ec6166971b3072460c44814 (patch)
tree9a36552c07e6fea22c597616229ffd79e437aef2 /test
parent7823d9c7e4f3c0485e8d96e44e0d94541762c6d1 (diff)
downloadhence-b6a3052c3ebde6114ec6166971b3072460c44814.tar.xz
Add more tests, fix misc bugs found
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rwxr-xr-xtest/test-duplicate-inputbin0 -> 18808 bytes
-rw-r--r--test/test-duplicate-input.c13
-rwxr-xr-xtest/test-short-keywordbin0 -> 19008 bytes
-rw-r--r--test/test-short-keyword.c52
5 files changed, 67 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile
index 053552f..6f04c4a 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -2,6 +2,8 @@ CFLAGS += -I../
TESTS = \
test-whitespace-input \
+ test-short-keyword \
+ test-duplicate-input \
test-logic-and \
test-logic-or \
test-logic-nand \
diff --git a/test/test-duplicate-input b/test/test-duplicate-input
new file mode 100755
index 0000000..236c6fc
--- /dev/null
+++ b/test/test-duplicate-input
Binary files differ
diff --git a/test/test-duplicate-input.c b/test/test-duplicate-input.c
new file mode 100644
index 0000000..8d1b88f
--- /dev/null
+++ b/test/test-duplicate-input.c
@@ -0,0 +1,13 @@
+#include <assert.h>
+
+#include "gate.h"
+#include "parser.h"
+
+int main(void) {
+ char test_string[] = "input test\n";
+ assert(0 == parse_line(test_string));
+ assert(gate_get_input_by_name("test") != NULL);
+ assert(0 != parse_line(test_string));
+ assert(gate_get_input_by_name("test") != NULL);
+ return 0;
+}
diff --git a/test/test-short-keyword b/test/test-short-keyword
new file mode 100755
index 0000000..39f58dc
--- /dev/null
+++ b/test/test-short-keyword
Binary files differ
diff --git a/test/test-short-keyword.c b/test/test-short-keyword.c
new file mode 100644
index 0000000..50d44d3
--- /dev/null
+++ b/test/test-short-keyword.c
@@ -0,0 +1,52 @@
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "gate.h"
+#include "parser.h"
+
+char *failures[] = {
+ "input\n",
+ "input \n",
+};
+
+char *passes[] = {
+ "input a\n",
+ "input aaaaaaaa\n",
+ "\n",
+ "\n\n",
+ "\r",
+ "\r\r",
+ "\r\n",
+ "\n\r",
+ "\n\n\r",
+ "\r\n\r",
+};
+
+int main(void) {
+ size_t i = 0;
+ char *string = NULL;
+
+ for (i = 0; i < sizeof(failures)/sizeof(failures[0]); i++) {
+ string = strdup(failures[i]);
+ if (string == NULL) {
+ perror("strdup");
+ return 1;
+ }
+ fprintf(stderr, "Testing xfail '%s'\n", string);
+ assert(0 != parse_line(string));
+ free(string);
+ }
+ for (i = 0; i < sizeof(passes)/sizeof(passes[0]); i++) {
+ string = strdup(passes[i]);
+ if (string == NULL) {
+ perror("strdup");
+ return 1;
+ }
+ fprintf(stderr, "Testing xpass '%s'\n", string);
+ assert(0 == parse_line(string));
+ free(string);
+ }
+ return 0;
+}