blob: f663f6495e922bce5d39ee702b9b521e0d4cb42e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
* blogc: A blog compiler.
* Copyright (C) 2014-2020 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 <string.h>
#include "../../src/blogc-git-receiver/pre-receive-parser.h"
#define _bgr_pre_receive_parse(a) bgr_pre_receive_parse(a, strlen(a))
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);
}
|