summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-08-17 09:24:44 -0500
committerGitHub <noreply@github.com>2016-08-17 09:24:44 -0500
commitc1b370e9313a13df350974e2237997cc651a5d67 (patch)
tree192fffba5ba3bb5982cb675955d647cbd170b54c /tests
parent635a922274046ee077235b9764d0360e33d735ab (diff)
parent5625d86b994fd81f1b0d887890e8168d7b5f46cc (diff)
downloadlibgit2-c1b370e9313a13df350974e2237997cc651a5d67.tar.gz
Merge pull request #3837 from novalis/dturner/indexv4
Support index v4
Diffstat (limited to 'tests')
-rw-r--r--tests/core/encoding.c39
-rw-r--r--tests/index/version.c41
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/core/encoding.c b/tests/core/encoding.c
new file mode 100644
index 000000000..7d91720f4
--- /dev/null
+++ b/tests/core/encoding.c
@@ -0,0 +1,39 @@
+#include "clar_libgit2.h"
+#include "varint.h"
+
+void test_core_encoding__decode(void)
+{
+ const unsigned char *buf = (unsigned char *)"AB";
+ size_t size;
+
+ cl_assert(git_decode_varint(buf, &size) == 65);
+ cl_assert(size == 1);
+
+ buf = (unsigned char *)"\xfe\xdc\xbaXY";
+ cl_assert(git_decode_varint(buf, &size) == 267869656);
+ cl_assert(size == 4);
+
+ buf = (unsigned char *)"\xaa\xaa\xfe\xdc\xbaXY";
+ cl_assert(git_decode_varint(buf, &size) == 1489279344088ULL);
+ cl_assert(size == 6);
+
+ buf = (unsigned char *)"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xfe\xdc\xbaXY";
+ cl_assert(git_decode_varint(buf, &size) == 0);
+ cl_assert(size == 0);
+
+}
+
+void test_core_encoding__encode(void)
+{
+ unsigned char buf[100];
+ cl_assert(git_encode_varint(buf, 100, 65) == 1);
+ cl_assert(buf[0] == 'A');
+
+ cl_assert(git_encode_varint(buf, 100, 267869656) == 4);
+ cl_assert(!memcmp(buf, "\xfe\xdc\xbaX", 4));
+
+ cl_assert(git_encode_varint(buf, 100, 1489279344088ULL) == 6);
+ cl_assert(!memcmp(buf, "\xaa\xaa\xfe\xdc\xbaX", 6));
+
+ cl_assert(git_encode_varint(buf, 1, 1489279344088ULL) == -1);
+}
diff --git a/tests/index/version.c b/tests/index/version.c
new file mode 100644
index 000000000..3fd240d3c
--- /dev/null
+++ b/tests/index/version.c
@@ -0,0 +1,41 @@
+#include "clar_libgit2.h"
+#include "index.h"
+
+static git_repository *g_repo = NULL;
+
+void test_index_version__can_write_v4(void)
+{
+ git_index *index;
+ const git_index_entry *entry;
+
+ g_repo = cl_git_sandbox_init("filemodes");
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ cl_assert(index->on_disk);
+ cl_assert(git_index_version(index) == 2);
+
+ cl_assert(git_index_entrycount(index) == 6);
+
+ cl_git_pass(git_index_set_version(index, 4));
+
+ cl_git_pass(git_index_write(index));
+ git_index_free(index);
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_assert(git_index_version(index) == 4);
+
+ entry = git_index_get_bypath(index, "exec_off", 0);
+ cl_assert(entry);
+ entry = git_index_get_bypath(index, "exec_off2on_staged", 0);
+ cl_assert(entry);
+ entry = git_index_get_bypath(index, "exec_on", 0);
+ cl_assert(entry);
+
+ git_index_free(index);
+}
+
+void test_index_version__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ g_repo = NULL;
+}