1 #include <glib.h>
2 #include <arv.h>
3 #include <string.h>
4 
5 #define ARAVIS_COMPILATION
6 #include "../src/arvbufferprivate.h"
7 
8 typedef struct {
9 	const char *name;
10 	GType value_type;
11 } NodeTypes;
12 
13 NodeTypes node_value_types[] = {
14 	{"RWFloat",			G_TYPE_DOUBLE},
15 	{"P_RWFloat_Min",		G_TYPE_DOUBLE},
16 	{"P_RWFloat_Max",		G_TYPE_DOUBLE},
17 	{"P_RWFloat_Inc",		G_TYPE_DOUBLE},
18 	{"P_RWFloat",			G_TYPE_DOUBLE},
19 	{"RWBoolean",			G_TYPE_BOOLEAN},
20 	{"P_RWBoolean",			G_TYPE_BOOLEAN},
21 	{"RWInteger",			G_TYPE_INT64},
22 	{"P_RWInteger",			G_TYPE_INT64},
23 	{"P_RWInteger_Min",		G_TYPE_INT64},
24 	{"P_RWInteger_Max",		G_TYPE_INT64},
25 	{"P_RWInteger_Inc",		G_TYPE_INT64},
26 	{"Enumeration",			G_TYPE_INT64},
27 	{"EnumerationValue",		G_TYPE_INT64},
28 	{"IntRegisterA",		G_TYPE_INT64},
29 	{"IntRegisterB",		G_TYPE_INT64},
30 	{"IntSwissKnifeTest",		G_TYPE_INT64},
31 	{"DeviceUserID",		G_TYPE_STRING}
32 };
33 
34 static void
node_value_type_test(void)35 node_value_type_test (void)
36 {
37 	ArvDevice *device;
38 	ArvGc *genicam;
39 	ArvGcNode *node;
40 	int i;
41 
42 	device = arv_fake_device_new ("TEST0");
43 	g_assert (ARV_IS_FAKE_DEVICE (device));
44 
45 	genicam = arv_device_get_genicam (device);
46 	g_assert (ARV_IS_GC (genicam));
47 
48 	for (i = 0; i < G_N_ELEMENTS (node_value_types); i++) {
49 		node = arv_gc_get_node (genicam, node_value_types[i].name);
50 		g_assert (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == node_value_types[i].value_type);
51 	}
52 
53 	g_object_unref (device);
54 }
55 
56 static void
integer_test(void)57 integer_test (void)
58 {
59 	ArvDevice *device;
60 	ArvGc *genicam;
61 	ArvGcNode *node;
62 	gint64 v_int64;
63 	const char *v_string;
64 
65 	device = arv_fake_device_new ("TEST0");
66 	g_assert (ARV_IS_FAKE_DEVICE (device));
67 
68 	genicam = arv_device_get_genicam (device);
69 	g_assert (ARV_IS_GC (genicam));
70 
71 	node = arv_gc_get_node (genicam, "RWInteger");
72 	g_assert (ARV_IS_GC_INTEGER_NODE (node));
73 
74 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
75 	g_assert_cmpint (v_int64, ==, 1);
76 
77 	v_int64 = arv_gc_integer_get_min (ARV_GC_INTEGER (node), NULL);
78 	g_assert_cmpint (v_int64, ==, -10);
79 
80 	v_int64 = arv_gc_integer_get_max (ARV_GC_INTEGER (node), NULL);
81 	g_assert_cmpint (v_int64, ==, 10);
82 
83 	v_int64 = arv_gc_integer_get_inc (ARV_GC_INTEGER (node), NULL);
84 	g_assert_cmpint (v_int64, ==, 2);
85 
86 	v_string = arv_gc_feature_node_get_value_as_string (ARV_GC_FEATURE_NODE (node), NULL);
87 	g_assert_cmpstr (v_string, ==, "1");
88 
89 	arv_gc_integer_set_value (ARV_GC_INTEGER (node), 2, NULL);
90 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
91 	g_assert_cmpint (v_int64, ==, 2);
92 
93 	node = arv_gc_get_node (genicam, "P_RWInteger");
94 	g_assert (ARV_IS_GC_INTEGER_NODE (node));
95 
96 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
97 	g_assert_cmpint (v_int64, ==, 2);
98 
99 	v_int64 = arv_gc_integer_get_min (ARV_GC_INTEGER (node), NULL);
100 	g_assert_cmpint (v_int64, ==, -20);
101 
102 	v_int64 = arv_gc_integer_get_max (ARV_GC_INTEGER (node), NULL);
103 	g_assert_cmpint (v_int64, ==, 20);
104 
105 	v_int64 = arv_gc_integer_get_inc (ARV_GC_INTEGER (node), NULL);
106 	g_assert_cmpint (v_int64, ==, 3);
107 
108 	g_object_unref (device);
109 }
110 
111 static void
indexed_test(void)112 indexed_test (void)
113 {
114 	ArvDevice *device;
115 	ArvGc *genicam;
116 	ArvGcNode *node;
117 	ArvGcNode *selector;
118 	gint64 v_int64;
119 	double v_double;
120 
121 	device = arv_fake_device_new ("TEST0");
122 	g_assert (ARV_IS_FAKE_DEVICE (device));
123 
124 	genicam = arv_device_get_genicam (device);
125 	g_assert (ARV_IS_GC (genicam));
126 
127 	node = arv_gc_get_node (genicam, "Table");
128 	g_assert (ARV_IS_GC_INTEGER_NODE (node));
129 
130 	selector = arv_gc_get_node (genicam, "TableSelector");
131 	g_assert (ARV_IS_GC_INTEGER_NODE (selector));
132 
133 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
134 	g_assert_cmpint (v_int64, ==, 200);
135 
136 	arv_gc_integer_set_value (ARV_GC_INTEGER (node), 150, NULL);
137 
138 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
139 	g_assert_cmpint (v_int64, ==, 150);
140 
141 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), -1, NULL);
142 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
143 	g_assert_cmpint (v_int64, ==, 600);
144 
145 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), 10, NULL);
146 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
147 	g_assert_cmpint (v_int64, ==, 100);
148 
149 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), 20, NULL);
150 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
151 	g_assert_cmpint (v_int64, ==, 150);
152 
153 	node = arv_gc_get_node (genicam, "Multiplexer");
154 	g_assert (ARV_IS_GC_INTEGER_NODE (node));
155 
156 	selector = arv_gc_get_node (genicam, "MultiplexerSelector");
157 	g_assert (ARV_IS_GC_INTEGER_NODE (selector));
158 
159 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (selector), NULL);
160 	g_assert_cmpint (v_int64, ==, 20);
161 
162 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
163 	g_assert_cmpint (v_int64, ==, 200);
164 
165 	arv_gc_integer_set_value (ARV_GC_INTEGER (node), 150, NULL);
166 
167 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
168 	g_assert_cmpint (v_int64, ==, 150);
169 
170 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), -1, NULL);
171 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
172 	g_assert_cmpint (v_int64, ==, 600);
173 
174 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), 10, NULL);
175 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
176 	g_assert_cmpint (v_int64, ==, 100);
177 
178 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), 20, NULL);
179 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
180 	g_assert_cmpint (v_int64, ==, 150);
181 
182 	node = arv_gc_get_node (genicam, "FloatTable");
183 	g_assert (ARV_IS_GC_FLOAT_NODE (node));
184 
185 	selector = arv_gc_get_node (genicam, "FloatTableSelector");
186 	g_assert (ARV_IS_GC_INTEGER_NODE (selector));
187 
188 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
189 	g_assert_cmpfloat (v_double, ==, 200.2);
190 
191 	arv_gc_float_set_value (ARV_GC_FLOAT (node), 150.15, NULL);
192 
193 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
194 	g_assert_cmpfloat (v_double, ==, 150.15);
195 
196 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), -1, NULL);
197 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
198 	g_assert_cmpfloat (v_double, ==, 600.6);
199 
200 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), 10, NULL);
201 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
202 	g_assert_cmpfloat (v_double, ==, 100.1);
203 
204 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), 20, NULL);
205 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
206 	g_assert_cmpint (v_double, ==, 150.15);
207 
208 	node = arv_gc_get_node (genicam, "FloatMultiplexer");
209 	g_assert (ARV_IS_GC_FLOAT_NODE (node));
210 
211 	selector = arv_gc_get_node (genicam, "FloatMultiplexerSelector");
212 	g_assert (ARV_IS_GC_INTEGER_NODE (selector));
213 
214 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (selector), NULL);
215 	g_assert_cmpint (v_int64, ==, 20);
216 
217 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
218 	g_assert_cmpfloat (v_double, ==, 200.2);
219 
220 	arv_gc_float_set_value (ARV_GC_FLOAT (node), 150.15, NULL);
221 
222 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
223 	g_assert_cmpfloat (v_double, ==, 150.15);
224 
225 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), -1, NULL);
226 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
227 	g_assert_cmpfloat (v_double, ==, 600.6);
228 
229 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), 10, NULL);
230 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
231 	g_assert_cmpfloat (v_double, ==, 100.1);
232 
233 	arv_gc_integer_set_value (ARV_GC_INTEGER (selector), 20, NULL);
234 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
235 	g_assert_cmpfloat (v_double, ==, 150.15);
236 
237 	g_object_unref (device);
238 }
239 
240 static void
boolean_test(void)241 boolean_test (void)
242 {
243 	ArvDevice *device;
244 	ArvGc *genicam;
245 	ArvGcNode *node;
246 	ArvGcNode *node_b;
247 	gboolean v_boolean;
248 	const char *v_string;
249 	gint64 v_int64;
250 
251 	device = arv_fake_device_new ("TEST0");
252 	g_assert (ARV_IS_FAKE_DEVICE (device));
253 
254 	genicam = arv_device_get_genicam (device);
255 	g_assert (ARV_IS_GC (genicam));
256 
257 	node = arv_gc_get_node (genicam, "RWBoolean");
258 	g_assert (ARV_IS_GC_BOOLEAN (node));
259 	g_assert (ARV_IS_GC_INTEGER (node));
260 
261 	v_boolean = arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node), NULL);
262 	g_assert_cmpint (v_boolean, ==, TRUE);
263 
264 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
265 	g_assert_cmpint (v_int64, ==, 1);
266 
267 	v_string = arv_gc_feature_node_get_value_as_string (ARV_GC_FEATURE_NODE (node), NULL);
268 	g_assert_cmpstr (v_string, ==, "true");
269 
270 	arv_gc_boolean_set_value (ARV_GC_BOOLEAN (node), 0, NULL);
271 	v_boolean = arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node), NULL);
272 	g_assert_cmpint (v_boolean, ==, FALSE);
273 
274 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
275 	g_assert_cmpint (v_int64, ==, 0);
276 
277 	v_string = arv_gc_feature_node_get_value_as_string (ARV_GC_FEATURE_NODE (node), NULL);
278 	g_assert_cmpstr (v_string, ==, "false");
279 
280 	node = arv_gc_get_node (genicam, "P_RWBoolean");
281 	g_assert (ARV_IS_GC_BOOLEAN (node));
282 
283 	v_boolean = arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node), NULL);
284 	g_assert_cmpint (v_boolean, ==, TRUE);
285 
286 	node_b = arv_gc_get_node (genicam, "RWBooleanValue");
287 	g_assert (ARV_IS_GC_INTEGER (node_b));
288 
289 	arv_gc_integer_set_value (ARV_GC_INTEGER (node_b), 42, NULL);
290 
291 	v_boolean = arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node), NULL);
292 	g_assert_cmpint (v_boolean, ==, FALSE);
293 
294 	g_object_unref (device);
295 }
296 
297 static void
float_test(void)298 float_test (void)
299 {
300 	ArvDevice *device;
301 	ArvGc *genicam;
302 	ArvGcNode *node;
303 	double v_double;
304 	const char *v_string;
305 
306 	device = arv_fake_device_new ("TEST0");
307 	g_assert (ARV_IS_FAKE_DEVICE (device));
308 
309 	genicam = arv_device_get_genicam (device);
310 	g_assert (ARV_IS_GC (genicam));
311 
312 	node = arv_gc_get_node (genicam, "RWFloat");
313 	g_assert (ARV_IS_GC_FLOAT_NODE (node));
314 
315 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
316 	g_assert_cmpfloat (v_double, ==, 0.1);
317 
318 	v_double = arv_gc_float_get_min (ARV_GC_FLOAT (node), NULL);
319 	g_assert_cmpfloat (v_double, ==, -10.0);
320 
321 	v_double = arv_gc_float_get_max (ARV_GC_FLOAT (node), NULL);
322 	g_assert_cmpfloat (v_double, ==, 10.0);
323 
324 	v_double = arv_gc_float_get_inc (ARV_GC_FLOAT (node), NULL);
325 	g_assert_cmpfloat (v_double, ==, 2.0);
326 
327 	v_string = arv_gc_feature_node_get_value_as_string (ARV_GC_FEATURE_NODE (node), NULL);
328 	g_assert_cmpstr (v_string, ==, "0.1");
329 
330 	arv_gc_float_set_value (ARV_GC_FLOAT (node), 0.2, NULL);
331 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
332 	g_assert_cmpfloat (v_double, ==, 0.2);
333 
334 	node = arv_gc_get_node (genicam, "P_RWFloat");
335 	g_assert (ARV_IS_GC_FLOAT_NODE (node));
336 
337 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
338 	g_assert_cmpfloat (v_double, ==, 0.2);
339 
340 	v_double = arv_gc_float_get_min (ARV_GC_FLOAT (node), NULL);
341 	g_assert_cmpfloat (v_double, ==, -20.0);
342 
343 	v_double = arv_gc_float_get_max (ARV_GC_FLOAT (node), NULL);
344 	g_assert_cmpfloat (v_double, ==, 20.0);
345 
346 	v_double = arv_gc_float_get_inc (ARV_GC_FLOAT (node), NULL);
347 	g_assert_cmpfloat (v_double, ==, 3.0);
348 
349 	g_object_unref (device);
350 }
351 
352 static void
enumeration_test(void)353 enumeration_test (void)
354 {
355 	ArvDevice *device;
356 	ArvGc *genicam;
357 	ArvGcNode *node;
358 	gint64 v_int64;
359 	gint64 *values;
360 	guint n_values;
361 	const char *v_string;
362 
363 	device = arv_fake_device_new ("TEST0");
364 	g_assert (ARV_IS_FAKE_DEVICE (device));
365 
366 	genicam = arv_device_get_genicam (device);
367 	g_assert (ARV_IS_GC (genicam));
368 
369 	node = arv_gc_get_node (genicam, "Enumeration");
370 	g_assert (ARV_IS_GC_ENUMERATION (node));
371 	g_assert (ARV_IS_GC_INTEGER (node));
372 	g_assert (ARV_IS_GC_STRING (node));
373 
374 	v_int64 = arv_gc_enumeration_get_int_value (ARV_GC_ENUMERATION (node), NULL);
375 	g_assert_cmpint (v_int64, ==, 0);
376 
377 	values = arv_gc_enumeration_get_available_int_values (ARV_GC_ENUMERATION (node), &n_values, NULL);
378 	g_assert_cmpint (n_values, ==, 2);
379 	g_assert (values != NULL);
380 	g_free (values);
381 
382 	arv_gc_enumeration_set_string_value (ARV_GC_ENUMERATION (node), "Entry1", NULL);
383 
384 	v_int64 = arv_gc_enumeration_get_int_value (ARV_GC_ENUMERATION (node), NULL);
385 	g_assert_cmpint (v_int64, ==, 1);
386 
387 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
388 	g_assert_cmpint (v_int64, ==, 1);
389 
390 	v_string = arv_gc_string_get_value (ARV_GC_STRING (node), NULL);
391 	g_assert_cmpstr (v_string, ==, "Entry1");
392 
393 	arv_gc_string_set_value (ARV_GC_STRING (node), "Entry0", NULL);
394 
395 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
396 	g_assert_cmpint (v_int64, ==, 0);
397 
398 	v_string = arv_gc_string_get_value (ARV_GC_STRING (node), NULL);
399 	g_assert_cmpstr (v_string, ==, "Entry0");
400 
401 	v_int64 = arv_gc_string_get_max_length (ARV_GC_STRING (node), NULL);
402 	g_assert_cmpint (v_int64, ==, strlen ("EntryNotImplemented"));
403 
404 	g_object_unref (device);
405 }
406 
407 static void
swiss_knife_test(void)408 swiss_knife_test (void)
409 {
410 	ArvDevice *device;
411 	ArvGc *genicam;
412 	ArvGcNode *node;
413 	gint64 value;
414 
415 	device = arv_fake_device_new ("TEST0");
416 	g_assert (ARV_IS_FAKE_DEVICE (device));
417 
418 	genicam = arv_device_get_genicam (device);
419 	g_assert (ARV_IS_GC (genicam));
420 
421 	node = arv_gc_get_node (genicam, "IntSwissKnifeTest");
422 	g_assert (ARV_IS_GC_SWISS_KNIFE (node));
423 
424 	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
425 	g_assert_cmpint (value, ==, 0x1234);
426 
427 	node = arv_gc_get_node (genicam, "IntSwissKnifeTestEntity");
428 	g_assert (ARV_IS_GC_SWISS_KNIFE (node));
429 
430 	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
431 	g_assert_cmpint (value, ==, 0x10305070);
432 
433 	node = arv_gc_get_node (genicam, "IntSwissKnifeTestEntity2");
434 	g_assert (ARV_IS_GC_SWISS_KNIFE (node));
435 
436 	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
437 	g_assert_cmpint (value, ==, 3);
438 
439 	node = arv_gc_get_node (genicam, "IntSwissKnifeBug699228");
440 	g_assert (ARV_IS_GC_SWISS_KNIFE (node));
441 
442 	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
443 	g_assert_cmpint (value, ==, 4);
444 
445 	node = arv_gc_get_node (genicam, "IntSwissKnifeTestSubAndConstant");
446 	g_assert (ARV_IS_GC_SWISS_KNIFE (node));
447 
448 	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
449 	g_assert_cmpint (value, ==, 140);
450 
451 	g_object_unref (device);
452 }
453 
454 static void
converter_test(void)455 converter_test (void)
456 {
457 	ArvDevice *device;
458 	ArvGc *genicam;
459 	ArvGcNode *node;
460 	double v_double;
461 	gint64 v_int64;
462 
463 	device = arv_fake_device_new ("TEST0");
464 	g_assert (ARV_IS_FAKE_DEVICE (device));
465 
466 	genicam = arv_device_get_genicam (device);
467 	g_assert (ARV_IS_GC (genicam));
468 
469 	node = arv_gc_get_node (genicam, "Converter");
470 	g_assert (ARV_IS_GC_CONVERTER (node));
471 
472 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
473 	g_assert_cmpfloat (v_double, ==, 200.0);
474 
475 	arv_gc_feature_node_set_value_from_string (ARV_GC_FEATURE_NODE (node), "100.0", NULL);
476 	v_double = arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL);
477 	g_assert_cmpfloat (v_double, ==, 100.0);
478 
479 	node = arv_gc_get_node (genicam, "IntConverter");
480 	g_assert (ARV_IS_GC_CONVERTER (node));
481 
482 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
483 	g_assert_cmpint (v_int64, ==, 5);
484 
485 	arv_gc_feature_node_set_value_from_string (ARV_GC_FEATURE_NODE (node), "100", NULL);
486 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
487 	g_assert_cmpint (v_int64, ==, 100);
488 
489 	node = arv_gc_get_node (genicam, "Enumeration");
490 	g_assert (ARV_IS_GC_ENUMERATION (node));
491 	arv_gc_integer_set_value (ARV_GC_INTEGER (node), 1, NULL);
492 
493 	node = arv_gc_get_node (genicam, "ConverterEnumeration");
494 	g_assert (ARV_IS_GC_CONVERTER (node));
495 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
496 	g_assert_cmpint (v_int64, ==, 5);
497 
498 	node = arv_gc_get_node (genicam, "IntConverterTestSubAndConstant");
499 	g_assert (ARV_IS_GC_CONVERTER (node));
500 
501 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
502 	g_assert_cmpint (v_int64, ==, 10000);
503 
504 	arv_gc_integer_set_value (ARV_GC_INTEGER (node), 100, NULL);
505 	v_int64 = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL);
506 	g_assert_cmpint (v_int64, ==, 1000);
507 
508 	g_object_unref (device);
509 }
510 
511 static void
register_test(void)512 register_test (void)
513 {
514 	ArvDevice *device;
515 	ArvGc *genicam;
516 	ArvGcNode *node_a;
517 	ArvGcNode *node_b;
518 	ArvGcNode *node_c;
519 	ArvGcNode *node_sc;
520 	gint64 value;
521 
522 	device = arv_fake_device_new ("TEST0");
523 	g_assert (ARV_IS_FAKE_DEVICE (device));
524 
525 	genicam = arv_device_get_genicam (device);
526 	g_assert (ARV_IS_GC (genicam));
527 
528 	node_a = arv_gc_get_node (genicam, "IntRegisterA");
529 	g_assert (ARV_IS_GC_REGISTER (node_a));
530 
531 	value = arv_gc_register_get_address (ARV_GC_REGISTER (node_a), NULL);
532 	g_assert_cmpint (value, ==, 0x1050);
533 
534 	node_b = arv_gc_get_node (genicam, "IntRegisterB");
535 	g_assert (ARV_IS_GC_REGISTER (node_b));
536 
537 	value = arv_gc_register_get_address (ARV_GC_REGISTER (node_b), NULL);
538 	g_assert_cmpint (value, ==, 0x20ff);
539 
540 	node_c = arv_gc_get_node (genicam, "IntRegisterC");
541 	g_assert (ARV_IS_GC_REGISTER (node_c));
542 
543 	arv_gc_integer_set_value (ARV_GC_INTEGER (node_c), 0, NULL);
544 
545 	node_sc = arv_gc_get_node (genicam, "IntSignedRegisterC");
546 	g_assert (ARV_IS_GC_REGISTER (node_sc));
547 
548 	arv_gc_integer_set_value (ARV_GC_INTEGER (node_sc), -1, NULL);
549 
550 	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_sc), NULL);
551 	g_assert_cmpint (value, ==, -1);
552 
553 	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_c), NULL);
554 	g_assert_cmpint (value, ==, 0x00000000ffffffff);
555 
556 	arv_gc_integer_set_value (ARV_GC_INTEGER (node_sc), 0x7fffffff, NULL);
557 
558 	value = arv_gc_integer_get_value (ARV_GC_INTEGER (node_sc), NULL);
559 	g_assert_cmpint (value, ==, 0x7fffffff);
560 
561 	g_object_unref (device);
562 }
563 
564 GRegex *arv_gv_device_get_url_regex (void);
565 
566 static void
url_test(void)567 url_test (void)
568 {
569 	char **tokens;
570 
571 	tokens = g_regex_split (arv_gv_device_get_url_regex (), "Local:Basler_Ace_GigE_e7c9b87e_Version_3_3.zip;c0000000;10cca", 0);
572 
573 	g_assert_cmpint (g_strv_length (tokens), ==, 6);
574 
575 	g_assert_cmpstr (tokens[0], ==, "");
576 	g_assert_cmpstr (tokens[1], ==, "Local:");
577 	g_assert_cmpstr (tokens[2], ==, "Basler_Ace_GigE_e7c9b87e_Version_3_3.zip");
578 	g_assert_cmpstr (tokens[3], ==, "c0000000");
579 	g_assert_cmpstr (tokens[4], ==, "10cca");
580 
581 	g_strfreev (tokens);
582 
583 	tokens = g_regex_split (arv_gv_device_get_url_regex (), "Local:C4_2040_GigE_1.0.0.zip;0x8C400904;0x4D30", 0);
584 
585 	g_assert_cmpint (g_strv_length (tokens), ==, 6);
586 
587 	g_assert_cmpstr (tokens[0], ==, "");
588 	g_assert_cmpstr (tokens[1], ==, "Local:");
589 	g_assert_cmpstr (tokens[2], ==, "C4_2040_GigE_1.0.0.zip");
590 	g_assert_cmpstr (tokens[3], ==, "8C400904");
591 	g_assert_cmpstr (tokens[4], ==, "4D30");
592 
593 	g_strfreev (tokens);
594 
595 }
596 
597 static void
mandatory_test(void)598 mandatory_test (void)
599 {
600 	ArvDevice *device;
601 	ArvGc *genicam;
602 	ArvGcNode *node;
603 
604 	device = arv_fake_device_new ("TEST0");
605 	g_assert (ARV_IS_FAKE_DEVICE (device));
606 
607 	genicam = arv_device_get_genicam (device);
608 	g_assert (ARV_IS_GC (genicam));
609 
610 	node = arv_gc_get_node (genicam, "TLParamsLocked");
611 	g_assert (ARV_IS_GC_INTEGER (node));
612 
613 	g_object_unref (device);
614 }
615 
616 typedef struct __attribute__((__packed__)) {
617 	guint32 id;
618 	guint32 size;
619 } ArvChunkInfos;
620 
621 static ArvBuffer *
create_buffer_with_chunk_data(void)622 create_buffer_with_chunk_data (void)
623 {
624 	ArvBuffer *buffer;
625 	ArvChunkInfos *chunk_infos;
626 	char *data;
627 	size_t size;
628 	guint32 *int_value;
629 	guint offset;
630 	double float_value;
631 	int i;
632 
633 	size = 64 + 8 + 64 + 8 + 4 * sizeof (ArvChunkInfos);
634 
635 	buffer = arv_buffer_new (size, NULL);
636 	buffer->priv->gvsp_payload_type = ARV_GVSP_PAYLOAD_TYPE_CHUNK_DATA;
637 	buffer->priv->status = ARV_BUFFER_STATUS_SUCCESS;
638 	data = (char *) arv_buffer_get_data (buffer, &size);
639 
640 	memset ((char *) data, '\0', size);
641 
642 	offset = size - sizeof (ArvChunkInfos);
643 	chunk_infos = (ArvChunkInfos *) &data[offset];
644 	chunk_infos->id = GUINT32_TO_BE (0x12345678);
645 	chunk_infos->size = GUINT32_TO_BE (8);
646 
647 	int_value = (guint32 *) &data[offset - 8];
648 	*int_value = GUINT32_TO_BE (0x11223344);
649 
650 	offset -= 8 + sizeof (ArvChunkInfos);
651 	chunk_infos = (ArvChunkInfos *) &data[offset];
652 	chunk_infos->id = GUINT32_TO_BE (0x87654321);
653 	chunk_infos->size = GUINT32_TO_BE (64);
654 
655 	memcpy ((char *) &data[offset - 64], "Hello" ,sizeof ("Hello"));
656 
657 	offset -= 64 + sizeof (ArvChunkInfos);
658 	chunk_infos = (ArvChunkInfos *) &data[offset];
659 	chunk_infos->id = GUINT32_TO_BE (0x12345679);
660 	chunk_infos->size = GUINT32_TO_BE (8);
661 
662 	float_value = 1.1;
663 	for (i = 0; i < sizeof (float_value); i++)
664 		data[offset - i - 1] = ((char *) &float_value)[i];
665 
666 	offset -= 8 + sizeof (ArvChunkInfos);
667 	chunk_infos = (ArvChunkInfos *) &data[offset];
668 	chunk_infos->id = GUINT32_TO_BE (0x44444444);
669 	chunk_infos->size = GUINT32_TO_BE (64);
670 
671 	g_assert (offset == 64);
672 
673 #if 0
674 	{
675 		GString *string;
676 		string= g_string_new ("");
677 		arv_g_string_append_hex_dump (string, data, size);
678 		printf ("%s\n", string->str);
679 		g_string_free (string, TRUE);
680 	}
681 #endif
682 
683 	return buffer;
684 }
685 
686 static void
chunk_data_test(void)687 chunk_data_test (void)
688 {
689 	ArvDevice *device;
690 	ArvChunkParser *parser;
691 	ArvBuffer *buffer;
692 	ArvGc *genicam;
693 	guint32 int_value;
694 	double float_value;
695 	const char *chunk_data;
696 	const char *data;
697 	const char *string_value;
698 	size_t size;
699 	size_t chunk_data_size;
700 
701 	device = arv_fake_device_new ("TEST0");
702 	g_assert (ARV_IS_FAKE_DEVICE (device));
703 
704 	parser = arv_device_create_chunk_parser (device);
705 	g_assert (ARV_IS_CHUNK_PARSER (parser));
706 
707 	g_object_get (parser, "genicam", &genicam, NULL);
708 	g_object_unref (genicam);
709 
710 	buffer = create_buffer_with_chunk_data ();
711 	g_assert (ARV_IS_BUFFER (buffer));
712 
713 	data = arv_buffer_get_data (buffer, &size);
714 
715 	chunk_data = arv_buffer_get_chunk_data (buffer, 0x12345678, &chunk_data_size);
716 	g_assert (chunk_data != NULL);
717 	g_assert_cmpint (chunk_data_size, ==, 8);
718 	g_assert_cmpint (chunk_data - data, ==, 64 + 64 + 8 + 3 * sizeof (ArvChunkInfos));
719 
720 	chunk_data = arv_buffer_get_chunk_data (buffer, 0x12345679, &chunk_data_size);
721 	g_assert (chunk_data != NULL);
722 	g_assert_cmpint (chunk_data_size, ==, 8);
723 	g_assert_cmpint (chunk_data - data, ==, 64 + sizeof (ArvChunkInfos));
724 
725 	chunk_data = arv_buffer_get_chunk_data (buffer, 0x87654321, &chunk_data_size);
726 	g_assert (chunk_data != NULL);
727 	g_assert_cmpint (chunk_data_size, ==, 64);
728 	g_assert_cmpint (chunk_data - data, ==, 64 + 8 + 2 * sizeof (ArvChunkInfos));
729 
730 	chunk_data = arv_buffer_get_chunk_data (buffer, 0x01020304, &chunk_data_size);
731 	g_assert (chunk_data == NULL);
732 	g_assert_cmpint (chunk_data_size, ==, 0);
733 
734 	int_value = arv_chunk_parser_get_integer_value (parser, buffer, "ChunkInt");
735 	g_assert_cmpint (int_value, ==, 0x11223344);
736 
737 	float_value = arv_chunk_parser_get_float_value (parser, buffer, "ChunkFloat");
738 	g_assert_cmpfloat (float_value, ==, 1.1);
739 
740 	string_value = arv_chunk_parser_get_string_value (parser, buffer, "ChunkString");
741 	g_assert_cmpstr (string_value, ==, "Hello");
742 
743 	arv_chunk_parser_get_integer_value (parser, buffer, "Dummy");
744 	arv_chunk_parser_get_float_value (parser, buffer, "Dummy");
745 	arv_chunk_parser_get_string_value (parser, buffer, "Dummy");
746 
747 	g_object_unref (buffer);
748 	g_object_unref (parser);
749 	g_object_unref (device);
750 }
751 
752 int
main(int argc,char * argv[])753 main (int argc, char *argv[])
754 {
755 	int result;
756 
757 	g_test_init (&argc, &argv, NULL);
758 
759 	arv_g_type_init ();
760 
761 	arv_set_fake_camera_genicam_filename (GENICAM_FILENAME);
762 
763 	g_test_add_func ("/genicam/value-type", node_value_type_test);
764 	g_test_add_func ("/genicam/integer", integer_test);
765 	g_test_add_func ("/genicam/boolean", boolean_test);
766 	g_test_add_func ("/genicam/float", float_test);
767 	g_test_add_func ("/genicam/enumeration", enumeration_test);
768 	g_test_add_func ("/genicam/swissknife", swiss_knife_test);
769 	g_test_add_func ("/genicam/converter", converter_test);
770 	g_test_add_func ("/genicam/register", register_test);
771 	g_test_add_func ("/genicam/url", url_test);
772 	g_test_add_func ("/genicam/mandatory", mandatory_test);
773 	g_test_add_func ("/genicam/chunk-data", chunk_data_test);
774 	g_test_add_func ("/genicam/indexed", indexed_test);
775 
776 	result = g_test_run();
777 
778 	arv_shutdown ();
779 
780 	return result;
781 }
782 
783