star-gf

Compute Gebhart factors
git clone git://git.meso-star.fr/star-gf.git
Log | Files | Refs | README | LICENSE

test_sgf_device.c (2549B)


      1 /* Copyright (C) 2021, 2024 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2015-2018 EDF S.A., France (syrthes-support@edf.fr)
      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 "sgf.h"
     18 #include "test_sgf_utils.h"
     19 
     20 #include <rsys/logger.h>
     21 #include <rsys/rsys.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 logger logger;
     35   struct mem_allocator allocator;
     36   struct sgf_device* dev;
     37   (void)argc, (void)argv;
     38 
     39   CHK(sgf_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG);
     40   CHK(sgf_device_create(NULL, NULL, 0, &dev) == RES_OK);
     41 
     42   CHK(sgf_device_ref_get(NULL) == RES_BAD_ARG);
     43   CHK(sgf_device_ref_get(dev) == RES_OK);
     44   CHK(sgf_device_ref_put(NULL) == RES_BAD_ARG);
     45   CHK(sgf_device_ref_put(dev) == RES_OK);
     46   CHK(sgf_device_ref_put(dev) == RES_OK);
     47 
     48   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     49 
     50   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     51   CHK(sgf_device_create(NULL, &allocator, 1, NULL) == RES_BAD_ARG);
     52   CHK(sgf_device_create(NULL, &allocator, 1, &dev) == RES_OK);
     53   CHK(sgf_device_ref_put(dev) == RES_OK);
     54   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     55 
     56   CHK(logger_init(&allocator, &logger) == RES_OK);
     57   logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
     58   logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
     59   logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
     60 
     61   CHK(sgf_device_create(&logger, NULL, 0, NULL) == RES_BAD_ARG);
     62   CHK(sgf_device_create(&logger, NULL, 0, &dev) == RES_OK);
     63   CHK(sgf_device_ref_put(dev) == RES_OK);
     64 
     65   CHK(sgf_device_create(&logger, &allocator, 4, NULL) == RES_BAD_ARG);
     66   CHK(sgf_device_create(&logger, &allocator, 4, &dev) == RES_OK);
     67   CHK(sgf_device_ref_put(dev) == RES_OK);
     68 
     69   logger_release(&logger);
     70   check_memory_allocator(&allocator);
     71   mem_shutdown_proxy_allocator(&allocator);
     72   CHK(mem_allocated_size() == 0);
     73   return 0;
     74 }