2 * Copyright (c) 2011 Tim Kientzle
3 * Copyright (c) 2014 Michihiro NAKAJIMA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 __FBSDID("$FreeBSD$");
31 extern const char * __archive_write_get_passphrase(struct archive_write *);
36 struct archive* a = archive_write_new();
37 struct archive_write* aw = (struct archive_write *)a;
40 archive_write_add_filter_gzip(a);
41 archive_write_set_format_iso9660(a);
44 assertEqualInt(ARCHIVE_OK, archive_write_set_passphrase(a, "pass1"));
45 /* An empty passphrase cannot be accepted. */
46 assertEqualInt(ARCHIVE_FAILED, archive_write_set_passphrase(a, ""));
47 /* NULL passphrases cannot be accepted. */
48 assertEqualInt(ARCHIVE_FAILED, archive_write_set_passphrase(a, NULL));
49 /* Check a passphrase. */
50 assertEqualString("pass1", __archive_write_get_passphrase(aw));
51 /* Change the passphrase. */
52 assertEqualInt(ARCHIVE_OK, archive_write_set_passphrase(a, "pass2"));
53 assertEqualString("pass2", __archive_write_get_passphrase(aw));
55 archive_write_free(a);
58 DEFINE_TEST(test_archive_write_set_passphrase)
66 callback1(struct archive *a, void *_client_data)
72 cnt = (int *)_client_data;
74 return ("passCallBack");
77 DEFINE_TEST(test_archive_write_set_passphrase_callback)
79 struct archive* a = archive_write_new();
80 struct archive_write* aw = (struct archive_write *)a;
83 archive_write_set_format_zip(a);
85 assertEqualInt(ARCHIVE_OK,
86 archive_write_set_passphrase_callback(a, &cnt, callback1));
87 /* Check a passphrase. */
88 assertEqualString("passCallBack", __archive_write_get_passphrase(aw));
89 assertEqualInt(1, cnt);
90 /* Callback function should be called just once. */
91 assertEqualString("passCallBack", __archive_write_get_passphrase(aw));
92 assertEqualInt(1, cnt);
94 archive_write_free(a);