]> git.proxmox.com Git - libgit2.git/blobdiff - tests/config/config_helpers.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / config / config_helpers.c
index 53bd945a0dabdf0b68132d10de0e6096b57ef068..ecdab5bf616501a68e4559267acade37d1d8ad74 100644 (file)
@@ -8,12 +8,13 @@ void assert_config_entry_existence(
        bool is_supposed_to_exist)
 {
        git_config *config;
-       const char *out;
+       git_config_entry *entry = NULL;
        int result;
 
        cl_git_pass(git_repository_config__weakptr(&config, repo));
-       
-       result = git_config_get_string(&out, config, name);
+
+       result = git_config_get_entry(&entry, config, name);
+       git_config_entry_free(entry);
 
        if (is_supposed_to_exist)
                cl_git_pass(result);
@@ -27,11 +28,40 @@ void assert_config_entry_value(
        const char *expected_value)
 {
        git_config *config;
-       const char *out;
+       git_buf buf = GIT_BUF_INIT;
 
        cl_git_pass(git_repository_config__weakptr(&config, repo));
 
-       cl_git_pass(git_config_get_string(&out, config, name));
+       cl_git_pass(git_config_get_string_buf(&buf, config, name));
+
+       cl_assert_equal_s(expected_value, buf.ptr);
+       git_buf_dispose(&buf);
+}
+
+static int count_config_entries_cb(
+       const git_config_entry *entry,
+       void *payload)
+{
+       int *how_many = (int *)payload;
+
+       GIT_UNUSED(entry);
+
+       (*how_many)++;
+
+       return 0;
+}
+
+int count_config_entries_match(git_repository *repo, const char *pattern)
+{
+       git_config *config;
+       int how_many = 0;
+
+       cl_git_pass(git_repository_config(&config, repo));
+
+       cl_assert_equal_i(0, git_config_foreach_match(
+               config, pattern, count_config_entries_cb, &how_many));
+
+       git_config_free(config);
 
-       cl_assert_equal_s(expected_value, out);
+       return how_many;
 }