star-ck

Describe the radiative properties of gas mixtures
git clone git://git.meso-star.fr/star-ck.git
Log | Files | Refs | README | LICENSE

test_sck.c (2215B)


      1 /* Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2020, 2021 CNRS
      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 "sck.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 sck_create_args args = SCK_CREATE_ARGS_DEFAULT;
     35   struct sck* sck;
     36   (void)argc, (void)argv;
     37 
     38   CHK(sck_create(NULL, &sck) == RES_BAD_ARG);
     39   CHK(sck_create(&args, NULL) == RES_BAD_ARG);
     40   CHK(sck_create(&args, &sck) == RES_OK);
     41 
     42   CHK(sck_ref_get(NULL) == RES_BAD_ARG);
     43   CHK(sck_ref_get(sck) == RES_OK);
     44   CHK(sck_ref_put(NULL) == RES_BAD_ARG);
     45   CHK(sck_ref_put(sck) == RES_OK);
     46   CHK(sck_ref_put(sck) == RES_OK);
     47 
     48   CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
     49   args.allocator = &allocator;
     50   args.verbose = 1;
     51   CHK(sck_create(&args, &sck) == RES_OK);
     52   CHK(sck_ref_put(sck) == RES_OK);
     53 
     54   CHK(logger_init(&allocator, &logger) == RES_OK);
     55   logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
     56   logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
     57   logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
     58 
     59   args.logger = &logger;
     60   args.verbose = 0;
     61   CHK(sck_create(&args, &sck) == RES_OK);
     62   CHK(sck_ref_put(sck) == RES_OK);
     63   args.allocator = NULL;
     64   CHK(sck_create(&args, &sck) == RES_OK);
     65   CHK(sck_ref_put(sck) == RES_OK);
     66 
     67   logger_release(&logger);
     68   mem_shutdown_proxy_allocator(&allocator);
     69   CHK(mem_allocated_size() == 0);
     70   return 0;
     71 }
     72