summaryrefslogtreecommitdiff
path: root/src/journal/test-catalog.c
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2015-11-08 12:51:51 +0100
committerStef Walter <stef@thewalter.net>2016-02-05 17:07:01 +0100
commit9d85882aa8ef1c54171419703f48d59d9df1b75c (patch)
tree03c4411d0766338a8ec1f7b19503c3fd7eabd48e /src/journal/test-catalog.c
parentdbae138dc1a30080241cab172a4cf5cf3bb48203 (diff)
journal: Refactor test-catalog importing tests
One function per test. Remove shared state between tests.
Diffstat (limited to 'src/journal/test-catalog.c')
-rw-r--r--src/journal/test-catalog.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c
index 4f1392c218..b03a16d2fc 100644
--- a/src/journal/test-catalog.c
+++ b/src/journal/test-catalog.c
@@ -46,10 +46,16 @@ static const char *no_catalog_dirs[] = {
NULL
};
-static void test_import(Hashmap *h, const char* contents, ssize_t size, int code) {
+static Hashmap * test_import(const char* contents, ssize_t size, int code) {
int r;
char name[] = "/tmp/test-catalog.XXXXXX";
_cleanup_close_ int fd;
+ Hashmap *h;
+
+ if (size < 0)
+ size = strlen(contents);
+
+ assert_se(h = hashmap_new(&catalog_hash_ops));
fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
assert_se(fd >= 0);
@@ -59,45 +65,50 @@ static void test_import(Hashmap *h, const char* contents, ssize_t size, int code
assert_se(r == code);
unlink(name);
-}
-static void test_catalog_importing(void) {
- Hashmap *h;
+ return h;
+}
- assert_se(h = hashmap_new(&catalog_hash_ops));
+static void test_catalog_import_invalid(void) {
+ _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
-#define BUF "xxx"
- test_import(h, BUF, sizeof(BUF), -EINVAL);
-#undef BUF
+ h = test_import("xxx", -1, -EINVAL);
assert_se(hashmap_isempty(h));
- log_debug("----------------------------------------");
+}
-#define BUF \
+static void test_catalog_import_badid(void) {
+ _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ const char *input =
"-- 0027229ca0644181a76c4e92458afaff dededededededededededededededede\n" \
"Subject: message\n" \
"\n" \
-"payload\n"
- test_import(h, BUF, sizeof(BUF), -EINVAL);
-#undef BUF
+"payload\n";
+ h = test_import(input, -1, -EINVAL);
+}
- log_debug("----------------------------------------");
+static void test_catalog_import_one(void) {
+ _cleanup_hashmap_free_free_free_ Hashmap *h = NULL;
+ char *payload;
+ Iterator j;
-#define BUF \
+ const char *input =
"-- 0027229ca0644181a76c4e92458afaff dededededededededededededededed\n" \
"Subject: message\n" \
"\n" \
-"payload\n"
- test_import(h, BUF, sizeof(BUF), 0);
-#undef BUF
+"payload\n";
+ const char *expect =
+"Subject: message\n" \
+"\n" \
+"payload\n";
+ h = test_import(input, -1, 0);
assert_se(hashmap_size(h) == 1);
- log_debug("----------------------------------------");
-
- hashmap_free_free(h);
+ HASHMAP_FOREACH(payload, h, j) {
+ assert_se(streq(expect, payload));
+ }
}
-
static const char* database = NULL;
static void test_catalog_update(void) {
@@ -162,7 +173,9 @@ int main(int argc, char *argv[]) {
test_catalog_file_lang();
- test_catalog_importing();
+ test_catalog_import_invalid();
+ test_catalog_import_badid();
+ test_catalog_import_one();
test_catalog_update();