1248590Smm/*- 2248590Smm * Copyright (c) 2003-2008 Tim Kientzle 3248590Smm * Copyright (c) 2012 Michihiro NAKAJIMA 4248590Smm * All rights reserved. 5248590Smm * 6248590Smm * Redistribution and use in source and binary forms, with or without 7248590Smm * modification, are permitted provided that the following conditions 8248590Smm * are met: 9248590Smm * 1. Redistributions of source code must retain the above copyright 10248590Smm * notice, this list of conditions and the following disclaimer. 11248590Smm * 2. Redistributions in binary form must reproduce the above copyright 12248590Smm * notice, this list of conditions and the following disclaimer in the 13248590Smm * documentation and/or other materials provided with the distribution. 14248590Smm * 15248590Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16248590Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17248590Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18248590Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19248590Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20248590Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21248590Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22248590Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23248590Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24248590Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25248590Smm */ 26248590Smm#include "test.h" 27248590Smm 28248590SmmDEFINE_TEST(test_read_filter_lzop) 29248590Smm{ 30248590Smm const char *reference = "test_read_filter_lzop.tar.lzo"; 31248590Smm /* lrzip tracks directories as files, ensure that we list everything */ 32248590Smm const char *n[] = { 33248590Smm "d1/", "d1/f2", "d1/f3", "d1/f1", "f1", "f2", "f3", NULL }; 34248590Smm struct archive_entry *ae; 35248590Smm struct archive *a; 36248590Smm int i, r; 37248590Smm 38248590Smm extract_reference_file(reference); 39248590Smm assert((a = archive_read_new()) != NULL); 40248590Smm r = archive_read_support_filter_lzop(a); 41248590Smm if (r != ARCHIVE_OK) { 42248590Smm if (r == ARCHIVE_WARN && !canLzop()) { 43248590Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 44248590Smm skipping("lzop compression is not supported " 45248590Smm "on this platform"); 46248590Smm } else 47248590Smm assertEqualIntA(a, ARCHIVE_OK, r); 48248590Smm return; 49248590Smm } 50248590Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 51248590Smm assertEqualIntA(a, ARCHIVE_OK, 52248590Smm archive_read_open_filename(a, reference, 10240)); 53248590Smm 54248590Smm /* Read entries, match up names with list above. */ 55248590Smm for (i = 0; n[i] != NULL; ++i) { 56248590Smm failure("Could not read file %d (%s) from %s", 57248590Smm i, n[i], reference); 58248590Smm assertEqualIntA(a, ARCHIVE_OK, 59248590Smm archive_read_next_header(a, &ae)); 60248590Smm assertEqualString(n[i], archive_entry_pathname(ae)); 61248590Smm } 62248590Smm 63248590Smm /* Verify the end-of-archive. */ 64248590Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 65248590Smm 66248590Smm /* Verify that the format detection worked. */ 67248590Smm assertEqualInt(archive_filter_count(a), 2); 68248590Smm assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_LZOP); 69248590Smm assertEqualString(archive_filter_name(a, 0), "lzop"); 70248590Smm assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); 71248590Smm 72248590Smm assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 73248590Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 74248590Smm} 75