star-enclosures-2d

Extract enclosures from 2D geometry
git clone git://git.meso-star.fr/star-enclosures-2d.git
Log | Files | Refs | README | LICENSE

test_senc2d_device.c (2533B)


      1 /* Copyright (C) 2018-2021, 2023, 2024 |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 "senc2d.h"
     17 #include "test_senc2d_utils.h"
     18 
     19 #include <rsys/logger.h>
     20 
     21 #include <stdio.h>
     22 
     23 static INLINE 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 senc2d_device* dev;
     37   (void)argc, (void)argv;
     38 
     39   BA(senc2d_device_create(NULL, NULL, 0, 0, NULL));
     40   BA(senc2d_device_create(NULL, NULL, 0, 0, &dev));
     41   OK(senc2d_device_create(NULL, NULL, 1, 0, &dev));
     42   BA(senc2d_device_ref_get(NULL));
     43   OK(senc2d_device_ref_get(dev));
     44   BA(senc2d_device_ref_put(NULL));
     45   OK(senc2d_device_ref_put(dev));
     46   OK(senc2d_device_ref_put(dev));
     47 
     48   OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
     49 
     50   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     51   BA(senc2d_device_create(NULL, &allocator, 1, 0, NULL));
     52   OK(senc2d_device_create(NULL, &allocator, 1, 0, &dev));
     53   OK(senc2d_device_ref_put(dev));
     54   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     55 
     56   OK(logger_init(&allocator, &logger));
     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   BA(senc2d_device_create(&logger, NULL, 1, 0, NULL));
     62   OK(senc2d_device_create(&logger, NULL, 1, 0, &dev));
     63   OK(senc2d_device_ref_put(dev));
     64 
     65   BA(senc2d_device_create(&logger, &allocator, 1, 0, NULL));
     66   OK(senc2d_device_create(&logger, &allocator, 1, 0, &dev));
     67   OK(senc2d_device_ref_put(dev));
     68 
     69   OK(senc2d_device_create(&logger, &allocator, SENC2D_NTHREADS_DEFAULT, 0, &dev));
     70   OK(senc2d_device_ref_put(dev));
     71 
     72   logger_release(&logger);
     73   check_memory_allocator(&allocator);
     74   mem_shutdown_proxy_allocator(&allocator);
     75   CHK(mem_allocated_size() == 0);
     76   return 0;
     77 }