[contrib][haskell] Hkl.Xrd.OneD
[hkl.git] / tests / hkl3d-test-t.c
blob6c5871f130afeb9ad0d161280dc626d7608b5a0c
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-2017 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"
27 #include "tap/hkl-tap.h"
29 #define MODEL_FILENAME "data/diffabs.yaml"
31 static void check_model_validity(Hkl3D *hkl3d)
33 uint i, j;
34 uint len;
35 int res;
36 Hkl3DObject *obji;
37 Hkl3DObject *objj;
39 res = TRUE;
41 /* imported 1 config files with 7 Hkl3DObjects */
42 res &= DIAG(hkl3d->config->len == 1);
43 res &= DIAG(hkl3d->config->models[0]->len == 7);
45 /* all Hkl3DObjects must have a different axis_name */
46 len = hkl3d->config->models[0]->len;
47 for(i=0;i<len; ++i){
48 obji = hkl3d->config->models[0]->objects[i];
49 for (j=1; j<len-i; ++j){
50 objj = hkl3d->config->models[0]->objects[i+j];
51 if(!(strcmp(obji->axis_name, objj->axis_name))){
52 res &= DIAG(FALSE);
53 break;
56 obji++;
59 /* check the _movingObjects validity, all Hkl3DAxis must have a size of 1 */
60 for(i=0; i<6; ++i)
61 res &= DIAG(hkl3d->geometry->axes[i]->len == 1);
63 ok(res == TRUE, "no identical objects");
66 /* check the collision and that the right axes are colliding */
67 static void check_collision(Hkl3D *hkl3d)
69 char buffer[1000];
70 int res = TRUE;
72 /* check the collision and that the right axes are colliding */
73 res &= DIAG(hkl_geometry_set_values_v(hkl3d->geometry->geometry,
74 HKL_UNIT_USER, NULL,
75 23., 0., 0., 0., 0., 0.));
77 res &= DIAG(hkl3d_is_colliding(hkl3d) == TRUE);
78 strcpy(buffer, "");
80 /* now check that only delta and mu are colliding */
81 for(size_t 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 &= DIAG(tmp == TRUE);
95 else
96 res &= DIAG(tmp == FALSE);
98 ok(res == TRUE, "collision [%s]", buffer);
101 static void check_no_collision(Hkl3D *hkl3d)
103 int res = TRUE;
104 int i;
106 /* check that rotating around komega/kappa/kphi do not create collisison */
107 res &= DIAG(hkl_geometry_set_values_v(hkl3d->geometry->geometry,
108 HKL_UNIT_USER, NULL,
109 0., 0., 0., 0., 0., 0.));
110 /* komega */
111 for(i=0; i<=360; i=i+10){
112 res &= DIAG(hkl_geometry_set_values_v(hkl3d->geometry->geometry,
113 HKL_UNIT_USER, NULL,
114 0., i, 0., 0., 0., 0.));
115 res &= DIAG(hkl3d_is_colliding(hkl3d) == FALSE);
118 /* kappa */
119 for(i=0; i<=360; i=i+10){
120 res &= DIAG(hkl_geometry_set_values_v(hkl3d->geometry->geometry,
121 HKL_UNIT_USER, NULL,
122 0., 0., i, 0., 0., 0.));
123 res &= DIAG(hkl3d_is_colliding(hkl3d) == FALSE);
126 /* kphi */
127 for(i=0; i<=360; i=i+10){
128 res &= DIAG(hkl_geometry_set_values_v(hkl3d->geometry->geometry,
129 HKL_UNIT_USER, NULL,
130 0., 0., 0., i, 0., 0.));
131 res &= DIAG(hkl3d_is_colliding(hkl3d) == FALSE);
133 ok(res == TRUE, "no-collision");
136 int main(void)
138 char* filename;
139 const HklFactory *factory;
140 HklGeometry *geometry;
141 Hkl3D *hkl3d;
143 factory = hkl_factory_get_by_name("K6C", NULL);
144 geometry = hkl_factory_create_new_geometry(factory);
146 /* compute the filename of the diffractometer config file */
147 filename = test_file_path(MODEL_FILENAME);
148 hkl3d = hkl3d_new(filename, geometry);
150 plan(3);
151 check_model_validity(hkl3d);
152 check_collision(hkl3d);
153 check_no_collision(hkl3d);
154 /* TODO add/remove object*/
156 hkl3d_free(hkl3d);
157 test_file_path_free(filename);
158 hkl_geometry_free(geometry);
160 return 0;