[hkl] fix an unit test issue discovered on small endian arch
[hkl.git] / tests / hkl-parameter-t.c
blob409688166688379866e880a8dace138177fa8fbd
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-2015 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/float.h>
26 #include "hkl-parameter-private.h"
28 static void new(void)
30 HklParameter *p;
32 ok(NULL == hkl_parameter_new("", "", 2, 1, 3,
33 FALSE, TRUE,
34 &hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
35 ok(NULL == hkl_parameter_new("", "", 2, 1, 3,
36 FALSE, TRUE,
37 &hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
38 ok(NULL == hkl_parameter_new("", "", 2, 1, 3,
39 FALSE, TRUE,
40 &hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
41 ok(NULL == hkl_parameter_new("toto", "", 2, 1, 3,
42 FALSE, TRUE,
43 &hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
45 ok(NULL == hkl_parameter_new("toto", "", 1, 2, 3,
46 FALSE, TRUE,
47 &hkl_unit_angle_rad, &hkl_unit_length_nm), __func__);
49 p = hkl_parameter_new("toto", "no description", 1, 2, 3,
50 FALSE, TRUE,
51 &hkl_unit_angle_rad, &hkl_unit_angle_deg);
52 ok(0 == !p, __func__);
53 is_double(1., p->range.min, HKL_EPSILON, __func__);
54 is_double(2., p->_value, HKL_EPSILON, __func__);
55 is_double(3., p->range.max, HKL_EPSILON, __func__);
56 ok(FALSE == p->fit, __func__);
57 ok(TRUE == p->changed, __func__);
58 ok(&hkl_unit_angle_rad == p->unit, __func__);
59 ok(&hkl_unit_angle_deg == p->punit, __func__);
61 hkl_parameter_free(p);
64 static void new_copy(void)
66 HklParameter *copy, *p;
68 p = hkl_parameter_new("toto", "no description", 1, 2, 3,
69 FALSE, TRUE,
70 &hkl_unit_angle_rad, &hkl_unit_angle_deg);
72 copy = hkl_parameter_new_copy(p);
74 ok(copy->name == p->name, __func__);
75 ok(copy->description == p->description, __func__);
76 is_double(copy->range.min, p->range.min, HKL_EPSILON, __func__);
77 is_double(copy->_value, p->_value, HKL_EPSILON, __func__);
78 is_double(copy->range.max, p->range.max, HKL_EPSILON, __func__);
79 ok(copy->fit == p->fit, __func__);
80 ok(copy->changed == p->changed, __func__);
81 ok(&hkl_unit_angle_rad == copy->unit, __func__);
82 ok(&hkl_unit_angle_deg == copy->punit, __func__);
84 hkl_parameter_free(copy);
85 hkl_parameter_free(p);
88 static void init(void)
90 HklParameter *p;
92 ok(NULL == hkl_parameter_new("", "no description", 2, 1, 3,
93 FALSE, TRUE,
94 &hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
95 ok(NULL == hkl_parameter_new("", "no description", 2, 1, 3,
96 FALSE, TRUE,
97 &hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
98 ok(NULL == hkl_parameter_new("", "no description", 2, 1, 3,
99 FALSE, TRUE,
100 &hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
101 ok(NULL == hkl_parameter_new("toto", "no description", 2, 1, 3,
102 FALSE, TRUE,
103 &hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
104 ok(NULL == hkl_parameter_new("toto", "no description", 1, 2, 3,
105 FALSE, TRUE,
106 &hkl_unit_angle_rad, &hkl_unit_length_nm), __func__);
107 p = hkl_parameter_new("toto", "no description", 1, 2, 3,
108 FALSE, TRUE,
109 &hkl_unit_angle_rad, &hkl_unit_angle_deg);
110 ok(NULL != p, __func__);
112 hkl_parameter_free(p);
115 static void is_valid(void)
117 HklParameter *p;
118 GError *error;
120 p = hkl_parameter_new("toto", "no description", 1, 2, 3,
121 FALSE, TRUE,
122 &hkl_unit_angle_rad, &hkl_unit_angle_deg);
123 ok(TRUE == hkl_parameter_is_valid(p), __func__);
125 error= NULL;
126 ok(TRUE == hkl_parameter_value_set(p, 10, HKL_UNIT_DEFAULT, &error), __func__);
127 ok(error == NULL, __func__);
128 ok(FALSE == hkl_parameter_is_valid(p), __func__);
130 hkl_parameter_free(p);
133 static void min_max(void)
135 HklParameter *p;
136 double min, max;
137 GError *error;
139 p = hkl_parameter_new("toto", "no description", 1, 2, 3,
140 FALSE, TRUE,
141 &hkl_unit_angle_rad, &hkl_unit_angle_deg);
142 hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
143 is_double(1, min, HKL_EPSILON, __func__);
144 is_double(3, max, HKL_EPSILON, __func__);
146 ok(TRUE == hkl_parameter_min_max_set(p, 1.1, 4, HKL_UNIT_DEFAULT, NULL), __func__);
147 hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
148 is_double(1.1, min, HKL_EPSILON, __func__);
149 is_double(4, max, HKL_EPSILON, __func__);
151 error = NULL;
152 ok(FALSE == hkl_parameter_min_max_set(p, 4, 1, HKL_UNIT_DEFAULT, &error), __func__);
153 ok(error != NULL, __func__);
154 g_clear_error(&error);
156 /* nothing should have changed */
157 hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
158 is_double(1.1, min, HKL_EPSILON, __func__);
159 is_double(4, max, HKL_EPSILON, __func__);
161 hkl_parameter_free(p);
164 static void getter(void)
166 HklParameter *p;
168 p = hkl_parameter_new("toto", "no description", 1, 2, 3,
169 FALSE, TRUE,
170 &hkl_unit_angle_rad, &hkl_unit_angle_deg);
172 ok(NULL == hkl_parameter_axis_v_get(p), __func__);
173 ok(NULL == hkl_parameter_quaternion_get(p), __func__);
174 ok(NULL != hkl_parameter_description_get(p), __func__);
176 hkl_parameter_free(p);
179 int main(int argc, char** argv)
181 plan(44);
183 new();
184 new_copy();
185 init();
186 is_valid();
187 min_max();
188 getter();
189 return 0;