htgop

Optical properties of a gas mixture
git clone git://git.meso-star.fr/htgop.git
Log | Files | Refs | README | LICENSE

test_htgop.c (2140B)


      1 /* Copyright (C) 2018-2021, 2023 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #include "htgop.h"
     17 #include "test_htgop_utils.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 htgop* htgop;
     35   (void)argc, (void)argv;
     36 
     37   CHK(htgop_create(NULL, NULL, 0, NULL) == RES_BAD_ARG);
     38   CHK(htgop_create(NULL, NULL, 0, &htgop) == RES_OK);
     39 
     40   CHK(htgop_ref_get(NULL) == RES_BAD_ARG);
     41   CHK(htgop_ref_get(htgop) == RES_OK);
     42   CHK(htgop_ref_put(NULL) == RES_BAD_ARG);
     43   CHK(htgop_ref_put(htgop) == RES_OK);
     44   CHK(htgop_ref_put(htgop) == RES_OK);
     45 
     46   CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
     47   CHK(htgop_create(NULL, &allocator, 1, &htgop) == RES_OK);
     48   CHK(htgop_ref_put(htgop) == RES_OK);
     49 
     50   CHK(logger_init(&allocator, &logger) == RES_OK);
     51   logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
     52   logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
     53   logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
     54 
     55   CHK(htgop_create(&logger, &allocator, 0, &htgop) == RES_OK);
     56   CHK(htgop_ref_put(htgop) == RES_OK);
     57   CHK(htgop_create(&logger, NULL, 0, &htgop) == RES_OK);
     58   CHK(htgop_ref_put(htgop) == RES_OK);
     59 
     60   logger_release(&logger);
     61   check_memory_allocator(&allocator);
     62   mem_shutdown_proxy_allocator(&allocator);
     63   CHK(mem_allocated_size() == 0);
     64   return 0;
     65 }