rename hkl_engine_pseudo_axes_get -> hkl_engine_pseudo_axes_names_get
[hkl.git] / tests / hkl3d-test-t.c
blob730aa1113687fb7ce4b5f8f6d6db3f8061a05cdb
1 /* This file is part of the hkl3d library.
3 * The hkl library 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.
8 * The hkl library 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.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2010-2013 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
21 * Oussama Sboui <sboui@synchrotron-soleil.fr>
23 #include <string.h>
25 #include "hkl3d.h"
26 #include "tap/basic.h"
28 #define MODEL_FILENAME "data/diffabs.yaml"
30 static void check_model_validity(Hkl3D *hkl3d)
32 uint i, j;
33 uint len;
34 int res;
35 Hkl3DObject *obji;
36 Hkl3DObject *objj;
38 res = TRUE;
40 /* imported 1 config files with 7 Hkl3DObjects */
41 res &= hkl3d->config->len == 1;
42 res &= hkl3d->config->models[0]->len == 7;
44 /* all Hkl3DObjects must have a different axis_name */
45 len = hkl3d->config->models[0]->len;
46 for(i=0;i<len; ++i){
47 obji = hkl3d->config->models[0]->objects[i];
48 for (j=1; j<len-i; ++j){
49 objj = hkl3d->config->models[0]->objects[i+j];
50 if(!(strcmp(obji->axis_name, objj->axis_name))){
51 res &= FALSE;
52 break;
55 obji++;
58 /* check the _movingObjects validity, all Hkl3DAxis must have a size of 1 */
59 for(i=0; i<6; ++i)
60 res &= hkl3d->geometry->axes[i]->len == 1;
62 ok(res == TRUE, "no identical objects");
65 /* check the collision and that the right axes are colliding */
66 static void check_collision(Hkl3D *hkl3d)
68 char buffer[1000];
69 int res;
70 int i;
72 /* check the collision and that the right axes are colliding */
73 res = TRUE;
74 hkl_geometry_set_values_unit_v(hkl3d->geometry->geometry,
75 23., 0., 0., 0., 0., 0.);
77 res &= hkl3d_is_colliding(hkl3d) == TRUE;
78 strcpy(buffer, "");
80 /* now check that only delta and mu are colliding */
81 for(i=0; i<hkl3d->config->models[0]->len; ++i){
82 const char *name;
83 int tmp;
85 name = hkl3d->config->models[0]->objects[i]->axis_name;
86 tmp = hkl3d->config->models[0]->objects[i]->is_colliding == TRUE;
87 /* add the colliding axes to the buffer */
88 if(tmp){
89 strcat(buffer, " ");
90 strcat(buffer, name);
93 if(!strcmp(name, "mu") || !strcmp(name, "delta"))
94 res &= tmp == TRUE;
95 else
96 res &= tmp == FALSE;
98 ok(res == TRUE, "collision [%s]", buffer);
101 static void check_no_collision(Hkl3D *hkl3d)
103 int res;
104 int i;
106 /* check that rotating around komega/kappa/kphi do not create collisison */
107 res = TRUE;
108 hkl_geometry_set_values_unit_v(hkl3d->geometry->geometry,
109 0., 0., 0., 0., 0., 0.);
110 /* komega */
111 for(i=0; i<=360; i=i+10){
112 hkl_geometry_set_values_unit_v(hkl3d->geometry->geometry,
113 0., i, 0., 0., 0., 0.);
114 res &= hkl3d_is_colliding(hkl3d) == FALSE;
117 /* kappa */
118 for(i=0; i<=360; i=i+10){
119 hkl_geometry_set_values_unit_v(hkl3d->geometry->geometry,
120 0., 0., i, 0., 0., 0.);
121 res &= hkl3d_is_colliding(hkl3d) == FALSE;
124 /* kphi */
125 for(i=0; i<=360; i=i+10){
126 hkl_geometry_set_values_unit_v(hkl3d->geometry->geometry,
127 0., 0., 0., i, 0., 0.);
128 res &= hkl3d_is_colliding(hkl3d) == FALSE;
130 ok(res == TRUE, "no-collision");
133 int main(int argc, char** argv)
135 char* filename;
136 const HklFactory *factory;
137 HklGeometry *geometry;
138 Hkl3D *hkl3d;
140 factory = hkl_factory_get_by_name("K6C");
141 geometry = hkl_factory_create_new_geometry(factory);
143 /* compute the filename of the diffractometer config file */
144 filename = test_file_path(MODEL_FILENAME);
145 hkl3d = hkl3d_new(filename, geometry);
147 plan(3);
148 check_model_validity(hkl3d);
149 check_collision(hkl3d);
150 check_no_collision(hkl3d);
151 /* TODO add/remove object*/
153 hkl3d_free(hkl3d);
154 test_file_path_free(filename);
155 hkl_geometry_free(geometry);
157 return 0;