mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 05:42:07 +00:00

git_oid_ncmp was making some assumptions about the length of the data - this shifts the check to the top of the loop so it will work more robustly, limits the max, and adds some tests to verify the functionality.
49 lines
1.6 KiB
C
49 lines
1.6 KiB
C
#include "clar_libgit2.h"
|
|
|
|
static git_oid id;
|
|
static git_oid idp;
|
|
static git_oid idm;
|
|
const char *str_oid = "ae90f12eea699729ed24555e40b9fd669da12a12";
|
|
const char *str_oid_p = "ae90f12eea699729ed";
|
|
const char *str_oid_m = "ae90f12eea699729ed24555e40b9fd669da12a12THIS IS EXTRA TEXT THAT SHOULD GET IGNORED";
|
|
|
|
void test_core_oid__initialize(void)
|
|
{
|
|
cl_git_pass(git_oid_fromstr(&id, str_oid));
|
|
cl_git_pass(git_oid_fromstrp(&idp, str_oid_p));
|
|
cl_git_fail(git_oid_fromstrp(&idm, str_oid_m));
|
|
}
|
|
|
|
void test_core_oid__streq(void)
|
|
{
|
|
cl_assert(git_oid_streq(&id, str_oid) == 0);
|
|
cl_assert(git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == -1);
|
|
|
|
cl_assert(git_oid_streq(&id, "deadbeef") == -1);
|
|
cl_assert(git_oid_streq(&id, "I'm not an oid.... :)") == -1);
|
|
|
|
cl_assert(git_oid_streq(&idp, "ae90f12eea699729ed0000000000000000000000") == 0);
|
|
cl_assert(git_oid_streq(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") == -1);
|
|
|
|
cl_assert(git_oid_streq(&idp, "deadbeef") == -1);
|
|
cl_assert(git_oid_streq(&idp, "I'm not an oid.... :)") == -1);
|
|
|
|
void test_core_oid__ncmp(void)
|
|
{
|
|
cl_assert(!git_oid_ncmp(&id, &idp, 0));
|
|
cl_assert(!git_oid_ncmp(&id, &idp, 1));
|
|
cl_assert(!git_oid_ncmp(&id, &idp, 2));
|
|
cl_assert(!git_oid_ncmp(&id, &idp, 17));
|
|
cl_assert(!git_oid_ncmp(&id, &idp, 18));
|
|
cl_assert(git_oid_ncmp(&id, &idp, 19));
|
|
cl_assert(git_oid_ncmp(&id, &idp, 40));
|
|
cl_assert(git_oid_ncmp(&id, &idp, 41));
|
|
cl_assert(git_oid_ncmp(&id, &idp, 42));
|
|
|
|
cl_assert(!git_oid_ncmp(&id, &id, 0));
|
|
cl_assert(!git_oid_ncmp(&id, &id, 1));
|
|
cl_assert(!git_oid_ncmp(&id, &id, 39));
|
|
cl_assert(!git_oid_ncmp(&id, &id, 40));
|
|
cl_assert(!git_oid_ncmp(&id, &id, 41));
|
|
}
|