diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-10-04 23:58:10 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-10-04 23:58:10 +0200 |
commit | 13be5bd50238daa2be6b42104ba20aeea427655b (patch) | |
tree | 3e66986cd1ebbd98f06f61ff45127745fd54bc01 /tests/blogc-git-receiver | |
parent | 3fff4bb3172f77b292b0c913749e81bedd3545f3 (diff) | |
download | blogc-13be5bd50238daa2be6b42104ba20aeea427655b.tar.gz blogc-13be5bd50238daa2be6b42104ba20aeea427655b.tar.bz2 blogc-13be5bd50238daa2be6b42104ba20aeea427655b.zip |
git-receiver: splitted and tested pre-receive input parser
Diffstat (limited to 'tests/blogc-git-receiver')
-rw-r--r-- | tests/blogc-git-receiver/check_pre_receive_parser.c | 101 |
1 files changed, 101 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); +} |