star-hitran

Load line-by-line data from the HITRAN database
git clone git://git.meso-star.fr/star-hitran.git
Log | Files | Refs | README | LICENSE

test_shtr.c (2452B)


      1 /* Copyright (C) 2022, 2025, 2026 |Méso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2025, 2026 Université de Lorraine
      3  * Copyright (C) 2022 Centre National de la Recherche Scientifique
      4  * Copyright (C) 2022 Université Paul Sabatier
      5  *
      6  * This program is free software: you can redistribute it and/or modify
      7  * it under the terms of the GNU General Public License as published by
      8  * the Free Software Foundation, either version 3 of the License, or
      9  * (at your option) any later version.
     10  *
     11  * This program is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     14  * GNU General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU General Public License
     17  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     18 
     19 #include "shtr.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 shtr* shtr;
     37   struct shtr_create_args args = SHTR_CREATE_ARGS_DEFAULT;
     38   (void)argc, (void)argv;
     39 
     40   CHK(shtr_create(NULL, &shtr) == RES_BAD_ARG);
     41   CHK(shtr_create(&args, NULL) == RES_BAD_ARG);
     42   CHK(shtr_create(&args, &shtr) == RES_OK);
     43 
     44   CHK(shtr_ref_get(NULL) == RES_BAD_ARG);
     45   CHK(shtr_ref_get(shtr) == RES_OK);
     46   CHK(shtr_ref_put(NULL) == RES_BAD_ARG);
     47   CHK(shtr_ref_put(shtr) == RES_OK);
     48   CHK(shtr_ref_put(shtr) == RES_OK);
     49 
     50   CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
     51   args.allocator = &allocator;
     52   args.verbose = 1;
     53   CHK(shtr_create(&args, &shtr) == RES_OK);
     54   CHK(MEM_ALLOCATED_SIZE(&allocator) != 0);
     55   CHK(shtr_ref_put(shtr) == RES_OK);
     56 
     57   CHK(logger_init(&allocator, &logger) == RES_OK);
     58   logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
     59   logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
     60   logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
     61 
     62   args.logger = &logger;
     63   CHK(shtr_create(&args, &shtr) == RES_OK);
     64   CHK(shtr_ref_put(shtr) == RES_OK);
     65   args.allocator = NULL;
     66   CHK(shtr_create(&args, &shtr) == RES_OK);
     67   CHK(shtr_ref_put(shtr) == RES_OK);
     68 
     69   logger_release(&logger);
     70   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     71   mem_shutdown_proxy_allocator(&allocator);
     72   CHK(mem_allocated_size() == 0);
     73   return 0;
     74 }