summaryrefslogtreecommitdiff
path: root/tests/libgit2/core
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-06-14 22:29:10 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2022-06-20 17:12:49 -0400
commit6c57bac6b18f6a30e1a8c8272a8dc367f202aa88 (patch)
tree776f5f9023d3b0076229d1750ff6cedbcd54ef7a /tests/libgit2/core
parentd103620158bb5aca73bc0dad8a230ceda417ab47 (diff)
downloadlibgit2-6c57bac6b18f6a30e1a8c8272a8dc367f202aa88.tar.gz
sha256: make sha256 an experimental optional feature
libgit2 can be built with optional, experimental sha256 support. This allows consumers to begin testing and providing feedback for our sha256 support while we continue to develop it, and allows us to make API breaking changes while we iterate on a final sha256 implementation. The results will be `git2-experimental.dll` and installed as `git2-experimental.h` to avoid confusion with a production libgit2.
Diffstat (limited to 'tests/libgit2/core')
-rw-r--r--tests/libgit2/core/oid.c22
-rw-r--r--tests/libgit2/core/oidmap.c14
-rw-r--r--tests/libgit2/core/pool.c5
3 files changed, 29 insertions, 12 deletions
diff --git a/tests/libgit2/core/oid.c b/tests/libgit2/core/oid.c
index f17054d55..dc93f738c 100644
--- a/tests/libgit2/core/oid.c
+++ b/tests/libgit2/core/oid.c
@@ -9,6 +9,7 @@ const char *str_oid_sha1 = "ae90f12eea699729ed24555e40b9fd669da12a12";
const char *str_oid_sha1_p = "ae90f12eea699729ed";
const char *str_oid_sha1_m = "ae90f12eea699729ed24555e40b9fd669da12a12THIS IS EXTRA TEXT THAT SHOULD GET IGNORED";
+#ifdef GIT_EXPERIMENTAL_SHA256
static git_oid id_sha256;
static git_oid idp_sha256;
static git_oid idm_sha256;
@@ -16,6 +17,7 @@ static git_oid idm_sha256;
const char *str_oid_sha256 = "d3e63d2f2e43d1fee23a74bf19a0ede156cba2d1bd602eba13de433cea1bb512";
const char *str_oid_sha256_p = "d3e63d2f2e43d1fee2";
const char *str_oid_sha256_m = "d3e63d2f2e43d1fee23a74bf19a0ede156cba2d1bd602eba13de433cea1bb512 GARBAGE EXTRA TEXT AT THE END";
+#endif
void test_core_oid__initialize(void)
{
@@ -23,9 +25,11 @@ void test_core_oid__initialize(void)
cl_git_pass(git_oid_fromstrp(&idp_sha1, str_oid_sha1_p, GIT_OID_SHA1));
cl_git_fail(git_oid_fromstrp(&idm_sha1, str_oid_sha1_m, GIT_OID_SHA1));
+#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_oid_fromstr(&id_sha256, str_oid_sha256, GIT_OID_SHA256));
cl_git_pass(git_oid_fromstrp(&idp_sha256, str_oid_sha256_p, GIT_OID_SHA256));
cl_git_fail(git_oid_fromstrp(&idm_sha256, str_oid_sha256_m, GIT_OID_SHA256));
+#endif
}
void test_core_oid__streq_sha1(void)
@@ -48,6 +52,7 @@ void test_core_oid__streq_sha1(void)
void test_core_oid__streq_sha256(void)
{
+#ifdef GIT_EXPERIMENTAL_SHA256
cl_assert_equal_i(0, git_oid_streq(&id_sha256, str_oid_sha256));
cl_assert_equal_i(-1, git_oid_streq(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
@@ -62,6 +67,7 @@ void test_core_oid__streq_sha256(void)
cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "deadbeef"));
cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "I'm not an oid.... :)"));
+#endif
}
void test_core_oid__strcmp_sha1(void)
@@ -84,6 +90,7 @@ void test_core_oid__strcmp_sha1(void)
void test_core_oid__strcmp_sha256(void)
{
+#ifdef GIT_EXPERIMENTAL_SHA256
cl_assert_equal_i(0, git_oid_strcmp(&id_sha256, str_oid_sha256));
cl_assert(git_oid_strcmp(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0);
@@ -98,6 +105,7 @@ void test_core_oid__strcmp_sha256(void)
cl_assert(git_oid_strcmp(&idp_sha256, "deadbeef") < 0);
cl_assert_equal_i(-1, git_oid_strcmp(&idp_sha256, "I'm not an oid.... :)"));
+#endif
}
void test_core_oid__ncmp_sha1(void)
@@ -121,6 +129,7 @@ void test_core_oid__ncmp_sha1(void)
void test_core_oid__ncmp_sha256(void)
{
+#ifdef GIT_EXPERIMENTAL_SHA256
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 0));
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 1));
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 2));
@@ -142,6 +151,7 @@ void test_core_oid__ncmp_sha256(void)
cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 63));
cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 64));
cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 65));
+#endif
}
void test_core_oid__is_hexstr(void)
@@ -154,25 +164,25 @@ void test_core_oid__is_hexstr(void)
void test_core_oid__fmt_substr_sha1(void)
{
- char buf[GIT_OID_MAX_HEXSIZE];
+ char buf[GIT_OID_MAX_HEXSIZE + 1];
- memset(buf, 0, GIT_OID_MAX_HEXSIZE);
+ memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1);
git_oid_fmt_substr(buf, &id_sha1, 0, 40);
cl_assert_equal_s(buf, str_oid_sha1);
- memset(buf, 0, GIT_OID_MAX_HEXSIZE);
+ memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1);
git_oid_fmt_substr(buf, &id_sha1, 0, 18);
cl_assert_equal_s(buf, str_oid_sha1_p);
- memset(buf, 0, GIT_OID_MAX_HEXSIZE);
+ memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1);
git_oid_fmt_substr(buf, &id_sha1, 0, 5);
cl_assert_equal_s(buf, "ae90f");
- memset(buf, 0, GIT_OID_MAX_HEXSIZE);
+ memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1);
git_oid_fmt_substr(buf, &id_sha1, 5, 5);
cl_assert_equal_s(buf, "12eea");
- memset(buf, 0, GIT_OID_MAX_HEXSIZE);
+ memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1);
git_oid_fmt_substr(buf, &id_sha1, 5, 6);
cl_assert_equal_s(buf, "12eea6");
}
diff --git a/tests/libgit2/core/oidmap.c b/tests/libgit2/core/oidmap.c
index 317631c4e..34374ceef 100644
--- a/tests/libgit2/core/oidmap.c
+++ b/tests/libgit2/core/oidmap.c
@@ -28,7 +28,9 @@ void test_core_oidmap__initialize(void)
test_oids[i].oid.id[ 9] = (unsigned char)(i >> 8);
test_oids[i].oid.id[10] = (unsigned char)(i >> 16);
test_oids[i].oid.id[11] = (unsigned char)(i >> 24);
+#ifdef GIT_EXPERIMENTAL_SHA256
test_oids[i].oid.type = GIT_OID_SHA1;
+#endif
}
cl_git_pass(git_oidmap_new(&g_map));
@@ -94,9 +96,9 @@ void test_core_oidmap__get_fails_with_nonexisting_key(void)
void test_core_oidmap__setting_oid_persists(void)
{
git_oid oids[] = {
- { GIT_OID_SHA1, { 0x01 }},
- { GIT_OID_SHA1, { 0x02 }},
- { GIT_OID_SHA1, { 0x03 }}
+ GIT_OID_INIT(GIT_OID_SHA1, { 0x01 }),
+ GIT_OID_INIT(GIT_OID_SHA1, { 0x02 }),
+ GIT_OID_INIT(GIT_OID_SHA1, { 0x03 })
};
cl_git_pass(git_oidmap_set(g_map, &oids[0], "one"));
@@ -111,9 +113,9 @@ void test_core_oidmap__setting_oid_persists(void)
void test_core_oidmap__setting_existing_key_updates(void)
{
git_oid oids[] = {
- { GIT_OID_SHA1, { 0x01 }},
- { GIT_OID_SHA1, { 0x02 }},
- { GIT_OID_SHA1, { 0x03 }}
+ GIT_OID_INIT(GIT_OID_SHA1, { 0x01 }),
+ GIT_OID_INIT(GIT_OID_SHA1, { 0x02 }),
+ GIT_OID_INIT(GIT_OID_SHA1, { 0x03 })
};
cl_git_pass(git_oidmap_set(g_map, &oids[0], "one"));
diff --git a/tests/libgit2/core/pool.c b/tests/libgit2/core/pool.c
index 21aad3275..e16d85202 100644
--- a/tests/libgit2/core/pool.c
+++ b/tests/libgit2/core/pool.c
@@ -27,7 +27,12 @@ void test_core_pool__oid(void)
#ifndef GIT_DEBUG_POOL
/* with fixed page size, allocation must end up with these values */
+
+# ifdef GIT_EXPERIMENTAL_SHA256
cl_assert_equal_i(sizeof(void *) == 8 ? 90 : 82, git_pool__open_pages(&p));
+# else
+ cl_assert_equal_i(sizeof(void *) == 8 ? 55 : 45, git_pool__open_pages(&p));
+# endif
#endif
git_pool_clear(&p);
}