test_atrtp.c (2327B)
1 /* Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com) 2 * Copyright (C) 2020, 2021 Centre National de la Recherche Scientifique 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #include "atrtp.h" 18 19 #include <rsys/logger.h> 20 21 static void 22 log_stream(const char* msg, void* ctx) 23 { 24 ASSERT(msg); 25 (void)msg, (void)ctx; 26 printf("%s\n", msg); 27 } 28 29 int 30 main(int argc, char** argv) 31 { 32 struct mem_allocator allocator; 33 struct logger logger; 34 struct atrtp* atrtp; 35 (void)argc, (void)argv; 36 37 CHK(atrtp_create(NULL, NULL, 0, NULL) == RES_BAD_ARG); 38 CHK(atrtp_create(NULL, NULL, 0, &atrtp) == RES_OK); 39 40 CHK(atrtp_ref_get(NULL) == RES_BAD_ARG); 41 CHK(atrtp_ref_get(atrtp) == RES_OK); 42 CHK(atrtp_ref_put(NULL) == RES_BAD_ARG); 43 CHK(atrtp_ref_put(atrtp) == RES_OK); 44 CHK(atrtp_ref_put(atrtp) == RES_OK); 45 46 CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); 47 CHK(atrtp_create(NULL, &allocator, 1, &atrtp) == RES_OK); 48 CHK(atrtp_ref_put(atrtp) == RES_OK); 49 50 CHK(logger_init(&allocator, &logger) == RES_OK); 51 logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); 52 logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); 53 logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); 54 55 CHK(atrtp_create(&logger, &allocator, 0, &atrtp) == RES_OK); 56 CHK(atrtp_ref_put(atrtp) == RES_OK); 57 CHK(atrtp_create(&logger, NULL, 0, &atrtp) == RES_OK); 58 CHK(atrtp_ref_put(atrtp) == RES_OK); 59 60 logger_release(&logger); 61 if(MEM_ALLOCATED_SIZE(&allocator)) { 62 char dump[512]; 63 MEM_DUMP(&allocator, dump, sizeof(dump)/sizeof(char)); 64 fprintf(stderr, "%s\n", dump); 65 FATAL("Memory leaks\n"); 66 } 67 mem_shutdown_proxy_allocator(&allocator); 68 CHK(mem_allocated_size() == 0); 69 return 0; 70 } 71