1228753Smm/*- 2228753Smm * Copyright (c) 2009 Michihiro NAKAJIMA 3228753Smm * Copyright (c) 2003-2008 Tim Kientzle 4228753Smm * All rights reserved. 5228753Smm * 6228753Smm * Redistribution and use in source and binary forms, with or without 7228753Smm * modification, are permitted provided that the following conditions 8228753Smm * are met: 9228753Smm * 1. Redistributions of source code must retain the above copyright 10228753Smm * notice, this list of conditions and the following disclaimer. 11228753Smm * 2. Redistributions in binary form must reproduce the above copyright 12228753Smm * notice, this list of conditions and the following disclaimer in the 13228753Smm * documentation and/or other materials provided with the distribution. 14228753Smm * 15228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25228753Smm */ 26228753Smm#include "test.h" 27228763Smm__FBSDID("$FreeBSD: releng/11.0/contrib/libarchive/libarchive/test/test_compat_lzma.c 248616 2013-03-22 13:36:03Z mm $"); 28228753Smm 29228753Smm/* 30228753SmmExecute the following to rebuild the data for this program: 31228753Smm tail -n +33 test_compat_lzma.c | /bin/sh 32228753Smm 33228753Smm# Use lzma command of XZ Utils. 34228753Smmname=test_compat_lzma_1 35228753Smmzcmd=lzma 36228753Smmzsuffix=lzma 37228753Smmztar_suffix=tlz 38228753Smmdir="$name`date +%Y%m%d%H%M%S`.$USER" 39228753Smmmktarfile() 40228753Smm{ 41228753Smmmkdir $dir 42228753Smmecho "f1" > $dir/f1 43228753Smmecho "f2" > $dir/f2 44228753Smmecho "f3" > $dir/f3 45228753Smmmkdir $dir/d1 46228753Smmecho "f1" > $dir/d1/f1 47228753Smmecho "f2" > $dir/d1/f2 48228753Smmecho "f3" > $dir/d1/f3 49228753Smm(cd $dir; tar cf ../$name.tar f1 f2 f3 d1/f1 d1/f2 d1/f3) 50228753Smmrm -r $dir 51228753Smm} 52228753Smmmktarfile 53228753Smm$zcmd $name.tar 54228753Smmmv $name.tar.$zsuffix $name.$ztar_suffix 55228753Smmecho "This is unrelated junk data at the end of the file" >> $name.$ztar_suffix 56228753Smmuuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu 57228753Smmrm -f $name.$ztar_suffix 58228753Smm# 59228753Smm# Use option -e 60228753Smm# 61228753Smmname=test_compat_lzma_2 62228753Smmdir="$name`date +%Y%m%d%H%M%S`.$USER" 63228753Smmmktarfile 64228753Smm$zcmd -e $name.tar 65228753Smmmv $name.tar.$zsuffix $name.$ztar_suffix 66228753Smmuuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu 67228753Smmrm -f $name.$ztar_suffix 68228753Smm# 69228753Smm# Use lzma command of LZMA SDK with option -d12. 70228753Smm# 71228753Smmname=test_compat_lzma_3 72228753Smmzcmd=lzmasdk # Change this path to use lzma of LZMA SDK. 73228753Smmdir="$name`date +%Y%m%d%H%M%S`.$USER" 74228753Smmmktarfile 75228753Smm$zcmd e -d12 $name.tar $name.$ztar_suffix 76228753Smmrm -f $name.tar 77228753Smmuuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu 78228753Smmrm -f $name.$ztar_suffix 79228753Smm 80228753Smmexit 0 81228753Smm*/ 82228753Smm 83228753Smm/* 84228753Smm * Verify our ability to read sample files compatibly with unlzma. 85228753Smm * 86228753Smm * In particular: 87228753Smm * * unlzma will read multiple lzma streams, concatenating the output 88228753Smm * * unlzma will read lzma streams which is made by lzma with option -e, 89228753Smm * concatenating the output 90228753Smm * 91228753Smm * Verify our ability to read sample files compatibly with lzma of 92228753Smm * LZMA SDK. 93228753Smm * * lzma will read lzma streams which is made by lzma with option -d12, 94228753Smm * concatenating the output 95228753Smm */ 96228753Smm 97228753Smm/* 98228753Smm * All of the sample files have the same contents; they're just 99228753Smm * compressed in different ways. 100228753Smm */ 101228753Smmstatic void 102228753Smmcompat_lzma(const char *name) 103228753Smm{ 104228753Smm const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; 105228753Smm struct archive_entry *ae; 106228753Smm struct archive *a; 107228753Smm int i, r; 108228753Smm 109228753Smm assert((a = archive_read_new()) != NULL); 110232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 111232153Smm r = archive_read_support_filter_lzma(a); 112228753Smm if (r == ARCHIVE_WARN) { 113228753Smm skipping("lzma reading not fully supported on this platform"); 114232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 115228753Smm return; 116228753Smm } 117228753Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 118228753Smm extract_reference_file(name); 119228753Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); 120228753Smm 121228753Smm /* Read entries, match up names with list above. */ 122228753Smm for (i = 0; i < 6; ++i) { 123228753Smm failure("Could not read file %d (%s) from %s", i, n[i], name); 124228753Smm assertEqualIntA(a, ARCHIVE_OK, 125228753Smm archive_read_next_header(a, &ae)); 126228753Smm assertEqualString(n[i], archive_entry_pathname(ae)); 127228753Smm } 128228753Smm 129228753Smm /* Verify the end-of-archive. */ 130228753Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 131228753Smm 132228753Smm /* Verify that the format detection worked. */ 133248616Smm assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_LZMA); 134248616Smm assertEqualString(archive_filter_name(a, 0), "lzma"); 135228753Smm assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); 136228753Smm 137228753Smm assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 138232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 139228753Smm} 140228753Smm 141228753Smm 142228753SmmDEFINE_TEST(test_compat_lzma) 143228753Smm{ 144228753Smm /* This sample has been added junk datas to its tail. */ 145228753Smm compat_lzma("test_compat_lzma_1.tlz"); 146228753Smm /* This sample has been made by lzma with option -e, 147228753Smm * the first byte of which is 0x5e. 148228753Smm * Not supported in libarchive 2.7.* and earlier */ 149228753Smm compat_lzma("test_compat_lzma_2.tlz"); 150228753Smm /* This sample has been made by lzma of LZMA SDK with 151228753Smm * option -d12, second byte and third byte of which is 152228753Smm * not zero. 153228753Smm * Not supported in libarchive 2.7.* and earlier */ 154228753Smm compat_lzma("test_compat_lzma_3.tlz"); 155228753Smm} 156