+static const char *catalog_dirs[] = {
+ CATALOG_DIR,
+ NULL,
+};
+
+static const char *no_catalog_dirs[] = {
+ "/bin/hopefully/with/no/catalog",
+ NULL
+};
+
+static void test_import(Hashmap *h, struct strbuf *sb,
+ const char* contents, ssize_t size, int code) {
+ int r;
+ char name[] = "/tmp/test-catalog.XXXXXX";
+ _cleanup_close_ int fd = mkstemp(name);
+ assert(fd >= 0);
+ assert_se(write(fd, contents, size) == size);
+
+ r = catalog_import_file(h, sb, name);
+ assert(r == code);
+
+ unlink(name);
+}
+
+static void test_catalog_importing(void) {
+ Hashmap *h;
+ struct strbuf *sb;
+
+ assert_se(h = hashmap_new(catalog_hash_func, catalog_compare_func));
+ assert_se(sb = strbuf_new());
+
+#define BUF "xxx"
+ test_import(h, sb, BUF, sizeof(BUF), -EINVAL);
+#undef BUF
+ assert(hashmap_isempty(h));
+ log_debug("----------------------------------------");
+
+#define BUF \
+"-- 0027229ca0644181a76c4e92458afaff dededededededededededededededede\n" \
+"Subject: message\n" \
+"\n" \
+"payload\n"
+ test_import(h, sb, BUF, sizeof(BUF), -EINVAL);
+#undef BUF
+
+ log_debug("----------------------------------------");
+
+#define BUF \
+"-- 0027229ca0644181a76c4e92458afaff dededededededededededededededed\n" \
+"Subject: message\n" \
+"\n" \
+"payload\n"
+ test_import(h, sb, BUF, sizeof(BUF), 0);
+#undef BUF
+
+ assert(hashmap_size(h) == 1);