summaryrefslogtreecommitdiffstats
path: root/tests/mode.c
blob: 850209ff59a61eb01e506a44d337f82274e2be37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright (C) 2023  Patrick McDermott
 *
 * This file is part of opkg-opk.
 *
 * opkg-opk is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * opkg-opk is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with opkg-opk.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "defs.h"
#include "mode.h"

static unsigned int _test_num = 0U;

static void
_test(mode_t cur_mode, const char *mode_str, int exp_ret, mode_t exp_mode)
{
	mode_t got_mode;

	if (opkg_opk_helper_mode_parse(cur_mode, mode_str, &got_mode)
			!= exp_ret
			|| got_mode != exp_mode) {
		fputs("not ", stdout);
	}
	printf("ok %u - cur_mode=0%06o mode_str=\"%s\"\n",
			++_test_num, cur_mode, mode_str);
	printf("\texp=0%06o got=0%06o\n", exp_mode, got_mode);
}

int
main()
{
	umask(0022);
	puts("1..12");
	_test(0000644,  "a+x" , OPKG_OPK_OK, 0000755);
	_test(0000755, "go-x" , OPKG_OPK_OK, 0000744);
	_test(0000744,  "a=rw", OPKG_OPK_OK, 0000666);
	_test(0000644,  "u+s" , OPKG_OPK_OK, 0004644);
	_test(0000644,  "g+s" , OPKG_OPK_OK, 0002644);
	_test(0000644,  "a+"  , OPKG_OPK_OK, 0000644);
	_test(0000644,  "g=u" , OPKG_OPK_OK, 0000664);
	_test(0000644,  "u=o" , OPKG_OPK_OK, 0000444);
	_test(0000664,  "o+g" , OPKG_OPK_OK, 0000666);
	_test(0000644,   "+wx", OPKG_OPK_OK, 0000755);  /* Affected by umask. */
	_test(0040755,  "a+t" , OPKG_OPK_OK, 0041755);
	_test(0040755,   "+t" , OPKG_OPK_OK, 0041755);

	return EXIT_SUCCESS;
}