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