From 13be5bd50238daa2be6b42104ba20aeea427655b Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 4 Oct 2016 23:58:10 +0200 Subject: git-receiver: splitted and tested pre-receive input parser --- .../blogc-git-receiver/check_pre_receive_parser.c | 101 +++++++++++++++++++++ tests/common/check_stdin.c | 53 +++++++++++ 2 files changed, 154 insertions(+) create mode 100644 tests/blogc-git-receiver/check_pre_receive_parser.c create mode 100644 tests/common/check_stdin.c (limited to 'tests') 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 + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#include +#include +#include +#include +#include +#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 + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#include +#include +#include +#include +#include +#include +#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); +} -- cgit v1.2.3-18-g5258