]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
test argument handling in archive_read_open2
authorRoman Neuhauser <neuhauser@sigpipe.cz>
Wed, 30 Mar 2011 21:42:16 +0000 (17:42 -0400)
committerRoman Neuhauser <neuhauser@sigpipe.cz>
Wed, 30 Mar 2011 21:42:16 +0000 (17:42 -0400)
results in aborts when archive_read_callback == NULL

SVN-Revision: 3130

Makefile.am
libarchive/test/CMakeLists.txt
libarchive/test/test_archive_read_open2.c [new file with mode: 0644]

index 8dae99c7ec976ed1d37836c66dfb4b3283a32eb5..71fae436ef59743a4620b85acc8fbf403a4574b9 100644 (file)
@@ -248,6 +248,7 @@ libarchive_test_SOURCES=                                    \
        libarchive/test/test_archive_read_close_twice_open_filename.c   \
        libarchive/test/test_archive_read_next_header_empty.c   \
        libarchive/test/test_archive_read_next_header_raw.c     \
+       libarchive/test/test_archive_read_open2.c               \
        libarchive/test/test_archive_read_set_filter_option.c   \
        libarchive/test/test_archive_read_set_format_option.c   \
        libarchive/test/test_archive_read_set_option.c          \
index 75b27c609f7646bc861e2021fe683aa214224f62..98d905a90308a6c84b1070f461eff800569fa70e 100644 (file)
@@ -19,6 +19,7 @@ IF(ENABLE_TEST)
     test_archive_read_close_twice_open_filename.c
     test_archive_read_next_header_empty.c
     test_archive_read_next_header_raw.c
+    test_archive_read_open2.c
     test_archive_read_set_filter_option.c
     test_archive_read_set_format_option.c
     test_archive_read_set_option.c
diff --git a/libarchive/test/test_archive_read_open2.c b/libarchive/test/test_archive_read_open2.c
new file mode 100644 (file)
index 0000000..c62f6f7
--- /dev/null
@@ -0,0 +1,99 @@
+/*-
+ * Copyright (c) 2011 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+static int
+open_cb(struct archive *a, void *client)
+{
+       return 0;
+}
+static ssize_t
+read_cb(struct archive *a, void *client, const void **buff)
+{
+       return (ssize_t)0;
+}
+static off_t
+skip_cb(struct archive *a, void *client, off_t request)
+{
+       return (off_t)0;
+}
+static int
+close_cb(struct archive *a, void *client)
+{
+       return 0;
+}
+
+static void
+test(int formatted, archive_open_callback *o, archive_read_callback *r,
+    archive_skip_callback *s, archive_close_callback *c,
+    int rv, const char *msg)
+{
+       struct archive* a = archive_read_new();
+       if (formatted)
+           assertEqualInt(ARCHIVE_OK,
+               archive_read_support_format_empty(a));
+       assertEqualInt(rv,
+           archive_read_open2(a, NULL, o, r, s, c));
+       assertEqualString(msg, archive_error_string(a));
+       archive_read_free(a);
+}
+
+DEFINE_TEST(test_archive_read_open2)
+{
+       const char *no_reader =
+           "No reader function provided to archive_read_open";
+       const char *no_formats = "No formats registered";
+
+       test(1, NULL, NULL, NULL, NULL,
+           ARCHIVE_FATAL, no_reader);
+       test(1, open_cb, NULL, NULL, NULL,
+           ARCHIVE_FATAL, no_reader);
+       test(1, open_cb, read_cb, NULL, NULL,
+           ARCHIVE_OK, NULL);
+       test(1, open_cb, read_cb, skip_cb, NULL,
+           ARCHIVE_OK, NULL);
+       test(1, open_cb, read_cb, skip_cb, close_cb,
+           ARCHIVE_OK, NULL);
+       test(1, NULL, read_cb, skip_cb, close_cb,
+           ARCHIVE_OK, NULL);
+       test(1, open_cb, read_cb, skip_cb, NULL,
+           ARCHIVE_OK, NULL);
+       test(1, NULL, read_cb, skip_cb, NULL,
+           ARCHIVE_OK, NULL);
+       test(1, NULL, read_cb, NULL, NULL,
+           ARCHIVE_OK, NULL);
+
+       test(0, NULL, NULL, NULL, NULL,
+           ARCHIVE_FATAL, no_reader);
+       test(0, open_cb, NULL, NULL, NULL,
+           ARCHIVE_FATAL, no_reader);
+       test(0, open_cb, read_cb, NULL, NULL,
+           ARCHIVE_FATAL, no_formats);
+       test(0, open_cb, read_cb, skip_cb, NULL,
+           ARCHIVE_FATAL, no_formats);
+       test(0, open_cb, read_cb, skip_cb, close_cb,
+           ARCHIVE_FATAL, no_formats);
+}