[hkl] add hkl_geometry_[sample/detector]_rotation_get
[hkl.git] / tests / hkl-detector-t.c
blob0e059a1c0585a953cd2800a5dd8efc021efae279
1 /* This file is part of the hkl 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) 2003-2016 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>
22 #include "hkl.h"
23 #include <tap/basic.h>
24 #include <tap/hkl-tap.h>
26 #include "hkl-axis-private.h" /* temporary */
27 #include "hkl-detector-private.h"
29 static void new(void)
31 HklDetector *detector1;
32 HklDetector *detector2;
34 detector1 = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
35 ok(1 == detector1->idx, __func__);
36 ok(NULL == detector1->holder, __func__);
38 detector2 = hkl_detector_new_copy(detector1);
40 ok(detector1->idx == detector2->idx, __func__);
41 ok(detector1->holder == detector2->holder, __func__);
43 hkl_detector_free(detector1);
44 hkl_detector_free(detector2);
47 static void attach_to_holder(void)
49 HklDetector *detector = NULL;
50 HklGeometry *geometry = NULL;
51 HklHolder *holder = NULL;
53 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
54 geometry = hkl_geometry_new(NULL);
55 holder = hkl_geometry_add_holder(geometry);
56 hkl_detector_attach_to_holder(detector, holder);
58 ok(1 == detector->idx, __func__);
59 ok(holder == detector->holder, __func__);
61 hkl_geometry_free(geometry);
62 hkl_detector_free(detector);
65 static void compute_kf(void)
67 int res = TRUE;
68 HklDetector *detector = NULL;
69 HklGeometry *geometry = NULL;
70 HklHolder *holder = NULL;
71 HklVector kf;
72 HklVector kf_ref = {{0, HKL_TAU / HKL_SOURCE_DEFAULT_WAVE_LENGTH, 0}};
74 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
75 geometry = hkl_geometry_new(NULL);
76 /* add a fake first holder */
77 holder = hkl_geometry_add_holder(geometry);
78 /* for now all detectors MUST be connected to the second
79 * holder. We will decide about a better API to connect
80 * geometry and detector */
81 holder = hkl_geometry_add_holder(geometry);
82 hkl_holder_add_rotation_axis(holder, "a", 1, 0, 0);
83 hkl_holder_add_rotation_axis(holder, "b", 0, 1, 0);
85 res &= DIAG(hkl_parameter_value_set(darray_item(geometry->axes, 0), M_PI_2, HKL_UNIT_DEFAULT, NULL));
86 res &= DIAG(hkl_parameter_value_set(darray_item(geometry->axes, 1), M_PI_2, HKL_UNIT_DEFAULT, NULL));
88 hkl_detector_attach_to_holder(detector, holder);
89 hkl_detector_compute_kf(detector, geometry, &kf);
90 res &= DIAG(0 == hkl_vector_cmp(&kf_ref, &kf));
92 ok(res, __func__);
94 hkl_geometry_free(geometry);
95 hkl_detector_free(detector);
98 int main(void)
100 plan(7);
102 new();
103 attach_to_holder();
104 compute_kf();
106 return 0;