signature.c 2.07 KB
Newer Older
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
#include "clar_libgit2.h"

static int try_build_signature(const char *name, const char *email, git_time_t time, int offset)
{
	git_signature *sign;
	int error = GIT_SUCCESS;

	if ((error =  git_signature_new(&sign, name, email, time, offset)) < GIT_SUCCESS)
		return error;

	git_signature_free((git_signature *)sign);

	return error;
}


void test_commit_signature__create_trim(void)
{
   // creating a signature trims leading and trailing spaces
   git_signature *sign;
	cl_git_pass(git_signature_new(&sign, "  nulltoken ", "   emeric.fermas@gmail.com     ", 1234567890, 60));
	cl_assert(strcmp(sign->name, "nulltoken") == 0);
	cl_assert(strcmp(sign->email, "emeric.fermas@gmail.com") == 0);
	git_signature_free((git_signature *)sign);
}


void test_commit_signature__create_empties(void)
{
   // can not create a signature with empty name or email
	cl_git_pass(try_build_signature("nulltoken", "emeric.fermas@gmail.com", 1234567890, 60));

	cl_git_fail(try_build_signature("", "emeric.fermas@gmail.com", 1234567890, 60));
	cl_git_fail(try_build_signature("   ", "emeric.fermas@gmail.com", 1234567890, 60));
	cl_git_fail(try_build_signature("nulltoken", "", 1234567890, 60));
	cl_git_fail(try_build_signature("nulltoken", "  ", 1234567890, 60));
}

void test_commit_signature__create_one_char(void)
{
   // creating a one character signature
	git_signature *sign;
	cl_git_pass(git_signature_new(&sign, "x", "foo@bar.baz", 1234567890, 60));
	cl_assert(strcmp(sign->name, "x") == 0);
	cl_assert(strcmp(sign->email, "foo@bar.baz") == 0);
	git_signature_free((git_signature *)sign);
}

void test_commit_signature__create_two_char(void)
{
   // creating a two character signature
	git_signature *sign;
	cl_git_pass(git_signature_new(&sign, "xx", "x@y.z", 1234567890, 60));
	cl_assert(strcmp(sign->name, "xx") == 0);
	cl_assert(strcmp(sign->email, "x@y.z") == 0);
	git_signature_free((git_signature *)sign);
}

void test_commit_signature__create_zero_char(void)
{
   // creating a zero character signature
	git_signature *sign;
	cl_git_fail(git_signature_new(&sign, "", "x@y.z", 1234567890, 60));
	cl_assert(sign == NULL);
}