]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: Added initial fs-metawrap unit test.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 21 Apr 2016 14:54:54 +0000 (17:54 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 22 Apr 2016 22:41:53 +0000 (01:41 +0300)
src/lib-fs/Makefile.am
src/lib-fs/test-fs-metawrap.c [new file with mode: 0644]

index 5df3c5dd458d8cbc439dca9aac199df23c9ec3c2..9a445cb949f94c7502097ed4e5fd45d766e290ed 100644 (file)
@@ -36,3 +36,28 @@ headers = \
 
 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
diff --git a/src/lib-fs/test-fs-metawrap.c b/src/lib-fs/test-fs-metawrap.c
new file mode 100644 (file)
index 0000000..b09c92d
--- /dev/null
@@ -0,0 +1,56 @@
+/* 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);
+}