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