pkginc_libdir=$(pkgincludedir)
pkginc_lib_HEADERS = $(headers)
+
+noinst_PROGRAMS = $(test_programs)
+
+test_programs = \
+ test-fs-metawrap
+
+test_deps = \
+ $(noinst_LTLIBRARIES) \
+ ../lib-dict/libdict.la \
+ ../lib-test/libtest.la \
+ ../lib/liblib.la
+
+test_libs = \
+ $(test_deps) \
+ $(MODULE_LIBS)
+
+test_fs_metawrap_SOURCES = test-fs-metawrap.c
+test_fs_metawrap_LDADD = $(test_libs)
+test_fs_metawrap_DEPENDENCIES = $(test_deps)
+
+check: check-am check-test
+check-test: all-am
+ for bin in $(test_programs); do \
+ if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \
+ done
--- /dev/null
+/* Copyright (c) 2016 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "str.h"
+#include "istream.h"
+#include "fs-test.h"
+#include "test-common.h"
+
+static void test_fs_metawrap_stat(void)
+{
+ struct fs_settings fs_set;
+ struct fs *fs;
+ struct fs_file *file;
+ struct test_fs_file *test_file;
+ struct istream *input;
+ struct stat st;
+ const char *error;
+ unsigned int i;
+
+ test_begin("fs metawrap stat");
+
+ memset(&fs_set, 0, sizeof(fs_set));
+ if (fs_init("metawrap", "test", &fs_set, &fs, &error) < 0)
+ i_fatal("fs_init() failed: %s", error);
+
+ for (i = 0; i < 2; i++) {
+ file = fs_file_init(fs, "foo", FS_OPEN_MODE_READONLY);
+
+ test_file = test_fs_file_get(fs, 0);
+ str_append(test_file->contents, "key:value\n\n12345678901234567890");
+
+ if (i == 0) {
+ input = fs_read_stream(file, 2);
+ test_istream_set_max_buffer_size(test_file->input, 2);
+ } else {
+ input = NULL;
+ }
+
+ test_assert_idx(fs_stat(file, &st) == 0 && st.st_size == 20, i);
+
+ if (input != NULL)
+ i_stream_unref(&input);
+ fs_file_deinit(&file);
+ }
+ fs_deinit(&fs);
+ test_end();
+}
+
+int main(void)
+{
+ static void (*test_functions[])(void) = {
+ test_fs_metawrap_stat,
+ NULL
+ };
+ return test_run(test_functions);
+}