1228753Smm/*- 2228753Smm * Copyright (c) 2007 Kai Wang 3228753Smm * Copyright (c) 2007 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 * in this position and unchanged. 12228753Smm * 2. Redistributions in binary form must reproduce the above copyright 13228753Smm * notice, this list of conditions and the following disclaimer in the 14228753Smm * documentation and/or other materials provided with the distribution. 15228753Smm * 16228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 17228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 20228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26228753Smm */ 27228753Smm 28228753Smm#include "test.h" 29228763Smm__FBSDID("$FreeBSD$"); 30228753Smm 31228753SmmDEFINE_TEST(test_read_format_raw) 32228753Smm{ 33228753Smm char buff[512]; 34228753Smm struct archive_entry *ae; 35228753Smm struct archive *a; 36228753Smm const char *reffile1 = "test_read_format_raw.data"; 37228753Smm const char *reffile2 = "test_read_format_raw.data.Z"; 38228753Smm 39228753Smm /* First, try pulling data out of an uninterpretable file. */ 40228753Smm extract_reference_file(reffile1); 41228753Smm assert((a = archive_read_new()) != NULL); 42232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 43228753Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 44228753Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_raw(a)); 45228753Smm assertEqualIntA(a, ARCHIVE_OK, 46228753Smm archive_read_open_filename(a, reffile1, 512)); 47228753Smm 48228753Smm /* First (and only!) Entry */ 49232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 50228753Smm assertEqualString("data", archive_entry_pathname(ae)); 51228753Smm /* Most fields should be unset (unknown) */ 52228753Smm assert(!archive_entry_size_is_set(ae)); 53228753Smm assert(!archive_entry_atime_is_set(ae)); 54228753Smm assert(!archive_entry_ctime_is_set(ae)); 55228753Smm assert(!archive_entry_mtime_is_set(ae)); 56228753Smm assertEqualInt(4, archive_read_data(a, buff, 32)); 57228753Smm assertEqualMem(buff, "foo\n", 4); 58228753Smm 59228753Smm /* Test EOF */ 60228753Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 61228753Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 62232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 63228753Smm 64228753Smm 65228753Smm /* Second, try the same with a compressed file. */ 66228753Smm extract_reference_file(reffile2); 67228753Smm assert((a = archive_read_new()) != NULL); 68232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 69228753Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_raw(a)); 70228753Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 71228753Smm assertEqualIntA(a, ARCHIVE_OK, 72228753Smm archive_read_open_filename(a, reffile2, 1)); 73228753Smm 74228753Smm /* First (and only!) Entry */ 75232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 76228753Smm assertEqualString("data", archive_entry_pathname(ae)); 77228753Smm /* Most fields should be unset (unknown) */ 78228753Smm assert(!archive_entry_size_is_set(ae)); 79228753Smm assert(!archive_entry_atime_is_set(ae)); 80228753Smm assert(!archive_entry_ctime_is_set(ae)); 81228753Smm assert(!archive_entry_mtime_is_set(ae)); 82228753Smm assertEqualInt(4, archive_read_data(a, buff, 32)); 83228753Smm assertEqualMem(buff, "foo\n", 4); 84228753Smm 85228753Smm /* Test EOF */ 86228753Smm assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 87228753Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 88232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 89228753Smm} 90