Blame tests/core/iconv.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "path.h"
Packit Service 20376f
Packit Service 20376f
#ifdef GIT_USE_ICONV
Packit Service 20376f
static git_path_iconv_t ic;
Packit Service 20376f
static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
Packit Service 20376f
static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
void test_core_iconv__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
#ifdef GIT_USE_ICONV
Packit Service 20376f
	cl_git_pass(git_path_iconv_init_precompose(&ic);;
Packit Service 20376f
#endif
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_core_iconv__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
#ifdef GIT_USE_ICONV
Packit Service 20376f
	git_path_iconv_clear(&ic);
Packit Service 20376f
#endif
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_core_iconv__unchanged(void)
Packit Service 20376f
{
Packit Service 20376f
#ifdef GIT_USE_ICONV
Packit Service 20376f
	const char *data = "Ascii data", *original = data;
Packit Service 20376f
	size_t datalen = strlen(data);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
Packit Service 20376f
	GIT_UNUSED(datalen);
Packit Service 20376f
Packit Service 20376f
	/* There are no high bits set, so this should leave data untouched */
Packit Service 20376f
	cl_assert(data == original);
Packit Service 20376f
#endif
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_core_iconv__decomposed_to_precomposed(void)
Packit Service 20376f
{
Packit Service 20376f
#ifdef GIT_USE_ICONV
Packit Service 20376f
	const char *data = nfd;
Packit Service 20376f
	size_t datalen, nfdlen = strlen(nfd);
Packit Service 20376f
Packit Service 20376f
	datalen = nfdlen;
Packit Service 20376f
	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
Packit Service 20376f
	GIT_UNUSED(datalen);
Packit Service 20376f
Packit Service 20376f
	/* The decomposed nfd string should be transformed to the nfc form
Packit Service 20376f
	 * (on platforms where iconv is enabled, of course).
Packit Service 20376f
	 */
Packit Service 20376f
	cl_assert_equal_s(nfc, data);
Packit Service 20376f
Packit Service 20376f
	/* should be able to do it multiple times with the same git_path_iconv_t */
Packit Service 20376f
	data = nfd; datalen = nfdlen;
Packit Service 20376f
	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
Packit Service 20376f
	cl_assert_equal_s(nfc, data);
Packit Service 20376f
Packit Service 20376f
	data = nfd; datalen = nfdlen;
Packit Service 20376f
	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
Packit Service 20376f
	cl_assert_equal_s(nfc, data);
Packit Service 20376f
#endif
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_core_iconv__precomposed_is_unmodified(void)
Packit Service 20376f
{
Packit Service 20376f
#ifdef GIT_USE_ICONV
Packit Service 20376f
	const char *data = nfc;
Packit Service 20376f
	size_t datalen = strlen(nfc);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_path_iconv(&ic, &data, &datalen));
Packit Service 20376f
	GIT_UNUSED(datalen);
Packit Service 20376f
Packit Service 20376f
	/* data is already in precomposed form, so even though some bytes have
Packit Service 20376f
	 * the high-bit set, the iconv transform should result in no change.
Packit Service 20376f
	 */
Packit Service 20376f
	cl_assert_equal_s(nfc, data);
Packit Service 20376f
#endif
Packit Service 20376f
}