summaryrefslogtreecommitdiff
path: root/src/http_req_range_test.c
blob: 3532582c2be970f5059919760cac2177582bb288 (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
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>

#include <tap.h>

#include "http_req_range.h"
#include "log.h"

int main(void) {
	http_req_range *r, *ranges = http_request_range_init();
	buffer *b = buffer_init();

	log_init();
	plan_tests(7);

	buffer_copy_string_len(b, CONST_STR_LEN("bytes=0-0"));
	ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0");
	for (r = ranges; r; r = r->next) {
		diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end);
	}
	http_request_range_reset(ranges);

	buffer_copy_string_len(b, CONST_STR_LEN("bytes=1-2,3-4"));
	ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "1-2,3-4");
	for (r = ranges; r; r = r->next) {
		diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end);
	}
	http_request_range_reset(ranges);

	buffer_copy_string_len(b, CONST_STR_LEN("bytes=-0"));
	ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "-0");
	for (r = ranges; r; r = r->next) {
		diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end);
	}
	http_request_range_reset(ranges);

	buffer_copy_string_len(b, CONST_STR_LEN("bytes=0-"));
	ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-");
	for (r = ranges; r; r = r->next) {
		diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end);
	}
	http_request_range_reset(ranges);

	buffer_copy_string_len(b, CONST_STR_LEN("bytes=0-0,0-"));
	ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0,0-");
	for (r = ranges; r; r = r->next) {
		diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end);
	}
	http_request_range_reset(ranges);

	buffer_copy_string_len(b, CONST_STR_LEN("bytes=0-0,-0"));
	ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0,-0");
	for (r = ranges; r; r = r->next) {
		diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end);
	}
	http_request_range_reset(ranges);

	buffer_copy_string_len(b, CONST_STR_LEN("bytes=1-2,3-4,5-"));
	ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "1-2,3-4,5-");
	for (r = ranges; r; r = r->next) {
		diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end);
	}

	http_request_range_free(ranges);

	buffer_free(b);
	log_free();

	return exit_status();
}