1231200Smm/*- 2231200Smm * Copyright (c) 2011 Tim Kientzle 3231200Smm * All rights reserved. 4231200Smm * 5231200Smm * Redistribution and use in source and binary forms, with or without 6231200Smm * modification, are permitted provided that the following conditions 7231200Smm * are met: 8231200Smm * 1. Redistributions of source code must retain the above copyright 9231200Smm * notice, this list of conditions and the following disclaimer. 10231200Smm * 2. Redistributions in binary form must reproduce the above copyright 11231200Smm * notice, this list of conditions and the following disclaimer in the 12231200Smm * documentation and/or other materials provided with the distribution. 13231200Smm * 14231200Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15231200Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16231200Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17231200Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18231200Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19231200Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20231200Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21231200Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22231200Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23231200Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24231200Smm */ 25231200Smm#include "test.h" 26231200Smm__FBSDID("$FreeBSD$"); 27231200Smm 28231200Smmstatic int 29231200Smmopen_cb(struct archive *a, void *client) 30231200Smm{ 31231200Smm (void)a; /* UNUSED */ 32231200Smm (void)client; /* UNUSED */ 33231200Smm return 0; 34231200Smm} 35231200Smmstatic ssize_t 36231200Smmread_cb(struct archive *a, void *client, const void **buff) 37231200Smm{ 38231200Smm (void)a; /* UNUSED */ 39231200Smm (void)client; /* UNUSED */ 40231200Smm (void)buff; /* UNUSED */ 41231200Smm return (ssize_t)0; 42231200Smm} 43231200Smmstatic int64_t 44231200Smmskip_cb(struct archive *a, void *client, int64_t request) 45231200Smm{ 46231200Smm (void)a; /* UNUSED */ 47231200Smm (void)client; /* UNUSED */ 48231200Smm (void)request; /* UNUSED */ 49231200Smm return (int64_t)0; 50231200Smm} 51231200Smmstatic int 52231200Smmclose_cb(struct archive *a, void *client) 53231200Smm{ 54231200Smm (void)a; /* UNUSED */ 55231200Smm (void)client; /* UNUSED */ 56231200Smm return 0; 57231200Smm} 58231200Smm 59231200Smmstatic void 60231200Smmtest(int formatted, archive_open_callback *o, archive_read_callback *r, 61231200Smm archive_skip_callback *s, archive_close_callback *c, 62231200Smm int rv, const char *msg) 63231200Smm{ 64231200Smm struct archive* a = archive_read_new(); 65231200Smm if (formatted) 66231200Smm assertEqualInt(ARCHIVE_OK, 67231200Smm archive_read_support_format_empty(a)); 68231200Smm assertEqualInt(rv, 69231200Smm archive_read_open2(a, NULL, o, r, s, c)); 70231200Smm assertEqualString(msg, archive_error_string(a)); 71231200Smm archive_read_free(a); 72231200Smm} 73231200Smm 74231200SmmDEFINE_TEST(test_archive_read_open2) 75231200Smm{ 76231200Smm const char *no_reader = 77231200Smm "No reader function provided to archive_read_open"; 78231200Smm const char *no_formats = "No formats registered"; 79231200Smm 80231200Smm test(1, NULL, NULL, NULL, NULL, 81231200Smm ARCHIVE_FATAL, no_reader); 82231200Smm test(1, open_cb, NULL, NULL, NULL, 83231200Smm ARCHIVE_FATAL, no_reader); 84231200Smm test(1, open_cb, read_cb, NULL, NULL, 85231200Smm ARCHIVE_OK, NULL); 86231200Smm test(1, open_cb, read_cb, skip_cb, NULL, 87231200Smm ARCHIVE_OK, NULL); 88231200Smm test(1, open_cb, read_cb, skip_cb, close_cb, 89231200Smm ARCHIVE_OK, NULL); 90231200Smm test(1, NULL, read_cb, skip_cb, close_cb, 91231200Smm ARCHIVE_OK, NULL); 92231200Smm test(1, open_cb, read_cb, skip_cb, NULL, 93231200Smm ARCHIVE_OK, NULL); 94231200Smm test(1, NULL, read_cb, skip_cb, NULL, 95231200Smm ARCHIVE_OK, NULL); 96231200Smm test(1, NULL, read_cb, NULL, NULL, 97231200Smm ARCHIVE_OK, NULL); 98231200Smm 99231200Smm test(0, NULL, NULL, NULL, NULL, 100231200Smm ARCHIVE_FATAL, no_reader); 101231200Smm test(0, open_cb, NULL, NULL, NULL, 102231200Smm ARCHIVE_FATAL, no_reader); 103231200Smm test(0, open_cb, read_cb, NULL, NULL, 104231200Smm ARCHIVE_FATAL, no_formats); 105231200Smm test(0, open_cb, read_cb, skip_cb, NULL, 106231200Smm ARCHIVE_FATAL, no_formats); 107231200Smm test(0, open_cb, read_cb, skip_cb, close_cb, 108231200Smm ARCHIVE_FATAL, no_formats); 109231200Smm} 110