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_node.c (7069B)


      1 /* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2016-2018 CNRS
      3 *
      4 * This program is free software: you can redistribute it and/or modify
      5 * it under the terms of the GNU General Public License as published by
      6 * the Free Software Foundation, either version 3 of the License, or
      7 * (at your option) any later version.
      8 *
      9 * This program is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #include "sanim.h"
     18 #include "test_sanim_utils.h"
     19 
     20 #include <rsys/double33.h>
     21 
     22 int
     23 main(int argc, char** argv)
     24 {
     25   struct mem_allocator allocator;
     26   struct my_type *t1, *t2, *ptr;
     27   struct sanim_pivot pivot = SANIM_PIVOT_NULL;
     28   struct sanim_tracking tracking = SANIM_TRACKING_NULL;
     29   struct sanim_node s1 = SANIM_NODE_NULL, s2 = SANIM_NODE_NULL;
     30   size_t count;
     31   int p;
     32   double transform1[12], transform2[12];
     33   double transl[3], transl_[3], rot[3], rot_[3];
     34   (void) argc, (void) argv;
     35 
     36   tracking.policy = TRACKING_SUN;
     37   pivot.type = PIVOT_SINGLE_AXIS;
     38   d3(pivot.data.pivot1.ref_normal, 0, 0, 1);
     39 
     40   mem_init_proxy_allocator(&allocator, &mem_default_allocator);
     41 
     42   CHK(my_type_create(NULL, &t1) == RES_OK);
     43   CHK(my_type_ref_put(NULL) == RES_BAD_ARG);
     44   CHK(my_type_ref_get(NULL) == RES_BAD_ARG);
     45   CHK(my_type_ref_get(t1) == RES_OK);
     46   CHK(my_type_ref_put(t1) == RES_OK);
     47   CHK(my_type_ref_put(t1) == RES_OK);
     48   CHK(my_type_create(&allocator, &t1) == RES_OK);
     49   CHK(my_type_create(&allocator, NULL) == RES_BAD_ARG);
     50   CHK(my_type_create(&allocator, &t2) == RES_OK);
     51   CHK(my_type_ref_put(t1) == RES_OK);
     52 
     53   CHK(my_type_pivot_create(&allocator, NULL, &tracking, &t1) == RES_BAD_ARG);
     54   CHK(my_type_pivot_create(&allocator, &pivot, NULL, &t1) == RES_BAD_ARG);
     55   CHK(my_type_pivot_create(&allocator, &pivot, &tracking, NULL) == RES_BAD_ARG);
     56   CHK(my_type_pivot_create(&allocator, &pivot, &tracking, &t1) == RES_OK);
     57 
     58   CHK(my_type_is_pivot(NULL, &p) == RES_BAD_ARG);
     59   CHK(my_type_is_pivot(t1, NULL) == RES_BAD_ARG);
     60   CHK(my_type_is_pivot(t1, &p) == RES_OK);
     61   CHK(p == 1);
     62   CHK(my_type_ref_put(t1) == RES_OK);
     63 
     64   CHK(my_type_create(&allocator, &t1) == RES_OK);
     65 
     66   CHK(my_type_is_pivot(t1, &p) == RES_OK);
     67   CHK(p == 0);
     68 
     69   CHK(my_type_add_child(NULL, t1) == RES_BAD_ARG);
     70   CHK(my_type_add_child(t1, NULL) == RES_BAD_ARG);
     71   CHK(my_type_add_child(t1, t1) == RES_BAD_ARG);
     72   CHK(my_type_add_child(t1, t2) == RES_OK);
     73   CHK(my_type_add_child(t1, t2) == RES_BAD_ARG);
     74   CHK(my_type_add_child(t2, t1) == RES_BAD_ARG);
     75 
     76   CHK(my_type_copy_create(NULL, &ptr) == RES_BAD_ARG);
     77   CHK(my_type_copy_create(t1, NULL) == RES_BAD_ARG);
     78 
     79   CHK(my_type_get_father(t1, NULL) == RES_BAD_ARG);
     80   CHK(my_type_get_father(NULL, &ptr) == RES_BAD_ARG);
     81   CHK(my_type_get_children_count(t1, NULL) == RES_BAD_ARG);
     82   CHK(my_type_get_children_count(NULL, &count) == RES_BAD_ARG);
     83   CHK(my_type_get_children_count(t1, &count) == RES_OK);
     84   CHK(count == 1);
     85   CHK(my_type_get_child(NULL, 0, &ptr) == RES_BAD_ARG);
     86   CHK(my_type_get_child(t1, 10, &ptr) == RES_BAD_ARG);
     87   CHK(my_type_get_child(t1, 0, NULL) == RES_BAD_ARG);
     88   CHK(my_type_get_child(t1, 0, &ptr) == RES_OK);
     89   CHK(ptr == t2);
     90   CHK(my_type_get_father(t1, NULL) == RES_BAD_ARG);
     91   CHK(my_type_get_father(NULL, &ptr) == RES_BAD_ARG);
     92   CHK(my_type_get_father(t1, &ptr) == RES_OK);
     93   CHK(ptr == NULL);
     94   CHK(my_type_get_father(t2, &ptr) == RES_OK);
     95   CHK(ptr == t1);
     96 
     97   CHK(my_type_set_translation(NULL, transl) == RES_BAD_ARG);
     98   CHK(my_type_set_translation(t1, NULL) == RES_BAD_ARG);
     99   CHK(my_type_set_translation(t1, transl) == RES_OK);
    100 
    101   CHK(my_type_get_translation(NULL, transl_) == RES_BAD_ARG);
    102   CHK(my_type_get_translation(t1, NULL) == RES_BAD_ARG);
    103   CHK(my_type_get_translation(t1, transl_) == RES_OK);
    104   CHK(d3_eq(transl, transl_) == 1);
    105 
    106   CHK(my_type_set_rotations(NULL, rot) == RES_BAD_ARG);
    107   CHK(my_type_set_rotations(t1, NULL) == RES_BAD_ARG);
    108   CHK(my_type_set_rotations(t1, rot) == RES_OK);
    109 
    110   CHK(my_type_get_rotations(NULL, rot_) == RES_BAD_ARG);
    111   CHK(my_type_get_rotations(t1, NULL) == RES_BAD_ARG);
    112   CHK(my_type_get_rotations(t1, rot_) == RES_OK);
    113   CHK(d3_eq(rot, rot_) == 1);
    114 
    115   CHK(my_type_get_transform(NULL, transform1) == RES_BAD_ARG);
    116   CHK(my_type_get_transform(t1, NULL) == RES_BAD_ARG);
    117   CHK(my_type_get_transform(t1, transform1) == RES_OK);
    118 
    119   CHK(my_type_copy_create(NULL, &ptr) == RES_BAD_ARG);
    120   CHK(my_type_copy_create(t1, NULL) == RES_BAD_ARG);
    121   /*t1->my_data = 1;*/
    122   CHK(my_type_copy_create(t1, &ptr) == RES_OK);
    123   CHK(t1->my_data == ptr->my_data);
    124   CHK(my_type_get_transform(ptr, transform2) == RES_OK);
    125   CHK(d34_eq_eps(transform1, transform2, 0) == 1);
    126   CHK(my_type_ref_put(ptr) == RES_OK);
    127 
    128   CHK(my_type_recursive_copy(&allocator, NULL, &ptr) == RES_BAD_ARG);
    129   CHK(my_type_recursive_copy(&allocator, t1, NULL) == RES_BAD_ARG);
    130   CHK(my_type_recursive_copy(&allocator, t1, &t1) == RES_BAD_ARG);
    131   CHK(my_type_recursive_copy(&allocator, t1, &ptr) == RES_OK);
    132 
    133   tracking.policy = TRACKING_POINT;
    134   tracking.data.node_target.tracked_node = NULL;
    135   CHK(my_type_track_me(NULL, &tracking) == RES_BAD_ARG);
    136   CHK(my_type_track_me(t1, NULL) == RES_BAD_ARG);
    137   CHK(my_type_track_me(t1, &tracking) == RES_OK);
    138   CHK(tracking.policy == TRACKING_NODE_TARGET);
    139   CHK(&t1->node == tracking.data.node_target.tracked_node);
    140 
    141   /* Some sanim API tests that cannot be carried out through my_type testing.
    142    * Test use of non-initialized sanim nodes. */
    143   CHK(sanim_node_is_initialized(NULL, &p) == RES_BAD_ARG);
    144   CHK(sanim_node_is_initialized(&s1, NULL) == RES_BAD_ARG);
    145   CHK(sanim_node_is_initialized(&s1, &p) == RES_OK);
    146   CHK(p == 0);
    147   CHK(sanim_node_release(&s1) == RES_OK); /* safe release of uninitialized nodes */
    148   CHK(sanim_node_initialize(&allocator, NULL) == RES_BAD_ARG);
    149   CHK(sanim_node_initialize(&allocator, &s1) == RES_OK);
    150   CHK(sanim_node_is_initialized(&s1, &p) == RES_OK);
    151   CHK(p == 1);
    152   CHK(sanim_node_release(&s1) == RES_OK);
    153   CHK(sanim_node_is_initialized(&s2, &p) == RES_OK);
    154   CHK(p == 0);
    155   CHK(sanim_node_initialize_pivot(&allocator, NULL, &tracking, &s2) == RES_BAD_ARG);
    156   CHK(sanim_node_initialize_pivot(&allocator, &pivot, NULL, &s2) == RES_BAD_ARG);
    157   CHK(sanim_node_initialize_pivot(&allocator, &pivot, &tracking, NULL) == RES_BAD_ARG);
    158   CHK(sanim_node_initialize_pivot(&allocator, &pivot, &tracking, &s2) == RES_OK);
    159   CHK(sanim_node_is_initialized(&s2, &p) == RES_OK);
    160   CHK(p == 1);
    161   CHK(sanim_node_release(NULL) == RES_BAD_ARG);
    162   CHK(sanim_node_release(&s2) == RES_OK);
    163   CHK(sanim_node_release(&s2) == RES_OK); /* safe mumtiple release */
    164 
    165   /* release memory */
    166   CHK(my_type_ref_put(t1) == RES_OK);
    167   CHK(my_type_ref_put(t2) == RES_OK);
    168   CHK(my_type_ref_put(ptr) == RES_OK);
    169   check_memory_allocator(&allocator);
    170   mem_shutdown_proxy_allocator(&allocator);
    171   CHK(mem_allocated_size() == 0);
    172   return 0;
    173 }