test_entry_strmode.c revision 228761
115177Snate/*-
215284Snate * Copyright (c) 2003-2007 Tim Kientzle
315284Snate * All rights reserved.
415284Snate *
515284Snate * Redistribution and use in source and binary forms, with or without
615284Snate * modification, are permitted provided that the following conditions
715284Snate * are met:
815284Snate * 1. Redistributions of source code must retain the above copyright
915284Snate *    notice, this list of conditions and the following disclaimer.
1015284Snate * 2. Redistributions in binary form must reproduce the above copyright
1115284Snate *    notice, this list of conditions and the following disclaimer in the
1215284Snate *    documentation and/or other materials provided with the distribution.
1315284Snate *
1415284Snate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
1515284Snate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1615284Snate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1715284Snate * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
1815284Snate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1915284Snate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2015284Snate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2115284Snate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2215284Snate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2315284Snate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2415284Snate */
2510217Sphk#include "test.h"
2630171Scharnier__FBSDID("$FreeBSD: head/lib/libarchive/test/test_entry_strmode.c 201247 2009-12-30 05:59:21Z kientzle $");
2730171Scharnier
2830171ScharnierDEFINE_TEST(test_entry_strmode)
2950479Speter{
3030171Scharnier	struct archive_entry *entry;
3130171Scharnier
3259656Siwasaki	assert((entry = archive_entry_new()) != NULL);
3359656Siwasaki
3459656Siwasaki	archive_entry_set_mode(entry, AE_IFREG | 0642);
3559656Siwasaki	assertEqualString(archive_entry_strmode(entry), "-rw-r---w- ");
3659656Siwasaki
3730171Scharnier	/* Regular file + hardlink still shows as regular file. */
3810217Sphk	archive_entry_set_mode(entry, AE_IFREG | 0644);
3910217Sphk	archive_entry_set_hardlink(entry, "link");
4010217Sphk	assertEqualString(archive_entry_strmode(entry), "-rw-r--r-- ");
4130171Scharnier
4210217Sphk	archive_entry_set_mode(entry, 0640);
43188633Simp	archive_entry_set_hardlink(entry, "link");
44188633Simp	assertEqualString(archive_entry_strmode(entry), "hrw-r----- ");
4510217Sphk	archive_entry_set_hardlink(entry, NULL);
4610217Sphk
4716487Snate	archive_entry_set_mode(entry, AE_IFDIR | 0777);
4816487Snate	assertEqualString(archive_entry_strmode(entry), "drwxrwxrwx ");
4916487Snate
5016487Snate	archive_entry_set_mode(entry, AE_IFBLK | 03642);
5116487Snate	assertEqualString(archive_entry_strmode(entry), "brw-r-S-wT ");
5210217Sphk
5316487Snate	archive_entry_set_mode(entry, AE_IFCHR | 05777);
54185124Simp	assertEqualString(archive_entry_strmode(entry), "crwsrwxrwt ");
55185124Simp
56185124Simp	archive_entry_set_mode(entry, AE_IFSOCK | 0222);
57185124Simp	assertEqualString(archive_entry_strmode(entry), "s-w--w--w- ");
58185124Simp
59185124Simp	archive_entry_set_mode(entry, AE_IFIFO | 0444);
60185124Simp	assertEqualString(archive_entry_strmode(entry), "pr--r--r-- ");
61185124Simp
62185124Simp	archive_entry_set_mode(entry, AE_IFLNK | 04000);
63185124Simp	assertEqualString(archive_entry_strmode(entry), "l--S------ ");
64185124Simp
65185124Simp	archive_entry_acl_add_entry(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
66185124Simp	    0007, ARCHIVE_ENTRY_ACL_GROUP, 78, "group78");
67185124Simp	assertEqualString(archive_entry_strmode(entry), "l--S------+");
68185124Simp
69185124Simp	/* Release the experimental entry. */
70185124Simp	archive_entry_free(entry);
71185124Simp}
72185124Simp