Deleted Added
full compact
test_option_C_mtree.c (337351) test_option_C_mtree.c (348607)
1/*-
2 * Copyright (c) 2018 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Arshan Khanifar <arshankhanifar@gmail.com>
6 * under sponsorship from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 12 unchanged lines hidden (view full) ---

21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28#include "test.h"
1/*-
2 * Copyright (c) 2018 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Arshan Khanifar <arshankhanifar@gmail.com>
6 * under sponsorship from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 12 unchanged lines hidden (view full) ---

21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28#include "test.h"
29__FBSDID("$FreeBSD: stable/11/contrib/libarchive/tar/test/test_option_C_mtree.c 337351 2018-08-05 14:35:30Z mm $");
29__FBSDID("$FreeBSD: stable/11/contrib/libarchive/tar/test/test_option_C_mtree.c 348607 2019-06-04 10:35:54Z mm $");
30
31DEFINE_TEST(test_option_C_mtree)
32{
33 char *p0;
34 size_t s;
35 int r;
36 p0 = NULL;
37 char *content = "./foo type=file uname=root gname=root mode=0755\n";
38 char *filename = "output.tar";
30
31DEFINE_TEST(test_option_C_mtree)
32{
33 char *p0;
34 size_t s;
35 int r;
36 p0 = NULL;
37 char *content = "./foo type=file uname=root gname=root mode=0755\n";
38 char *filename = "output.tar";
39#if defined(_WIN32) && !defined(CYGWIN)
40 char *p;
41#endif
39
40 /* an absolute path to mtree file */
41 char *mtree_file = "/METALOG.mtree";
42 char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1);
43 strcpy(absolute_path, testworkdir);
44 strcat(absolute_path, mtree_file );
45
46 /* Create an archive using an mtree file. */
47 assertMakeFile(absolute_path, 0777, content);
48 assertMakeDir("bar", 0775);
49 assertMakeFile("bar/foo", 0777, "abc");
50
42
43 /* an absolute path to mtree file */
44 char *mtree_file = "/METALOG.mtree";
45 char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1);
46 strcpy(absolute_path, testworkdir);
47 strcat(absolute_path, mtree_file );
48
49 /* Create an archive using an mtree file. */
50 assertMakeFile(absolute_path, 0777, content);
51 assertMakeDir("bar", 0775);
52 assertMakeFile("bar/foo", 0777, "abc");
53
51 r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path);
54#if defined(_WIN32) && !defined(CYGWIN)
55 p = absolute_path;
56 while(*p != '\0') {
57 if (*p == '/')
58 *p = '\\';
59 p++;
60 }
52
61
62 r = systemf("%s -cf %s -C bar @%s >step1.out 2>step1.err", testprog, filename, absolute_path);
53 failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path);
63 failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path);
64#else
65 r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path);
66 failure("Error invoking %s -cf %s -C bar \"@%s\"", testprog, filename, absolute_path);
67#endif
68
54 assertEqualInt(r, 0);
55 assertEmptyFile("step1.out");
56 assertEmptyFile("step1.err");
57
58 /* Do validation of the constructed archive. */
59
60 p0 = slurpfile(&s, "output.tar");
61 if (!assert(p0 != NULL))
62 goto done;
63 if (!assert(s >= 2048))
64 goto done;
65 assertEqualMem(p0 + 0, "./foo", 5);
66 assertEqualMem(p0 + 512, "abc", 3);
67 assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);
68 assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
69done:
70 free(p0);
69 assertEqualInt(r, 0);
70 assertEmptyFile("step1.out");
71 assertEmptyFile("step1.err");
72
73 /* Do validation of the constructed archive. */
74
75 p0 = slurpfile(&s, "output.tar");
76 if (!assert(p0 != NULL))
77 goto done;
78 if (!assert(s >= 2048))
79 goto done;
80 assertEqualMem(p0 + 0, "./foo", 5);
81 assertEqualMem(p0 + 512, "abc", 3);
82 assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);
83 assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
84done:
85 free(p0);
86 free(absolute_path);
71}
72
73
87}
88
89