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>
23 #include <tap/basic.h>
24 #include <tap/float.h>
26 #include "hkl-parameter-private.h"
32 ok(NULL
== hkl_parameter_new("", "", 2, 1, 3,
34 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
35 ok(NULL
== hkl_parameter_new("", "", 2, 1, 3,
37 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
38 ok(NULL
== hkl_parameter_new("", "", 2, 1, 3,
40 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
41 ok(NULL
== hkl_parameter_new("toto", "", 2, 1, 3,
43 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
45 ok(NULL
== hkl_parameter_new("toto", "", 1, 2, 3,
47 &hkl_unit_angle_rad
, &hkl_unit_length_nm
), __func__
);
49 p
= hkl_parameter_new("toto", "no description", 1, 2, 3,
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,
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)
92 ok(NULL
== hkl_parameter_new("", "no description", 2, 1, 3,
94 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
95 ok(NULL
== hkl_parameter_new("", "no description", 2, 1, 3,
97 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
98 ok(NULL
== hkl_parameter_new("", "no description", 2, 1, 3,
100 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
101 ok(NULL
== hkl_parameter_new("toto", "no description", 2, 1, 3,
103 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
104 ok(NULL
== hkl_parameter_new("toto", "no description", 1, 2, 3,
106 &hkl_unit_angle_rad
, &hkl_unit_length_nm
), __func__
);
107 p
= hkl_parameter_new("toto", "no description", 1, 2, 3,
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)
120 p
= hkl_parameter_new("toto", "no description", 1, 2, 3,
122 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
);
123 ok(TRUE
== hkl_parameter_is_valid(p
), __func__
);
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)
139 p
= hkl_parameter_new("toto", "no description", 1, 2, 3,
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__
);
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)
168 p
= hkl_parameter_new("toto", "no description", 1, 2, 3,
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
)