aboutsummaryrefslogtreecommitdiffstats
path: root/broken/propagate/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'broken/propagate/src/tests')
-rw-r--r--broken/propagate/src/tests/Makefile23
-rw-r--r--broken/propagate/src/tests/test_base64.c88
-rw-r--r--broken/propagate/src/tests/test_explode.c39
3 files changed, 150 insertions, 0 deletions
diff --git a/broken/propagate/src/tests/Makefile b/broken/propagate/src/tests/Makefile
new file mode 100644
index 0000000..6f81535
--- /dev/null
+++ b/broken/propagate/src/tests/Makefile
@@ -0,0 +1,23 @@
+TEST_EXPLODE = test_explode
+TEST_B64 = test_base64
+CFLAGS = -g -Wall -std=c99
+LDFLAGS =
+
+all: $(TEST_EXPLODE) $(TEST_B64)
+
+%.o: %.c
+ $(CC) -o $@ -c $< $(CFLAGS) $(LDFLAGS) -I../
+
+$(TEST_EXPLODE): test_explode.o ../libihf.o
+ $(CC) test_explode.o ../libihf.o -o $(TEST_EXPLODE) $(LDFLAGS) $(CFLAGS) -I../
+
+$(TEST_B64): test_base64.o ../base64.o
+ $(CC) test_base64.o ../base64.o -o $(TEST_B64) $(LDFLAGS) $(CFLAGS) -I../
+
+.PHONY: clean mrproper
+
+mrproper: clean
+
+clean:
+ rm -f $(TEST_EXPLODE) $(TEST_B64) *~ *.o
+
diff --git a/broken/propagate/src/tests/test_base64.c b/broken/propagate/src/tests/test_base64.c
new file mode 100644
index 0000000..e32ff65
--- /dev/null
+++ b/broken/propagate/src/tests/test_base64.c
@@ -0,0 +1,88 @@
+/*
+ ihf - Tool for bypassing firewalls
+ Copyright (C) 2012 m_101, laurent
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "base64.h"
+
+#define TEST_STR "ag0 arg1 arg2 arg3 arg4\n"
+
+void print_array_uint8_t (uint8_t *array, int n_elements) {
+ int idx_array;
+
+ if (!array || n_elements <= 0)
+ return;
+
+ for (idx_array = 0; idx_array < n_elements; idx_array++)
+ printf("%02x ", array[idx_array]);
+ putchar('\n');
+}
+
+int main(int argc, char *argv[]) {
+ int idx_buf, sz_buf;
+ char *buf;
+ // b64
+ struct base64_decode_context dctx;
+ char *b64_encoded, *b64_decoded;
+ size_t len_decoded;
+
+ sz_buf = 256 + strlen(TEST_STR) + 1;
+
+ buf = calloc(sz_buf, sizeof(*buf));
+ if (!buf) {
+ fprintf(stderr, "error: Could not alloc buffer\n");
+ return -1;
+ }
+
+ for (idx_buf = 0; idx_buf < 256; idx_buf++)
+ buf[idx_buf] = idx_buf;
+ memcpy(buf + 256, TEST_STR, strlen(TEST_STR));
+
+ printf("printing array...\n");
+ print_array_uint8_t (buf, sz_buf - 1);
+
+ printf("\nEncoding buffer ...\n");
+ base64_encode_alloc(buf, sz_buf - 1, &b64_encoded);
+ if (!b64_encoded) {
+ fprintf(stderr, "error: Could not encode buffer\n");
+ return -1;
+ }
+
+ printf("encoded: %s\n\n", b64_encoded);
+
+ printf("Decoding buffer ...\n");
+ base64_decode_ctx_init (&dctx);
+ base64_decode_alloc_ctx(&dctx,
+ b64_encoded, strlen(b64_encoded),
+ &b64_decoded, &len_decoded);
+ printf("len_decoded: %lu\n\n", len_decoded);
+
+ printf("printing array...\n");
+ print_array_uint8_t (b64_decoded, len_decoded);
+
+ printf("comparing arrays...\n");
+ if (memcmp(buf, b64_decoded, len_decoded))
+ printf("Decoding failed\n");
+ else
+ printf("Decoding succeeded\n");
+
+ return 0;
+}
+
diff --git a/broken/propagate/src/tests/test_explode.c b/broken/propagate/src/tests/test_explode.c
new file mode 100644
index 0000000..0210397
--- /dev/null
+++ b/broken/propagate/src/tests/test_explode.c
@@ -0,0 +1,39 @@
+/*
+ ihf - Tool for bypassing firewalls
+ Copyright (C) 2012 m_101, laurent
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "libihf.h"
+
+#define TEST_STR "arg0 arg1 arg2 arg3 arg4\n"
+
+int main(int argc, char *argv[]) {
+ char *toxplod = strdup(TEST_STR);
+ int n_exploded;
+ char **exploded = explode(toxplod, strlen(toxplod) + 1, " ", &n_exploded);
+ int idx_exploded;
+
+ printf("\nn_exploded: %d\n", n_exploded);
+ for (idx_exploded = 0; idx_exploded < n_exploded; idx_exploded++) {
+ printf("exploded %d: %s\n", idx_exploded, exploded[idx_exploded]);
+ }
+
+ return 0;
+}
+