2 * Copyright (c) 2003-2007 Tim Kientzle
3 * Copyright (c) 2009 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.
27 __FBSDID("$FreeBSD$");
29 static const char archive[] = {
30 "begin 644 test_read_uu.Z\n"
31 "M'YV0+@`('$BPH,&#\"!,J7,BP(4(8$&_4J`$\"`,08$F%4O)AQ(\\2/(#7&@#%C\n"
32 "M!@T8-##.L`$\"QL@:-F(``%'#H<V;.'/J!%!G#ITP<BS\"H).FS<Z$1(T>/1A2\n"
33 "IHU\"0%9=*G4JUJM6K6+-JW<JUJ]>O8,.*'4NVK-FS:-.J7<NVK=NW9P$`\n"
38 static const char archive64[] = {
39 "begin-base64 644 test_read_uu.Z\n"
40 "H52QLgAIHEiwoMGDCBMqXMiwIUIYEG/UqAECAMQYEmFUvJhxI8SPIDXGgDFjBg0YNDDOsAECxsga\n"
41 "NmIAAFHDoc2bOHPqBFBnDp0wcizCoJOmzc6ERI0ePRhSo1CQFZdKnUq1qtWrWLNq3cq1q9evYMOK\n"
42 "HUu2rNmzaNOqXcu2rdu3ZwE=\n"
46 static const char extradata[] = {
47 "From uudecode@libarchive Mon Jun 2 03:03:31 2008\n"
48 "Return-Path: <uudecode@libarchive>\n"
49 "Received: from libarchive (localhost [127.0.0.1])\n"
50 " by libarchive (8.14.2/8.14.2) with ESMTP id m5233UT1006448\n"
51 " for <uudecode@libarchive>; Mon, 2 Jun 2008 03:03:31 GMT\n"
52 " (envelope-from uudecode@libarchive)\n"
53 "Received: (from uudecode@localhost)\n"
54 " by libarchive (8.14.2/8.14.2/Submit) id m5233U3e006406\n"
55 " for uudecode; Mon, 2 Jun 2008 03:03:30 GMT\n"
56 " (envelope-from root)\n"
57 "Date: Mon, 2 Jun 2008 03:03:30 GMT\n"
58 "From: Libarchive Test <uudecode@libarchive>\n"
59 "Message-Id: <200806020303.m5233U3e006406@libarchive>\n"
60 "To: uudecode@libarchive\n"
61 "Subject: Libarchive uudecode test\n"
63 "* Redistribution and use in source and binary forms, with or without\n"
64 "* modification, are permitted provided that the following conditions\n"
67 "01234567890abcdeghijklmnopqrstuvwxyz\n"
68 "01234567890ABCEFGHIJKLMNOPQRSTUVWXYZ\n"
73 test_read_uu_sub(const char *uudata, size_t uusize)
75 struct archive_entry *ae;
80 assert(NULL != (buff = malloc(uusize + 64 * 1024)));
83 for (extra = 0; extra <= 64; extra = extra==0?1:extra*2) {
84 size_t size = extra * 1024;
87 /* Add extra text size of which is from 1K bytes to
88 * 64Kbytes before uuencoded data. */
90 if (size > sizeof(extradata)-1) {
91 memcpy(p, extradata, sizeof(extradata)-1);
92 p += sizeof(extradata)-1;
93 size -= sizeof(extradata)-1;
95 memcpy(p, extradata, size-1);
97 *p++ = '\n';/* the last of extra text must have
102 memcpy(p, uudata, uusize);
103 size = extra * 1024 + uusize;
105 assert((a = archive_read_new()) != NULL);
106 assertEqualIntA(a, ARCHIVE_OK,
107 archive_read_support_compression_all(a));
108 assertEqualIntA(a, ARCHIVE_OK,
109 archive_read_support_format_all(a));
110 assertEqualIntA(a, ARCHIVE_OK,
111 read_open_memory(a, buff, size, 2));
112 assertEqualIntA(a, ARCHIVE_OK,
113 archive_read_next_header(a, &ae));
114 failure("archive_compression_name(a)=\"%s\"",
115 archive_compression_name(a));
116 assertEqualInt(archive_compression(a),
117 ARCHIVE_COMPRESSION_COMPRESS);
118 failure("archive_format_name(a)=\"%s\"",
119 archive_format_name(a));
120 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
121 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
122 assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
127 DEFINE_TEST(test_read_uu)
129 /* Read the traditional uuencoded data. */
130 test_read_uu_sub(archive, sizeof(archive)-1);
131 /* Read the Base64 uuencoded data. */
132 test_read_uu_sub(archive64, sizeof(archive64)-1);