test_mrumtl.c (2279B)
1 /* Copyright (C) 2020-2023 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "mrumtl.h" 17 #include <rsys/logger.h> 18 19 static void 20 log_stream(const char* msg, void* ctx) 21 { 22 ASSERT(msg); 23 (void)msg, (void)ctx; 24 printf("%s", msg); 25 } 26 27 int 28 main(int argc, char** argv) 29 { 30 struct mem_allocator allocator; 31 struct logger logger; 32 struct mrumtl_create_args args = MRUMTL_CREATE_ARGS_DEFAULT; 33 struct mrumtl* mrumtl; 34 (void)argc, (void)argv; 35 36 CHK(mrumtl_create(NULL, &mrumtl) == RES_BAD_ARG); 37 CHK(mrumtl_create(&args, NULL) == RES_BAD_ARG); 38 CHK(mrumtl_create(&args, &mrumtl) == RES_OK); 39 40 CHK(mrumtl_ref_get(NULL) == RES_BAD_ARG); 41 CHK(mrumtl_ref_get(mrumtl) == RES_OK); 42 CHK(mrumtl_ref_put(NULL) == RES_BAD_ARG); 43 CHK(mrumtl_ref_put(mrumtl) == RES_OK); 44 CHK(mrumtl_ref_put(mrumtl) == RES_OK); 45 46 CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); 47 args.allocator = &allocator; 48 args.verbose = 1; 49 CHK(mrumtl_create(&args, &mrumtl) == RES_OK); 50 CHK(mrumtl_ref_put(mrumtl) == RES_OK); 51 52 CHK(logger_init(&mem_default_allocator, &logger) == RES_OK); 53 logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); 54 logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); 55 logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); 56 57 args.logger = &logger; 58 args.verbose = 0; 59 CHK(mrumtl_create(&args, &mrumtl) == RES_OK); 60 CHK(mrumtl_ref_put(mrumtl) == RES_OK); 61 args.allocator = NULL; 62 CHK(mrumtl_create(&args, &mrumtl) == RES_OK); 63 CHK(mrumtl_ref_put(mrumtl) == RES_OK); 64 65 mem_shutdown_proxy_allocator(&allocator); 66 logger_release(&logger); 67 CHK(mem_allocated_size() == 0); 68 return 0; 69 }