fixtures.h 962 Bytes
Newer Older
Vicent Marti committed
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
static const char *
fixture_path(const char *base, const char *fixture_name)
{
	static char _path[4096];
	size_t root_len;

	root_len = strlen(base);
	strncpy(_path, base, sizeof(_path));

	if (_path[root_len - 1] != '/')
		_path[root_len++] = '/';

	if (fixture_name[0] == '/')
		fixture_name++;

	strncpy(_path + root_len,
		fixture_name,
		sizeof(_path) - root_len);

	return _path;
}

#ifdef CLAR_FIXTURE_PATH
const char *cl_fixture(const char *fixture_name)
{
	return fixture_path(CLAR_FIXTURE_PATH, fixture_name);
}

void cl_fixture_sandbox(const char *fixture_name)
{
	fs_copy(cl_fixture(fixture_name), _clar_path);
}

34 35 36 37 38 39 40 41 42 43 44 45
const char *cl_fixture_basename(const char *fixture_name)
{
	const char *p;

	for (p = fixture_name; *p; p++) {
		if (p[0] == '/' && p[1] && p[1] != '/')
			fixture_name = p+1;
	}

	return fixture_name;
}

Vicent Marti committed
46 47
void cl_fixture_cleanup(const char *fixture_name)
{
48
	fs_rm(fixture_path(_clar_path, cl_fixture_basename(fixture_name)));
Vicent Marti committed
49 50
}
#endif