]>
Commit | Line | Data |
---|---|---|
55ebd7d3 CMN |
1 | #include "clar_libgit2.h" |
2 | ||
3 | void test_config_snapshot__create_snapshot(void) | |
4 | { | |
5 | int32_t tmp; | |
6 | git_config *cfg, *snapshot; | |
7 | const char *filename = "config-ext-change"; | |
8 | ||
9 | cl_git_mkfile(filename, "[old]\nvalue = 5\n"); | |
10 | ||
11 | cl_git_pass(git_config_open_ondisk(&cfg, filename)); | |
12 | ||
13 | cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value")); | |
14 | cl_assert_equal_i(5, tmp); | |
15 | ||
16 | cl_git_pass(git_config_snapshot(&snapshot, cfg)); | |
17 | ||
18 | /* Change the value on the file itself (simulate external process) */ | |
19 | cl_git_mkfile(filename, "[old]\nvalue = 56\n"); | |
20 | ||
55ebd7d3 CMN |
21 | cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value")); |
22 | cl_assert_equal_i(56, tmp); | |
23 | ||
24 | cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value")); | |
25 | cl_assert_equal_i(5, tmp); | |
26 | ||
27 | git_config_free(snapshot); | |
28 | git_config_free(cfg); | |
29 | } | |
30 | ||
31 | static int count_me(const git_config_entry *entry, void *payload) | |
32 | { | |
33 | int *n = (int *) payload; | |
34 | ||
35 | GIT_UNUSED(entry); | |
36 | ||
37 | (*n)++; | |
38 | ||
39 | return 0; | |
40 | } | |
41 | ||
42 | void test_config_snapshot__multivar(void) | |
43 | { | |
44 | int count = 0; | |
45 | git_config *cfg, *snapshot; | |
46 | const char *filename = "config-file"; | |
47 | ||
48 | cl_git_mkfile(filename, "[old]\nvalue = 5\nvalue = 6\n"); | |
49 | ||
50 | cl_git_pass(git_config_open_ondisk(&cfg, filename)); | |
51 | cl_git_pass(git_config_get_multivar_foreach(cfg, "old.value", NULL, count_me, &count)); | |
52 | ||
53 | cl_assert_equal_i(2, count); | |
54 | ||
55 | cl_git_pass(git_config_snapshot(&snapshot, cfg)); | |
56 | git_config_free(cfg); | |
57 | ||
58 | count = 0; | |
59 | cl_git_pass(git_config_get_multivar_foreach(snapshot, "old.value", NULL, count_me, &count)); | |
60 | ||
61 | cl_assert_equal_i(2, count); | |
62 | ||
63 | git_config_free(snapshot); | |
64 | } |