File: test_cache.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 (90 lines) | stat: -rw-r--r-- 2,048 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
#include "../../test.h"
#include "../../builders/build.h"
#include "../../prng.h"
#include "../../../src/base64.h"
#include "../../../src/fsops.h"
#include "../../../src/hexmap.h"
#include "../../../src/server/manio.h"
#include "../../../src/server/monitor/cache.h"
#include "../../../src/server/sdirs.h"
#include "../../../src/slist.h"
#include "../../builders/build_asfd_mock.h"

#define BASE		"utest_server_monitor_cache"
#define CLIENTNAME	"utestclient"

static void do_sdirs_init(struct sdirs *sdirs)
{
	fail_unless(!sdirs_init(sdirs,
		BASE, // directory
		CLIENTNAME,
		NULL, // client_lockdir
		"a_group", // dedup_group
		NULL // manual_delete
       ));
}

static void tear_down(struct sdirs **sdirs)
{
	sdirs_free(sdirs);
	fail_unless(!recursive_delete(BASE));
	alloc_check();
}

static struct sdirs *setup(void)
{
	struct sdirs *sdirs;
	prng_init(0);
	base64_init();
	fail_unless(!recursive_delete(BASE));
	fail_unless((sdirs=sdirs_alloc())!=NULL);
	do_sdirs_init(sdirs);
	return sdirs;
}

START_TEST(test_server_monitor_cache)
{
	struct sbuf *sb;
	struct sdirs *sdirs;
	struct slist *slist;
	struct manio *manio;
	unsigned long bno=5;

	sdirs=setup();
	slist=build_manifest(sdirs->manifest,
		/*manio_enties*/20, /*phase*/0);
        fail_unless((manio=manio_open(sdirs->manifest, "rb"))!=NULL);
        fail_unless((sb=sbuf_alloc())!=NULL);

	fail_unless(!cache_loaded(CLIENTNAME, bno));
	fail_unless(!cache_load(manio, sb, CLIENTNAME, bno));
	fail_unless(cache_loaded(CLIENTNAME, bno));
	fail_unless(!cache_loaded(CLIENTNAME, bno+1));
// FIX THIS: do an actual lookup.
//	fail_unless(cache_lookup("/"));
	cache_free();
	fail_unless(!cache_loaded(CLIENTNAME, bno));

	manio_close(&manio);
	sbuf_free(&sb);
	slist_free(&slist);
	tear_down(&sdirs);
}
END_TEST

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

	s=suite_create("server_monitor_cache");

	tc_core=tcase_create("Core");
	tcase_set_timeout(tc_core, 5);

	tcase_add_test(tc_core, test_server_monitor_cache);

	suite_add_tcase(s, tc_core);

	return s;
}