rnsl

Load a list of strings expanded by the shell
git clone git://git.meso-star.fr/rnsl.git
Log | Files | Refs | README | LICENSE

test_rnsl.c (2648B)


      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 "rnsl.h"
     24 
     25 #include <rsys/logger.h>
     26 
     27 static void
     28 log_stream(const char* msg, void* ctx)
     29 {
     30   ASSERT(msg);
     31   (void)msg, (void)ctx;
     32   printf("%s\n", msg);
     33 }
     34 
     35 int
     36 main(int argc, char** argv)
     37 {
     38   struct mem_allocator allocator;
     39   struct logger logger;
     40   struct rnsl_create_args args = RNSL_CREATE_ARGS_DEFAULT;
     41   struct rnsl* rnsl;
     42   (void)argc, (void)argv;
     43 
     44   CHK(rnsl_create(NULL, &rnsl) == RES_BAD_ARG);
     45   CHK(rnsl_create(&args, NULL) == RES_BAD_ARG);
     46   CHK(rnsl_create(&args, &rnsl) == RES_OK);
     47 
     48   CHK(rnsl_ref_get(NULL) == RES_BAD_ARG);
     49   CHK(rnsl_ref_get(rnsl) == RES_OK);
     50   CHK(rnsl_ref_put(NULL) == RES_BAD_ARG);
     51   CHK(rnsl_ref_put(rnsl) == RES_OK);
     52   CHK(rnsl_ref_put(rnsl) == RES_OK);
     53 
     54   CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
     55   args.allocator = &allocator;
     56   args.verbose = 1;
     57   CHK(rnsl_create(&args, &rnsl) == RES_OK);
     58   CHK(rnsl_ref_put(rnsl) == RES_OK);
     59 
     60   CHK(logger_init(&allocator, &logger) == RES_OK);
     61   logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
     62   logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
     63   logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
     64 
     65   args.logger = &logger;
     66   args.verbose = 0;
     67   CHK(rnsl_create(&args, &rnsl) == RES_OK);
     68   CHK(rnsl_ref_put(rnsl) == RES_OK);
     69   args.allocator = NULL;
     70   CHK(rnsl_create(&args, &rnsl) == RES_OK);
     71   CHK(rnsl_ref_put(rnsl) == RES_OK);
     72 
     73   logger_release(&logger);
     74   mem_shutdown_proxy_allocator(&allocator);
     75   CHK(mem_allocated_size() == 0);
     76   return 0;
     77 }
     78