| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
} |