1caf54c4fSMartin Matuska /*- 2caf54c4fSMartin Matuska * Copyright (c) 2003-2009 Tim Kientzle 3caf54c4fSMartin Matuska * All rights reserved. 4caf54c4fSMartin Matuska * 5caf54c4fSMartin Matuska * Redistribution and use in source and binary forms, with or without 6caf54c4fSMartin Matuska * modification, are permitted provided that the following conditions 7caf54c4fSMartin Matuska * are met: 8caf54c4fSMartin Matuska * 1. Redistributions of source code must retain the above copyright 9caf54c4fSMartin Matuska * notice, this list of conditions and the following disclaimer. 10caf54c4fSMartin Matuska * 2. Redistributions in binary form must reproduce the above copyright 11caf54c4fSMartin Matuska * notice, this list of conditions and the following disclaimer in the 12caf54c4fSMartin Matuska * documentation and/or other materials provided with the distribution. 13caf54c4fSMartin Matuska * 14caf54c4fSMartin Matuska * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15caf54c4fSMartin Matuska * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16caf54c4fSMartin Matuska * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17caf54c4fSMartin Matuska * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18caf54c4fSMartin Matuska * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19caf54c4fSMartin Matuska * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20caf54c4fSMartin Matuska * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21caf54c4fSMartin Matuska * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22caf54c4fSMartin Matuska * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23caf54c4fSMartin Matuska * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24caf54c4fSMartin Matuska */ 25caf54c4fSMartin Matuska #include "test.h" 26caf54c4fSMartin Matuska 27caf54c4fSMartin Matuska /* 28caf54c4fSMartin Matuska * Verify our ability to read various sample files. 29caf54c4fSMartin Matuska * It should be easy to add any new sample files sent in by users 30caf54c4fSMartin Matuska * to this collection of tests. 31caf54c4fSMartin Matuska */ 32caf54c4fSMartin Matuska 33caf54c4fSMartin Matuska /* Copy this function for each test file and adjust it accordingly. */ 34caf54c4fSMartin Matuska 35caf54c4fSMartin Matuska /* 36caf54c4fSMartin Matuska * test_compat_cpio_1.cpio checks heuristics for avoiding false 37caf54c4fSMartin Matuska * hardlinks. foo1 and foo2 are files that have nlinks=1 and so 38caf54c4fSMartin Matuska * should not be marked as hardlinks even though they have identical 39caf54c4fSMartin Matuska * ino values. bar1 and bar2 have nlinks=2 so should be marked 40caf54c4fSMartin Matuska * as hardlinks. 41caf54c4fSMartin Matuska */ 42caf54c4fSMartin Matuska static void 43caf54c4fSMartin Matuska test_compat_cpio_1(void) 44caf54c4fSMartin Matuska { 45caf54c4fSMartin Matuska char name[] = "test_compat_cpio_1.cpio"; 46caf54c4fSMartin Matuska struct archive_entry *ae; 47caf54c4fSMartin Matuska struct archive *a; 48caf54c4fSMartin Matuska 49caf54c4fSMartin Matuska assert((a = archive_read_new()) != NULL); 506c95142eSMartin Matuska assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 51caf54c4fSMartin Matuska assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 52caf54c4fSMartin Matuska extract_reference_file(name); 53caf54c4fSMartin Matuska assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 17)); 54caf54c4fSMartin Matuska 55caf54c4fSMartin Matuska /* Read first entry. */ 56caf54c4fSMartin Matuska assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 57caf54c4fSMartin Matuska assertEqualString("foo1", archive_entry_pathname(ae)); 58caf54c4fSMartin Matuska assertEqualString(NULL, archive_entry_hardlink(ae)); 59caf54c4fSMartin Matuska assertEqualInt(1260250228, archive_entry_mtime(ae)); 60caf54c4fSMartin Matuska assertEqualInt(1000, archive_entry_uid(ae)); 61caf54c4fSMartin Matuska assertEqualInt(1000, archive_entry_gid(ae)); 62caf54c4fSMartin Matuska assertEqualInt(0100644, archive_entry_mode(ae)); 63caf54c4fSMartin Matuska 64caf54c4fSMartin Matuska /* Read second entry. */ 65caf54c4fSMartin Matuska assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 66caf54c4fSMartin Matuska assertEqualString("foo2", archive_entry_pathname(ae)); 67caf54c4fSMartin Matuska assertEqualString(NULL, archive_entry_hardlink(ae)); 68caf54c4fSMartin Matuska assertEqualInt(1260250228, archive_entry_mtime(ae)); 69caf54c4fSMartin Matuska assertEqualInt(1000, archive_entry_uid(ae)); 70caf54c4fSMartin Matuska assertEqualInt(1000, archive_entry_gid(ae)); 71caf54c4fSMartin Matuska assertEqualInt(0100644, archive_entry_mode(ae)); 72caf54c4fSMartin Matuska 73caf54c4fSMartin Matuska /* Read third entry. */ 74caf54c4fSMartin Matuska assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 75caf54c4fSMartin Matuska assertEqualString("bar1", archive_entry_pathname(ae)); 76caf54c4fSMartin Matuska assertEqualString(NULL, archive_entry_hardlink(ae)); 77caf54c4fSMartin Matuska assertEqualInt(1260250228, archive_entry_mtime(ae)); 78caf54c4fSMartin Matuska assertEqualInt(1000, archive_entry_uid(ae)); 79caf54c4fSMartin Matuska assertEqualInt(1000, archive_entry_gid(ae)); 80caf54c4fSMartin Matuska assertEqualInt(0100644, archive_entry_mode(ae)); 81caf54c4fSMartin Matuska 82caf54c4fSMartin Matuska /* Read fourth entry. */ 83caf54c4fSMartin Matuska assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 84caf54c4fSMartin Matuska assertEqualString("bar2", archive_entry_pathname(ae)); 85caf54c4fSMartin Matuska assertEqualString("bar1", archive_entry_hardlink(ae)); 86caf54c4fSMartin Matuska assertEqualInt(1260250228, archive_entry_mtime(ae)); 87caf54c4fSMartin Matuska assertEqualInt(1000, archive_entry_uid(ae)); 88caf54c4fSMartin Matuska assertEqualInt(1000, archive_entry_gid(ae)); 89caf54c4fSMartin Matuska assertEqualInt(0100644, archive_entry_mode(ae)); 90caf54c4fSMartin Matuska 91caf54c4fSMartin Matuska /* Verify that the format detection worked. */ 92*acc60b03SMartin Matuska assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_NONE); 93caf54c4fSMartin Matuska assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); 94caf54c4fSMartin Matuska 95caf54c4fSMartin Matuska assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 966c95142eSMartin Matuska assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 97caf54c4fSMartin Matuska } 98caf54c4fSMartin Matuska 99caf54c4fSMartin Matuska 100caf54c4fSMartin Matuska DEFINE_TEST(test_compat_cpio) 101caf54c4fSMartin Matuska { 102caf54c4fSMartin Matuska test_compat_cpio_1(); 103caf54c4fSMartin Matuska } 104caf54c4fSMartin Matuska 105caf54c4fSMartin Matuska 106