1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * Copyright (c) 2009 Michihiro NAKAJIMA
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26#include "test.h"
27
28/*
29Execute the following command to rebuild the data for this program:
30   tail -n +32 test_read_format_cpio_svr4_bzip2_rpm.c | /bin/sh
31
32F=test_read_format_cpio_svr4_bzip2_rpm.rpm
33NAME=rpmsample
34TMPRPM=/tmp/rpm
35rm -rf ${TMPRPM}
36mkdir -p ${TMPRPM}/BUILD
37mkdir -p ${TMPRPM}/RPMS
38mkdir -p ${TMPRPM}/SOURCES
39mkdir -p ${TMPRPM}/SPECS
40mkdir -p ${TMPRPM}/SRPMS
41echo "hello" > ${TMPRPM}/BUILD/file1
42echo "hello" > ${TMPRPM}/BUILD/file2
43echo "hello" > ${TMPRPM}/BUILD/file3
44cat > ${TMPRPM}/SPECS/${NAME}.spec <<END
45##
46%define _topdir ${TMPRPM}
47%define _binary_payload w9.bzdio
48
49Summary: Sample data of RPM filter of libarchive
50Name: ${NAME}
51Version: 1.0.0
52Release: 1
53License: BSD
54URL: http://libarchive.github.com/
55BuildArch: noarch
56BuildRoot: %{_tmppath}/%{name}-%{version}-root
57
58%install
59rm -rf \$RPM_BUILD_ROOT
60
61mkdir -p \$RPM_BUILD_ROOT%{_sysconfdir}
62install -m 644 file1 \$RPM_BUILD_ROOT%{_sysconfdir}/file1
63install -m 644 file2 \$RPM_BUILD_ROOT%{_sysconfdir}/file2
64install -m 644 file3 \$RPM_BUILD_ROOT%{_sysconfdir}/file3
65TZ=utc touch -afm -t 197001020000.01 \$RPM_BUILD_ROOT%{_sysconfdir}/file1
66TZ=utc touch -afm -t 197001020000.01 \$RPM_BUILD_ROOT%{_sysconfdir}/file2
67TZ=utc touch -afm -t 197001020000.01 \$RPM_BUILD_ROOT%{_sysconfdir}/file3
68
69%files
70%{_sysconfdir}/file1
71%{_sysconfdir}/file2
72%{_sysconfdir}/file3
73
74%description
75Sample data.
76END
77#
78rpmbuild -bb ${TMPRPM}/SPECS/${NAME}.spec
79uuencode ${F} < ${TMPRPM}/RPMS/noarch/${NAME}-1.0.0-1.noarch.rpm > ${F}.uu
80
81rm -rf ${TMPRPM}
82exit 1
83*/
84
85DEFINE_TEST(test_read_format_cpio_svr4_bzip2_rpm)
86{
87	struct archive_entry *ae;
88	struct archive *a;
89	const char *name = "test_read_format_cpio_svr4_bzip2_rpm.rpm";
90	int r;
91
92	assert((a = archive_read_new()) != NULL);
93        r = archive_read_support_filter_bzip2(a);
94	if (r == ARCHIVE_WARN) {
95		skipping("bzip2 reading not fully supported on this platform");
96		assertEqualInt(ARCHIVE_OK, archive_read_free(a));
97		return;
98        }
99	assertEqualIntA(a, ARCHIVE_OK, r);
100	assertEqualIntA(a, ARCHIVE_OK,
101	    archive_read_support_filter_rpm(a));
102	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
103	extract_reference_file(name);
104	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2));
105
106	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
107	assertEqualString("./etc/file1", archive_entry_pathname(ae));
108	assertEqualInt(86401, archive_entry_mtime(ae));
109	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
110	assertEqualString("./etc/file2", archive_entry_pathname(ae));
111	assertEqualInt(86401, archive_entry_mtime(ae));
112	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
113	assertEqualString("./etc/file3", archive_entry_pathname(ae));
114	assertEqualInt(86401, archive_entry_mtime(ae));
115	assertEqualInt(archive_entry_is_encrypted(ae), 0);
116	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
117
118	/* Verify the end-of-archive. */
119	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
120
121	/* Verify that the format detection worked. */
122	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_BZIP2);
123	assertEqualString(archive_filter_name(a, 0), "bzip2");
124	assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_NOCRC);
125
126	assertEqualInt(ARCHIVE_OK, archive_read_close(a));
127	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
128}
129
130