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
f2e1d060
Commit
f2e1d060
authored
Feb 20, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1351 from arrbee/moar-treebuilder-tests
Add more treebuilder tests
parents
6ec37f72
0cfce06d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
+97
-0
tests-clar/object/tree/write.c
+97
-0
No files found.
tests-clar/object/tree/write.c
View file @
f2e1d060
...
@@ -163,3 +163,100 @@ void test_object_tree_write__sorted_subtrees(void)
...
@@ -163,3 +163,100 @@ void test_object_tree_write__sorted_subtrees(void)
git_treebuilder_free
(
builder
);
git_treebuilder_free
(
builder
);
}
}
void
test_object_tree_write__removing_and_re_adding_in_treebuilder
(
void
)
{
git_treebuilder
*
builder
;
int
i
,
aardvark_i
,
apple_i
,
apple_after_i
,
apple_extra_i
,
last_i
;
git_oid
blank_oid
,
tree_oid
;
git_tree
*
tree
;
struct
{
unsigned
int
attr
;
const
char
*
filename
;
}
entries
[]
=
{
{
GIT_FILEMODE_BLOB
,
"aardvark"
},
{
GIT_FILEMODE_BLOB
,
".first"
},
{
GIT_FILEMODE_BLOB
,
"apple"
},
{
GIT_FILEMODE_BLOB
,
"last"
},
{
GIT_FILEMODE_BLOB
,
"apple_after"
},
{
GIT_FILEMODE_BLOB
,
"after_aardvark"
},
{
0
,
NULL
},
};
memset
(
&
blank_oid
,
0x0
,
sizeof
(
blank_oid
));
cl_git_pass
(
git_treebuilder_create
(
&
builder
,
NULL
));
cl_assert_equal_i
(
0
,
(
int
)
git_treebuilder_entrycount
(
builder
));
for
(
i
=
0
;
entries
[
i
].
filename
;
++
i
)
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
entries
[
i
].
filename
,
&
blank_oid
,
entries
[
i
].
attr
));
cl_assert_equal_i
(
6
,
(
int
)
git_treebuilder_entrycount
(
builder
));
cl_git_pass
(
git_treebuilder_remove
(
builder
,
"apple"
));
cl_assert_equal_i
(
5
,
(
int
)
git_treebuilder_entrycount
(
builder
));
cl_git_pass
(
git_treebuilder_remove
(
builder
,
"apple_after"
));
cl_assert_equal_i
(
4
,
(
int
)
git_treebuilder_entrycount
(
builder
));
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
"before_last"
,
&
blank_oid
,
GIT_FILEMODE_BLOB
));
cl_assert_equal_i
(
5
,
(
int
)
git_treebuilder_entrycount
(
builder
));
/* reinsert apple_after */
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
"apple_after"
,
&
blank_oid
,
GIT_FILEMODE_BLOB
));
cl_assert_equal_i
(
6
,
(
int
)
git_treebuilder_entrycount
(
builder
));
cl_git_pass
(
git_treebuilder_remove
(
builder
,
"last"
));
cl_assert_equal_i
(
5
,
(
int
)
git_treebuilder_entrycount
(
builder
));
/* reinsert last */
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
"last"
,
&
blank_oid
,
GIT_FILEMODE_BLOB
));
cl_assert_equal_i
(
6
,
(
int
)
git_treebuilder_entrycount
(
builder
));
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
"apple_extra"
,
&
blank_oid
,
GIT_FILEMODE_BLOB
));
cl_assert_equal_i
(
7
,
(
int
)
git_treebuilder_entrycount
(
builder
));
cl_git_pass
(
git_treebuilder_write
(
&
tree_oid
,
g_repo
,
builder
));
git_treebuilder_free
(
builder
);
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
tree_oid
));
cl_assert_equal_i
(
7
,
(
int
)
git_tree_entrycount
(
tree
));
cl_assert
(
git_tree_entry_byname
(
tree
,
".first"
)
!=
NULL
);
cl_assert
(
git_tree_entry_byname
(
tree
,
"apple"
)
==
NULL
);
cl_assert
(
git_tree_entry_byname
(
tree
,
"apple_after"
)
!=
NULL
);
cl_assert
(
git_tree_entry_byname
(
tree
,
"apple_extra"
)
!=
NULL
);
cl_assert
(
git_tree_entry_byname
(
tree
,
"last"
)
!=
NULL
);
aardvark_i
=
apple_i
=
apple_after_i
=
apple_extra_i
=
last_i
=
-
1
;
for
(
i
=
0
;
i
<
7
;
++
i
)
{
const
git_tree_entry
*
entry
=
git_tree_entry_byindex
(
tree
,
i
);
if
(
!
strcmp
(
entry
->
filename
,
"aardvark"
))
aardvark_i
=
i
;
else
if
(
!
strcmp
(
entry
->
filename
,
"apple"
))
apple_i
=
i
;
else
if
(
!
strcmp
(
entry
->
filename
,
"apple_after"
))
apple_after_i
=
i
;
else
if
(
!
strcmp
(
entry
->
filename
,
"apple_extra"
))
apple_extra_i
=
i
;
else
if
(
!
strcmp
(
entry
->
filename
,
"last"
))
last_i
=
i
;
}
cl_assert_equal_i
(
-
1
,
apple_i
);
cl_assert_equal_i
(
6
,
last_i
);
cl_assert
(
aardvark_i
<
apple_after_i
);
cl_assert
(
apple_after_i
<
apple_extra_i
);
git_tree_free
(
tree
);
}
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