summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/test/test_read_format_ar.c
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2007-04-03 05:34:36 +0000
committerkientzle <kientzle@FreeBSD.org>2007-04-03 05:34:36 +0000
commitb356476feba52a0a45c8e89ebac5d6724a4e6d78 (patch)
treeee7ab4b960264dddb2ad2c445c0e861e145e0ca2 /lib/libarchive/test/test_read_format_ar.c
parentba7e53058343ca70fa1013a3af10139eac74e8c4 (diff)
downloadFreeBSD-src-b356476feba52a0a45c8e89ebac5d6724a4e6d78.zip
FreeBSD-src-b356476feba52a0a45c8e89ebac5d6724a4e6d78.tar.gz
'ar' format support for libarchive, contributed by Kai Wang.
Diffstat (limited to 'lib/libarchive/test/test_read_format_ar.c')
-rw-r--r--lib/libarchive/test/test_read_format_ar.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/lib/libarchive/test/test_read_format_ar.c b/lib/libarchive/test/test_read_format_ar.c
new file mode 100644
index 0000000..d3e4f0e
--- /dev/null
+++ b/lib/libarchive/test/test_read_format_ar.c
@@ -0,0 +1,104 @@
+/*-
+ * Copyright (c) 2007 Kai Wang
+ * Copyright (c) 2007 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
+ * in this position and unchanged.
+ * 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$");
+
+/*
+ * This "archive" is created by "GNU ar". Here we try to verify
+ * our GNU format handling functionality.
+ */
+static unsigned char archive[] = {
+'!','<','a','r','c','h','>',10,'/','/',' ',' ',' ',' ',' ',' ',' ',
+' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
+' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
+' ',' ',' ',' ',' ','4','0',' ',' ',' ',' ',' ',' ',' ',' ','`',10,
+'y','y','y','t','t','t','s','s','s','a','a','a','f','f','f','.','o',
+'/',10,'h','h','h','h','j','j','j','j','k','k','k','k','l','l','l',
+'l','.','o','/',10,10,'/','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
+' ',' ',' ',' ','1','1','7','5','4','6','5','6','5','2',' ',' ','1',
+'0','0','1',' ',' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4',
+' ',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ','`',10,'5','5','6',
+'6','7','7','8','8','g','g','h','h','.','o','/',' ',' ',' ',' ',' ',
+' ',' ',' ',' ','1','1','7','5','4','6','5','6','6','8',' ',' ','1',
+'0','0','1',' ',' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4',
+' ',' ','4',' ',' ',' ',' ',' ',' ',' ',' ',' ','`',10,'3','3','3',
+'3','/','1','9',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
+'1','1','7','5','4','6','5','7','1','3',' ',' ','1','0','0','1',' ',
+' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4',' ',' ','9',' ',
+' ',' ',' ',' ',' ',' ',' ',' ','`',10,'9','8','7','6','5','4','3',
+'2','1',10};
+
+char buff[64];
+
+DEFINE_TEST(test_read_format_ar)
+{
+ struct archive_entry *ae;
+ struct archive *a;
+ assert((a = archive_read_new()) != NULL);
+ assertA(0 == archive_read_support_compression_all(a));
+ assertA(0 == archive_read_support_format_all(a));
+ assertA(0 == archive_read_open_memory(a, archive, sizeof(archive)));
+
+ /* First we meet the string table */
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE);
+ assertA(archive_format(a) == ARCHIVE_FORMAT_AR);
+ assert(0 == strcmp("//", archive_entry_pathname(ae)));
+ assert(40 == archive_entry_size(ae));
+ assertA(40 == archive_read_data(a, buff, 45));
+
+ /* First Entry */
+ assertA(0 == archive_read_next_header(a, &ae));
+ assert(0 == strcmp("yyytttsssaaafff.o", archive_entry_pathname(ae)));
+ assert(8 == archive_entry_size(ae));
+ assertA(8 == archive_read_data(a, buff, 10));
+ assert(0 == memcmp(buff, "55667788", 8));
+
+ /* Second Entry */
+ assertA(0 == archive_read_next_header(a, &ae));
+ assert(0 == strcmp("gghh.o", archive_entry_pathname(ae)));
+ assert(4 == archive_entry_size(ae));
+ assertA(4 == archive_read_data(a, buff, 10));
+ assert(0 == memcmp(buff, "3333", 4));
+
+ /* Third Entry */
+ assertA(0 == archive_read_next_header(a, &ae));
+ assert(0 == strcmp("hhhhjjjjkkkkllll.o", archive_entry_pathname(ae)));
+ assert(9 == archive_entry_size(ae));
+ assertA(9 == archive_read_data(a, buff, 9));
+ assert(0 == memcmp(buff, "987654321", 9));
+
+ /* Test EOF */
+ assertA(1 == archive_read_next_header(a, &ae));
+ assert(0 == archive_read_close(a));
+#if ARCHIVE_API_VERSION > 1
+ assert(0 == archive_read_finish(a));
+#else
+ archive_read_finish(a);
+#endif
+}
OpenPOWER on IntegriCloud