1 /* 2 * Author: Karl MacMillan <kmacmillan (at) tresys.com> 3 * 4 * Copyright (C) 2006 Tresys Technology, LLC 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 #include "test-cond.h" 22 #include "parse_util.h" 23 #include "helpers.h" 24 25 #include <sepol/policydb/policydb.h> 26 #include <sepol/policydb/link.h> 27 #include <sepol/policydb/expand.h> 28 #include <sepol/policydb/conditional.h> 29 30 static policydb_t basemod; 31 static policydb_t base_expanded; 32 33 int cond_test_init(void) 34 { 35 if (policydb_init(&base_expanded)) { 36 fprintf(stderr, "out of memory!\n"); 37 policydb_destroy(&basemod); 38 return -1; 39 } 40 41 if (test_load_policy(&basemod, POLICY_BASE, 1, "test-cond", "refpolicy-base.conf")) 42 goto cleanup; 43 44 if (link_modules(NULL, &basemod, NULL, 0, 0)) { 45 fprintf(stderr, "link modules failed\n"); 46 goto cleanup; 47 } 48 49 if (expand_module(NULL, &basemod, &base_expanded, 0, 1)) { 50 fprintf(stderr, "expand module failed\n"); 51 goto cleanup; 52 } 53 54 return 0; 55 56 cleanup: 57 policydb_destroy(&basemod); 58 policydb_destroy(&base_expanded); 59 return -1; 60 } 61 62 int cond_test_cleanup(void) 63 { 64 policydb_destroy(&basemod); 65 policydb_destroy(&base_expanded); 66 67 return 0; 68 } 69 70 static void test_cond_expr_equal(void) 71 { 72 cond_node_t *a, *b; 73 74 a = base_expanded.cond_list; 75 while (a) { 76 b = base_expanded.cond_list; 77 while (b) { 78 if (a == b) { 79 CU_ASSERT(cond_expr_equal(a, b)); 80 } else { 81 CU_ASSERT(cond_expr_equal(a, b) == 0); 82 } 83 b = b->next; 84 } 85 a = a->next; 86 } 87 } 88 89 int cond_add_tests(CU_pSuite suite) 90 { 91 if (NULL == CU_add_test(suite, "cond_expr_equal", test_cond_expr_equal)) { 92 return CU_get_error(); 93 } 94 return 0; 95 } 96