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
629ba7f1
Commit
629ba7f1
authored
Feb 05, 2014
by
Ben Straub
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2027 from libgit2/rb/only-windows-is-windows
Some tests of paths that can't actually be written to disk
parents
df70de07
79ccb921
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
9 deletions
+91
-9
tests/object/tree/write.c
+91
-9
No files found.
tests/object/tree/write.c
View file @
629ba7f1
...
...
@@ -9,7 +9,7 @@ static const char *third_tree = "eb86d8b81d6adbd5290a935d6c9976882de98488";
static
git_repository
*
g_repo
;
/
/ Fixture setup and teardown
/
* Fixture setup and teardown */
void
test_object_tree_write__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
...
...
@@ -22,7 +22,7 @@ void test_object_tree_write__cleanup(void)
void
test_object_tree_write__from_memory
(
void
)
{
// write a tree from a memory
/* write a tree from a memory */
git_treebuilder
*
builder
;
git_tree
*
tree
;
git_oid
id
,
bid
,
rid
,
id2
;
...
...
@@ -31,7 +31,9 @@ void test_object_tree_write__from_memory(void)
git_oid_fromstr
(
&
id2
,
second_tree
);
git_oid_fromstr
(
&
bid
,
blob_oid
);
//create a second tree from first tree using `git_treebuilder_insert` on REPOSITORY_FOLDER.
/* create a second tree from first tree using `git_treebuilder_insert`
* on REPOSITORY_FOLDER.
*/
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
id
));
cl_git_pass
(
git_treebuilder_create
(
&
builder
,
tree
));
...
...
@@ -61,7 +63,7 @@ void test_object_tree_write__from_memory(void)
void
test_object_tree_write__subtree
(
void
)
{
// write a hierarchical tree from a memory
/* write a hierarchical tree from a memory */
git_treebuilder
*
builder
;
git_tree
*
tree
;
git_oid
id
,
bid
,
subtree_id
,
id2
,
id3
;
...
...
@@ -72,25 +74,25 @@ void test_object_tree_write__subtree(void)
git_oid_fromstr
(
&
id3
,
third_tree
);
git_oid_fromstr
(
&
bid
,
blob_oid
);
/
/create subtree
/
* create subtree */
cl_git_pass
(
git_treebuilder_create
(
&
builder
,
NULL
));
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
"new.txt"
,
&
bid
,
GIT_FILEMODE_BLOB
));
/
/-V536
NULL
,
builder
,
"new.txt"
,
&
bid
,
GIT_FILEMODE_BLOB
));
/
* -V536 */
cl_git_pass
(
git_treebuilder_write
(
&
subtree_id
,
g_repo
,
builder
));
git_treebuilder_free
(
builder
);
/
/ create parent tree
/
* create parent tree */
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
id
));
cl_git_pass
(
git_treebuilder_create
(
&
builder
,
tree
));
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
"new"
,
&
subtree_id
,
GIT_FILEMODE_TREE
));
/
/-V536
NULL
,
builder
,
"new"
,
&
subtree_id
,
GIT_FILEMODE_TREE
));
/
* -V536 */
cl_git_pass
(
git_treebuilder_write
(
&
id_hiearar
,
g_repo
,
builder
));
git_treebuilder_free
(
builder
);
git_tree_free
(
tree
);
cl_assert
(
git_oid_cmp
(
&
id_hiearar
,
&
id3
)
==
0
);
/
/ check data is correct
/
* check data is correct */
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
id_hiearar
));
cl_assert
(
2
==
git_tree_entrycount
(
tree
));
git_tree_free
(
tree
);
...
...
@@ -314,3 +316,83 @@ void test_object_tree_write__filtering(void)
git_tree_free
(
tree
);
}
void
test_object_tree_write__cruel_paths
(
void
)
{
static
const
char
*
the_paths
[]
=
{
"C:
\\
"
,
" : * ?
\"
\n
< > |"
,
"a
\\
b"
,
"
\\\\
b
\a
"
,
":
\\
"
,
"COM1"
,
"foo.aux"
,
REP1024
(
"1234"
),
/* 4096 char string */
REP1024
(
"12345678"
),
/* 8192 char string */
"
\xC5\xAA\x6E\xC4\xAD\x63\xC5\x8D\x64\x65\xCC\xBD
"
,
/* Ūnĭcōde̽ */
NULL
};
git_treebuilder
*
builder
;
git_tree
*
tree
;
git_oid
id
,
bid
,
subid
;
const
char
**
scan
;
int
count
=
0
,
i
,
j
;
git_tree_entry
*
te
;
git_oid_fromstr
(
&
bid
,
blob_oid
);
/* create tree */
cl_git_pass
(
git_treebuilder_create
(
&
builder
,
NULL
));
for
(
scan
=
the_paths
;
*
scan
;
++
scan
)
{
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
*
scan
,
&
bid
,
GIT_FILEMODE_BLOB
));
count
++
;
}
cl_git_pass
(
git_treebuilder_write
(
&
id
,
g_repo
,
builder
));
git_treebuilder_free
(
builder
);
/* check data is correct */
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
id
));
cl_assert_equal_i
(
count
,
git_tree_entrycount
(
tree
));
for
(
scan
=
the_paths
;
*
scan
;
++
scan
)
{
const
git_tree_entry
*
cte
=
git_tree_entry_byname
(
tree
,
*
scan
);
cl_assert
(
cte
!=
NULL
);
cl_assert_equal_s
(
*
scan
,
git_tree_entry_name
(
cte
));
}
for
(
scan
=
the_paths
;
*
scan
;
++
scan
)
{
cl_git_pass
(
git_tree_entry_bypath
(
&
te
,
tree
,
*
scan
));
cl_assert_equal_s
(
*
scan
,
git_tree_entry_name
(
te
));
git_tree_entry_free
(
te
);
}
git_tree_free
(
tree
);
/* let's try longer paths */
cl_git_pass
(
git_treebuilder_create
(
&
builder
,
NULL
));
for
(
scan
=
the_paths
;
*
scan
;
++
scan
)
{
cl_git_pass
(
git_treebuilder_insert
(
NULL
,
builder
,
*
scan
,
&
id
,
GIT_FILEMODE_TREE
));
}
cl_git_pass
(
git_treebuilder_write
(
&
subid
,
g_repo
,
builder
));
git_treebuilder_free
(
builder
);
/* check data is correct */
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
subid
));
cl_assert_equal_i
(
count
,
git_tree_entrycount
(
tree
));
for
(
i
=
0
;
i
<
count
;
++
i
)
{
for
(
j
=
0
;
j
<
count
;
++
j
)
{
git_buf
b
=
GIT_BUF_INIT
;
cl_git_pass
(
git_buf_joinpath
(
&
b
,
the_paths
[
i
],
the_paths
[
j
]));
cl_git_pass
(
git_tree_entry_bypath
(
&
te
,
tree
,
b
.
ptr
));
cl_assert_equal_s
(
the_paths
[
j
],
git_tree_entry_name
(
te
));
git_tree_entry_free
(
te
);
git_buf_free
(
&
b
);
}
}
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