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

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

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

11
	cl_git_pass(git_filebuf_open(&file, "git-test-config", 0));
12 13 14 15

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

16
	cl_git_pass(git_filebuf_commit(&file, 0666));
17 18 19 20
}

void test_config_stress__cleanup(void)
{
21
	p_unlink("git-test-config");
22 23 24 25 26 27 28 29
}

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

30
	cl_assert(git_path_exists("git-test-config"));
31
	cl_git_pass(git_config_file__ondisk(&file, "git-test-config"));
32 33 34
	cl_git_pass(git_config_new(&config));
	cl_git_pass(git_config_add_file(config, file, 0));

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

	git_config_free(config);
}
40 41 42 43 44 45 46 47 48 49 50

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

	cl_git_pass(git_config_file__ondisk(&file, cl_fixture("config/config12")));
	cl_git_pass(git_config_new(&config));
	cl_git_pass(git_config_add_file(config, file, 0));

51
	cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
52 53
	cl_assert(!strcmp(str, "hello! \" ; ; ; "));

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

57
	cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
58 59 60 61
	cl_assert(!strcmp(str, "this is \ba phrase"));

	git_config_free(config);
}