xref: /aosp_15_r20/external/selinux/libsepol/tests/test-expander-attr-map.c (revision 2d543d20722ada2425b5bdab9d0d1d29470e7bba)
1*2d543d20SAndroid Build Coastguard Worker /*
2*2d543d20SAndroid Build Coastguard Worker  * Authors: Chad Sellers <[email protected]>
3*2d543d20SAndroid Build Coastguard Worker  *          Joshua Brindle <[email protected]>
4*2d543d20SAndroid Build Coastguard Worker  *
5*2d543d20SAndroid Build Coastguard Worker  * Copyright (C) 2006 Tresys Technology, LLC
6*2d543d20SAndroid Build Coastguard Worker  *
7*2d543d20SAndroid Build Coastguard Worker  *  This library is free software; you can redistribute it and/or
8*2d543d20SAndroid Build Coastguard Worker  *  modify it under the terms of the GNU Lesser General Public
9*2d543d20SAndroid Build Coastguard Worker  *  License as published by the Free Software Foundation; either
10*2d543d20SAndroid Build Coastguard Worker  *  version 2.1 of the License, or (at your option) any later version.
11*2d543d20SAndroid Build Coastguard Worker  *
12*2d543d20SAndroid Build Coastguard Worker  *  This library is distributed in the hope that it will be useful,
13*2d543d20SAndroid Build Coastguard Worker  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14*2d543d20SAndroid Build Coastguard Worker  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15*2d543d20SAndroid Build Coastguard Worker  *  Lesser General Public License for more details.
16*2d543d20SAndroid Build Coastguard Worker  *
17*2d543d20SAndroid Build Coastguard Worker  *  You should have received a copy of the GNU Lesser General Public
18*2d543d20SAndroid Build Coastguard Worker  *  License along with this library; if not, write to the Free Software
19*2d543d20SAndroid Build Coastguard Worker  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20*2d543d20SAndroid Build Coastguard Worker  */
21*2d543d20SAndroid Build Coastguard Worker 
22*2d543d20SAndroid Build Coastguard Worker #include "test-expander-attr-map.h"
23*2d543d20SAndroid Build Coastguard Worker #include "test-common.h"
24*2d543d20SAndroid Build Coastguard Worker #include "helpers.h"
25*2d543d20SAndroid Build Coastguard Worker 
26*2d543d20SAndroid Build Coastguard Worker #include <sepol/policydb/policydb.h>
27*2d543d20SAndroid Build Coastguard Worker #include <CUnit/Basic.h>
28*2d543d20SAndroid Build Coastguard Worker #include <stdlib.h>
29*2d543d20SAndroid Build Coastguard Worker 
30*2d543d20SAndroid Build Coastguard Worker extern policydb_t base_expanded2;
31*2d543d20SAndroid Build Coastguard Worker 
test_expander_attr_mapping(void)32*2d543d20SAndroid Build Coastguard Worker void test_expander_attr_mapping(void)
33*2d543d20SAndroid Build Coastguard Worker {
34*2d543d20SAndroid Build Coastguard Worker 	/* note that many cases are omitted because they don't make sense
35*2d543d20SAndroid Build Coastguard Worker 	   (i.e. declaring in an optional and then using it in the base) or
36*2d543d20SAndroid Build Coastguard Worker 	   because declare in optional then require in a different optional
37*2d543d20SAndroid Build Coastguard Worker 	   logic still doesn't work */
38*2d543d20SAndroid Build Coastguard Worker 
39*2d543d20SAndroid Build Coastguard Worker 	const char *typesb1[] = { "attr_check_base_1_1_t", "attr_check_base_1_2_t" };
40*2d543d20SAndroid Build Coastguard Worker 	const char *typesb2[] = { "attr_check_base_2_1_t", "attr_check_base_2_2_t" };
41*2d543d20SAndroid Build Coastguard Worker 	const char *typesb3[] = { "attr_check_base_3_1_t", "attr_check_base_3_2_t",
42*2d543d20SAndroid Build Coastguard Worker 		"attr_check_base_3_3_t", "attr_check_base_3_4_t"
43*2d543d20SAndroid Build Coastguard Worker 	};
44*2d543d20SAndroid Build Coastguard Worker 	const char *typesb4[] = { "attr_check_base_4_1_t", "attr_check_base_4_2_t" };
45*2d543d20SAndroid Build Coastguard Worker 	const char *typesb5[] = { "attr_check_base_5_1_t", "attr_check_base_5_2_t" };
46*2d543d20SAndroid Build Coastguard Worker 	const char *typesb6[] = { "attr_check_base_6_1_t", "attr_check_base_6_2_t",
47*2d543d20SAndroid Build Coastguard Worker 		"attr_check_base_6_3_t", "attr_check_base_6_4_t"
48*2d543d20SAndroid Build Coastguard Worker 	};
49*2d543d20SAndroid Build Coastguard Worker 	const char *typesbo2[] = { "attr_check_base_optional_2_1_t",
50*2d543d20SAndroid Build Coastguard Worker 		"attr_check_base_optional_2_2_t"
51*2d543d20SAndroid Build Coastguard Worker 	};
52*2d543d20SAndroid Build Coastguard Worker 	const char *typesbo5[] = { "attr_check_base_optional_5_1_t",
53*2d543d20SAndroid Build Coastguard Worker 		"attr_check_base_optional_5_2_t"
54*2d543d20SAndroid Build Coastguard Worker 	};
55*2d543d20SAndroid Build Coastguard Worker 	const char *typesm2[] = { "attr_check_mod_2_1_t", "attr_check_mod_2_2_t" };
56*2d543d20SAndroid Build Coastguard Worker 	const char *typesm4[] = { "attr_check_mod_4_1_t", "attr_check_mod_4_2_t" };
57*2d543d20SAndroid Build Coastguard Worker 	const char *typesm5[] = { "attr_check_mod_5_1_t", "attr_check_mod_5_2_t" };
58*2d543d20SAndroid Build Coastguard Worker 	const char *typesm6[] = { "attr_check_mod_6_1_t", "attr_check_mod_6_2_t",
59*2d543d20SAndroid Build Coastguard Worker 		"attr_check_mod_6_3_t", "attr_check_mod_6_4_t"
60*2d543d20SAndroid Build Coastguard Worker 	};
61*2d543d20SAndroid Build Coastguard Worker 	const char *typesmo2[] = { "attr_check_mod_optional_4_1_t",
62*2d543d20SAndroid Build Coastguard Worker 		"attr_check_mod_optional_4_2_t"
63*2d543d20SAndroid Build Coastguard Worker 	};
64*2d543d20SAndroid Build Coastguard Worker 	const char *typesb10[] = { "attr_check_base_10_1_t", "attr_check_base_10_2_t" };
65*2d543d20SAndroid Build Coastguard Worker 	const char *typesb11[] = { "attr_check_base_11_3_t", "attr_check_base_11_4_t" };
66*2d543d20SAndroid Build Coastguard Worker 	const char *typesm10[] = { "attr_check_mod_10_1_t", "attr_check_mod_10_2_t" };
67*2d543d20SAndroid Build Coastguard Worker 	const char *typesm11[] = { "attr_check_mod_11_3_t", "attr_check_mod_11_4_t" };
68*2d543d20SAndroid Build Coastguard Worker 
69*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_1", NULL, typesb1, 2);
70*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_2", NULL, typesb2, 2);
71*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_3", NULL, typesb3, 4);
72*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_4", NULL, typesb4, 2);
73*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_5", NULL, typesb5, 2);
74*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_6", NULL, typesb6, 4);
75*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_optional_2", NULL, typesbo2, 2);
76*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_optional_5", NULL, typesbo5, 2);
77*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_2", NULL, typesm2, 2);
78*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_4", NULL, typesm4, 2);
79*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_5", NULL, typesm5, 2);
80*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_6", NULL, typesm6, 4);
81*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_optional_4", NULL, typesmo2, 2);
82*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_7", NULL, NULL, 0);
83*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_8", NULL, NULL, 0);
84*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_9", NULL, NULL, 0);
85*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_10", NULL, typesb10, 2);
86*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_11", NULL, typesb11, 2);
87*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_7", NULL, NULL, 0);
88*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_8", NULL, NULL, 0);
89*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_9", NULL, NULL, 0);
90*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_10", NULL, typesm10, 2);
91*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_11", NULL, typesm11, 2);
92*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_base_optional_8", NULL, NULL, 0);
93*2d543d20SAndroid Build Coastguard Worker 	test_attr_types(&base_expanded2, "attr_check_mod_optional_7", NULL, NULL, 0);
94*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_5"));
95*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_5_1_t"));
96*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_5_2_t"));
97*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_8"));
98*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_8_1_t"));
99*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_8_2_t"));
100*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_4"));
101*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_4_1_t"));
102*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_4_2_t"));
103*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_7"));
104*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_7_1_t"));
105*2d543d20SAndroid Build Coastguard Worker 	CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_7_2_t"));
106*2d543d20SAndroid Build Coastguard Worker }
107