]> git.proxmox.com Git - libgit2.git/blame - tests-clar/config/stress.c
tests-clar: ifdef GIT_WIN32 win helper functions
[libgit2.git] / tests-clar / config / stress.c
CommitLineData
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
d1a721c5
VM
9void test_config_stress__initialize(void)
10{
bf038dab 11 git_filebuf file = GIT_FILEBUF_INIT;
d1a721c5 12
a1abe66a 13 cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0));
d1a721c5
VM
14
15 git_filebuf_printf(&file, "[color]\n\tui = auto\n");
16 git_filebuf_printf(&file, "[core]\n\teditor = \n");
17
9462c471 18 cl_git_pass(git_filebuf_commit(&file, 0666));
d1a721c5
VM
19}
20
21void test_config_stress__cleanup(void)
22{
a1abe66a 23 p_unlink(TEST_CONFIG);
d1a721c5
VM
24}
25
26void test_config_stress__dont_break_on_invalid_input(void)
27{
28 const char *editor, *color;
d1a721c5
VM
29 git_config *config;
30
a1abe66a 31 cl_assert(git_path_exists(TEST_CONFIG));
32 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
d1a721c5 33
255c38c5
VM
34 cl_git_pass(git_config_get_string(&color, config, "color.ui"));
35 cl_git_pass(git_config_get_string(&editor, config, "core.editor"));
d1a721c5
VM
36
37 git_config_free(config);
38}
2c1075d6
CMN
39
40void test_config_stress__comments(void)
41{
2c1075d6
CMN
42 git_config *config;
43 const char *str;
44
a1abe66a 45 cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
2c1075d6 46
255c38c5 47 cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
2c1075d6
CMN
48 cl_assert(!strcmp(str, "hello! \" ; ; ; "));
49
255c38c5 50 cl_git_pass(git_config_get_string(&str, config, "some.section.multi"));
2c1075d6
CMN
51 cl_assert(!strcmp(str, "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#"));
52
255c38c5 53 cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
2c1075d6
CMN
54 cl_assert(!strcmp(str, "this is \ba phrase"));
55
56 git_config_free(config);
57}
5d9cfa07
CMN
58
59void test_config_stress__escape_subsection_names(void)
60{
5d9cfa07
CMN
61 git_config *config;
62 const char *str;
63
64 cl_assert(git_path_exists("git-test-config"));
a1abe66a 65 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
5d9cfa07
CMN
66
67 cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
68 git_config_free(config);
69
a1abe66a 70 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
5d9cfa07
CMN
71
72 cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other"));
73 cl_assert(!strcmp("foo", str));
14e1bc15 74 git_config_free(config);
5d9cfa07 75}