core/file: Add struct cache_file
I want to reuse as much file code as I can for cache files, but I need a new struct since data and cache files track different properties. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
9e0f017e61
commit
12949651f7
|
@ -53,6 +53,19 @@ struct file {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct cache_file {
|
||||||
|
FILE *cf_file; /* The cache file's IO stream. */
|
||||||
|
gchar *cf_name; /* The cache file's basename. */
|
||||||
|
gchar *cf_subdir; /* The cache file's subdirectory. */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CACHE_FILE_INIT(cfsubdir, cfname) \
|
||||||
|
{ \
|
||||||
|
.cf_file = NULL, \
|
||||||
|
.cf_subdir = cfsubdir, \
|
||||||
|
.cf_name = cfname, \
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize a new file object. */
|
/* Initialize a new file object. */
|
||||||
void file_init(struct file *, const gchar *, unsigned int, unsigned int);
|
void file_init(struct file *, const gchar *, unsigned int, unsigned int);
|
||||||
|
|
||||||
|
|
|
@ -143,10 +143,20 @@ static void test_versioning()
|
||||||
test_equal((void *)fin.f_file, NULL);
|
test_equal((void *)fin.f_file, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_cache()
|
||||||
|
{
|
||||||
|
struct cache_file file = CACHE_FILE_INIT("dir", "file.txt");
|
||||||
|
|
||||||
|
test_equal((void *)file.cf_file, NULL);
|
||||||
|
test_equal(file.cf_name, "file.txt");
|
||||||
|
test_equal(file.cf_subdir, "dir");
|
||||||
|
}
|
||||||
|
|
||||||
DECLARE_UNIT_TESTS(
|
DECLARE_UNIT_TESTS(
|
||||||
UNIT_TEST("File (Path = NULL)", test_null),
|
UNIT_TEST("File (Path = NULL)", test_null),
|
||||||
UNIT_TEST("File (Path = \"\")", test_empty),
|
UNIT_TEST("File (Path = \"\")", test_empty),
|
||||||
UNIT_TEST("File (Path = \"file.txt\")", test_file),
|
UNIT_TEST("File (Path = \"file.txt\")", test_file),
|
||||||
UNIT_TEST("File I/O", test_io),
|
UNIT_TEST("File I/O", test_io),
|
||||||
UNIT_TEST("File Versioning", test_versioning),
|
UNIT_TEST("File Versioning", test_versioning),
|
||||||
|
UNIT_TEST("File Cache", test_cache),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue