]>
Commit | Line | Data |
---|---|---|
3fd1520c | 1 | #include "clar_libgit2.h" |
d1a721c5 VM |
2 | |
3 | #include "filebuf.h" | |
4 | #include "fileops.h" | |
5 | #include "posix.h" | |
6 | ||
a1abe66a | 7 | #define TEST_CONFIG "git-test-config" |
8 | ||
9a97f49e CMN |
9 | static git_buf buf = GIT_BUF_INIT; |
10 | ||
d1a721c5 VM |
11 | void test_config_stress__initialize(void) |
12 | { | |
bf038dab | 13 | git_filebuf file = GIT_FILEBUF_INIT; |
d1a721c5 | 14 | |
1d3a8aeb | 15 | cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0, 0666)); |
d1a721c5 VM |
16 | |
17 | git_filebuf_printf(&file, "[color]\n\tui = auto\n"); | |
18 | git_filebuf_printf(&file, "[core]\n\teditor = \n"); | |
19 | ||
1d3a8aeb | 20 | cl_git_pass(git_filebuf_commit(&file)); |
d1a721c5 VM |
21 | } |
22 | ||
23 | void test_config_stress__cleanup(void) | |
24 | { | |
ac3d33df | 25 | git_buf_dispose(&buf); |
a1abe66a | 26 | p_unlink(TEST_CONFIG); |
d1a721c5 VM |
27 | } |
28 | ||
29 | void test_config_stress__dont_break_on_invalid_input(void) | |
30 | { | |
d1a721c5 VM |
31 | git_config *config; |
32 | ||
a1abe66a | 33 | cl_assert(git_path_exists(TEST_CONFIG)); |
34 | cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); | |
d1a721c5 | 35 | |
9a97f49e CMN |
36 | cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui")); |
37 | cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor")); | |
d1a721c5 VM |
38 | |
39 | git_config_free(config); | |
40 | } | |
2c1075d6 | 41 | |
9a97f49e CMN |
42 | void assert_config_value(git_config *config, const char *key, const char *value) |
43 | { | |
44 | git_buf_clear(&buf); | |
45 | cl_git_pass(git_config_get_string_buf(&buf, config, key)); | |
46 | cl_assert_equal_s(value, git_buf_cstr(&buf)); | |
47 | } | |
48 | ||
2c1075d6 CMN |
49 | void test_config_stress__comments(void) |
50 | { | |
2c1075d6 | 51 | git_config *config; |
2c1075d6 | 52 | |
a1abe66a | 53 | cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12"))); |
2c1075d6 | 54 | |
9a97f49e CMN |
55 | assert_config_value(config, "some.section.test2", "hello"); |
56 | assert_config_value(config, "some.section.test3", "welcome"); | |
57 | assert_config_value(config, "some.section.other", "hello! \" ; ; ; "); | |
58 | assert_config_value(config, "some.section.other2", "cool! \" # # # "); | |
59 | assert_config_value(config, "some.section.multi", "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#"); | |
60 | assert_config_value(config, "some.section.multi2", "good, this is a ; multiline comment # with ;\n special chars and other stuff !@#"); | |
61 | assert_config_value(config, "some.section.back", "this is \ba phrase"); | |
2c1075d6 CMN |
62 | |
63 | git_config_free(config); | |
64 | } | |
5d9cfa07 CMN |
65 | |
66 | void test_config_stress__escape_subsection_names(void) | |
67 | { | |
5d9cfa07 | 68 | git_config *config; |
5d9cfa07 CMN |
69 | |
70 | cl_assert(git_path_exists("git-test-config")); | |
a1abe66a | 71 | cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); |
5d9cfa07 CMN |
72 | |
73 | cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo")); | |
74 | git_config_free(config); | |
75 | ||
a1abe66a | 76 | cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); |
5d9cfa07 | 77 | |
9a97f49e CMN |
78 | assert_config_value(config, "some.sec\\tion.other", "foo"); |
79 | ||
14e1bc15 | 80 | git_config_free(config); |
5d9cfa07 | 81 | } |
9f35754a CMN |
82 | |
83 | void test_config_stress__trailing_backslash(void) | |
84 | { | |
85 | git_config *config; | |
9f35754a CMN |
86 | const char *path = "C:\\iam\\some\\windows\\path\\"; |
87 | ||
88 | cl_assert(git_path_exists("git-test-config")); | |
89 | cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); | |
90 | cl_git_pass(git_config_set_string(config, "windows.path", path)); | |
91 | git_config_free(config); | |
92 | ||
93 | cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); | |
9a97f49e CMN |
94 | assert_config_value(config, "windows.path", path); |
95 | ||
9f35754a CMN |
96 | git_config_free(config); |
97 | } | |
9dac1f95 CMN |
98 | |
99 | void test_config_stress__complex(void) | |
100 | { | |
101 | git_config *config; | |
9dac1f95 CMN |
102 | const char *path = "./config-immediate-multiline"; |
103 | ||
104 | cl_git_mkfile(path, "[imm]\n multi = \"\\\nfoo\""); | |
105 | cl_git_pass(git_config_open_ondisk(&config, path)); | |
9a97f49e CMN |
106 | assert_config_value(config, "imm.multi", "foo"); |
107 | ||
9dac1f95 CMN |
108 | git_config_free(config); |
109 | } | |
a2f96479 CMN |
110 | |
111 | void test_config_stress__quick_write(void) | |
112 | { | |
113 | git_config *config_w, *config_r; | |
114 | const char *path = "./config-quick-write"; | |
115 | const char *key = "quick.write"; | |
116 | int32_t i; | |
117 | ||
118 | /* Create an external writer for one instance with the other one */ | |
119 | cl_git_pass(git_config_open_ondisk(&config_w, path)); | |
120 | cl_git_pass(git_config_open_ondisk(&config_r, path)); | |
121 | ||
122 | /* Write and read in the same second (repeat to increase the chance of it happening) */ | |
123 | for (i = 0; i < 10; i++) { | |
124 | int32_t val; | |
125 | cl_git_pass(git_config_set_int32(config_w, key, i)); | |
126 | cl_git_pass(git_config_get_int32(&val, config_r, key)); | |
127 | cl_assert_equal_i(i, val); | |
128 | } | |
9031be18 PS |
129 | |
130 | git_config_free(config_r); | |
131 | git_config_free(config_w); | |
a2f96479 | 132 | } |