star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.com/star-3d.git
Log | Files | Refs | README | LICENSE

test_s3d_device.c (2484B)


      1 /* Copyright (C) 2015-2023, 2026 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This file is part of Star-3D.
      4  *
      5  * Star-3D is free software: you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation, either version 3 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * Star-3D is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with Star-3D. If not, see <http://www.gnu.org/licenses/>. */
     17 
     18 #include "s3d.h"
     19 #include "test_s3d_utils.h"
     20 #include <rsys/logger.h>
     21 
     22 static void
     23 log_stream(const char* msg, void* ctx)
     24 {
     25   ASSERT(msg);
     26   (void)msg, (void)ctx;
     27   printf("%s\n", msg);
     28 }
     29 
     30 int
     31 main(int argc, char** argv)
     32 {
     33   struct logger logger;
     34   struct mem_allocator allocator;
     35   struct s3d_device* dev;
     36   (void)argc, (void)argv;
     37 
     38   CHK(s3d_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG);
     39   CHK(s3d_device_create(NULL, NULL, 0, &dev) == RES_OK);
     40 
     41   CHK(s3d_device_ref_get(NULL) == RES_BAD_ARG);
     42   CHK(s3d_device_ref_get(dev) == RES_OK);
     43   CHK(s3d_device_ref_put(NULL) == RES_BAD_ARG);
     44   CHK(s3d_device_ref_put(dev) == RES_OK);
     45   CHK(s3d_device_ref_put(dev) == RES_OK);
     46 
     47   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     48 
     49   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     50   CHK(s3d_device_create(NULL, &allocator, 0, NULL) == RES_BAD_ARG);
     51   CHK(s3d_device_create(NULL, &allocator, 0, &dev) == RES_OK);
     52   CHK(s3d_device_ref_put(dev) == RES_OK);
     53   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     54 
     55   CHK(logger_init(&allocator, &logger) == RES_OK);
     56   logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
     57   logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
     58   logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
     59 
     60   CHK(s3d_device_create(&logger, NULL, 0, NULL) == RES_BAD_ARG);
     61   CHK(s3d_device_create(&logger, NULL, 0, &dev) == RES_OK);
     62   CHK(s3d_device_ref_put(dev) == RES_OK);
     63 
     64   CHK(s3d_device_create(&logger, &allocator, 1, NULL) == RES_BAD_ARG);
     65   CHK(s3d_device_create(&logger, &allocator, 1, &dev) == RES_OK);
     66   CHK(s3d_device_ref_put(dev) == RES_OK);
     67 
     68   logger_release(&logger);
     69   check_memory_allocator(&allocator);
     70   mem_shutdown_proxy_allocator(&allocator);
     71   CHK(mem_allocated_size() == 0);
     72   return 0;
     73 }
     74