aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/blogc-git-receiver/check_pre_receive_parser.c101
-rw-r--r--tests/common/check_stdin.c53
2 files changed, 154 insertions, 0 deletions
diff --git a/tests/blogc-git-receiver/check_pre_receive_parser.c b/tests/blogc-git-receiver/check_pre_receive_parser.c
new file mode 100644
index 0000000..0c716fa
--- /dev/null
+++ b/tests/blogc-git-receiver/check_pre_receive_parser.c
@@ -0,0 +1,101 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <stdlib.h>
+#include "../../src/blogc-git-receiver/pre-receive-parser.h"
+
+
+static void
+test_pre_receive_parse(void **state)
+{
+ assert_null(bgr_pre_receive_parse(""));
+ assert_null(bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62"));
+ assert_null(bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "));
+ assert_null(bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f3"));
+ assert_null(bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f3 "));
+ assert_null(bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f3 "
+ "refs/heads/lol"));
+ assert_null(bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f3 "
+ "refs/heads/lol"));
+ assert_null(bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f3 "
+ "refs/heads/master"));
+ assert_null(bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f3 "
+ "refs/heads/master asd\n"));
+ char *t;
+ t = bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f3 "
+ "refs/heads/master\n");
+ assert_non_null(t);
+ assert_string_equal(t, "3fff4bb3172f77b292b0c913749e81bedd3545f3");
+ free(t);
+ t = bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545fa "
+ "refs/heads/master\n"
+ "4f1f932f6ef6d6c9770266775c2db072964d7a63 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f4 "
+ "refs/heads/bola\n"
+ );
+ assert_non_null(t);
+ assert_string_equal(t, "3fff4bb3172f77b292b0c913749e81bedd3545fa");
+ free(t);
+ t = bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a63 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f4 "
+ "refs/heads/bola\n"
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545fb "
+ "refs/heads/master\n"
+ );
+ assert_non_null(t);
+ assert_string_equal(t, "3fff4bb3172f77b292b0c913749e81bedd3545fb");
+ free(t);
+ t = bgr_pre_receive_parse(
+ "4f1f932f6ef6d6c9770266775c2db072964d7a63 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f4 "
+ "refs/heads/bola\n"
+ "4f1f932f6ef6d6c9770266775c2db072964d7a62 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545fc "
+ "refs/heads/master\n"
+ "4f1f932f6ef6d6c9770266775c2db072964d7a64 "
+ "3fff4bb3172f77b292b0c913749e81bedd3545f5 "
+ "refs/heads/bolao\n"
+ );
+ assert_non_null(t);
+ assert_string_equal(t, "3fff4bb3172f77b292b0c913749e81bedd3545fc");
+ free(t);
+}
+
+
+int
+main(void)
+{
+ const UnitTest tests[] = {
+ unit_test(test_pre_receive_parse),
+ };
+ return run_tests(tests);
+}
diff --git a/tests/common/check_stdin.c b/tests/common/check_stdin.c
new file mode 100644
index 0000000..c0d222d
--- /dev/null
+++ b/tests/common/check_stdin.c
@@ -0,0 +1,53 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <string.h>
+#include <stdio.h>
+#include "../../src/common/stdin.h"
+
+
+int
+__wrap_fgetc(FILE *stream)
+{
+ assert_int_equal(fileno(stream), fileno(stdin));
+ return mock_type(int);
+}
+
+
+static void
+test_read(void **state)
+{
+ will_return(__wrap_fgetc, EOF);
+ char *t = bc_stdin_read();
+ assert_non_null(t);
+ assert_string_equal(t, "");
+ free(t);
+ will_return(__wrap_fgetc, 'b');
+ will_return(__wrap_fgetc, 'o');
+ will_return(__wrap_fgetc, 'l');
+ will_return(__wrap_fgetc, 'a');
+ will_return(__wrap_fgetc, EOF);
+ t = bc_stdin_read();
+ assert_non_null(t);
+ assert_string_equal(t, "bola");
+ free(t);
+}
+
+
+int
+main(void)
+{
+ const UnitTest tests[] = {
+ unit_test(test_read),
+ };
+ return run_tests(tests);
+}