1 #include <glib.h>
2 #include <arv.h>
3
4 static void
load_fake_camera_genicam_test(void)5 load_fake_camera_genicam_test (void)
6 {
7 const char *genicam_xml;
8 size_t size;
9
10 genicam_xml = arv_get_fake_camera_genicam_xml (&size);
11 g_assert (genicam_xml != NULL);
12 g_assert (size != 0);
13
14 genicam_xml = arv_get_fake_camera_genicam_xml (NULL);
15 g_assert (genicam_xml != NULL);
16 }
17
18 static void
trigger_registers_test(void)19 trigger_registers_test (void)
20 {
21 ArvDevice *device;
22 ArvGc *genicam;
23 ArvGcNode *node;
24 gint64 address;
25
26 device = arv_fake_device_new ("TEST0");
27 g_assert (ARV_IS_FAKE_DEVICE (device));
28
29 genicam = arv_device_get_genicam (device);
30 g_assert (ARV_IS_GC (genicam));
31
32 node = arv_gc_get_node (genicam, "TriggerModeRegister");
33 g_assert (ARV_IS_GC_NODE (node));
34
35 address = arv_gc_register_get_address (ARV_GC_REGISTER (node), NULL);
36 g_assert_cmpint (address, ==, ARV_FAKE_CAMERA_REGISTER_TRIGGER_MODE);
37
38 address = arv_gc_register_get_address (ARV_GC_REGISTER (arv_gc_get_node (genicam,
39 "TriggerSourceRegister")), NULL);
40 g_assert_cmpint (address, ==, ARV_FAKE_CAMERA_REGISTER_TRIGGER_SOURCE);
41
42 address = arv_gc_register_get_address (ARV_GC_REGISTER (arv_gc_get_node (genicam,
43 "TriggerActivationRegister")), NULL);
44 g_assert_cmpint (address, ==, ARV_FAKE_CAMERA_REGISTER_TRIGGER_ACTIVATION);
45
46 arv_device_set_string_feature_value (device, "TriggerSelector", "AcquisitionStart");
47
48 address = arv_gc_register_get_address (ARV_GC_REGISTER (node), NULL);
49 g_assert_cmpint (address, ==, ARV_FAKE_CAMERA_REGISTER_TRIGGER_MODE +
50 ARV_FAKE_CAMERA_REGISTER_ACQUISITION_START_OFFSET);
51
52 g_object_unref (device);
53 }
54
55 static void
registers_test(void)56 registers_test (void)
57 {
58 ArvDevice *device;
59 ArvGc *genicam;
60 ArvGcNode *node;
61 ArvGcNode *node_a;
62 ArvGcNode *node_b;
63 ArvGcNode *node_c;
64 gint64 value;
65 gint64 address;
66
67 device = arv_fake_device_new ("TEST0");
68 g_assert (ARV_IS_FAKE_DEVICE (device));
69
70 genicam = arv_device_get_genicam (device);
71 g_assert (ARV_IS_GC (genicam));
72
73 node = arv_gc_get_node (genicam, "TestRegister");
74 g_assert (ARV_IS_GC_NODE (node));
75
76 address = arv_gc_register_get_address (ARV_GC_REGISTER (node), NULL);
77 g_assert_cmpint (address, ==, 0x1f0);
78
79 arv_gc_integer_set_value (ARV_GC_INTEGER (node), 0x12345678, NULL);
80 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
81 g_assert_cmpint (value, ==, 0x12345678);
82
83 node_a = arv_gc_get_node (genicam, "StructEntry_0_15");
84 g_assert (ARV_IS_GC_NODE (node_a));
85 node_b = arv_gc_get_node (genicam, "StructEntry_16_31");
86 g_assert (ARV_IS_GC_NODE (node_b));
87 node_c = arv_gc_get_node (genicam, "StructEntry_16");
88 g_assert (ARV_IS_GC_NODE (node_c));
89
90 value = arv_gc_register_get_address (ARV_GC_REGISTER (node_a), NULL);
91 g_assert_cmpint (value, ==, address);
92 value = arv_gc_register_get_address (ARV_GC_REGISTER (node_b), NULL);
93 g_assert_cmpint (value, ==, address);
94 value = arv_gc_register_get_address (ARV_GC_REGISTER (node_c), NULL);
95 g_assert_cmpint (value, ==, address);
96
97 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_a), NULL);
98 g_assert_cmpint (value, ==, 0x5678);
99
100 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_b), NULL);
101 g_assert_cmpint (value, ==, 0x1234);
102
103 arv_gc_integer_set_value (ARV_GC_INTEGER (node_b), 0x10101010, NULL);
104
105 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_a), NULL);
106 g_assert_cmpint (value, ==, 0x5678);
107
108 arv_gc_integer_set_value (ARV_GC_INTEGER (node_a), 0xabcdefaa, NULL);
109
110 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_a), NULL);
111 g_assert_cmpint (value, ==, -4182);
112
113 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_b), NULL);
114 g_assert_cmpint (value, ==, 0x1010);
115
116 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_c), NULL);
117 g_assert_cmpint (value, ==, 0x0);
118
119 arv_gc_integer_set_value (ARV_GC_INTEGER (node_c), 0xff, NULL);
120
121 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_c), NULL);
122 g_assert_cmpint (value, ==, -1);
123
124 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_b), NULL);
125 g_assert_cmpint (value, ==, 0x1011);
126
127 arv_gc_integer_set_value (ARV_GC_INTEGER (node_b), 0xff, NULL);
128
129 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_b), NULL);
130 g_assert_cmpint (value, ==, 0xff);
131
132 arv_gc_integer_set_value (ARV_GC_INTEGER (node_c), 0x0, NULL);
133
134 value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_c), NULL);
135 g_assert_cmpint (value, ==, 0);
136
137 g_object_unref (device);
138 }
139
140 static void
fake_device_test(void)141 fake_device_test (void)
142 {
143 ArvDevice *device;
144 ArvDeviceStatus status;
145 int int_value;
146 double dbl_value;
147 double boolean_value;
148 gint64 minimum, maximum;
149 gint64 *values;
150 const char **string_values;
151 const char *string_value;
152 guint n_values;
153 double float_minimum, float_maximum;
154 const char *genicam;
155 gsize size;
156
157 device = arv_fake_device_new ("TEST0");
158 g_assert (ARV_IS_FAKE_DEVICE (device));
159
160 genicam = arv_device_get_genicam_xml (device, &size);
161 g_assert (genicam != NULL);
162
163 /* Check default */
164 int_value = arv_device_get_integer_feature_value (device, "Width");
165 g_assert_cmpint (int_value, ==, ARV_FAKE_CAMERA_WIDTH_DEFAULT);
166
167 arv_device_set_integer_feature_value (device, "Width", 1024);
168 int_value = arv_device_get_integer_feature_value (device, "Width");
169 g_assert_cmpint (int_value, ==, 1024);
170
171 /* Check default */
172 int_value = arv_device_get_integer_feature_value (device, "Height");
173 g_assert_cmpint (int_value, ==, ARV_FAKE_CAMERA_HEIGHT_DEFAULT);
174
175 arv_device_set_integer_feature_value (device, "Height", 1024);
176 int_value = arv_device_get_integer_feature_value (device, "Height");
177 g_assert_cmpint (int_value, ==, 1024);
178
179 int_value = arv_device_get_integer_feature_value (device, "BinningHorizontal");
180 g_assert_cmpint (int_value, ==, ARV_FAKE_CAMERA_BINNING_HORIZONTAL_DEFAULT);
181 int_value = arv_device_get_integer_feature_value (device, "BinningVertical");
182 g_assert_cmpint (int_value, ==, ARV_FAKE_CAMERA_BINNING_VERTICAL_DEFAULT);
183 int_value = arv_device_get_integer_feature_value (device, "PixelFormat");
184 g_assert_cmpint (int_value, ==, ARV_FAKE_CAMERA_PIXEL_FORMAT_DEFAULT);
185
186 dbl_value = arv_device_get_float_feature_value (device, "AcquisitionFrameRate");
187 g_assert_cmpfloat (dbl_value, ==, ARV_FAKE_CAMERA_ACQUISITION_FRAME_RATE_DEFAULT);
188 dbl_value = arv_device_get_float_feature_value (device, "ExposureTimeAbs");
189 g_assert_cmpfloat (dbl_value, ==, ARV_FAKE_CAMERA_EXPOSURE_TIME_US_DEFAULT);
190
191 int_value = arv_device_get_integer_feature_value (device, "GainRaw");
192 g_assert_cmpint (int_value, ==, 0);
193 int_value = arv_device_get_integer_feature_value (device, "GainAuto");
194 g_assert_cmpint (int_value, ==, 1);
195
196 int_value = arv_device_get_integer_feature_value (device, "PayloadSize");
197 g_assert_cmpint (int_value, ==, 1024 * 1024);
198
199 arv_device_set_boolean_feature_value (device, "TestBoolean", FALSE);
200 boolean_value = arv_device_get_boolean_feature_value (device, "TestBoolean");
201 g_assert_cmpint (boolean_value, ==, FALSE);
202 int_value = arv_device_get_integer_feature_value (device, "TestRegister");
203 g_assert_cmpint (int_value, ==, 123);
204
205 arv_device_set_boolean_feature_value (device, "TestBoolean", TRUE);
206 boolean_value = arv_device_get_boolean_feature_value (device, "TestBoolean");
207 g_assert_cmpint (boolean_value, ==, TRUE);
208 int_value = arv_device_get_integer_feature_value (device, "TestRegister");
209 g_assert_cmpint (int_value, ==, 321);
210
211 arv_device_get_integer_feature_bounds (device, "Width", &minimum, &maximum);
212 g_assert_cmpint (minimum, ==, 1);
213 g_assert_cmpint (maximum, ==, 2048);
214
215 arv_device_get_float_feature_bounds (device, "ExposureTimeAbs", &float_minimum, &float_maximum);
216 g_assert_cmpfloat (float_minimum, ==, 10.0);
217 g_assert_cmpfloat (float_maximum, ==, 10000000.0);
218
219 arv_device_set_float_feature_value (device, "ExposureTimeAbs", 20.0);
220 dbl_value = arv_device_get_float_feature_value (device, "ExposureTimeAbs");
221 g_assert_cmpfloat (dbl_value, ==, 20.0);
222
223 values = arv_device_get_available_enumeration_feature_values (device, "GainAuto", &n_values);
224 g_assert (values != NULL);
225 g_assert_cmpint (n_values, ==, 3);
226 g_free (values);
227
228 string_values = arv_device_get_available_enumeration_feature_values_as_strings (device, "GainAuto", &n_values);
229 g_assert (string_values != NULL);
230 g_assert_cmpint (n_values, ==, 3);
231 g_free (string_values);
232
233 arv_device_set_string_feature_value (device, "TestStringReg", "String");
234 string_value = arv_device_get_string_feature_value (device, "TestStringReg");
235 g_assert_cmpstr (string_value, ==, "String");
236
237 status = arv_device_get_status (device);
238 g_assert_cmpint (status, ==, ARV_DEVICE_STATUS_SUCCESS);
239
240 g_object_unref (device);
241 }
242
243 static void
fake_device_error_test(void)244 fake_device_error_test (void)
245 {
246 ArvDevice *device;
247 ArvDeviceStatus status;
248 int int_value;
249 double boolean_value;
250
251 device = arv_fake_device_new ("TEST0");
252 g_assert (ARV_IS_FAKE_DEVICE (device));
253
254 int_value = arv_device_get_integer_feature_value (device, "Unknown");
255 g_assert_cmpint (int_value, ==, 0);
256
257 boolean_value = arv_device_get_boolean_feature_value (device, "Unknown");
258 g_assert_cmpint (boolean_value, ==, 0);
259
260 status = arv_device_get_status (device);
261 g_assert_cmpint (status, ==, ARV_DEVICE_STATUS_SUCCESS);
262
263 g_object_unref (device);
264 }
265
266 static void
fill_pattern_cb(ArvBuffer * buffer,void * fill_pattern_data,guint32 exposure_time_us,guint32 gain,ArvPixelFormat pixel_format)267 fill_pattern_cb (ArvBuffer *buffer, void *fill_pattern_data, guint32 exposure_time_us, guint32 gain, ArvPixelFormat pixel_format)
268 {
269 gint *counter = fill_pattern_data;
270
271 (*counter)++;
272 }
273
274 static void
fake_stream_test(void)275 fake_stream_test (void)
276 {
277 ArvCamera *camera;
278 ArvDevice *device;
279 ArvFakeCamera *fake_camera;
280 ArvStream *stream;
281 ArvBuffer *buffer;
282 guint64 n_completed_buffers;
283 guint64 n_failures;
284 guint64 n_underruns;
285 gint n_input_buffers;
286 gint n_output_buffers;
287 gint payload;
288 gint counter = 0;
289
290 camera = arv_camera_new ("Fake_1");
291 g_assert (ARV_IS_CAMERA (camera));
292
293 device = arv_camera_get_device (camera);
294 g_assert (ARV_IS_DEVICE (device));
295
296 fake_camera = arv_fake_device_get_fake_camera (ARV_FAKE_DEVICE (device));
297 g_assert (ARV_IS_FAKE_CAMERA (fake_camera));
298
299 stream = arv_camera_create_stream (camera, NULL, NULL);
300 g_assert (ARV_IS_STREAM (stream));
301
302 arv_fake_camera_set_fill_pattern (fake_camera, fill_pattern_cb, &counter);
303
304 payload = arv_camera_get_payload (camera);
305 arv_stream_push_buffer (stream, arv_buffer_new (payload, NULL));
306 arv_camera_set_acquisition_mode (camera, ARV_ACQUISITION_MODE_SINGLE_FRAME);
307 arv_camera_start_acquisition (camera);
308 buffer = arv_stream_pop_buffer (stream);
309 arv_camera_stop_acquisition (camera);
310
311 arv_fake_camera_set_fill_pattern (fake_camera, NULL, NULL);
312
313 g_assert_cmpint (counter, ==, 1);
314
315 g_assert (ARV_IS_BUFFER (buffer));
316
317 arv_stream_get_statistics (stream, &n_completed_buffers, &n_failures, &n_underruns);
318 g_assert_cmpint (n_completed_buffers, == ,1);
319 g_assert_cmpint (n_failures, ==, 0);
320 g_assert_cmpint (n_underruns, ==, 0);
321
322 arv_stream_get_n_buffers (stream, &n_input_buffers, &n_output_buffers);
323 g_assert_cmpint (n_input_buffers, ==, 0);
324 g_assert_cmpint (n_output_buffers, ==, 0);
325
326 g_clear_object (&buffer);
327 g_clear_object (&stream);
328 g_clear_object (&camera);
329 }
330
331 int
main(int argc,char * argv[])332 main (int argc, char *argv[])
333 {
334 int result;
335
336 g_test_init (&argc, &argv, NULL);
337
338 arv_g_type_init ();
339
340 arv_enable_interface ("Fake");
341
342 arv_update_device_list ();
343
344 arv_set_fake_camera_genicam_filename (GENICAM_FILENAME);
345
346 g_test_add_func ("/fake/load-fake-camera-genicam", load_fake_camera_genicam_test);
347 g_test_add_func ("/fake/trigger-registers", trigger_registers_test);
348 g_test_add_func ("/fake/registers", registers_test);
349 g_test_add_func ("/fake/fake-device", fake_device_test);
350 g_test_add_func ("/fake/fake-device-error", fake_device_error_test);
351 g_test_add_func ("/fake/fake-stream", fake_stream_test);
352
353 result = g_test_run();
354
355 arv_shutdown ();
356
357 return result;
358 }
359
360