File: test_fdirs.c

package info (click to toggle)
burp 3.1.4-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,684 kB
  • sloc: ansic: 50,989; sh: 3,612; cpp: 2,859; makefile: 868
file content (93 lines) | stat: -rw-r--r-- 2,521 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "../test.h"
#include "../builders/build_file.h"
#include "../../src/alloc.h"
#include "../../src/conf.h"
#include "../../src/conffile.h"
#include "../../src/fsops.h"
#include "../../src/server/fdirs.h"
#include "../../src/server/sdirs.h"

#define BASE	"utest_server_fdirs"

static struct conf **setup_confs(void)
{
	struct conf **confs;
	const char *conffile=BASE "/burp.conf";
	confs=confs_alloc();
	confs_init(confs);
	fail_unless(!recursive_delete(BASE));
	build_file(conffile, MIN_SERVER_CONF);
	fail_unless(!conf_load_global_only(conffile, confs));
	set_string(confs[OPT_CNAME], "utestclient");
	return confs;
}

static struct sdirs *setup_sdirs(struct conf **confs)
{
	struct sdirs *sdirs;
	fail_unless((sdirs=sdirs_alloc())!=NULL);
	fail_unless(sdirs_init_from_confs(sdirs, confs)==0);
	return sdirs;
}

static struct fdirs *setup(struct sdirs *sdirs)
{
	struct fdirs *fdirs;
	fail_unless((fdirs=fdirs_alloc())!=NULL);
	return fdirs;
}

static void tear_down(struct fdirs **fdirs,
	struct sdirs **sdirs, struct conf ***confs)
{
	fail_unless(!recursive_delete(BASE));
	fdirs_free(fdirs);
	sdirs_free(sdirs);
	confs_free(confs);
	alloc_check();
}

#define CLIENTDIR	"/a/directory/utestclient"
#define FINISHING	CLIENTDIR "/finishing"
#define CURRENT		CLIENTDIR "/current"

START_TEST(test_fdirs)
{
	struct fdirs *fdirs;
	struct sdirs *sdirs;
	struct conf **confs;
	confs=setup_confs();
	sdirs=setup_sdirs(confs);
	fdirs=setup(sdirs);
	fail_unless(fdirs_init(fdirs, sdirs, "realcurrent")==0);
	ck_assert_str_eq(fdirs->manifest, FINISHING "/manifest.gz");
	ck_assert_str_eq(fdirs->deletionsfile, FINISHING "/deletions");
	ck_assert_str_eq(fdirs->datadir, FINISHING "/data");
	ck_assert_str_eq(fdirs->datadirtmp, FINISHING "/data.tmp");
	ck_assert_str_eq(fdirs->currentdup, FINISHING "/currentdup");
	ck_assert_str_eq(fdirs->currentduptmp, FINISHING "/currentdup.tmp");
	ck_assert_str_eq(fdirs->currentdupdata, FINISHING "/currentdup/data");
	ck_assert_str_eq(fdirs->timestamp, FINISHING "/timestamp");
	ck_assert_str_eq(fdirs->fullrealcurrent, CLIENTDIR "/realcurrent");
	ck_assert_str_eq(fdirs->logpath, FINISHING "/log");
	ck_assert_str_eq(fdirs->hlinked, FINISHING "/hardlinked");
	ck_assert_str_eq(fdirs->hlinkedcurrent, CURRENT "/hardlinked");

	tear_down(&fdirs, &sdirs, &confs);
}
END_TEST

Suite *suite_server_fdirs(void)
{
	Suite *s;
	TCase *tc_core;

	s=suite_create("server_fdirs");

	tc_core=tcase_create("Core");

	tcase_add_test(tc_core, test_fdirs);
	suite_add_tcase(s, tc_core);

	return s;
}