test_library.c (1472B)
1 /* Copyright (C) 2013-2023, 2025 Vincent Forest (vaplv@free.fr) 2 * 3 * The RSys library is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published 5 * by the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * The RSys library is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #ifdef TEST_LIBRARY_BUILD_LIB 17 #include "rsys.h" 18 #include <stdio.h> 19 20 extern EXPORT_SYM void 21 exported_func(void); 22 23 void 24 exported_func(void) 25 { 26 printf("exported_func\n"); 27 } 28 29 #else 30 #include "library.h" 31 #include "mem_allocator.h" 32 33 int 34 main(int argc, char** argv) 35 { 36 void* lib = NULL; 37 (void)argc, (void)argv; 38 39 CHK(library_open(NULL) == NULL); 40 CHK(library_open("none") == NULL); 41 lib = library_open("./" SHARED_LIBRARY_NAME("test_lib")); 42 CHK(lib != NULL); 43 44 CHK(library_get_symbol(lib, "exported_func_BAD") == NULL); 45 CHK(library_get_symbol(lib, "exported_func") != NULL); 46 47 CHK(library_close(NULL) == RES_BAD_ARG); 48 CHK(library_close(lib) == RES_OK); 49 50 CHK(MEM_ALLOCATED_SIZE(&mem_default_allocator) == 0); 51 52 return 0; 53 } 54 #endif