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-2014 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", 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", 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 is_double(copy
->range
.min
, p
->range
.min
, HKL_EPSILON
, __func__
);
76 is_double(copy
->_value
, p
->_value
, HKL_EPSILON
, __func__
);
77 is_double(copy
->range
.max
, p
->range
.max
, HKL_EPSILON
, __func__
);
78 ok(copy
->fit
== p
->fit
, __func__
);
79 ok(copy
->changed
== p
->changed
, __func__
);
80 ok(&hkl_unit_angle_rad
== copy
->unit
, __func__
);
81 ok(&hkl_unit_angle_deg
== copy
->punit
, __func__
);
83 hkl_parameter_free(copy
);
84 hkl_parameter_free(p
);
87 static void init(void)
91 ok(NULL
== hkl_parameter_new("", 2, 1, 3,
93 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
94 ok(NULL
== hkl_parameter_new("", 2, 1, 3,
96 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
97 ok(NULL
== hkl_parameter_new("", 2, 1, 3,
99 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
100 ok(NULL
== hkl_parameter_new("toto", 2, 1, 3,
102 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
), __func__
);
103 ok(NULL
== hkl_parameter_new("toto", 1, 2, 3,
105 &hkl_unit_angle_rad
, &hkl_unit_length_nm
), __func__
);
106 p
= hkl_parameter_new("toto", 1, 2, 3,
108 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
);
109 ok(NULL
!= p
, __func__
);
111 hkl_parameter_free(p
);
114 static void is_valid(void)
119 p
= hkl_parameter_new("toto", 1, 2, 3,
121 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
);
122 ok(TRUE
== hkl_parameter_is_valid(p
), __func__
);
125 ok(TRUE
== hkl_parameter_value_set(p
, 10, HKL_UNIT_DEFAULT
, &error
), __func__
);
126 ok(error
== NULL
, __func__
);
127 ok(FALSE
== hkl_parameter_is_valid(p
), __func__
);
129 hkl_parameter_free(p
);
132 static void min_max(void)
138 p
= hkl_parameter_new("toto", 1, 2, 3,
140 &hkl_unit_angle_rad
, &hkl_unit_angle_deg
);
141 hkl_parameter_min_max_get(p
, &min
, &max
, HKL_UNIT_DEFAULT
);
142 is_double(1, min
, HKL_EPSILON
, __func__
);
143 is_double(3, max
, HKL_EPSILON
, __func__
);
145 ok(TRUE
== hkl_parameter_min_max_set(p
, 1.1, 4, HKL_UNIT_DEFAULT
, NULL
), __func__
);
146 hkl_parameter_min_max_get(p
, &min
, &max
, HKL_UNIT_DEFAULT
);
147 is_double(1.1, min
, HKL_EPSILON
, __func__
);
148 is_double(4, max
, HKL_EPSILON
, __func__
);
151 ok(FALSE
== hkl_parameter_min_max_set(p
, 4, 1, HKL_UNIT_DEFAULT
, &error
), __func__
);
152 ok(error
!= NULL
, __func__
);
153 g_clear_error(&error
);
155 /* nothing should have changed */
156 hkl_parameter_min_max_get(p
, &min
, &max
, HKL_UNIT_DEFAULT
);
157 is_double(1.1, min
, HKL_EPSILON
, __func__
);
158 is_double(4, max
, HKL_EPSILON
, __func__
);
160 hkl_parameter_free(p
);
163 int main(int argc
, char** argv
)