xref: /freebsd/contrib/libarchive/cpio/test/test_option_C_upper.c (revision bd66c1b43e33540205dbc1187c2f2a15c58b57ba)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2003-2007 Tim Kientzle
5  * All rights reserved.
6  */
7 #include "test.h"
8 
DEFINE_TEST(test_option_C_upper)9 DEFINE_TEST(test_option_C_upper)
10 {
11 	int r;
12 
13 	/*
14 	 * Create a file on disk.
15 	 */
16 	assertMakeFile("file", 0644, NULL);
17 
18 	/* Create an archive without -C; this should be 512 bytes. */
19 	r = systemf("echo file | %s -o > small.cpio 2>small.err", testprog);
20 	assertEqualInt(r, 0);
21 	assertTextFileContents("1 block\n", "small.err");
22 	assertFileSize("small.cpio", 512);
23 
24 	/* Create an archive with -C 513; this should be 513 bytes. */
25 	r = systemf("echo file | %s -o -C 513 > 513.cpio 2>513.err",
26 		    testprog);
27 	assertEqualInt(r, 0);
28 	assertTextFileContents("1 block\n", "513.err");
29 	assertFileSize("513.cpio", 513);
30 
31 	/* Create an archive with -C 12345; this should be 12345 bytes. */
32 	r = systemf("echo file | %s -o -C12345 > 12345.cpio 2>12345.err",
33 		    testprog);
34 	assertEqualInt(r, 0);
35 	assertTextFileContents("1 block\n", "12345.err");
36 	assertFileSize("12345.cpio", 12345);
37 
38 	/* Create an archive with invalid -C request */
39 	assert(0 != systemf("echo file | %s -o -C > bad.cpio 2>bad.err",
40 			    testprog));
41 	assertEmptyFile("bad.cpio");
42 }
43