1309587Smm/*-
2309587Smm * Copyright (c) 2016 Martin Matuska
3309587Smm * All rights reserved.
4309587Smm *
5309587Smm * Redistribution and use in source and binary forms, with or without
6309587Smm * modification, are permitted provided that the following conditions
7309587Smm * are met:
8309587Smm * 1. Redistributions of source code must retain the above copyright
9309587Smm *    notice, this list of conditions and the following disclaimer.
10309587Smm * 2. Redistributions in binary form must reproduce the above copyright
11309587Smm *    notice, this list of conditions and the following disclaimer in the
12309587Smm *    documentation and/or other materials provided with the distribution.
13309587Smm *
14309587Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15309587Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16309587Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17309587Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18309587Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19309587Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20309587Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21309587Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22309587Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23309587Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24309587Smm */
25309587Smm#include "test.h"
26309587Smm__FBSDID("$FreeBSD");
27309587Smm
28309587Smm/*
29309587Smm * Verify our ability to read sample files created by plexus-archiver version
30309587Smm * 2.6.2 and lower (project switched to Apache Commons Compress with 2.6.3).
31309587Smm *
32309587Smm * These files may have tar entries with uid and gid header fields filled with
33309587Smm * spaces without any octal digit.
34309587Smm */
35309587Smm
36309587SmmDEFINE_TEST(test_compat_plexus_archiver_tar)
37309587Smm{
38309587Smm	char name[] = "test_compat_plexus_archiver_tar.tar";
39309587Smm	struct archive_entry *ae;
40309587Smm	struct archive *a;
41309587Smm	int r;
42309587Smm
43309587Smm	assert((a = archive_read_new()) != NULL);
44309587Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
45309587Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
46309587Smm	extract_reference_file(name);
47309587Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name,
48309587Smm	    10240));
49309587Smm
50309587Smm	/* Read first entry. */
51309587Smm	assertEqualIntA(a, ARCHIVE_OK, r = archive_read_next_header(a, &ae));
52309587Smm	if (r != ARCHIVE_OK) {
53309587Smm		archive_read_free(a);
54309587Smm		return;
55309587Smm	}
56309587Smm	assertEqualString("commons-logging-1.2/NOTICE.txt",
57309587Smm	    archive_entry_pathname(ae));
58309587Smm	assertEqualInt(1404583896, archive_entry_mtime(ae));
59309587Smm	assertEqualInt(0100664, archive_entry_mode(ae));
60309587Smm	assertEqualInt(0, archive_entry_uid(ae));
61309587Smm	assertEqualInt(0, archive_entry_gid(ae));
62309587Smm
63309587Smm	/* Verify that the format detection worked. */
64309587Smm	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_NONE);
65309587Smm	assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
66309587Smm
67309587Smm	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
68309587Smm	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
69309587Smm}
70