summaryrefslogtreecommitdiff
path: root/tests/network/protocol/negotiation.c
blob: 0fa76a257ecb1b9e3b854fba6ed433fd7606633e (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
#include "clar_libgit2.h"
#include "transports/smart.h"

static git_pkt *pkt;

void test_network_protocol_negotiation__cleanup(void)
{
	git_pkt_free(pkt);
	pkt = NULL;
}

void test_network_protocol_negotiation__have(void)
{
	const char buf[] = "0032have 7e47fe2bd8d01d481f44d7af0531bd93d3b21c01\n";
	const char *rest;
	git_oid id;
	git_pkt_have_want *ppkt;

	git_oid_fromstr(&id, "7e47fe2bd8d01d481f44d7af0531bd93d3b21c01");

	cl_git_pass(git_pkt_parse_line(&pkt, buf, &rest, sizeof(buf)));
	cl_assert_equal_i(GIT_PKT_HAVE, pkt->type);
	ppkt = (git_pkt_have_want *) pkt;
	cl_assert(!git_oid_cmp(&id, &ppkt->id));
}

void test_network_protocol_negotiation__want(void)
{
	const char buf[] = "0032want 7e47fe2bd8d01d481f44d7af0531bd93d3b21c01\n";
	const char *rest;
	git_oid id;
	git_pkt_have_want *ppkt;

	git_oid_fromstr(&id, "7e47fe2bd8d01d481f44d7af0531bd93d3b21c01");

	cl_git_pass(git_pkt_parse_line(&pkt, buf, &rest, sizeof(buf)));
	cl_assert_equal_i(GIT_PKT_WANT, pkt->type);
	ppkt = (git_pkt_have_want *) pkt;
	cl_assert(!git_oid_cmp(&id, &ppkt->id));
}