aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-05-11 17:26:15 +0200
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-05-11 17:26:15 +0200
commitd37eb3feb226623431a464b189edf2fc2f31beed (patch)
treeaa9af0ddc40adfea6f47d73003060c1da331b52c
parentf58400c634eea6f865db8486e7e174f67bb555ce (diff)
downloadstring2-d37eb3feb226623431a464b189edf2fc2f31beed.tar.gz
string2-d37eb3feb226623431a464b189edf2fc2f31beed.zip
Add tests
-rw-r--r--test/Makefile35
-rw-r--r--test/main.c14
-rwxr-xr-xtest/test1bin0 -> 16344 bytes
-rw-r--r--test/test_split.c41
4 files changed, 90 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..fec56d9
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,35 @@
+# See LICENSE file for copyright and license details.
+
+CC = cc
+SRC != find * -name '*.c'
+OBJ = ${SRC:.c=.o}
+
+LIBNAME = str2
+SHARED = ../lib${LIBNAME}.so
+
+#WARNINGS = -Wall -Werror -pedantic
+STANDARD = -std=c99
+CFLAGS = ${WARNINGS} -I../src/
+LFLAGS = -l${LIBNAME} -L../ -Wl,-rpath=../
+
+NAME = test1
+
+all: ${SHARED} ${NAME}
+ @echo
+ @echo '+-----------------+'
+ @echo '| Executing tests |'
+ @echo '+-----------------+'
+ @echo
+ ./${NAME}
+
+${SHARED}:
+ @make -C ..
+
+.c.o:
+ ${CC} ${CFLAGS} -c $< -o $@
+
+${NAME}: ${OBJ}
+ ${CC} ${LFLAGS} -o $@ ${OBJ}
+
+clean:
+ rm -f ${OBJ} ${NAME} *.core
diff --git a/test/main.c b/test/main.c
new file mode 100644
index 0000000..479d529
--- /dev/null
+++ b/test/main.c
@@ -0,0 +1,14 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdlib.h>
+
+void test_split1();
+void test_split2();
+
+int main(int argc, char** argv)
+{
+ test_split1();
+ test_split2();
+
+ return EXIT_SUCCESS;
+}
diff --git a/test/test1 b/test/test1
new file mode 100755
index 0000000..b83a949
--- /dev/null
+++ b/test/test1
Binary files differ
diff --git a/test/test_split.c b/test/test_split.c
new file mode 100644
index 0000000..7b19caa
--- /dev/null
+++ b/test/test_split.c
@@ -0,0 +1,41 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string2.h>
+
+#define assert(c) if (c == 0) { printf("%s:%d\n", __FILE__, __LINE__); exit(1);}
+#define log(str) printf("%s: %s\n", __func__, str);
+
+void
+test_split1()
+{
+ log("Running...");
+
+ char *str = "STR_1\nSTR_2";
+ int size;
+ char **tokens = strsplit(str, '\n', &size);
+
+ assert(size == 2);
+ assert(strncmp("STR_1", tokens[0], 5) == 0);
+ assert(strncmp("STR_2", tokens[1], 5) == 0);
+
+ log("OK\n");
+}
+
+void
+test_split2()
+{
+ log("Running...");
+
+ char *str = "\nSTR_1\nSTR_2";
+ int size;
+ char **tokens = strsplit(str, '\n', &size);
+
+ assert(size == 3);
+ assert(strlen(tokens[0]) == 0);
+ assert(strncmp("STR_1", tokens[1], 5) == 0);
+ assert(strncmp("STR_2", tokens[2], 5) == 0);
+
+ log("OK\n");
+}