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_lexer.h" 346cd6a6acSopenharmony_ci 356cd6a6acSopenharmony_ci#include "../../src/cil_lexer.h" 366cd6a6acSopenharmony_ci 376cd6a6acSopenharmony_civoid test_cil_lexer_setup(CuTest *tc) { 386cd6a6acSopenharmony_ci char *test_str = "(test \"qstring\");comment\n"; 396cd6a6acSopenharmony_ci uint32_t str_size = strlen(test_str); 406cd6a6acSopenharmony_ci char *buffer = malloc(str_size + 2); 416cd6a6acSopenharmony_ci 426cd6a6acSopenharmony_ci memset(buffer+str_size, 0, 2); 436cd6a6acSopenharmony_ci strncpy(buffer, test_str, str_size); 446cd6a6acSopenharmony_ci 456cd6a6acSopenharmony_ci int rc = cil_lexer_setup(buffer, str_size + 2); 466cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 476cd6a6acSopenharmony_ci 486cd6a6acSopenharmony_ci free(buffer); 496cd6a6acSopenharmony_ci} 506cd6a6acSopenharmony_ci 516cd6a6acSopenharmony_civoid test_cil_lexer_next(CuTest *tc) { 526cd6a6acSopenharmony_ci char *test_str = "(test \"qstring\") ;comment\n"; 536cd6a6acSopenharmony_ci uint32_t str_size = strlen(test_str); 546cd6a6acSopenharmony_ci char *buffer = malloc(str_size + 2); 556cd6a6acSopenharmony_ci 566cd6a6acSopenharmony_ci memset(buffer+str_size, 0, 2); 576cd6a6acSopenharmony_ci strcpy(buffer, test_str); 586cd6a6acSopenharmony_ci 596cd6a6acSopenharmony_ci cil_lexer_setup(buffer, str_size + 2); 606cd6a6acSopenharmony_ci 616cd6a6acSopenharmony_ci struct token test_tok; 626cd6a6acSopenharmony_ci 636cd6a6acSopenharmony_ci int rc = cil_lexer_next(&test_tok); 646cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 656cd6a6acSopenharmony_ci 666cd6a6acSopenharmony_ci CuAssertIntEquals(tc, OPAREN, test_tok.type); 676cd6a6acSopenharmony_ci CuAssertStrEquals(tc, "(", test_tok.value); 686cd6a6acSopenharmony_ci CuAssertIntEquals(tc, 1, test_tok.line); 696cd6a6acSopenharmony_ci 706cd6a6acSopenharmony_ci rc = cil_lexer_next(&test_tok); 716cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 726cd6a6acSopenharmony_ci 736cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SYMBOL, test_tok.type); 746cd6a6acSopenharmony_ci CuAssertStrEquals(tc, "test", test_tok.value); 756cd6a6acSopenharmony_ci CuAssertIntEquals(tc, 1, test_tok.line); 766cd6a6acSopenharmony_ci 776cd6a6acSopenharmony_ci rc = cil_lexer_next(&test_tok); 786cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 796cd6a6acSopenharmony_ci 806cd6a6acSopenharmony_ci CuAssertIntEquals(tc, QSTRING, test_tok.type); 816cd6a6acSopenharmony_ci CuAssertStrEquals(tc, "\"qstring\"", test_tok.value); 826cd6a6acSopenharmony_ci CuAssertIntEquals(tc, 1, test_tok.line); 836cd6a6acSopenharmony_ci 846cd6a6acSopenharmony_ci rc = cil_lexer_next(&test_tok); 856cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 866cd6a6acSopenharmony_ci 876cd6a6acSopenharmony_ci CuAssertIntEquals(tc, CPAREN, test_tok.type); 886cd6a6acSopenharmony_ci CuAssertStrEquals(tc, ")", test_tok.value); 896cd6a6acSopenharmony_ci CuAssertIntEquals(tc, 1, test_tok.line); 906cd6a6acSopenharmony_ci 916cd6a6acSopenharmony_ci rc = cil_lexer_next(&test_tok); 926cd6a6acSopenharmony_ci CuAssertIntEquals(tc, SEPOL_OK, rc); 936cd6a6acSopenharmony_ci 946cd6a6acSopenharmony_ci CuAssertIntEquals(tc, COMMENT, test_tok.type); 956cd6a6acSopenharmony_ci CuAssertStrEquals(tc, ";comment", test_tok.value); 966cd6a6acSopenharmony_ci CuAssertIntEquals(tc, 1, test_tok.line); 976cd6a6acSopenharmony_ci 986cd6a6acSopenharmony_ci free(buffer); 996cd6a6acSopenharmony_ci} 1006cd6a6acSopenharmony_ci 101