solstice-anim

Geometry animation library of the solstice app
git clone git://git.meso-star.com/solstice-anim.git
Log | Files | Refs | README | LICENSE

test_sanim_search.c (2806B)


      1 
      2 /* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com)
      3  * Copyright (C) 2016-2018 CNRS
      4 *
      5 * This program 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 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
     17 
     18 #include "sanim.h"
     19 #include "test_sanim_utils.h"
     20 
     21 #include <rsys/double33.h>
     22 
     23 struct data {
     24   struct my_type * result;
     25 };
     26 
     27 static res_T
     28 search(const struct sanim_node* n, void* data_, int* found)
     29 {
     30   int pivot;
     31   ASSERT(n && found);
     32   if (!data_) return RES_BAD_ARG;
     33   SANIM(node_is_pivot(n, &pivot));
     34   if (pivot) {
     35     struct my_type* node;
     36     struct data* data = data_;
     37     node = CONTAINER_OF(n, struct my_type, node);
     38     data->result = node;
     39     *found = 1;
     40   }
     41   return RES_OK;
     42 }
     43 
     44 int
     45 main(int argc, char** argv)
     46 {
     47   struct mem_allocator allocator;
     48   struct my_type *t1, *t2, *t3;
     49   struct sanim_pivot pivot = SANIM_PIVOT_NULL;
     50   struct sanim_tracking tracking = SANIM_TRACKING_NULL;
     51   struct data data;
     52   int found = 0;
     53   (void) argc, (void) argv;
     54 
     55   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     56 
     57   tracking.policy = TRACKING_SUN;
     58   pivot.type = PIVOT_SINGLE_AXIS;
     59   d3(pivot.data.pivot1.ref_normal, 0, 0, 1);
     60 
     61   /* ref_normal not in the YZ plane */
     62   CHK(my_type_create(&allocator, &t1) == RES_OK);
     63   CHK(my_type_pivot_create(&allocator, &pivot, &tracking, &t2) == RES_OK);
     64   CHK(my_type_create(&allocator, &t3) == RES_OK);
     65 
     66   CHK(my_type_add_child(t1, t2) == RES_OK);
     67   CHK(my_type_add_child(t2, t3) == RES_OK);
     68 
     69   data.result = NULL;
     70 
     71   CHK(sanim_node_search_tree(NULL, &data, search, &found) == RES_BAD_ARG);
     72   CHK(sanim_node_search_tree(&t1->node, NULL, search, &found) == RES_BAD_ARG);
     73   CHK(sanim_node_search_tree(&t1->node, &data, NULL, &found) == RES_BAD_ARG);
     74   CHK(sanim_node_search_tree(&t1->node, &data, search, NULL) == RES_BAD_ARG);
     75   CHK(sanim_node_search_tree(&t1->node, &data, search, &found) == RES_OK);
     76   CHK(data.result == t2);
     77 
     78   data.result = NULL;
     79   CHK(sanim_node_search_tree(&t3->node, &data, search, &found) == RES_OK);
     80   CHK(data.result == NULL);
     81   
     82   /* release memory */
     83   CHK(my_type_ref_put(t1) == RES_OK);
     84   CHK(my_type_ref_put(t2) == RES_OK);
     85   CHK(my_type_ref_put(t3) == RES_OK);
     86   check_memory_allocator(&allocator);
     87   mem_shutdown_proxy_allocator(&allocator);
     88   CHK(mem_allocated_size() == 0);
     89   return 0;
     90 }