summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-04-11 17:41:21 +0200
committerCarlos Martín Nieto <cmn@elego.de>2011-04-11 17:43:56 +0200
commit55c197cdd37b34c7b4877bc0434c297075e11222 (patch)
tree05dcc126d117b1753e07f0a173cf9498a38ac4f9 /tests
parentb075b9910c56c356d53439fd34486a905146211a (diff)
parentfdd0cc9e8948bb65c9a461c58e5094a3613bd975 (diff)
downloadlibgit2-55c197cdd37b34c7b4877bc0434c297075e11222.tar.gz
Merge upstream/development
Diffstat (limited to 'tests')
-rw-r--r--tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1bin82 -> 82 bytes
-rw-r--r--tests/resources/testrepo.git/refs/tags/point_to_blob1
-rw-r--r--tests/t00-core.c4
-rw-r--r--tests/t08-tag.c18
-rw-r--r--tests/t09-tree.c26
-rw-r--r--tests/t10-refs.c9
-rw-r--r--tests/t12-repo.c18
-rw-r--r--tests/t14-hiredis.c123
-rw-r--r--tests/t15-config.c (renamed from tests/t14-config.c)0
-rw-r--r--tests/test_main.c2
10 files changed, 181 insertions, 20 deletions
diff --git a/tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 b/tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
index 03770969a..697c94c92 100644
--- a/tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
+++ b/tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
Binary files differ
diff --git a/tests/resources/testrepo.git/refs/tags/point_to_blob b/tests/resources/testrepo.git/refs/tags/point_to_blob
new file mode 100644
index 000000000..f874a3ffc
--- /dev/null
+++ b/tests/resources/testrepo.git/refs/tags/point_to_blob
@@ -0,0 +1 @@
+1385f264afb75a56a5bec74243be9b367ba4ca08
diff --git a/tests/t00-core.c b/tests/t00-core.c
index 4cb111428..ab9a683a7 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -233,7 +233,7 @@ BEGIN_TEST(path3, "prettify and validate a path to a file")
must_fail(ensure_file_path_normalized("d1/s1///s2/..//../s3/", NULL, 0));
must_pass(ensure_file_path_normalized("d1/s1//../s2/../../d2", "d2", CWD_AS_PREFIX | PATH_AS_SUFFIX));
must_fail(ensure_file_path_normalized("dir/sub/../", NULL, 0));
- must_pass(ensure_file_path_normalized("../../a/../../b/c/d/../../e", "b/e", PATH_AS_SUFFIX));
+ must_pass(ensure_file_path_normalized("../a/../b/c/d/../../e", "b/e", PATH_AS_SUFFIX));
must_fail(ensure_file_path_normalized("....", NULL, 0));
must_fail(ensure_file_path_normalized("...", NULL, 0));
must_fail(ensure_file_path_normalized("./...", NULL, 0));
@@ -309,7 +309,7 @@ BEGIN_TEST(path4, "validate and prettify a path to a folder")
must_pass(ensure_dir_path_normalized("d1/s1///s2/..//../s3/", "d1/s3/", CWD_AS_PREFIX | PATH_AS_SUFFIX));
must_pass(ensure_dir_path_normalized("d1/s1//../s2/../../d2", "d2/", CWD_AS_PREFIX | PATH_AS_SUFFIX));
must_pass(ensure_dir_path_normalized("dir/sub/../", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX));
- must_pass(ensure_dir_path_normalized("../../a/../../b/c/d/../../e", "b/e/", PATH_AS_SUFFIX));
+ must_pass(ensure_dir_path_normalized("../a/../b/c/d/../../e", "b/e/", PATH_AS_SUFFIX));
must_fail(ensure_dir_path_normalized("....", NULL, 0));
must_fail(ensure_dir_path_normalized("...", NULL, 0));
must_fail(ensure_dir_path_normalized("./...", NULL, 0));
diff --git a/tests/t08-tag.c b/tests/t08-tag.c
index e7016488f..de67fdd93 100644
--- a/tests/t08-tag.c
+++ b/tests/t08-tag.c
@@ -119,13 +119,10 @@ BEGIN_TEST(write0, "write a tag to the repository and read it again")
END_TEST
-BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid and read it again")
+BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid should fail")
git_repository *repo;
- git_tag *tag;
git_oid target_id, tag_id;
const git_signature *tagger;
- git_reference *ref_tag;
- git_object *zombie;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
@@ -135,7 +132,7 @@ BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid
tagger = git_signature_new(TAGGER_NAME, TAGGER_EMAIL, 123456789, 60);
must_be_true(tagger != NULL);
- must_pass(git_tag_create(
+ must_fail(git_tag_create(
&tag_id, /* out id */
repo,
"the-zombie-tag",
@@ -146,17 +143,6 @@ BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid
git_signature_free((git_signature *)tagger);
- must_pass(git_tag_lookup(&tag, repo, &tag_id));
-
- /* The non existent target can not be looked up */
- must_fail(git_tag_target(&zombie, tag));
-
- must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/the-zombie-tag"));
-
- must_pass(git_reference_delete(ref_tag));
- must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag));
-
- git_tag_close(tag);
git_repository_free(repo);
END_TEST
diff --git a/tests/t09-tree.c b/tests/t09-tree.c
index e4252dbca..bd88642fa 100644
--- a/tests/t09-tree.c
+++ b/tests/t09-tree.c
@@ -29,6 +29,10 @@
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
+static const char *blob_oid = "fa49b077972391ad58037050f2a75f74e3671e92";
+static const char *first_tree = "181037049a54a1eb5fab404658a3a250b44335d7";
+static const char *second_tree = "f60079018b664e4e79329a7ef9559c8d9e0378d1";
+
#if 0
static int print_tree(git_repository *repo, const git_oid *tree_oid, int depth)
{
@@ -126,11 +130,33 @@ BEGIN_TEST(write0, "write a tree from an index")
END_TEST
#endif
+BEGIN_TEST(write2, "write a tree from a memory")
+ git_repository *repo;
+ git_treebuilder *builder;
+ git_tree *tree;
+ git_oid id, bid, rid, id2;
+
+ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
+ git_oid_mkstr(&id, first_tree);
+ git_oid_mkstr(&id2, second_tree);
+ git_oid_mkstr(&bid, blob_oid);
+
+ //create a second tree from first tree using `git_treebuilder_insert` on REPOSITORY_FOLDER.
+ must_pass(git_tree_lookup(&tree, repo, &id));
+ must_pass(git_treebuilder_create(&builder, tree));
+ must_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644));
+ must_pass(git_treebuilder_write(&rid,repo,builder));
+
+ must_be_true(git_oid_cmp(&rid, &id2) == 0);
+ close_temp_repo(repo);
+END_TEST
+
BEGIN_SUITE(tree)
//ADD_TEST(print0);
ADD_TEST(read0);
ADD_TEST(read1);
//ADD_TEST(write0);
//ADD_TEST(write1);
+ ADD_TEST(write2);
END_SUITE
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index 2797cd8ac..a6a560193 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -456,6 +456,11 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_be_true((reference->type & GIT_REF_PACKED) == 0);
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
+ /*
+ * We are now trying to pack also a loose reference
+ * called `points_to_blob`, to make sure we can properly
+ * pack weak tags
+ */
must_pass(git_reference_packall(repo));
/* Ensure the packed-refs file exists */
@@ -877,10 +882,10 @@ BEGIN_TEST(list0, "try to list all the references in our test repo")
printf("# %s\n", ref_list.strings[i]);
}*/
- /* We have exactly 7 refs in total if we include the packed ones:
+ /* We have exactly 8 refs in total if we include the packed ones:
* there is a reference that exists both in the packfile and as
* loose, but we only list it once */
- must_be_true(ref_list.count == 7);
+ must_be_true(ref_list.count == 8);
git_strarray_free(&ref_list);
git_repository_free(repo);
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index adf20cfd7..70dba4255 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -194,6 +194,8 @@ BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git"
must_pass(remove_placeholders(TEMP_REPO_FOLDER, "dummy-marker.txt"));
must_pass(git_repository_open(&repo, TEMP_REPO_FOLDER));
+ must_be_true(git_repository_path(repo) != NULL);
+ must_be_true(git_repository_workdir(repo) == NULL);
git_repository_free(repo);
must_pass(rmdir_recurs(TEMP_REPO_FOLDER));
@@ -211,6 +213,8 @@ BEGIN_TEST(open1, "Open a standard repository that has just been initialized by
must_pass(remove_placeholders(DEST_REPOSITORY_FOLDER, "dummy-marker.txt"));
must_pass(git_repository_open(&repo, DEST_REPOSITORY_FOLDER));
+ must_be_true(git_repository_path(repo) != NULL);
+ must_be_true(git_repository_workdir(repo) != NULL);
git_repository_free(repo);
must_pass(rmdir_recurs(TEMP_REPO_FOLDER));
@@ -244,6 +248,19 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t
rmdir_recurs(TEMP_REPO_FOLDER);
END_TEST
+BEGIN_TEST(empty0, "test if a repository is empty or not")
+
+ git_repository *repo_empty, *repo_normal;
+
+ must_pass(git_repository_open(&repo_normal, REPOSITORY_FOLDER));
+ must_be_true(git_repository_is_empty(repo_normal) == 0);
+ git_repository_free(repo_normal);
+
+ must_pass(git_repository_open(&repo_empty, EMPTY_BARE_REPOSITORY_FOLDER));
+ must_be_true(git_repository_is_empty(repo_empty) == 1);
+ git_repository_free(repo_empty);
+END_TEST
+
BEGIN_SUITE(repository)
ADD_TEST(odb0);
ADD_TEST(odb1);
@@ -253,5 +270,6 @@ BEGIN_SUITE(repository)
ADD_TEST(open0);
ADD_TEST(open1);
ADD_TEST(open2);
+ ADD_TEST(empty0);
END_SUITE
diff --git a/tests/t14-hiredis.c b/tests/t14-hiredis.c
new file mode 100644
index 000000000..c743f7d48
--- /dev/null
+++ b/tests/t14-hiredis.c
@@ -0,0 +1,123 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+#include "test_lib.h"
+#include "odb.h"
+
+#ifdef GIT2_HIREDIS_BACKEND
+#include "t03-data.h"
+#include "fileops.h"
+#include "git2/odb_backend.h"
+
+
+static int cmp_objects(git_odb_object *odb_obj, git_rawobj *raw)
+{
+ if (raw->type != git_odb_object_type(odb_obj))
+ return -1;
+
+ if (raw->len != git_odb_object_size(odb_obj))
+ return -1;
+
+ if ((raw->len > 0) && (memcmp(raw->data, git_odb_object_data(odb_obj), raw->len) != 0))
+ return -1;
+
+ return 0;
+}
+
+static git_odb *open_hiredis_odb(void)
+{
+ git_odb *odb;
+ git_odb_backend *hiredis;
+
+ if (git_odb_new(&odb) < GIT_SUCCESS)
+ return NULL;
+
+ if (git_odb_backend_hiredis(&hiredis, "127.0.0.1", 6379) < GIT_SUCCESS)
+ return NULL;
+
+ if (git_odb_add_backend(odb, hiredis, 0) < GIT_SUCCESS)
+ return NULL;
+
+ return odb;
+}
+
+#define TEST_WRITE(PTR) {\
+ git_odb *db; \
+ git_oid id1, id2; \
+ git_odb_object *obj; \
+ db = open_hiredis_odb(); \
+ must_be_true(db != NULL); \
+ must_pass(git_oid_mkstr(&id1, PTR.id)); \
+ must_pass(git_odb_write(&id2, db, PTR##_obj.data, PTR##_obj.len, PTR##_obj.type)); \
+ must_be_true(git_oid_cmp(&id1, &id2) == 0); \
+ must_pass(git_odb_read(&obj, db, &id1)); \
+ must_pass(cmp_objects(obj, &PTR##_obj)); \
+ git_odb_object_close(obj); \
+ git_odb_close(db); \
+}
+
+BEGIN_TEST(hiredis0, "write a commit, read it back (hiredis backend)")
+ TEST_WRITE(commit);
+END_TEST
+
+BEGIN_TEST(hiredis1, "write a tree, read it back (hiredis backend)")
+ TEST_WRITE(tree);
+END_TEST
+
+BEGIN_TEST(hiredis2, "write a tag, read it back (hiredis backend)")
+ TEST_WRITE(tag);
+END_TEST
+
+BEGIN_TEST(hiredis3, "write a zero-byte entry, read it back (hiredis backend)")
+ TEST_WRITE(zero);
+END_TEST
+
+BEGIN_TEST(hiredis4, "write a one-byte entry, read it back (hiredis backend)")
+ TEST_WRITE(one);
+END_TEST
+
+BEGIN_TEST(hiredis5, "write a two-byte entry, read it back (hiredis backend)")
+ TEST_WRITE(two);
+END_TEST
+
+BEGIN_TEST(hiredis6, "write some bytes in an entry, read it back (hiredis backend)")
+ TEST_WRITE(some);
+END_TEST
+
+
+BEGIN_SUITE(hiredis)
+ ADD_TEST(hiredis0);
+ ADD_TEST(hiredis1);
+ ADD_TEST(hiredis2);
+ ADD_TEST(hiredis3);
+ ADD_TEST(hiredis4);
+ ADD_TEST(hiredis5);
+ ADD_TEST(hiredis6);
+END_SUITE
+
+#else /* no hiredis builtin */
+BEGIN_SUITE(hiredis)
+ /* empty */
+END_SUITE
+#endif
diff --git a/tests/t14-config.c b/tests/t15-config.c
index 2cbd05896..2cbd05896 100644
--- a/tests/t14-config.c
+++ b/tests/t15-config.c
diff --git a/tests/test_main.c b/tests/test_main.c
index c99722e80..0f5f16a26 100644
--- a/tests/test_main.c
+++ b/tests/test_main.c
@@ -41,6 +41,7 @@ DECLARE_SUITE(tag);
DECLARE_SUITE(tree);
DECLARE_SUITE(refs);
DECLARE_SUITE(sqlite);
+DECLARE_SUITE(hiredis);
DECLARE_SUITE(repository);
DECLARE_SUITE(threads);
DECLARE_SUITE(config);
@@ -60,6 +61,7 @@ static libgit2_suite suite_methods[]= {
SUITE_NAME(sqlite),
SUITE_NAME(repository),
SUITE_NAME(threads),
+ SUITE_NAME(hiredis),
SUITE_NAME(config),
};