test_archive_read_set_options.c revision 232153
1/*- 2 * Copyright (c) 2011 Tim Kientzle 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "test.h" 27__FBSDID("$FreeBSD$"); 28 29#define should(__a, __code, __opts) \ 30assertEqualInt(__code, archive_read_set_options(__a, __opts)) 31 32static void 33test(int pristine) 34{ 35 struct archive* a = archive_read_new(); 36 int halfempty_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK; 37 int known_option_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK; 38 39 if (!pristine) { 40 archive_read_support_filter_all(a); 41 archive_read_support_format_all(a); 42 } 43 44 /* NULL and "" denote `no option', so they're ok no matter 45 * what, if any, formats are registered */ 46 should(a, ARCHIVE_OK, NULL); 47 should(a, ARCHIVE_OK, ""); 48 49 /* unknown modules and options */ 50 should(a, ARCHIVE_FAILED, "fubar:snafu"); 51 assertEqualString("Unknown module name: `fubar'", 52 archive_error_string(a)); 53 should(a, ARCHIVE_FAILED, "fubar:snafu=betcha"); 54 assertEqualString("Unknown module name: `fubar'", 55 archive_error_string(a)); 56 57 /* unknown modules and options */ 58 should(a, ARCHIVE_FAILED, "snafu"); 59 assertEqualString("Undefined option: `snafu'", 60 archive_error_string(a)); 61 should(a, ARCHIVE_FAILED, "snafu=betcha"); 62 assertEqualString("Undefined option: `snafu'", 63 archive_error_string(a)); 64 65 /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_FAILED otherwise */ 66 should(a, known_option_rv, "iso9660:joliet"); 67 if (pristine) { 68 assertEqualString("Unknown module name: `iso9660'", 69 archive_error_string(a)); 70 } 71 should(a, known_option_rv, "iso9660:joliet"); 72 if (pristine) { 73 assertEqualString("Unknown module name: `iso9660'", 74 archive_error_string(a)); 75 } 76 should(a, known_option_rv, "joliet"); 77 if (pristine) { 78 assertEqualString("Undefined option: `joliet'", 79 archive_error_string(a)); 80 } 81 should(a, known_option_rv, "!joliet"); 82 if (pristine) { 83 assertEqualString("Undefined option: `joliet'", 84 archive_error_string(a)); 85 } 86 87 should(a, ARCHIVE_OK, ","); 88 should(a, ARCHIVE_OK, ",,"); 89 90 should(a, halfempty_options_rv, ",joliet"); 91 if (pristine) { 92 assertEqualString("Undefined option: `joliet'", 93 archive_error_string(a)); 94 } 95 should(a, halfempty_options_rv, "joliet,"); 96 if (pristine) { 97 assertEqualString("Undefined option: `joliet'", 98 archive_error_string(a)); 99 } 100 101 should(a, ARCHIVE_FAILED, "joliet,snafu"); 102 if (pristine) { 103 assertEqualString("Undefined option: `joliet'", 104 archive_error_string(a)); 105 } else { 106 assertEqualString("Undefined option: `snafu'", 107 archive_error_string(a)); 108 } 109 110 should(a, ARCHIVE_FAILED, "iso9660:snafu"); 111 if (pristine) { 112 assertEqualString("Unknown module name: `iso9660'", 113 archive_error_string(a)); 114 } else { 115 assertEqualString("Undefined option: `iso9660:snafu'", 116 archive_error_string(a)); 117 } 118 119 archive_read_finish(a); 120} 121 122DEFINE_TEST(test_archive_read_set_options) 123{ 124 test(1); 125 test(0); 126} 127