Home | History | Annotate | Line # | Download | only in test
      1      1.1     joerg /*-
      2  1.1.1.3  christos  * SPDX-License-Identifier: BSD-2-Clause
      3  1.1.1.3  christos  *
      4      1.1     joerg  * Copyright (c) 2003-2007 Tim Kientzle
      5      1.1     joerg  * Copyright (c) 2012 Michihiro NAKAJIMA
      6      1.1     joerg  * All rights reserved.
      7      1.1     joerg  */
      8      1.1     joerg #include "test.h"
      9      1.1     joerg 
     10      1.1     joerg DEFINE_TEST(test_option_a)
     11      1.1     joerg {
     12      1.1     joerg 	size_t s;
     13      1.1     joerg 	char *p;
     14      1.1     joerg 
     15      1.1     joerg 	/* Create a file. */
     16      1.1     joerg 	assertMakeFile("f", 0644, "a");
     17      1.1     joerg 
     18      1.1     joerg 	/* Test1: archive it with .tar.Z suffix. */
     19      1.1     joerg 	assertEqualInt(0,
     20      1.1     joerg 	    systemf("%s -acf test1.tar.Z f 2>test1.err", testprog));
     21      1.1     joerg 	assertEmptyFile("test1.err");
     22      1.1     joerg 	/* Check that the archive file has a compress signature. */
     23      1.1     joerg 	p = slurpfile(&s, "test1.tar.Z");
     24      1.1     joerg 	assert(s > 2);
     25      1.1     joerg 	failure("The archive should be compressed");
     26      1.1     joerg 	assertEqualMem(p, "\x1f\x9d", 2);
     27      1.1     joerg 	free(p);
     28      1.1     joerg 
     29      1.1     joerg 	/* Test2: archive it with .taZ suffix. */
     30      1.1     joerg 	assertEqualInt(0,
     31      1.1     joerg 	    systemf("%s -acf test2.taZ f 2>test2.err", testprog));
     32      1.1     joerg 	assertEmptyFile("test2.err");
     33      1.1     joerg 	/* Check that the archive file has a compress signature. */
     34      1.1     joerg 	p = slurpfile(&s, "test2.taZ");
     35      1.1     joerg 	assert(s > 2);
     36      1.1     joerg 	failure("The archive should be compressed");
     37      1.1     joerg 	assertEqualMem(p, "\x1f\x9d", 2);
     38      1.1     joerg 	free(p);
     39      1.1     joerg 
     40      1.1     joerg 	/* Test3: archive it with .tar.Z.uu suffix. */
     41      1.1     joerg 	assertEqualInt(0,
     42      1.1     joerg 	    systemf("%s -acf test3.tar.Z.uu f 2>test3.err", testprog));
     43      1.1     joerg 	assertEmptyFile("test3.err");
     44      1.1     joerg 	/* Check that the archive file has a compress signature. */
     45      1.1     joerg 	p = slurpfile(&s, "test3.tar.Z.uu");
     46      1.1     joerg 	assert(s > 12);
     47      1.1     joerg 	failure("The archive should be uuencoded");
     48      1.1     joerg 	assertEqualMem(p, "begin 644 -\n", 12);
     49      1.1     joerg 	free(p);
     50      1.1     joerg 
     51      1.1     joerg 	/* Test4: archive it with .zip suffix. */
     52      1.1     joerg 	assertEqualInt(0,
     53      1.1     joerg 	    systemf("%s -acf test4.zip f 2>test4.err", testprog));
     54      1.1     joerg 	assertEmptyFile("test4.err");
     55      1.1     joerg 	/* Check that the archive file has a compress signature. */
     56      1.1     joerg 	p = slurpfile(&s, "test4.zip");
     57      1.1     joerg 	assert(s > 4);
     58      1.1     joerg 	failure("The archive should be zipped");
     59      1.1     joerg 	assertEqualMem(p, "\x50\x4b\x03\x04", 4);
     60      1.1     joerg 	free(p);
     61      1.1     joerg 
     62      1.1     joerg 	/* Test5: archive it with .tar.Z suffix and --uuencode option. */
     63      1.1     joerg 	assertEqualInt(0,
     64      1.1     joerg 	    systemf("%s -acf test5.tar.Z --uuencode f 2>test5.err",
     65      1.1     joerg 		testprog));
     66      1.1     joerg 	assertEmptyFile("test5.err");
     67      1.1     joerg 	/* Check that the archive file has a compress signature. */
     68      1.1     joerg 	p = slurpfile(&s, "test5.tar.Z");
     69      1.1     joerg 	assert(s > 2);
     70      1.1     joerg 	failure("The archive should be compressed, ignoring --uuencode option");
     71      1.1     joerg 	assertEqualMem(p, "\x1f\x9d", 2);
     72      1.1     joerg 	free(p);
     73      1.1     joerg 
     74      1.1     joerg 	/* Test6: archive it with .xxx suffix(unknown suffix) and
     75      1.1     joerg 	 * --uuencode option. */
     76      1.1     joerg 	assertEqualInt(0,
     77      1.1     joerg 	    systemf("%s -acf test6.xxx --uuencode f 2>test6.err",
     78      1.1     joerg 		testprog));
     79      1.1     joerg 	assertEmptyFile("test6.err");
     80      1.1     joerg 	/* Check that the archive file has a compress signature. */
     81      1.1     joerg 	p = slurpfile(&s, "test6.xxx");
     82      1.1     joerg 	assert(s > 12);
     83      1.1     joerg 	failure("The archive should be uuencoded");
     84      1.1     joerg 	assertEqualMem(p, "begin 644 -\n", 12);
     85      1.1     joerg 	free(p);
     86      1.1     joerg 
     87      1.1     joerg 	/* Test7: archive it with .tar.Z suffix using a long-name option. */
     88      1.1     joerg 	assertEqualInt(0,
     89      1.1     joerg 	    systemf("%s --auto-compress -cf test7.tar.Z f 2>test7.err",
     90      1.1     joerg 		testprog));
     91      1.1     joerg 	assertEmptyFile("test7.err");
     92      1.1     joerg 	/* Check that the archive file has a compress signature. */
     93      1.1     joerg 	p = slurpfile(&s, "test7.tar.Z");
     94      1.1     joerg 	assert(s > 2);
     95      1.1     joerg 	failure("The archive should be compressed");
     96      1.1     joerg 	assertEqualMem(p, "\x1f\x9d", 2);
     97      1.1     joerg 	free(p);
     98      1.1     joerg }
     99