]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add extra text before the uuencoded data.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 31 Oct 2009 05:37:10 +0000 (01:37 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 31 Oct 2009 05:37:10 +0000 (01:37 -0400)
SVN-Revision: 1551

libarchive/test/test_read_uu.c

index 35742ed3426abc42499826b95a137a34048c9a15..1b6e63516073074a2a0b67bfc9102d4641672ce9 100644 (file)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2009 Michihiro NAKAJIMA
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  */
 #include "test.h"
 
-static unsigned char archive[] = {
-0x62,0x65,0x67,0x69,0x6e,0x20,0x36,0x34,
-0x34,0x20,0x74,0x65,0x73,0x74,0x5f,0x72,
-0x65,0x61,0x64,0x5f,0x75,0x75,0x2e,0x5a,
-0x0a,0x4d,0x27,0x59,0x56,0x30,0x2b,0x40,
-0x60,0x28,0x27,0x24,0x42,0x50,0x48,0x2c,
-0x26,0x23,0x22,0x21,0x2c,0x4a,0x37,0x2c,
-0x42,0x50,0x28,0x34,0x28,0x38,0x24,0x26,
-0x5f,0x34,0x4a,0x60,0x24,0x22,0x60,0x2c,
-0x30,0x38,0x24,0x46,0x25,0x34,0x4f,0x29,
-0x41,0x51,0x28,0x5c,0x32,0x2f,0x28,0x23,
-0x37,0x26,0x40,0x23,0x25,0x43,0x0a,0x4d,
-0x21,0x40,0x54,0x38,0x2d,0x23,0x23,0x2e,
-0x4c,0x60,0x24,0x22,0x51,0x4c,0x40,0x3a,
-0x2d,0x46,0x28,0x60,0x60,0x25,0x27,0x23,
-0x48,0x3c,0x56,0x3b,0x2e,0x27,0x2f,0x4a,
-0x21,0x25,0x21,0x47,0x23,0x49,0x54,0x50,
-0x3c,0x42,0x53,0x22,0x48,0x29,0x2e,0x46,
-0x53,0x3c,0x5a,0x24,0x31,0x28,0x54,0x3e,
-0x2f,0x31,0x41,0x32,0x0a,0x49,0x48,0x55,
-0x22,0x30,0x25,0x39,0x3d,0x2a,0x47,0x34,
-0x4a,0x55,0x4a,0x4d,0x36,0x4b,0x36,0x2b,
-0x2d,0x4a,0x57,0x3c,0x4a,0x55,0x4a,0x5d,
-0x3e,0x4f,0x38,0x2c,0x2e,0x2a,0x27,0x34,
-0x4e,0x56,0x4b,0x2d,0x46,0x53,0x3a,0x2d,
-0x2e,0x4a,0x37,0x3c,0x4e,0x56,0x4b,0x3d,
-0x4e,0x57,0x39,0x50,0x24,0x60,0x0a,0x60,
-0x0a,0x65,0x6e,0x64,0x0a
+static const char archive[] = {
+"begin 644 test_read_uu.Z\n"
+"M'YV0+@`('$BPH,&#\"!,J7,BP(4(8$&_4J`$\"`,08$F%4O)AQ(\\2/(#7&@#%C\n"
+"M!@T8-##.L`$\"QL@:-F(``%'#H<V;.'/J!%!G#ITP<BS\"H).FS<Z$1(T>/1A2\n"
+"IHU\"0%9=*G4JUJM6K6+-JW<JUJ]>O8,.*'4NVK-FS:-.J7<NVK=NW9P$`\n"
+"`\n"
+"end\n"
 };
 
-static unsigned char archive64[] = {
+static const char archive64[] = {
 "begin-base64 644 test_read_uu.Z\n"
 "H52QLgAIHEiwoMGDCBMqXMiwIUIYEG/UqAECAMQYEmFUvJhxI8SPIDXGgDFjBg0YNDDOsAECxsga\n"
 "NmIAAFHDoc2bOHPqBFBnDp0wcizCoJOmzc6ERI0ePRhSo1CQFZdKnUq1qtWrWLNq3cq1q9evYMOK\n"
@@ -62,36 +42,97 @@ static unsigned char archive64[] = {
 "====\n"
 };
 
+static const char extradata[] = {
+"From uudecode@libarchive Mon Jun  2 03:03:31 2008\n"
+"Return-Path: <uudecode@libarchive>\n"
+"Received: from libarchive (localhost [127.0.0.1])\n"
+"        by libarchive (8.14.2/8.14.2) with ESMTP id m5233UT1006448\n"
+"        for <uudecode@libarchive>; Mon, 2 Jun 2008 03:03:31 GMT\n"
+"        (envelope-from uudecode@libarchive)\n"
+"Received: (from uudecode@localhost)\n"
+"        by libarchive (8.14.2/8.14.2/Submit) id m5233U3e006406\n"
+"        for uudecode; Mon, 2 Jun 2008 03:03:30 GMT\n"
+"        (envelope-from root)\n"
+"Date: Mon, 2 Jun 2008 03:03:30 GMT\n"
+"From: Libarchive Test <uudecode@libarchive>\n"
+"Message-Id: <200806020303.m5233U3e006406@libarchive>\n"
+"To: uudecode@libarchive\n"
+"Subject: Libarchive uudecode test\n"
+"\n"
+"* Redistribution and use in source and binary forms, with or without\n"
+"* modification, are permitted provided that the following conditions\n"
+"* are met:\n"
+"\n"
+"01234567890abcdeghijklmnopqrstuvwxyz\n"
+"01234567890ABCEFGHIJKLMNOPQRSTUVWXYZ\n"
+"\n"
+};
+
 static void
-test_read_uu_sub(unsigned char *uudata, size_t uusize)
+test_read_uu_sub(const char *uudata, size_t uusize)
 {
        struct archive_entry *ae;
        struct archive *a;
-       assert((a = archive_read_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK,
-           archive_read_support_compression_all(a));
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
-       assertEqualIntA(a, ARCHIVE_OK,
-           read_open_memory(a, uudata, uusize, 2));
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
-       failure("archive_compression_name(a)=\"%s\"",
-           archive_compression_name(a));
-       assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS);
-       failure("archive_format_name(a)=\"%s\"", archive_format_name(a));
-       assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+       char *buff;
+       int extra;
+
+       
+       assert(NULL != (buff = malloc(uusize + 64 * 1024)));
+       if (buff == NULL)
+               return;
+       for (extra = 0; extra <= 64; extra = extra==0?1:extra*2) {
+               size_t size = extra * 1024;
+               char *p = buff;
+
+               /* Add extra text size of which is from 1K bytes to
+                * 64Kbytes before uuencoded data. */
+               while (size) {
+                       if (size > sizeof(extradata)-1) {
+                               memcpy(p, extradata, sizeof(extradata)-1);
+                               p += sizeof(extradata)-1;
+                               size -= sizeof(extradata)-1;
+                       } else {
+                               memcpy(p, extradata, size-1);
+                               p += size-1;
+                               *p++ = '\n';/* the last of extra text must have
+                                            * '\n' character. */
+                               break;
+                       }
+               }
+               memcpy(p, uudata, uusize);
+               size = extra * 1024 + uusize;
+               
+               assert((a = archive_read_new()) != NULL);
+               assertEqualIntA(a, ARCHIVE_OK,
+                   archive_read_support_compression_all(a));
+               assertEqualIntA(a, ARCHIVE_OK,
+                   archive_read_support_format_all(a));
+               assertEqualIntA(a, ARCHIVE_OK,
+                   read_open_memory(a, buff, size, 2));
+               assertEqualIntA(a, ARCHIVE_OK,
+                   archive_read_next_header(a, &ae));
+               failure("archive_compression_name(a)=\"%s\"",
+                   archive_compression_name(a));
+               assertEqualInt(archive_compression(a),
+                   ARCHIVE_COMPRESSION_COMPRESS);
+               failure("archive_format_name(a)=\"%s\"",
+                   archive_format_name(a));
+               assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
+               assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
 #if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_read_finish(a);
+               archive_read_finish(a);
 #else
-       assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
+               assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
 #endif
+       }
+       free(buff);
 }
 
 DEFINE_TEST(test_read_uu)
 {
        /* Read the traditional uuencoded data. */
-       test_read_uu_sub(archive, sizeof(archive));
-       /* Read the Base64 encoding data. */
+       test_read_uu_sub(archive, sizeof(archive)-1);
+       /* Read the Base64 uuencoded data. */
        test_read_uu_sub(archive64, sizeof(archive64)-1);
 }