Hash :
90aa2bf3
Author :
Date :
2014-10-25T19:51:12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#include "clar_libgit2.h"
void test_config_snapshot__create_snapshot(void)
{
int32_t tmp;
git_config *cfg, *snapshot, *new_snapshot;
const char *filename = "config-ext-change";
cl_git_mkfile(filename, "[old]\nvalue = 5\n");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
cl_assert_equal_i(5, tmp);
cl_git_pass(git_config_snapshot(&snapshot, cfg));
/* Change the value on the file itself (simulate external process) */
cl_git_mkfile(filename, "[old]\nvalue = 56\n");
cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
cl_assert_equal_i(56, tmp);
cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value"));
cl_assert_equal_i(5, tmp);
/* Change the value on the file itself (simulate external process) */
cl_git_mkfile(filename, "[old]\nvalue = 999\n");
cl_git_pass(git_config_snapshot(&new_snapshot, cfg));
/* New snapshot should see new value */
cl_git_pass(git_config_get_int32(&tmp, new_snapshot, "old.value"));
cl_assert_equal_i(999, tmp);
/* Old snapshot should still have the old value */
cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value"));
cl_assert_equal_i(5, tmp);
git_config_free(new_snapshot);
git_config_free(snapshot);
git_config_free(cfg);
}
static int count_me(const git_config_entry *entry, void *payload)
{
int *n = (int *) payload;
GIT_UNUSED(entry);
(*n)++;
return 0;
}
void test_config_snapshot__multivar(void)
{
int count = 0;
git_config *cfg, *snapshot;
const char *filename = "config-file";
cl_git_mkfile(filename, "[old]\nvalue = 5\nvalue = 6\n");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_get_multivar_foreach(cfg, "old.value", NULL, count_me, &count));
cl_assert_equal_i(2, count);
cl_git_pass(git_config_snapshot(&snapshot, cfg));
git_config_free(cfg);
count = 0;
cl_git_pass(git_config_get_multivar_foreach(snapshot, "old.value", NULL, count_me, &count));
cl_assert_equal_i(2, count);
git_config_free(snapshot);
}