16cd6a6acSopenharmony_ci/* 26cd6a6acSopenharmony_ci * Copyright 2011 Tresys Technology, LLC. All rights reserved. 36cd6a6acSopenharmony_ci * 46cd6a6acSopenharmony_ci * Redistribution and use in source and binary forms, with or without 56cd6a6acSopenharmony_ci * modification, are permitted provided that the following conditions are met: 66cd6a6acSopenharmony_ci * 76cd6a6acSopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, 86cd6a6acSopenharmony_ci * this list of conditions and the following disclaimer. 96cd6a6acSopenharmony_ci * 106cd6a6acSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, 116cd6a6acSopenharmony_ci * this list of conditions and the following disclaimer in the documentation 126cd6a6acSopenharmony_ci * and/or other materials provided with the distribution. 136cd6a6acSopenharmony_ci * 146cd6a6acSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS 156cd6a6acSopenharmony_ci * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 166cd6a6acSopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 176cd6a6acSopenharmony_ci * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 186cd6a6acSopenharmony_ci * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 196cd6a6acSopenharmony_ci * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 206cd6a6acSopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 216cd6a6acSopenharmony_ci * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 226cd6a6acSopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 236cd6a6acSopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 246cd6a6acSopenharmony_ci * 256cd6a6acSopenharmony_ci * The views and conclusions contained in the software and documentation are those 266cd6a6acSopenharmony_ci * of the authors and should not be interpreted as representing official policies, 276cd6a6acSopenharmony_ci * either expressed or implied, of Tresys Technology, LLC. 286cd6a6acSopenharmony_ci */ 296cd6a6acSopenharmony_ci 306cd6a6acSopenharmony_ci#include <sepol/policydb/policydb.h> 316cd6a6acSopenharmony_ci 326cd6a6acSopenharmony_ci#include "CuTest.h" 336cd6a6acSopenharmony_ci#include "test_cil.h" 346cd6a6acSopenharmony_ci 356cd6a6acSopenharmony_ci#include "../../src/cil_internal.h" 366cd6a6acSopenharmony_ci#include "../../src/cil_tree.h" 376cd6a6acSopenharmony_ci 386cd6a6acSopenharmony_civoid test_cil_symtab_array_init(CuTest *tc) { 396cd6a6acSopenharmony_ci struct cil_db *test_new_db; 406cd6a6acSopenharmony_ci test_new_db = malloc(sizeof(*test_new_db)); 416cd6a6acSopenharmony_ci 426cd6a6acSopenharmony_ci cil_symtab_array_init(test_new_db->symtab, cil_sym_sizes[CIL_SYM_ARRAY_ROOT]); 436cd6a6acSopenharmony_ci CuAssertPtrNotNull(tc, test_new_db->symtab); 446cd6a6acSopenharmony_ci 456cd6a6acSopenharmony_ci free(test_new_db); 466cd6a6acSopenharmony_ci} 476cd6a6acSopenharmony_ci 486cd6a6acSopenharmony_civoid test_cil_db_init(CuTest *tc) { 496cd6a6acSopenharmony_ci struct cil_db *test_db; 506cd6a6acSopenharmony_ci 516cd6a6acSopenharmony_ci cil_db_init(&test_db); 526cd6a6acSopenharmony_ci 536cd6a6acSopenharmony_ci CuAssertPtrNotNull(tc, test_db->ast); 546cd6a6acSopenharmony_ci CuAssertPtrNotNull(tc, test_db->symtab); 556cd6a6acSopenharmony_ci CuAssertPtrNotNull(tc, test_db->symtab); 566cd6a6acSopenharmony_ci} 576cd6a6acSopenharmony_ci 586cd6a6acSopenharmony_ci// TODO: Reach SEPOL_ERR return in cil_db_init ( currently can't produce a method to do so ) 596cd6a6acSopenharmony_ci 606cd6a6acSopenharmony_civoid test_cil_get_symtab_block(CuTest *tc) { 616cd6a6acSopenharmony_ci symtab_t *symtab = NULL; 626cd6a6acSopenharmony_ci 636cd6a6acSopenharmony_ci struct cil_tree_node *test_ast_node; 646cd6a6acSopenharmony_ci cil_tree_node_init(&test_ast_node); 656cd6a6acSopenharmony_ci 666cd6a6acSopenharmony_ci struct cil_db *test_db; 676cd6a6acSopenharmony_ci cil_db_init(&test_db); 686cd6a6acSopenharmony_ci 696cd6a6acSopenharmony_ci test_ast_node->parent = test_db->ast->root; 706cd6a6acSopenharmony_ci test_ast_node->parent->flavor = CIL_BLOCK; 716cd6a6acSopenharmony_ci test_ast_node->line = 1; 726cd6a6acSopenharmony_ci 736cd6a6acSopenharmony_ci int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS); 746cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 756cd6a6acSopenharmony_ci CuAssertPtrNotNull(tc, symtab); 766cd6a6acSopenharmony_ci} 776cd6a6acSopenharmony_ci 786cd6a6acSopenharmony_civoid test_cil_get_symtab_class(CuTest *tc) { 796cd6a6acSopenharmony_ci symtab_t *symtab = NULL; 806cd6a6acSopenharmony_ci 816cd6a6acSopenharmony_ci struct cil_tree_node *test_ast_node; 826cd6a6acSopenharmony_ci cil_tree_node_init(&test_ast_node); 836cd6a6acSopenharmony_ci 846cd6a6acSopenharmony_ci struct cil_db *test_db; 856cd6a6acSopenharmony_ci cil_db_init(&test_db); 866cd6a6acSopenharmony_ci 876cd6a6acSopenharmony_ci test_ast_node->parent = test_db->ast->root; 886cd6a6acSopenharmony_ci test_ast_node->parent->flavor = CIL_CLASS; 896cd6a6acSopenharmony_ci test_ast_node->line = 1; 906cd6a6acSopenharmony_ci 916cd6a6acSopenharmony_ci int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS); 926cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 936cd6a6acSopenharmony_ci CuAssertPtrNotNull(tc, symtab); 946cd6a6acSopenharmony_ci} 956cd6a6acSopenharmony_ci 966cd6a6acSopenharmony_civoid test_cil_get_symtab_root(CuTest *tc) { 976cd6a6acSopenharmony_ci symtab_t *symtab = NULL; 986cd6a6acSopenharmony_ci 996cd6a6acSopenharmony_ci struct cil_tree_node *test_ast_node; 1006cd6a6acSopenharmony_ci cil_tree_node_init(&test_ast_node); 1016cd6a6acSopenharmony_ci 1026cd6a6acSopenharmony_ci struct cil_db *test_db; 1036cd6a6acSopenharmony_ci cil_db_init(&test_db); 1046cd6a6acSopenharmony_ci 1056cd6a6acSopenharmony_ci test_ast_node->parent = test_db->ast->root; 1066cd6a6acSopenharmony_ci test_ast_node->parent->flavor = CIL_ROOT; 1076cd6a6acSopenharmony_ci test_ast_node->line = 1; 1086cd6a6acSopenharmony_ci 1096cd6a6acSopenharmony_ci int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS); 1106cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 1116cd6a6acSopenharmony_ci CuAssertPtrNotNull(tc, symtab); 1126cd6a6acSopenharmony_ci} 1136cd6a6acSopenharmony_ci 1146cd6a6acSopenharmony_civoid test_cil_get_symtab_flavor_neg(CuTest *tc) { 1156cd6a6acSopenharmony_ci symtab_t *symtab = NULL; 1166cd6a6acSopenharmony_ci 1176cd6a6acSopenharmony_ci struct cil_tree_node *test_ast_node; 1186cd6a6acSopenharmony_ci cil_tree_node_init(&test_ast_node); 1196cd6a6acSopenharmony_ci 1206cd6a6acSopenharmony_ci struct cil_db *test_db; 1216cd6a6acSopenharmony_ci cil_db_init(&test_db); 1226cd6a6acSopenharmony_ci 1236cd6a6acSopenharmony_ci test_ast_node->parent = test_db->ast->root; 1246cd6a6acSopenharmony_ci test_ast_node->parent->flavor = 1234567; 1256cd6a6acSopenharmony_ci test_ast_node->line = 1; 1266cd6a6acSopenharmony_ci 1276cd6a6acSopenharmony_ci int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS); 1286cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_ERR, rc); 1296cd6a6acSopenharmony_ci CuAssertPtrEquals(tc, symtab, NULL); 1306cd6a6acSopenharmony_ci} 1316cd6a6acSopenharmony_ci 1326cd6a6acSopenharmony_civoid test_cil_get_symtab_null_neg(CuTest *tc) { 1336cd6a6acSopenharmony_ci symtab_t *symtab = NULL; 1346cd6a6acSopenharmony_ci 1356cd6a6acSopenharmony_ci struct cil_tree_node *test_ast_node; 1366cd6a6acSopenharmony_ci cil_tree_node_init(&test_ast_node); 1376cd6a6acSopenharmony_ci 1386cd6a6acSopenharmony_ci struct cil_db *test_db; 1396cd6a6acSopenharmony_ci cil_db_init(&test_db); 1406cd6a6acSopenharmony_ci 1416cd6a6acSopenharmony_ci test_ast_node->parent = NULL; 1426cd6a6acSopenharmony_ci test_ast_node->line = 1; 1436cd6a6acSopenharmony_ci 1446cd6a6acSopenharmony_ci int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS); 1456cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_ERR, rc); 1466cd6a6acSopenharmony_ci CuAssertPtrEquals(tc, symtab, NULL); 1476cd6a6acSopenharmony_ci} 1486cd6a6acSopenharmony_ci 1496cd6a6acSopenharmony_civoid test_cil_get_symtab_node_null_neg(CuTest *tc) { 1506cd6a6acSopenharmony_ci symtab_t *symtab = NULL; 1516cd6a6acSopenharmony_ci 1526cd6a6acSopenharmony_ci struct cil_tree_node *test_ast_node = NULL; 1536cd6a6acSopenharmony_ci 1546cd6a6acSopenharmony_ci struct cil_db *test_db; 1556cd6a6acSopenharmony_ci cil_db_init(&test_db); 1566cd6a6acSopenharmony_ci 1576cd6a6acSopenharmony_ci int rc = cil_get_symtab(test_db, test_ast_node, &symtab, CIL_SYM_BLOCKS); 1586cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_ERR, rc); 1596cd6a6acSopenharmony_ci CuAssertPtrEquals(tc, symtab, NULL); 1606cd6a6acSopenharmony_ci CuAssertPtrEquals(tc, test_ast_node, NULL); 1616cd6a6acSopenharmony_ci} 1626cd6a6acSopenharmony_ci 1636cd6a6acSopenharmony_civoid test_cil_get_symtab_parent_null_neg(CuTest *tc) { 1646cd6a6acSopenharmony_ci symtab_t *symtab = NULL; 1656cd6a6acSopenharmony_ci 1666cd6a6acSopenharmony_ci struct cil_tree_node *test_ast_node; 1676cd6a6acSopenharmony_ci cil_tree_node_init(&test_ast_node); 1686cd6a6acSopenharmony_ci 1696cd6a6acSopenharmony_ci struct cil_db *test_db; 1706cd6a6acSopenharmony_ci cil_db_init(&test_db); 1716cd6a6acSopenharmony_ci 1726cd6a6acSopenharmony_ci test_ast_node->parent = NULL; 1736cd6a6acSopenharmony_ci test_ast_node->line = 1; 1746cd6a6acSopenharmony_ci 1756cd6a6acSopenharmony_ci int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS); 1766cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_ERR, rc); 1776cd6a6acSopenharmony_ci CuAssertPtrEquals(tc, symtab, NULL); 1786cd6a6acSopenharmony_ci} 1796cd6a6acSopenharmony_ci 180