Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
a7954d2a
Commit
a7954d2a
authored
Dec 04, 2011
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree: add test to ensure predictability of generation of object ids
parent
a22b14d3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
2 deletions
+74
-2
tests-clay/clay.h
+3
-0
tests-clay/clay_main.c
+11
-2
tests-clay/object/tree/buildfromindex.c
+60
-0
No files found.
tests-clay/clay.h
View file @
a7954d2a
...
...
@@ -158,6 +158,9 @@ extern void test_object_raw_size__validate_oid_size(void);
extern
void
test_object_raw_type2string__check_type_is_loose
(
void
);
extern
void
test_object_raw_type2string__convert_string_to_type
(
void
);
extern
void
test_object_raw_type2string__convert_type_to_string
(
void
);
extern
void
test_object_tree_buildfromindex__cleanup
(
void
);
extern
void
test_object_tree_buildfromindex__generate_predictable_object_ids
(
void
);
extern
void
test_object_tree_buildfromindex__initialize
(
void
);
extern
void
test_object_tree_frompath__cleanup
(
void
);
extern
void
test_object_tree_frompath__fail_when_processing_an_invalid_path
(
void
);
extern
void
test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment
(
void
);
...
...
tests-clay/clay_main.c
View file @
a7954d2a
...
...
@@ -245,6 +245,9 @@ static const struct clay_func _clay_cb_object_raw_type2string[] = {
{
"convert_string_to_type"
,
&
test_object_raw_type2string__convert_string_to_type
},
{
"convert_type_to_string"
,
&
test_object_raw_type2string__convert_type_to_string
}
};
static
const
struct
clay_func
_clay_cb_object_tree_buildfromindex
[]
=
{
{
"generate_predictable_object_ids"
,
&
test_object_tree_buildfromindex__generate_predictable_object_ids
}
};
static
const
struct
clay_func
_clay_cb_object_tree_frompath
[]
=
{
{
"fail_when_processing_an_invalid_path"
,
&
test_object_tree_frompath__fail_when_processing_an_invalid_path
},
{
"fail_when_processing_an_unknown_tree_segment"
,
&
test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment
},
...
...
@@ -438,6 +441,12 @@ static const struct clay_suite _clay_suites[] = {
_clay_cb_object_raw_type2string
,
3
},
{
"object::tree::buildfromindex"
,
{
"initialize"
,
&
test_object_tree_buildfromindex__initialize
},
{
"cleanup"
,
&
test_object_tree_buildfromindex__cleanup
},
_clay_cb_object_tree_buildfromindex
,
1
},
{
"object::tree::frompath"
,
{
"initialize"
,
&
test_object_tree_frompath__initialize
},
{
"cleanup"
,
&
test_object_tree_frompath__cleanup
},
...
...
@@ -493,8 +502,8 @@ static const struct clay_suite _clay_suites[] = {
}
};
static
size_t
_clay_suite_count
=
3
4
;
static
size_t
_clay_callback_count
=
11
3
;
static
size_t
_clay_suite_count
=
3
5
;
static
size_t
_clay_callback_count
=
11
4
;
/* Core test functions */
static
void
...
...
tests-clay/object/tree/buildfromindex.c
0 → 100644
View file @
a7954d2a
#include "clay_libgit2.h"
#include "posix.h"
static
git_repository
*
repo
;
static
void
file_create
(
const
char
*
filename
,
const
char
*
content
)
{
int
fd
;
fd
=
p_creat
(
filename
,
0666
);
cl_assert
(
fd
!=
0
);
cl_git_pass
(
p_write
(
fd
,
content
,
strlen
(
content
)));
cl_git_pass
(
p_close
(
fd
));
}
void
test_object_tree_buildfromindex__initialize
(
void
)
{
cl_fixture
(
"treebuilder"
);
cl_git_pass
(
git_repository_init
(
&
repo
,
"treebuilder/"
,
0
));
cl_git_pass
(
git_repository_open
(
&
repo
,
"treebuilder/.git"
));
cl_assert
(
repo
!=
NULL
);
}
void
test_object_tree_buildfromindex__cleanup
(
void
)
{
git_repository_free
(
repo
);
cl_fixture_cleanup
(
"treebuilder"
);
}
void
test_object_tree_buildfromindex__generate_predictable_object_ids
(
void
)
{
git_index
*
index
;
git_oid
blob_oid
,
tree_oid
,
expected_tree_oid
;
git_index_entry
*
entry
;
/*
* Add a new file to the index
*/
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
file_create
(
"treebuilder/test.txt"
,
"test
\n
"
);
cl_git_pass
(
git_index_add
(
index
,
"test.txt"
,
0
));
entry
=
git_index_get
(
index
,
0
);
/* $ echo "test" | git hash-object --stdin */
cl_git_pass
(
git_oid_fromstr
(
&
blob_oid
,
"9daeafb9864cf43055ae93beb0afd6c7d144bfa4"
));
cl_assert
(
git_oid_cmp
(
&
blob_oid
,
&
entry
->
oid
)
==
0
);
/*
* Build the tree from the index
*/
cl_git_pass
(
git_tree_create_fromindex
(
&
tree_oid
,
index
));
cl_git_pass
(
git_oid_fromstr
(
&
expected_tree_oid
,
"2b297e643c551e76cfa1f93810c50811382f9117"
));
cl_assert
(
git_oid_cmp
(
&
expected_tree_oid
,
&
tree_oid
)
==
0
);
git_index_free
(
index
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment