From 12949651f724ea041968c80d549e368e5eb2a1a8 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 31 Mar 2016 08:08:33 -0400 Subject: [PATCH] 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 --- include/core/file.h | 13 +++++++++++++ tests/core/file.c | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/core/file.h b/include/core/file.h index 053e8d85..b3d06121 100644 --- a/include/core/file.h +++ b/include/core/file.h @@ -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. */ void file_init(struct file *, const gchar *, unsigned int, unsigned int); diff --git a/tests/core/file.c b/tests/core/file.c index e013ca7d..ada2cb61 100644 --- a/tests/core/file.c +++ b/tests/core/file.c @@ -143,10 +143,20 @@ static void test_versioning() 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( UNIT_TEST("File (Path = NULL)", test_null), UNIT_TEST("File (Path = \"\")", test_empty), UNIT_TEST("File (Path = \"file.txt\")", test_file), UNIT_TEST("File I/O", test_io), UNIT_TEST("File Versioning", test_versioning), + UNIT_TEST("File Cache", test_cache), );