strtol.c 1.46 KB
Newer Older
1
#include "clar_libgit2.h"
schu committed
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

void test_core_strtol__int32(void)
{
	int32_t i;

	cl_git_pass(git__strtol32(&i, "123", NULL, 10));
	cl_assert(i == 123);
	cl_git_pass(git__strtol32(&i, "  +123 ", NULL, 10));
	cl_assert(i == 123);
	cl_git_pass(git__strtol32(&i, "  +2147483647 ", NULL, 10));
	cl_assert(i == 2147483647);
	cl_git_pass(git__strtol32(&i, "  -2147483648 ", NULL, 10));
	cl_assert(i == -2147483648LL);
	
	cl_git_fail(git__strtol32(&i, "  2147483657 ", NULL, 10));
	cl_git_fail(git__strtol32(&i, "  -2147483657 ", NULL, 10));
}

void test_core_strtol__int64(void)
{
	int64_t i;

	cl_git_pass(git__strtol64(&i, "123", NULL, 10));
	cl_assert(i == 123);
	cl_git_pass(git__strtol64(&i, "  +123 ", NULL, 10));
	cl_assert(i == 123);
	cl_git_pass(git__strtol64(&i, "  +2147483647 ", NULL, 10));
	cl_assert(i == 2147483647);
	cl_git_pass(git__strtol64(&i, "  -2147483648 ", NULL, 10));
	cl_assert(i == -2147483648LL);
	cl_git_pass(git__strtol64(&i, "  2147483657 ", NULL, 10));
	cl_assert(i == 2147483657LL);
	cl_git_pass(git__strtol64(&i, "  -2147483657 ", NULL, 10));
	cl_assert(i == -2147483657LL);
36 37 38 39 40 41 42 43
	cl_git_pass(git__strtol64(&i, " 9223372036854775807  ", NULL, 10));
	cl_assert(i == INT64_MAX);
	cl_git_pass(git__strtol64(&i, "   -9223372036854775808  ", NULL, 10));
	cl_assert(i == INT64_MIN);
	cl_git_pass(git__strtol64(&i, "   0x7fffffffffffffff  ", NULL, 16));
	cl_assert(i == INT64_MAX);
	cl_git_pass(git__strtol64(&i, "   -0x8000000000000000   ", NULL, 16));
	cl_assert(i == INT64_MIN);
schu committed
44 45
}