stress.c 1.94 KB
Newer Older
1
#include "clar_libgit2.h"
2 3 4 5 6

#include "filebuf.h"
#include "fileops.h"
#include "posix.h"

7 8
#define TEST_CONFIG "git-test-config"

9 10
void test_config_stress__initialize(void)
{
11
	git_filebuf file = GIT_FILEBUF_INIT;
12

13
	cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0));
14 15 16 17

	git_filebuf_printf(&file, "[color]\n\tui = auto\n");
	git_filebuf_printf(&file, "[core]\n\teditor = \n");

18
	cl_git_pass(git_filebuf_commit(&file, 0666));
19 20 21 22
}

void test_config_stress__cleanup(void)
{
23
	p_unlink(TEST_CONFIG);
24 25 26 27 28 29 30
}

void test_config_stress__dont_break_on_invalid_input(void)
{
	const char *editor, *color;
	git_config *config;

31 32
	cl_assert(git_path_exists(TEST_CONFIG));
	cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
33

34 35
	cl_git_pass(git_config_get_string(&color, config, "color.ui"));
	cl_git_pass(git_config_get_string(&editor, config, "core.editor"));
36 37 38

	git_config_free(config);
}
39 40 41 42 43 44

void test_config_stress__comments(void)
{
	git_config *config;
	const char *str;

45
	cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
46

47
	cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
48 49
	cl_assert(!strcmp(str, "hello! \" ; ; ; "));

50
	cl_git_pass(git_config_get_string(&str, config, "some.section.multi"));
51 52
	cl_assert(!strcmp(str, "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#"));

53
	cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
54 55 56 57
	cl_assert(!strcmp(str, "this is \ba phrase"));

	git_config_free(config);
}
58 59 60 61 62 63 64

void test_config_stress__escape_subsection_names(void)
{
	git_config *config;
	const char *str;

	cl_assert(git_path_exists("git-test-config"));
65
	cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
66 67 68 69

	cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
	git_config_free(config);

70
	cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
71 72 73

	cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other"));
	cl_assert(!strcmp("foo", str));
74
	git_config_free(config);
75
}