star-cpr

Clip 2D meshes with 2D polygons
git clone git://git.meso-star.fr/star-cpr.git
Log | Files | Refs | README | LICENSE

test_scpr_device.c (3446B)


      1 /* Copyright (C) 2016-2018, 2021-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 #define _POSIX_C_SOURCE 200112L
     17 
     18 #include "scpr.h"
     19 #include "test_scpr_utils.h"
     20 
     21 #include <rsys/rsys.h>
     22 
     23 #include <memory.h>
     24 
     25 int
     26 main(int argc, char** argv)
     27 {
     28   struct mem_allocator allocator;
     29   struct scpr_device_create_args args = SCPR_DEVICE_CREATE_ARGS_DEFAULT;
     30   struct scpr_device* dev;
     31   double r[2];
     32   const double d[5] = { 0, 1, 2, 3, 4};
     33   double tmpd[5];
     34   const int64_t i64[5] = { 0, 1, 2, 3, 4};
     35   int64_t tmp64[5];
     36   int in;
     37   (void)argc, (void)argv;
     38 
     39   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     40 
     41   args.allocator = &allocator;
     42 
     43   BAD(scpr_device_create(NULL, NULL));
     44   BAD(scpr_device_create(&args, NULL));
     45   BAD(scpr_device_create(NULL, &dev));
     46 
     47   args.precision = -1;
     48   BAD(scpr_device_create(&args, &dev));
     49 
     50   args.precision = SCPR_DEVICE_CREATE_ARGS_DEFAULT.precision;
     51   OK(scpr_device_create(&args, &dev));
     52 
     53   BAD(scpr_device_ref_get(NULL));
     54   OK(scpr_device_ref_get(dev));
     55 
     56   BAD(scpr_device_ref_put(NULL));
     57   OK(scpr_device_ref_put(dev));
     58 
     59   BAD(scpr_device_get_range(NULL, NULL));
     60   BAD(scpr_device_get_range(NULL, r));
     61   BAD(scpr_device_get_range(dev, NULL));
     62   OK(scpr_device_get_range(dev, r));
     63 
     64   BAD(scpr_device_in_range(NULL, NULL, 5, NULL));
     65   BAD(scpr_device_in_range(NULL, NULL, 5, &in));
     66   BAD(scpr_device_in_range(NULL, d, 5, NULL));
     67   BAD(scpr_device_in_range(dev, NULL, 5, NULL));
     68   BAD(scpr_device_in_range(NULL, d, 5, &in));
     69   BAD(scpr_device_in_range(dev, NULL, 5, &in));
     70   BAD(scpr_device_in_range(dev, d, 5, NULL));
     71   OK(scpr_device_in_range(dev, d, 5, &in));
     72   CHK(in);
     73   /* With out_of_range value */
     74   memcpy(tmpd, d, sizeof(d));
     75   tmpd[3] = r[1] + 1;
     76   OK(scpr_device_in_range(dev, tmpd, 5, &in));
     77   CHK(!in);
     78 
     79   BAD(scpr_device_scale(NULL, NULL, 5, NULL));
     80   BAD(scpr_device_scale(NULL, NULL, 5, tmp64));
     81   BAD(scpr_device_scale(NULL, d, 5, NULL));
     82   BAD(scpr_device_scale(dev, NULL, 5, NULL));
     83   BAD(scpr_device_scale(NULL, d, 5, tmp64));
     84   BAD(scpr_device_scale(dev, NULL, 5, tmp64));
     85   BAD(scpr_device_scale(dev, d, 5, NULL));
     86   OK(scpr_device_scale(dev, d, 5, tmp64));
     87   /* With out_of_range value */
     88   memcpy(tmpd, d, sizeof(d));
     89   tmpd[3] = r[1] + 1;
     90   BAD(scpr_device_scale(dev, tmpd, 5, tmp64));
     91 
     92   BAD(scpr_device_unscale(NULL, NULL, 5, NULL));
     93   BAD(scpr_device_unscale(NULL, NULL, 5, tmpd));
     94   BAD(scpr_device_unscale(NULL, i64, 5, NULL));
     95   BAD(scpr_device_unscale(dev, NULL, 5, NULL));
     96   BAD(scpr_device_unscale(NULL, i64, 5, tmpd));
     97   BAD(scpr_device_unscale(dev, NULL, 5, tmpd));
     98   BAD(scpr_device_unscale(dev, i64, 5, NULL));
     99   OK(scpr_device_unscale(dev, i64, 5, tmpd));
    100 
    101   OK(scpr_device_ref_put(dev));
    102 
    103   check_memory_allocator(&allocator);
    104   mem_shutdown_proxy_allocator(&allocator);
    105   CHK(mem_allocated_size() == 0);
    106   return 0;
    107 }
    108