test_archive_read_set_option.c revision 248616
155682Smarkm/*- 255682Smarkm * Copyright (c) 2011 Tim Kientzle 355682Smarkm * All rights reserved. 455682Smarkm * 555682Smarkm * Redistribution and use in source and binary forms, with or without 655682Smarkm * modification, are permitted provided that the following conditions 7233294Sstas * are met: 8233294Sstas * 1. Redistributions of source code must retain the above copyright 9233294Sstas * notice, this list of conditions and the following disclaimer. 10233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 11233294Sstas * notice, this list of conditions and the following disclaimer in the 12233294Sstas * documentation and/or other materials provided with the distribution. 13233294Sstas * 14233294Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15233294Sstas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16233294Sstas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17233294Sstas * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18233294Sstas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19233294Sstas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20233294Sstas * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21233294Sstas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22233294Sstas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23233294Sstas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24233294Sstas */ 25233294Sstas 26233294Sstas#include "test.h" 27233294Sstas__FBSDID("$FreeBSD$"); 28233294Sstas 29233294Sstas#define should(__a, __code, __m, __o, __v) \ 30233294SstasassertEqualInt(__code, archive_read_set_option(__a, __m, __o, __v)) 31233294Sstas 32233294Sstasstatic void 33233294Sstastest(int pristine) 34233294Sstas{ 35233294Sstas struct archive* a = archive_read_new(); 36233294Sstas int known_option_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK; 37233294Sstas 38120945Snectar if (!pristine) { 39233294Sstas archive_read_support_filter_all(a); 40233294Sstas archive_read_support_format_all(a); 41120945Snectar } 42178825Sdfr 43233294Sstas /* NULL and "" denote `no option', so they're ok no matter 44233294Sstas * what, if any, formats are registered */ 45233294Sstas should(a, ARCHIVE_OK, NULL, NULL, NULL); 46233294Sstas should(a, ARCHIVE_OK, "", "", ""); 47233294Sstas 48233294Sstas /* unknown modules and options */ 49233294Sstas should(a, ARCHIVE_FAILED, "fubar", "snafu", NULL); 50233294Sstas should(a, ARCHIVE_FAILED, "fubar", "snafu", "betcha"); 51233294Sstas 52233294Sstas /* unknown modules and options */ 53233294Sstas should(a, ARCHIVE_FAILED, NULL, "snafu", NULL); 54233294Sstas should(a, ARCHIVE_FAILED, NULL, "snafu", "betcha"); 55233294Sstas 56233294Sstas /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_WARN otherwise */ 57233294Sstas should(a, known_option_rv, "iso9660", "joliet", NULL); 58233294Sstas should(a, known_option_rv, "iso9660", "joliet", NULL); 59233294Sstas should(a, known_option_rv, NULL, "joliet", NULL); 60233294Sstas should(a, known_option_rv, NULL, "joliet", NULL); 61233294Sstas 62178825Sdfr archive_read_free(a); 63178825Sdfr} 64178825Sdfr 65178825SdfrDEFINE_TEST(test_archive_read_set_option) 66178825Sdfr{ 67233294Sstas test(1); 68233294Sstas test(0); 69233294Sstas} 70233294Sstas