Tag
Hash :
168fe39b
Author :
Date :
2018-11-28T14:26:57
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
#include "clar_libgit2.h"
#include "git2/odb_backend.h"
static git_repository *repo;
static git_odb *odb;
static git_odb_stream *stream;
void test_odb_streamwrite__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_odb(&odb, repo));
cl_git_pass(git_odb_open_wstream(&stream, odb, 14, GIT_OBJECT_BLOB));
cl_assert_equal_sz(14, stream->declared_size);
}
void test_odb_streamwrite__cleanup(void)
{
git_odb_stream_free(stream);
git_odb_free(odb);
cl_git_sandbox_cleanup();
}
void test_odb_streamwrite__can_accept_chunks(void)
{
git_oid oid;
cl_git_pass(git_odb_stream_write(stream, "deadbeef", 8));
cl_assert_equal_sz(8, stream->received_bytes);
cl_git_pass(git_odb_stream_write(stream, "deadbeef", 6));
cl_assert_equal_sz(8 + 6, stream->received_bytes);
cl_git_pass(git_odb_stream_finalize_write(&oid, stream));
}
void test_odb_streamwrite__can_detect_missing_bytes(void)
{
git_oid oid;
cl_git_pass(git_odb_stream_write(stream, "deadbeef", 8));
cl_assert_equal_sz(8, stream->received_bytes);
cl_git_pass(git_odb_stream_write(stream, "deadbeef", 4));
cl_assert_equal_sz(8 + 4, stream->received_bytes);
cl_git_fail(git_odb_stream_finalize_write(&oid, stream));
}
void test_odb_streamwrite__can_detect_additional_bytes(void)
{
cl_git_pass(git_odb_stream_write(stream, "deadbeef", 8));
cl_assert_equal_sz(8, stream->received_bytes);
cl_git_fail(git_odb_stream_write(stream, "deadbeef", 7));
}