]>
git.proxmox.com Git - libgit2.git/blob - tests/object/blob/fromstream.c
60ff3991b9ecfca19a3cb42407bfaabc4ab9d4ba
1 #include "clar_libgit2.h"
6 static git_repository
*repo
;
7 static char textual_content
[] = "libgit2\n\r\n\0";
9 void test_object_blob_fromstream__initialize(void)
11 repo
= cl_git_sandbox_init("testrepo.git");
14 void test_object_blob_fromstream__cleanup(void)
16 cl_git_sandbox_cleanup();
19 void test_object_blob_fromstream__multiple_write(void)
21 git_oid expected_id
, id
;
23 git_writestream
*stream
;
26 cl_git_pass(git_oid_fromstr(&expected_id
, "321cbdf08803c744082332332838df6bd160f8f9"));
28 cl_git_fail_with(GIT_ENOTFOUND
,
29 git_object_lookup(&blob
, repo
, &expected_id
, GIT_OBJECT_ANY
));
31 cl_git_pass(git_blob_create_from_stream(&stream
, repo
, NULL
));
33 for (i
= 0; i
< howmany
; i
++)
34 cl_git_pass(stream
->write(stream
, textual_content
, strlen(textual_content
)));
36 cl_git_pass(git_blob_create_from_stream_commit(&id
, stream
));
37 cl_assert_equal_oid(&expected_id
, &id
);
39 cl_git_pass(git_object_lookup(&blob
, repo
, &expected_id
, GIT_OBJECT_BLOB
));
41 git_object_free(blob
);
44 #define GITATTR "* text=auto\n" \
48 static void write_attributes(git_repository
*repo
)
50 git_str buf
= GIT_STR_INIT
;
52 cl_git_pass(git_str_joinpath(&buf
, git_repository_path(repo
), "info"));
53 cl_git_pass(git_str_joinpath(&buf
, git_str_cstr(&buf
), "attributes"));
55 cl_git_pass(git_futils_mkpath2file(git_str_cstr(&buf
), 0777));
56 cl_git_rewritefile(git_str_cstr(&buf
), GITATTR
);
58 git_str_dispose(&buf
);
61 static void assert_named_chunked_blob(const char *expected_sha
, const char *fake_name
)
63 git_oid expected_id
, id
;
64 git_writestream
*stream
;
67 cl_git_pass(git_oid_fromstr(&expected_id
, expected_sha
));
69 cl_git_pass(git_blob_create_from_stream(&stream
, repo
, fake_name
));
71 for (i
= 0; i
< howmany
; i
++)
72 cl_git_pass(stream
->write(stream
, textual_content
, strlen(textual_content
)));
74 cl_git_pass(git_blob_create_from_stream_commit(&id
, stream
));
76 cl_assert_equal_oid(&expected_id
, &id
);
79 void test_object_blob_fromstream__creating_a_blob_from_chunks_honors_the_attributes_directives(void)
81 write_attributes(repo
);
83 assert_named_chunked_blob("321cbdf08803c744082332332838df6bd160f8f9", "dummy.data");
84 assert_named_chunked_blob("e9671e138a780833cb689753570fd10a55be84fb", "dummy.txt");
85 assert_named_chunked_blob("e9671e138a780833cb689753570fd10a55be84fb", "dummy.dunno");