]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - lib/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / lib / libarchive / test / test_read_format_cpio_svr4_gzip_rpm.c
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 __FBSDID("$FreeBSD$");
28
29 /*
30 Execute the following command to rebuild the data for this program:
31    tail -n +32 test_read_format_cpio_svr4_gzip_rpm.c | /bin/sh
32
33 F=test_read_format_cpio_svr4_gzip_rpm.rpm
34 NAME=rpmsample
35 TMPRPM=/tmp/rpm
36 rm -rf ${TMPRPM}
37 mkdir -p ${TMPRPM}/BUILD
38 mkdir -p ${TMPRPM}/RPMS
39 mkdir -p ${TMPRPM}/SOURCES
40 mkdir -p ${TMPRPM}/SPECS
41 mkdir -p ${TMPRPM}/SRPMS
42 echo "hello" > ${TMPRPM}/BUILD/file1
43 echo "hello" > ${TMPRPM}/BUILD/file2
44 echo "hello" > ${TMPRPM}/BUILD/file3
45 cat > ${TMPRPM}/SPECS/${NAME}.spec <<END
46 ##
47 %define _topdir ${TMPRPM}
48 %define _binary_payload w9.gzdio
49
50 Summary: Sample data of RPM filter of libarchive
51 Name: ${NAME}
52 Version: 1.0.0
53 Release: 1
54 License: BSD
55 URL: http://code.google.com/p/libarchive
56 BuildArch: noarch
57 BuildRoot: %{_tmppath}/%{name}-%{version}-root
58
59 %install
60 rm -rf \$RPM_BUILD_ROOT
61
62 mkdir -p \$RPM_BUILD_ROOT%{_sysconfdir}
63 install -m 644 file1 \$RPM_BUILD_ROOT%{_sysconfdir}/file1
64 install -m 644 file2 \$RPM_BUILD_ROOT%{_sysconfdir}/file2
65 install -m 644 file3 \$RPM_BUILD_ROOT%{_sysconfdir}/file3
66 TZ=utc touch -afm -t 197001020000.01 \$RPM_BUILD_ROOT%{_sysconfdir}/file1
67 TZ=utc touch -afm -t 197001020000.01 \$RPM_BUILD_ROOT%{_sysconfdir}/file2
68 TZ=utc touch -afm -t 197001020000.01 \$RPM_BUILD_ROOT%{_sysconfdir}/file3
69
70 %files
71 %{_sysconfdir}/file1
72 %{_sysconfdir}/file2
73 %{_sysconfdir}/file3
74
75 %description
76 Sample data.
77 END
78 #
79 rpmbuild -bb ${TMPRPM}/SPECS/${NAME}.spec
80 uuencode ${F} < ${TMPRPM}/RPMS/noarch/${NAME}-1.0.0-1.noarch.rpm > ${F}.uu
81
82 rm -rf ${TMPRPM}
83 exit 1
84 */
85
86 DEFINE_TEST(test_read_format_cpio_svr4_gzip_rpm)
87 {
88         struct archive_entry *ae;
89         struct archive *a;
90         const char *name = "test_read_format_cpio_svr4_gzip_rpm.rpm";
91         int r;
92
93         assert((a = archive_read_new()) != NULL);
94         r = archive_read_support_compression_gzip(a);
95         if (r == ARCHIVE_WARN) {
96                 skipping("gzip reading not fully supported on this platform");
97                 assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
98                 return;
99         }
100         assertEqualIntA(a, ARCHIVE_OK, r);
101         assertEqualIntA(a, ARCHIVE_OK,
102             archive_read_support_compression_rpm(a));
103         assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
104         extract_reference_file(name);
105         assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2));
106
107         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
108         assertEqualString("./etc/file1", archive_entry_pathname(ae));
109         assertEqualInt(86401, archive_entry_mtime(ae));
110         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
111         assertEqualString("./etc/file2", archive_entry_pathname(ae));
112         assertEqualInt(86401, archive_entry_mtime(ae));
113         assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
114         assertEqualString("./etc/file3", archive_entry_pathname(ae));
115         assertEqualInt(86401, archive_entry_mtime(ae));
116
117         /* Verify the end-of-archive. */
118         assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
119   
120         /* Verify that the format detection worked. */
121         assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_GZIP);
122         assertEqualString(archive_compression_name(a), "gzip");
123         assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_NOCRC);
124  
125         assertEqualInt(ARCHIVE_OK, archive_read_close(a));
126         assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
127 }
128