1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2018 The FreeBSD Foundation
5 * All rights reserved.
6 *
7 * This software was developed by Arshan Khanifar <arshankhanifar@gmail.com>
8 * under sponsorship from the FreeBSD Foundation.
9 */
10 #include "test.h"
11
DEFINE_TEST(test_crlf_mtree)12 DEFINE_TEST(test_crlf_mtree)
13 {
14 char *p0;
15 size_t s;
16 int r;
17 p0 = NULL;
18 char *content = "#mtree\r\n"
19 "f type=file uname=\\\r\n"
20 "root gname=root mode=0755 content=bar/foo\r\n"
21 "g type=file uname=root gname=root mode=0755 content=bar/goo\r\n";
22 char *filename = "output.tar";
23 #if defined(_WIN32) && !defined(__CYGWIN__)
24 char *p;
25 #endif
26
27 /* an absolute path to mtree file */
28 char *mtree_file = "/METALOG.mtree";
29 char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1);
30 strcpy(absolute_path, testworkdir);
31 strcat(absolute_path, mtree_file );
32
33 /* Create an archive using an mtree file. */
34 assertMakeFile(absolute_path, 0777, content);
35 assertMakeDir("bar", 0775);
36 assertMakeFile("bar/foo", 0777, "abc");
37 assertMakeFile("bar/goo", 0777, "abc");
38
39 #if defined(_WIN32) && !defined(__CYGWIN__)
40 p = absolute_path;
41 while(*p != '\0') {
42 if (*p == '/')
43 *p = '\\';
44 p++;
45 }
46
47 r = systemf("%s -cf %s @%s >step1.out 2>step1.err", testprog, filename, absolute_path);
48 failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path);
49 #else
50 r = systemf("%s -cf %s \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path);
51 failure("Error invoking %s -cf %s -C bar \"@%s\"", testprog, filename, absolute_path);
52 #endif
53
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, "f", 2);
66 assertEqualMem(p0 + 512, "abc", 4);
67 assertEqualMem(p0 + 1024, "g", 2);
68 assertEqualMem(p0 + 1536, "abc", 4);
69 done:
70 free(p0);
71 free(absolute_path);
72 }
73
74
75