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