star-3d

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

test_s3d_device.c (2457B)


      1 /* Copyright (C) 2015-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 "s3d.h"
     17 #include "test_s3d_utils.h"
     18 #include <rsys/logger.h>
     19 
     20 static void
     21 log_stream(const char* msg, void* ctx)
     22 {
     23   ASSERT(msg);
     24   (void)msg, (void)ctx;
     25   printf("%s\n", msg);
     26 }
     27 
     28 int
     29 main(int argc, char** argv)
     30 {
     31   struct logger logger;
     32   struct mem_allocator allocator;
     33   struct s3d_device* dev;
     34   (void)argc, (void)argv;
     35 
     36   CHK(s3d_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG);
     37   CHK(s3d_device_create(NULL, NULL, 0, &dev) == RES_OK);
     38 
     39   CHK(s3d_device_ref_get(NULL) == RES_BAD_ARG);
     40   CHK(s3d_device_ref_get(dev) == RES_OK);
     41   CHK(s3d_device_ref_put(NULL) == RES_BAD_ARG);
     42   CHK(s3d_device_ref_put(dev) == RES_OK);
     43   CHK(s3d_device_ref_put(dev) == RES_OK);
     44 
     45   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     46 
     47   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     48   CHK(s3d_device_create(NULL, &allocator, 0, NULL) == RES_BAD_ARG);
     49   CHK(s3d_device_create(NULL, &allocator, 0, &dev) == RES_OK);
     50   CHK(s3d_device_ref_put(dev) == RES_OK);
     51   CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
     52 
     53   CHK(logger_init(&allocator, &logger) == RES_OK);
     54   logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
     55   logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
     56   logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
     57 
     58   CHK(s3d_device_create(&logger, NULL, 0, NULL) == RES_BAD_ARG);
     59   CHK(s3d_device_create(&logger, NULL, 0, &dev) == RES_OK);
     60   CHK(s3d_device_ref_put(dev) == RES_OK);
     61 
     62   CHK(s3d_device_create(&logger, &allocator, 1, NULL) == RES_BAD_ARG);
     63   CHK(s3d_device_create(&logger, &allocator, 1, &dev) == RES_OK);
     64   CHK(s3d_device_ref_put(dev) == RES_OK);
     65 
     66   logger_release(&logger);
     67   check_memory_allocator(&allocator);
     68   mem_shutdown_proxy_allocator(&allocator);
     69   CHK(mem_allocated_size() == 0);
     70   return 0;
     71 }
     72