1248590Smm/*-
2248590Smm * Copyright (c) 2012 Michihiro NAKAJIMA
3248590Smm * All rights reserved.
4248590Smm *
5248590Smm * Redistribution and use in source and binary forms, with or without
6248590Smm * modification, are permitted provided that the following conditions
7248590Smm * are met:
8248590Smm * 1. Redistributions of source code must retain the above copyright
9248590Smm *    notice, this list of conditions and the following disclaimer
10248590Smm *    in this position and unchanged.
11248590Smm * 2. Redistributions in binary form must reproduce the above copyright
12248590Smm *    notice, this list of conditions and the following disclaimer in the
13248590Smm *    documentation and/or other materials provided with the distribution.
14248590Smm *
15248590Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16248590Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17248590Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18248590Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19248590Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20248590Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21248590Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22248590Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23248590Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24248590Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25248590Smm */
26248590Smm
27248590Smm#include "test.h"
28248590Smm__FBSDID("$FreeBSD$");
29248590Smm#ifdef HAVE_SYS_STAT_H
30248590Smm#include <sys/stat.h>
31248590Smm#endif
32248590Smm
33248590Smmstatic char buff[4096];
34248590Smm
35248590SmmDEFINE_TEST(test_write_format_mtree_no_separator)
36248590Smm{
37248590Smm	struct archive_entry *ae;
38248590Smm	struct archive* a;
39248590Smm	size_t used;
40248590Smm
41248590Smm	/* Create a mtree format archive. */
42248590Smm	assert((a = archive_write_new()) != NULL);
43248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_mtree(a));
44248590Smm	assertEqualIntA(a, ARCHIVE_OK,
45248590Smm	    archive_write_open_memory(a, buff, sizeof(buff)-1, &used));
46248590Smm
47248590Smm	/* Write "." file.  */
48248590Smm	assert((ae = archive_entry_new()) != NULL);
49248590Smm	archive_entry_copy_pathname(ae, ".");
50248590Smm	archive_entry_set_mode(ae, AE_IFDIR | 0755);
51248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
52248590Smm	archive_entry_free(ae);
53248590Smm
54248590Smm	/* Write "noseparator" file.  */
55248590Smm	assert((ae = archive_entry_new()) != NULL);
56248590Smm	archive_entry_copy_pathname(ae, "noseparator");
57248590Smm	archive_entry_set_size(ae, 0);
58248590Smm	archive_entry_set_mode(ae, AE_IFREG | 0644);
59248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
60248590Smm	archive_entry_free(ae);
61248590Smm
62248590Smm	/* Write "./withseparator" file.  */
63248590Smm	assert((ae = archive_entry_new()) != NULL);
64248590Smm	archive_entry_copy_pathname(ae, "./withseparator");
65248590Smm	archive_entry_set_size(ae, 0);
66248590Smm	archive_entry_set_mode(ae, AE_IFREG | 0644);
67248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
68248590Smm	archive_entry_free(ae);
69248590Smm
70248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
71248590Smm        assertEqualInt(ARCHIVE_OK, archive_write_free(a));
72248590Smm
73248590Smm	/*
74248590Smm	 * Read the data and check it.
75248590Smm	 */
76248590Smm	assert((a = archive_read_new()) != NULL);
77248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
78248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
79248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used));
80248590Smm
81248590Smm	/* Read "." file. */
82248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
83248590Smm	failure("The path should be just \".\"");
84248590Smm	assertEqualString(archive_entry_pathname(ae), ".");
85248590Smm	assertEqualInt(archive_entry_mode(ae), AE_IFDIR | 0755);
86248590Smm
87248590Smm	/* Read "./noseparator" file. */
88248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
89248590Smm	failure("The path should have \"./\" prefix");
90248590Smm	assertEqualString(archive_entry_pathname(ae), "./noseparator");
91248590Smm	assertEqualInt(archive_entry_size(ae), 0);
92248590Smm	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
93248590Smm
94248590Smm	/* Read "./withseparator" file. */
95248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
96248590Smm	assertEqualString(archive_entry_pathname(ae), "./withseparator");
97248590Smm	assertEqualInt(archive_entry_size(ae), 0);
98248590Smm	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
99248590Smm
100248590Smm	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
101248590Smm	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
102248590Smm}
103248590Smm
104