unicode.c 1.5 KB
Newer Older
1 2 3 4 5 6
#include "clar_libgit2.h"

static git_repository *repo;

void test_refs_unicode__initialize(void)
{
7
	repo = cl_git_sandbox_init("testrepo.git");
8 9 10 11
}

void test_refs_unicode__cleanup(void)
{
12
	cl_git_sandbox_cleanup();
13
	repo = NULL;
14 15 16 17
}

void test_refs_unicode__create_and_lookup(void)
{
18
	git_reference *ref0, *ref1, *ref2;
19 20
	git_repository *repo2;

21
	const char *REFNAME = "refs/heads/" "\303\205" "ngstr" "\303\266" "m";
22 23 24
	const char *master = "refs/heads/master";

	/* Create the reference */
25
	cl_git_pass(git_reference_lookup(&ref0, repo, master));
26
	cl_git_pass(git_reference_create(
27
		&ref1, repo, REFNAME, git_reference_target(ref0), 0, NULL));
28
	cl_assert_equal_s(REFNAME, git_reference_name(ref1));
29
	git_reference_free(ref0);
30 31 32

	/* Lookup the reference in a different instance of the repository */
	cl_git_pass(git_repository_open(&repo2, "testrepo.git"));
33

34
	cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME));
35
	cl_assert_equal_oid(git_reference_target(ref1), git_reference_target(ref2));
36 37 38 39 40
	cl_assert_equal_s(REFNAME, git_reference_name(ref2));
	git_reference_free(ref2);

#if GIT_USE_ICONV
	/* Lookup reference by decomposed unicode name */
41

42 43
#define REFNAME_DECOMPOSED "refs/heads/" "A" "\314\212" "ngstro" "\314\210" "m"

44
	cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME_DECOMPOSED));
45
	cl_assert_equal_oid(git_reference_target(ref1), git_reference_target(ref2));
46
	cl_assert_equal_s(REFNAME, git_reference_name(ref2));
47 48 49 50
	git_reference_free(ref2);
#endif

	/* Cleanup */
51

52
	git_reference_free(ref1);
53 54
	git_repository_free(repo2);
}