1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal-recursive-util.c Would be in dbus-marshal-recursive.c, but only used in bus/tests
4 * Copyright (C) 2004, 2005 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifdef DBUS_BUILD_TESTS
28 #include "dbus-marshal-recursive.h"
29 #include "dbus-marshal-basic.h"
30 #include "dbus-internals.h"
34 basic_value_zero (DBusBasicValue *value)
37 #ifdef DBUS_HAVE_INT64
40 value->u64.first32 = 0;
41 value->u64.second32 = 0;
46 basic_value_equal (int type,
50 if (type == DBUS_TYPE_STRING ||
51 type == DBUS_TYPE_SIGNATURE ||
52 type == DBUS_TYPE_OBJECT_PATH)
54 return strcmp (lhs->str, rhs->str) == 0;
58 #ifdef DBUS_HAVE_INT64
59 return lhs->u64 == rhs->u64;
61 return lhs->u64.first32 == rhs->u64.first32 &&
62 lhs->u64.second32 == rhs->u64.second32;
68 equal_values_helper (DBusTypeReader *lhs,
74 lhs_type = _dbus_type_reader_get_current_type (lhs);
75 rhs_type = _dbus_type_reader_get_current_type (rhs);
77 if (lhs_type != rhs_type)
80 if (lhs_type == DBUS_TYPE_INVALID)
83 if (_dbus_type_is_basic (lhs_type))
85 DBusBasicValue lhs_value;
86 DBusBasicValue rhs_value;
88 basic_value_zero (&lhs_value);
89 basic_value_zero (&rhs_value);
91 _dbus_type_reader_read_basic (lhs, &lhs_value);
92 _dbus_type_reader_read_basic (rhs, &rhs_value);
94 return basic_value_equal (lhs_type, &lhs_value, &rhs_value);
98 DBusTypeReader lhs_sub;
99 DBusTypeReader rhs_sub;
101 _dbus_type_reader_recurse (lhs, &lhs_sub);
102 _dbus_type_reader_recurse (rhs, &rhs_sub);
104 return equal_values_helper (&lhs_sub, &rhs_sub);
109 * See whether the two readers point to identical data blocks.
111 * @param lhs reader 1
112 * @param rhs reader 2
113 * @returns #TRUE if the data blocks have the same values
116 _dbus_type_reader_equal_values (const DBusTypeReader *lhs,
117 const DBusTypeReader *rhs)
119 DBusTypeReader copy_lhs = *lhs;
120 DBusTypeReader copy_rhs = *rhs;
122 return equal_values_helper (©_lhs, ©_rhs);
126 #include "dbus-test.h"
127 #include "dbus-list.h"
131 /* Whether to do the OOM stuff (only with other expensive tests) */
132 #define TEST_OOM_HANDLING 0
133 /* We do start offset 0 through 9, to get various alignment cases. Still this
134 * obviously makes the test suite run 10x as slow.
136 #define MAX_INITIAL_OFFSET 9
138 /* Largest iteration count to test copying, realignment,
139 * etc. with. i.e. we only test this stuff with some of the smaller
142 #define MAX_ITERATIONS_FOR_EXPENSIVE_TESTS 1000
148 DBusString signature;
158 #define N_FENCE_BYTES 5
159 #define FENCE_BYTES_STR "abcde"
160 #define INITIAL_PADDING_BYTE '\0'
163 data_block_init (DataBlock *block,
167 if (!_dbus_string_init (&block->signature))
170 if (!_dbus_string_init (&block->body))
172 _dbus_string_free (&block->signature);
176 if (!_dbus_string_insert_bytes (&block->signature, 0, initial_offset,
177 INITIAL_PADDING_BYTE) ||
178 !_dbus_string_insert_bytes (&block->body, 0, initial_offset,
179 INITIAL_PADDING_BYTE) ||
180 !_dbus_string_append (&block->signature, FENCE_BYTES_STR) ||
181 !_dbus_string_append (&block->body, FENCE_BYTES_STR))
183 _dbus_string_free (&block->signature);
184 _dbus_string_free (&block->body);
188 block->byte_order = byte_order;
189 block->initial_offset = initial_offset;
195 data_block_save (DataBlock *block,
196 DataBlockState *state)
198 state->saved_sig_len = _dbus_string_get_length (&block->signature) - N_FENCE_BYTES;
199 state->saved_body_len = _dbus_string_get_length (&block->body) - N_FENCE_BYTES;
203 data_block_restore (DataBlock *block,
204 DataBlockState *state)
206 _dbus_string_delete (&block->signature,
207 state->saved_sig_len,
208 _dbus_string_get_length (&block->signature) - state->saved_sig_len - N_FENCE_BYTES);
209 _dbus_string_delete (&block->body,
210 state->saved_body_len,
211 _dbus_string_get_length (&block->body) - state->saved_body_len - N_FENCE_BYTES);
215 data_block_verify (DataBlock *block)
217 if (!_dbus_string_ends_with_c_str (&block->signature,
222 offset = _dbus_string_get_length (&block->signature) - N_FENCE_BYTES - 8;
226 _dbus_verbose_bytes_of_string (&block->signature,
228 _dbus_string_get_length (&block->signature) - offset);
229 _dbus_assert_not_reached ("block did not verify: bad bytes at end of signature");
231 if (!_dbus_string_ends_with_c_str (&block->body,
236 offset = _dbus_string_get_length (&block->body) - N_FENCE_BYTES - 8;
240 _dbus_verbose_bytes_of_string (&block->body,
242 _dbus_string_get_length (&block->body) - offset);
243 _dbus_assert_not_reached ("block did not verify: bad bytes at end of body");
246 _dbus_assert (_dbus_string_validate_nul (&block->signature,
247 0, block->initial_offset));
248 _dbus_assert (_dbus_string_validate_nul (&block->body,
249 0, block->initial_offset));
253 data_block_free (DataBlock *block)
255 data_block_verify (block);
257 _dbus_string_free (&block->signature);
258 _dbus_string_free (&block->body);
262 data_block_reset (DataBlock *block)
264 data_block_verify (block);
266 _dbus_string_delete (&block->signature,
267 block->initial_offset,
268 _dbus_string_get_length (&block->signature) - N_FENCE_BYTES - block->initial_offset);
269 _dbus_string_delete (&block->body,
270 block->initial_offset,
271 _dbus_string_get_length (&block->body) - N_FENCE_BYTES - block->initial_offset);
273 data_block_verify (block);
277 data_block_init_reader_writer (DataBlock *block,
278 DBusTypeReader *reader,
279 DBusTypeWriter *writer)
282 _dbus_type_reader_init (reader,
285 block->initial_offset,
287 block->initial_offset);
290 _dbus_type_writer_init (writer,
293 _dbus_string_get_length (&block->signature) - N_FENCE_BYTES,
295 _dbus_string_get_length (&block->body) - N_FENCE_BYTES);
299 real_check_expected_type (DBusTypeReader *reader,
301 const char *funcname,
306 t = _dbus_type_reader_get_current_type (reader);
310 _dbus_warn ("Read type %s while expecting %s at %s line %d\n",
311 _dbus_type_to_string (t),
312 _dbus_type_to_string (expected),
315 _dbus_assert_not_reached ("read wrong type");
319 #define check_expected_type(reader, expected) real_check_expected_type (reader, expected, _DBUS_FUNCTION_NAME, __LINE__)
321 #define NEXT_EXPECTING_TRUE(reader) do { if (!_dbus_type_reader_next (reader)) \
323 _dbus_warn ("_dbus_type_reader_next() should have returned TRUE at %s %d\n", \
324 _DBUS_FUNCTION_NAME, __LINE__); \
325 _dbus_assert_not_reached ("test failed"); \
329 #define NEXT_EXPECTING_FALSE(reader) do { if (_dbus_type_reader_next (reader)) \
331 _dbus_warn ("_dbus_type_reader_next() should have returned FALSE at %s %d\n", \
332 _DBUS_FUNCTION_NAME, __LINE__); \
333 _dbus_assert_not_reached ("test failed"); \
335 check_expected_type (reader, DBUS_TYPE_INVALID); \
338 typedef struct TestTypeNode TestTypeNode;
339 typedef struct TestTypeNodeClass TestTypeNodeClass;
340 typedef struct TestTypeNodeContainer TestTypeNodeContainer;
341 typedef struct TestTypeNodeContainerClass TestTypeNodeContainerClass;
345 const TestTypeNodeClass *klass;
348 struct TestTypeNodeContainer
354 struct TestTypeNodeClass
360 int subclass_detail; /* a bad hack to avoid a bunch of subclass casting */
362 dbus_bool_t (* construct) (TestTypeNode *node);
363 void (* destroy) (TestTypeNode *node);
365 dbus_bool_t (* write_value) (TestTypeNode *node,
367 DBusTypeWriter *writer,
369 dbus_bool_t (* read_value) (TestTypeNode *node,
370 DBusTypeReader *reader,
372 dbus_bool_t (* set_value) (TestTypeNode *node,
373 DBusTypeReader *reader,
374 DBusTypeReader *realign_root,
376 dbus_bool_t (* build_signature) (TestTypeNode *node,
378 dbus_bool_t (* write_multi) (TestTypeNode *node,
380 DBusTypeWriter *writer,
383 dbus_bool_t (* read_multi) (TestTypeNode *node,
384 DBusTypeReader *reader,
389 struct TestTypeNodeContainerClass
391 TestTypeNodeClass base;
394 /* FIXME this could be chilled out substantially by unifying
395 * the basic types into basic_write_value/basic_read_value
396 * and by merging read_value and set_value into one function
397 * taking a flag argument.
399 static dbus_bool_t int16_write_value (TestTypeNode *node,
401 DBusTypeWriter *writer,
403 static dbus_bool_t int16_read_value (TestTypeNode *node,
404 DBusTypeReader *reader,
406 static dbus_bool_t int16_set_value (TestTypeNode *node,
407 DBusTypeReader *reader,
408 DBusTypeReader *realign_root,
410 static dbus_bool_t int16_write_multi (TestTypeNode *node,
412 DBusTypeWriter *writer,
415 static dbus_bool_t int16_read_multi (TestTypeNode *node,
416 DBusTypeReader *reader,
419 static dbus_bool_t int32_write_value (TestTypeNode *node,
421 DBusTypeWriter *writer,
423 static dbus_bool_t int32_read_value (TestTypeNode *node,
424 DBusTypeReader *reader,
426 static dbus_bool_t int32_set_value (TestTypeNode *node,
427 DBusTypeReader *reader,
428 DBusTypeReader *realign_root,
430 static dbus_bool_t int32_write_multi (TestTypeNode *node,
432 DBusTypeWriter *writer,
435 static dbus_bool_t int32_read_multi (TestTypeNode *node,
436 DBusTypeReader *reader,
439 static dbus_bool_t int64_write_value (TestTypeNode *node,
441 DBusTypeWriter *writer,
443 static dbus_bool_t int64_read_value (TestTypeNode *node,
444 DBusTypeReader *reader,
446 static dbus_bool_t int64_set_value (TestTypeNode *node,
447 DBusTypeReader *reader,
448 DBusTypeReader *realign_root,
450 static dbus_bool_t string_write_value (TestTypeNode *node,
452 DBusTypeWriter *writer,
454 static dbus_bool_t string_read_value (TestTypeNode *node,
455 DBusTypeReader *reader,
457 static dbus_bool_t string_set_value (TestTypeNode *node,
458 DBusTypeReader *reader,
459 DBusTypeReader *realign_root,
461 static dbus_bool_t bool_write_value (TestTypeNode *node,
463 DBusTypeWriter *writer,
465 static dbus_bool_t bool_read_value (TestTypeNode *node,
466 DBusTypeReader *reader,
468 static dbus_bool_t bool_set_value (TestTypeNode *node,
469 DBusTypeReader *reader,
470 DBusTypeReader *realign_root,
472 static dbus_bool_t byte_write_value (TestTypeNode *node,
474 DBusTypeWriter *writer,
476 static dbus_bool_t byte_read_value (TestTypeNode *node,
477 DBusTypeReader *reader,
479 static dbus_bool_t byte_set_value (TestTypeNode *node,
480 DBusTypeReader *reader,
481 DBusTypeReader *realign_root,
483 static dbus_bool_t double_write_value (TestTypeNode *node,
485 DBusTypeWriter *writer,
487 static dbus_bool_t double_read_value (TestTypeNode *node,
488 DBusTypeReader *reader,
490 static dbus_bool_t double_set_value (TestTypeNode *node,
491 DBusTypeReader *reader,
492 DBusTypeReader *realign_root,
494 static dbus_bool_t object_path_write_value (TestTypeNode *node,
496 DBusTypeWriter *writer,
498 static dbus_bool_t object_path_read_value (TestTypeNode *node,
499 DBusTypeReader *reader,
501 static dbus_bool_t object_path_set_value (TestTypeNode *node,
502 DBusTypeReader *reader,
503 DBusTypeReader *realign_root,
505 static dbus_bool_t signature_write_value (TestTypeNode *node,
507 DBusTypeWriter *writer,
509 static dbus_bool_t signature_read_value (TestTypeNode *node,
510 DBusTypeReader *reader,
512 static dbus_bool_t signature_set_value (TestTypeNode *node,
513 DBusTypeReader *reader,
514 DBusTypeReader *realign_root,
516 static dbus_bool_t struct_write_value (TestTypeNode *node,
518 DBusTypeWriter *writer,
520 static dbus_bool_t struct_read_value (TestTypeNode *node,
521 DBusTypeReader *reader,
523 static dbus_bool_t struct_set_value (TestTypeNode *node,
524 DBusTypeReader *reader,
525 DBusTypeReader *realign_root,
527 static dbus_bool_t struct_build_signature (TestTypeNode *node,
529 static dbus_bool_t dict_write_value (TestTypeNode *node,
531 DBusTypeWriter *writer,
533 static dbus_bool_t dict_read_value (TestTypeNode *node,
534 DBusTypeReader *reader,
536 static dbus_bool_t dict_set_value (TestTypeNode *node,
537 DBusTypeReader *reader,
538 DBusTypeReader *realign_root,
540 static dbus_bool_t dict_build_signature (TestTypeNode *node,
542 static dbus_bool_t array_write_value (TestTypeNode *node,
544 DBusTypeWriter *writer,
546 static dbus_bool_t array_read_value (TestTypeNode *node,
547 DBusTypeReader *reader,
549 static dbus_bool_t array_set_value (TestTypeNode *node,
550 DBusTypeReader *reader,
551 DBusTypeReader *realign_root,
553 static dbus_bool_t array_build_signature (TestTypeNode *node,
555 static dbus_bool_t variant_write_value (TestTypeNode *node,
557 DBusTypeWriter *writer,
559 static dbus_bool_t variant_read_value (TestTypeNode *node,
560 DBusTypeReader *reader,
562 static dbus_bool_t variant_set_value (TestTypeNode *node,
563 DBusTypeReader *reader,
564 DBusTypeReader *realign_root,
566 static void container_destroy (TestTypeNode *node);
570 static const TestTypeNodeClass int16_class = {
572 sizeof (TestTypeNode),
584 static const TestTypeNodeClass uint16_class = {
586 sizeof (TestTypeNode),
590 int16_write_value, /* recycle from int16 */
591 int16_read_value, /* recycle from int16 */
592 int16_set_value, /* recycle from int16 */
594 int16_write_multi, /* recycle from int16 */
595 int16_read_multi /* recycle from int16 */
598 static const TestTypeNodeClass int32_class = {
600 sizeof (TestTypeNode),
612 static const TestTypeNodeClass uint32_class = {
614 sizeof (TestTypeNode),
618 int32_write_value, /* recycle from int32 */
619 int32_read_value, /* recycle from int32 */
620 int32_set_value, /* recycle from int32 */
622 int32_write_multi, /* recycle from int32 */
623 int32_read_multi /* recycle from int32 */
626 static const TestTypeNodeClass int64_class = {
628 sizeof (TestTypeNode),
640 static const TestTypeNodeClass uint64_class = {
642 sizeof (TestTypeNode),
646 int64_write_value, /* recycle from int64 */
647 int64_read_value, /* recycle from int64 */
648 int64_set_value, /* recycle from int64 */
654 static const TestTypeNodeClass string_0_class = {
656 sizeof (TestTypeNode),
657 0, /* string length */
668 static const TestTypeNodeClass string_1_class = {
670 sizeof (TestTypeNode),
671 1, /* string length */
682 /* with nul, a len 3 string should fill 4 bytes and thus is "special" */
683 static const TestTypeNodeClass string_3_class = {
685 sizeof (TestTypeNode),
686 3, /* string length */
697 /* with nul, a len 8 string should fill 9 bytes and thus is "special" (far-fetched I suppose) */
698 static const TestTypeNodeClass string_8_class = {
700 sizeof (TestTypeNode),
701 8, /* string length */
712 static const TestTypeNodeClass bool_class = {
714 sizeof (TestTypeNode),
726 static const TestTypeNodeClass byte_class = {
728 sizeof (TestTypeNode),
740 static const TestTypeNodeClass double_class = {
742 sizeof (TestTypeNode),
754 static const TestTypeNodeClass object_path_class = {
755 DBUS_TYPE_OBJECT_PATH,
756 sizeof (TestTypeNode),
760 object_path_write_value,
761 object_path_read_value,
762 object_path_set_value,
768 static const TestTypeNodeClass signature_class = {
770 sizeof (TestTypeNode),
774 signature_write_value,
775 signature_read_value,
782 static const TestTypeNodeClass struct_1_class = {
784 sizeof (TestTypeNodeContainer),
785 1, /* number of times children appear as fields */
791 struct_build_signature,
796 static const TestTypeNodeClass struct_2_class = {
798 sizeof (TestTypeNodeContainer),
799 2, /* number of times children appear as fields */
805 struct_build_signature,
810 static const TestTypeNodeClass dict_1_class = {
811 DBUS_TYPE_ARRAY, /* this is correct, a dict is an array of dict entry */
812 sizeof (TestTypeNodeContainer),
813 1, /* number of entries */
819 dict_build_signature,
824 static dbus_bool_t arrays_write_fixed_in_blocks = FALSE;
826 static const TestTypeNodeClass array_0_class = {
828 sizeof (TestTypeNodeContainer),
829 0, /* number of array elements */
835 array_build_signature,
840 static const TestTypeNodeClass array_1_class = {
842 sizeof (TestTypeNodeContainer),
843 1, /* number of array elements */
849 array_build_signature,
854 static const TestTypeNodeClass array_2_class = {
856 sizeof (TestTypeNodeContainer),
857 2, /* number of array elements */
863 array_build_signature,
868 static const TestTypeNodeClass array_9_class = {
870 sizeof (TestTypeNodeContainer),
871 9, /* number of array elements */
877 array_build_signature,
882 static const TestTypeNodeClass variant_class = {
884 sizeof (TestTypeNodeContainer),
896 static const TestTypeNodeClass* const
914 #define N_BASICS (_DBUS_N_ELEMENTS (basic_nodes))
916 static const TestTypeNodeClass* const
917 container_nodes[] = {
924 &dict_1_class /* last since we want struct and array before it */
925 /* array_9_class is omitted on purpose, it's too slow;
926 * we only use it in one hardcoded test below
929 #define N_CONTAINERS (_DBUS_N_ELEMENTS (container_nodes))
932 node_new (const TestTypeNodeClass *klass)
936 node = dbus_malloc0 (klass->instance_size);
942 if (klass->construct)
944 if (!(* klass->construct) (node))
955 node_destroy (TestTypeNode *node)
957 if (node->klass->destroy)
958 (* node->klass->destroy) (node);
963 node_write_value (TestTypeNode *node,
965 DBusTypeWriter *writer,
970 retval = (* node->klass->write_value) (node, block, writer, seed);
973 /* Handy to see where things break, but too expensive to do all the time */
974 data_block_verify (block);
981 node_read_value (TestTypeNode *node,
982 DBusTypeReader *reader,
986 DBusTypeReader restored;
988 _dbus_type_reader_save_mark (reader, &mark);
990 if (!(* node->klass->read_value) (node, reader, seed))
993 _dbus_type_reader_init_from_mark (&restored,
999 if (!(* node->klass->read_value) (node, &restored, seed))
1005 /* Warning: if this one fails due to OOM, it has side effects (can
1006 * modify only some of the sub-values). OK in a test suite, but we
1007 * never do this in real code.
1010 node_set_value (TestTypeNode *node,
1011 DBusTypeReader *reader,
1012 DBusTypeReader *realign_root,
1015 if (!(* node->klass->set_value) (node, reader, realign_root, seed))
1022 node_build_signature (TestTypeNode *node,
1025 if (node->klass->build_signature)
1026 return (* node->klass->build_signature) (node, str);
1028 return _dbus_string_append_byte (str, node->klass->typecode);
1032 node_append_child (TestTypeNode *node,
1033 TestTypeNode *child)
1035 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
1037 _dbus_assert (node->klass->instance_size >= (int) sizeof (TestTypeNodeContainer));
1039 if (!_dbus_list_append (&container->children, child))
1040 _dbus_assert_not_reached ("no memory"); /* we never check the return value on node_append_child anyhow - it's run from outside the malloc-failure test code */
1046 node_write_multi (TestTypeNode *node,
1048 DBusTypeWriter *writer,
1054 _dbus_assert (node->klass->write_multi != NULL);
1055 retval = (* node->klass->write_multi) (node, block, writer, seed, n_copies);
1058 /* Handy to see where things break, but too expensive to do all the time */
1059 data_block_verify (block);
1066 node_read_multi (TestTypeNode *node,
1067 DBusTypeReader *reader,
1071 _dbus_assert (node->klass->read_multi != NULL);
1073 if (!(* node->klass->read_multi) (node, reader, seed, n_copies))
1079 static int n_iterations_completed_total = 0;
1080 static int n_iterations_completed_this_test = 0;
1081 static int n_iterations_expected_this_test = 0;
1085 const DBusString *signature;
1088 TestTypeNode **nodes;
1090 } NodeIterationData;
1093 run_test_copy (NodeIterationData *nid)
1098 DBusTypeReader reader;
1099 DBusTypeWriter writer;
1101 _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
1107 if (!data_block_init (&dest, src->byte_order, src->initial_offset))
1110 data_block_init_reader_writer (src, &reader, NULL);
1111 data_block_init_reader_writer (&dest, NULL, &writer);
1113 /* DBusTypeWriter assumes it's writing into an existing signature,
1114 * so doesn't add nul on its own. We have to do that.
1116 if (!_dbus_string_insert_byte (&dest.signature,
1117 dest.initial_offset, '\0'))
1120 if (!_dbus_type_writer_write_reader (&writer, &reader))
1123 /* Data blocks should now be identical */
1124 if (!_dbus_string_equal (&src->signature, &dest.signature))
1126 _dbus_verbose ("SOURCE\n");
1127 _dbus_verbose_bytes_of_string (&src->signature, 0,
1128 _dbus_string_get_length (&src->signature));
1129 _dbus_verbose ("DEST\n");
1130 _dbus_verbose_bytes_of_string (&dest.signature, 0,
1131 _dbus_string_get_length (&dest.signature));
1132 _dbus_assert_not_reached ("signatures did not match");
1135 if (!_dbus_string_equal (&src->body, &dest.body))
1137 _dbus_verbose ("SOURCE\n");
1138 _dbus_verbose_bytes_of_string (&src->body, 0,
1139 _dbus_string_get_length (&src->body));
1140 _dbus_verbose ("DEST\n");
1141 _dbus_verbose_bytes_of_string (&dest.body, 0,
1142 _dbus_string_get_length (&dest.body));
1143 _dbus_assert_not_reached ("bodies did not match");
1150 data_block_free (&dest);
1156 run_test_values_only_write (NodeIterationData *nid)
1158 DBusTypeReader reader;
1159 DBusTypeWriter writer;
1164 _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
1168 data_block_reset (nid->block);
1170 sig_len = _dbus_string_get_length (nid->signature);
1172 _dbus_type_writer_init_values_only (&writer,
1173 nid->block->byte_order,
1176 _dbus_string_get_length (&nid->block->body) - N_FENCE_BYTES);
1177 _dbus_type_reader_init (&reader,
1178 nid->block->byte_order,
1181 nid->block->initial_offset);
1184 while (i < nid->n_nodes)
1186 if (!node_write_value (nid->nodes[i], nid->block, &writer, i))
1192 /* if we wrote any typecodes then this would fail */
1193 _dbus_assert (sig_len == _dbus_string_get_length (nid->signature));
1195 /* But be sure we wrote out the values correctly */
1197 while (i < nid->n_nodes)
1199 if (!node_read_value (nid->nodes[i], &reader, i))
1202 if (i + 1 == nid->n_nodes)
1203 NEXT_EXPECTING_FALSE (&reader);
1205 NEXT_EXPECTING_TRUE (&reader);
1213 data_block_reset (nid->block);
1217 /* offset the seed for setting, so we set different numbers than
1218 * we originally wrote. Don't offset by a huge number since in
1219 * some cases it's value = possibilities[seed % n_possibilities]
1220 * and we don't want to wrap around. bool_from_seed
1221 * is just seed % 2 even.
1225 run_test_set_values (NodeIterationData *nid)
1227 DBusTypeReader reader;
1228 DBusTypeReader realign_root;
1232 _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
1236 data_block_init_reader_writer (nid->block,
1239 realign_root = reader;
1242 while (i < nid->n_nodes)
1244 if (!node_set_value (nid->nodes[i],
1245 &reader, &realign_root,
1249 if (i + 1 == nid->n_nodes)
1250 NEXT_EXPECTING_FALSE (&reader);
1252 NEXT_EXPECTING_TRUE (&reader);
1257 /* Check that the new values were set */
1259 reader = realign_root;
1262 while (i < nid->n_nodes)
1264 if (!node_read_value (nid->nodes[i], &reader,
1268 if (i + 1 == nid->n_nodes)
1269 NEXT_EXPECTING_FALSE (&reader);
1271 NEXT_EXPECTING_TRUE (&reader);
1283 run_test_delete_values (NodeIterationData *nid)
1285 DBusTypeReader reader;
1289 _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
1293 data_block_init_reader_writer (nid->block,
1296 while ((t = _dbus_type_reader_get_current_type (&reader)) != DBUS_TYPE_INVALID)
1298 /* Right now, deleting only works on array elements. We delete
1299 * all array elements, and then verify that there aren't any
1302 if (t == DBUS_TYPE_ARRAY)
1304 DBusTypeReader array;
1308 _dbus_type_reader_recurse (&reader, &array);
1310 while (_dbus_type_reader_get_current_type (&array) != DBUS_TYPE_INVALID)
1313 _dbus_type_reader_next (&array);
1316 /* reset to start of array */
1317 _dbus_type_reader_recurse (&reader, &array);
1318 _dbus_verbose ("recursing into deletion loop reader.value_pos = %d array.value_pos = %d array.u.start_pos = %d\n",
1319 reader.value_pos, array.value_pos, array.u.array.start_pos);
1320 while ((elem_type = _dbus_type_reader_get_current_type (&array)) != DBUS_TYPE_INVALID)
1322 /* We don't want to always delete from the same part of the array. */
1323 static int cycle = 0;
1326 _dbus_assert (n_elements > 0);
1329 if (elem == 3 || elem >= n_elements) /* end of array */
1330 elem = n_elements - 1;
1332 _dbus_verbose ("deleting array element %d of %d type %s cycle %d reader pos %d elem pos %d\n",
1333 elem, n_elements, _dbus_type_to_string (elem_type),
1334 cycle, reader.value_pos, array.value_pos);
1337 if (!_dbus_type_reader_next (&array))
1338 _dbus_assert_not_reached ("should have had another element\n");
1342 if (!_dbus_type_reader_delete (&array, &reader))
1348 _dbus_type_reader_recurse (&reader, &array);
1356 _dbus_type_reader_next (&reader);
1359 /* Check that there are no array elements left */
1360 data_block_init_reader_writer (nid->block,
1363 while ((t = _dbus_type_reader_get_current_type (&reader)) != DBUS_TYPE_INVALID)
1365 _dbus_type_reader_next (&reader);
1375 run_test_nodes_iteration (void *data)
1377 NodeIterationData *nid = data;
1378 DBusTypeReader reader;
1379 DBusTypeWriter writer;
1384 * 1. write the value
1385 * 2. strcmp-compare with the signature we built
1387 * 4. type-iterate the signature and the value and see if they are the same type-wise
1391 data_block_init_reader_writer (nid->block,
1394 /* DBusTypeWriter assumes it's writing into an existing signature,
1395 * so doesn't add nul on its own. We have to do that.
1397 if (!_dbus_string_insert_byte (&nid->block->signature,
1398 nid->type_offset, '\0'))
1402 while (i < nid->n_nodes)
1404 if (!node_write_value (nid->nodes[i], nid->block, &writer, i))
1410 if (!_dbus_string_equal_substring (nid->signature, 0, _dbus_string_get_length (nid->signature),
1411 &nid->block->signature, nid->type_offset))
1413 _dbus_warn ("Expected signature '%s' and got '%s' with initial offset %d\n",
1414 _dbus_string_get_const_data (nid->signature),
1415 _dbus_string_get_const_data_len (&nid->block->signature, nid->type_offset, 0),
1417 _dbus_assert_not_reached ("wrong signature");
1421 while (i < nid->n_nodes)
1423 if (!node_read_value (nid->nodes[i], &reader, i))
1426 if (i + 1 == nid->n_nodes)
1427 NEXT_EXPECTING_FALSE (&reader);
1429 NEXT_EXPECTING_TRUE (&reader);
1434 if (n_iterations_expected_this_test <= MAX_ITERATIONS_FOR_EXPENSIVE_TESTS)
1436 /* this set values test uses code from copy and
1437 * values_only_write so would ideally be last so you get a
1438 * simpler test case for problems with copying or values_only
1439 * writing; but it also needs an already-written DataBlock so it
1440 * has to go first. Comment it out if it breaks, and see if the
1441 * later tests also break - debug them first if so.
1443 if (!run_test_set_values (nid))
1446 if (!run_test_delete_values (nid))
1449 if (!run_test_copy (nid))
1452 if (!run_test_values_only_write (nid))
1456 /* FIXME type-iterate both signature and value and compare the resulting
1457 * tree to the node tree perhaps
1464 data_block_reset (nid->block);
1470 run_test_nodes_in_one_configuration (TestTypeNode **nodes,
1472 const DBusString *signature,
1477 NodeIterationData nid;
1479 if (!data_block_init (&block, byte_order, initial_offset))
1480 _dbus_assert_not_reached ("no memory");
1482 nid.signature = signature;
1484 nid.type_offset = initial_offset;
1486 nid.n_nodes = n_nodes;
1488 if (TEST_OOM_HANDLING &&
1489 n_iterations_expected_this_test <= MAX_ITERATIONS_FOR_EXPENSIVE_TESTS)
1491 _dbus_test_oom_handling ("running test node",
1492 run_test_nodes_iteration,
1497 if (!run_test_nodes_iteration (&nid))
1498 _dbus_assert_not_reached ("no memory");
1501 data_block_free (&block);
1505 run_test_nodes (TestTypeNode **nodes,
1509 DBusString signature;
1511 if (!_dbus_string_init (&signature))
1512 _dbus_assert_not_reached ("no memory");
1517 if (! node_build_signature (nodes[i], &signature))
1518 _dbus_assert_not_reached ("no memory");
1523 _dbus_verbose (">>> test nodes with signature '%s'\n",
1524 _dbus_string_get_const_data (&signature));
1527 while (i <= MAX_INITIAL_OFFSET)
1529 run_test_nodes_in_one_configuration (nodes, n_nodes, &signature,
1530 DBUS_LITTLE_ENDIAN, i);
1531 run_test_nodes_in_one_configuration (nodes, n_nodes, &signature,
1532 DBUS_BIG_ENDIAN, i);
1537 n_iterations_completed_this_test += 1;
1538 n_iterations_completed_total += 1;
1540 if (n_iterations_completed_this_test == n_iterations_expected_this_test)
1542 fprintf (stderr, " 100%% %d this test (%d cumulative)\n",
1543 n_iterations_completed_this_test,
1544 n_iterations_completed_total);
1546 /* this happens to turn out well with mod == 1 */
1547 else if ((n_iterations_completed_this_test %
1548 (int)(n_iterations_expected_this_test / 10.0)) == 1)
1550 fprintf (stderr, " %d%% ", (int) (n_iterations_completed_this_test / (double) n_iterations_expected_this_test * 100));
1553 _dbus_string_free (&signature);
1556 #define N_VALUES (N_BASICS * N_CONTAINERS + N_BASICS)
1558 static TestTypeNode*
1559 value_generator (int *ip)
1562 const TestTypeNodeClass *child_klass;
1563 const TestTypeNodeClass *container_klass;
1564 TestTypeNode *child;
1567 _dbus_assert (i <= N_VALUES);
1573 else if (i < N_BASICS)
1575 node = node_new (basic_nodes[i]);
1579 /* imagine an array:
1580 * container 0 of basic 0
1581 * container 0 of basic 1
1582 * container 0 of basic 2
1583 * container 1 of basic 0
1584 * container 1 of basic 1
1585 * container 1 of basic 2
1589 container_klass = container_nodes[i / N_BASICS];
1590 child_klass = basic_nodes[i % N_BASICS];
1592 node = node_new (container_klass);
1593 child = node_new (child_klass);
1595 node_append_child (node, child);
1598 *ip += 1; /* increment the generator */
1604 build_body (TestTypeNode **nodes,
1607 DBusString *signature,
1612 DBusTypeReader reader;
1613 DBusTypeWriter writer;
1618 if (! node_build_signature (nodes[i], signature))
1619 _dbus_assert_not_reached ("no memory");
1624 if (!data_block_init (&block, byte_order, 0))
1625 _dbus_assert_not_reached ("no memory");
1627 data_block_init_reader_writer (&block,
1630 /* DBusTypeWriter assumes it's writing into an existing signature,
1631 * so doesn't add nul on its own. We have to do that.
1633 if (!_dbus_string_insert_byte (&block.signature,
1635 _dbus_assert_not_reached ("no memory");
1640 if (!node_write_value (nodes[i], &block, &writer, i))
1641 _dbus_assert_not_reached ("no memory");
1646 if (!_dbus_string_copy_len (&block.body, 0,
1647 _dbus_string_get_length (&block.body) - N_FENCE_BYTES,
1649 _dbus_assert_not_reached ("oom");
1651 data_block_free (&block);
1655 dbus_internal_do_not_use_generate_bodies (int sequence,
1657 DBusString *signature,
1660 TestTypeNode *nodes[1];
1664 nodes[0] = value_generator (&sequence);
1666 if (nodes[0] == NULL)
1671 build_body (nodes, n_nodes, byte_order, signature, body);
1677 node_destroy (nodes[i]);
1685 make_and_run_values_inside_container (const TestTypeNodeClass *container_klass,
1689 TestTypeNode *container;
1690 TestTypeNode *child;
1693 root = node_new (container_klass);
1695 for (i = 1; i < n_nested; i++)
1697 child = node_new (container_klass);
1698 node_append_child (container, child);
1702 /* container should now be the most-nested container */
1705 while ((child = value_generator (&i)))
1707 node_append_child (container, child);
1709 run_test_nodes (&root, 1);
1711 _dbus_list_clear (&((TestTypeNodeContainer*)container)->children);
1712 node_destroy (child);
1715 node_destroy (root);
1719 start_next_test (const char *format,
1722 n_iterations_completed_this_test = 0;
1723 n_iterations_expected_this_test = expected;
1725 fprintf (stderr, ">>> >>> ");
1726 fprintf (stderr, format,
1727 n_iterations_expected_this_test);
1731 make_and_run_test_nodes (void)
1735 /* We try to do this in order of "complicatedness" so that test
1736 * failures tend to show up in the simplest test case that
1737 * demonstrates the failure. There are also some tests that run
1738 * more than once for this reason, first while going through simple
1739 * cases, second while going through a broader range of complex
1742 /* Each basic node. The basic nodes should include:
1744 * - each fixed-size type (in such a way that it has different values each time,
1745 * so we can tell if we mix two of them up)
1746 * - strings of various lengths
1750 /* Each container node. The container nodes should include:
1752 * struct with 1 and 2 copies of the contained item
1753 * array with 0, 1, 2 copies of the contained item
1756 /* Let a "value" be a basic node, or a container containing a single basic node.
1757 * Let n_values be the number of such values i.e. (n_container * n_basic + n_basic)
1758 * When iterating through all values to make combinations, do the basic types
1759 * first and the containers second.
1761 /* Each item is shown with its number of iterations to complete so
1762 * we can keep a handle on this unit test
1765 /* FIXME test just an empty body, no types at all */
1767 start_next_test ("Each value by itself %d iterations\n", N_VALUES);
1771 while ((node = value_generator (&i)))
1773 run_test_nodes (&node, 1);
1775 node_destroy (node);
1779 start_next_test ("Each value by itself with arrays as blocks %d iterations\n", N_VALUES);
1780 arrays_write_fixed_in_blocks = TRUE;
1784 while ((node = value_generator (&i)))
1786 run_test_nodes (&node, 1);
1788 node_destroy (node);
1791 arrays_write_fixed_in_blocks = FALSE;
1793 start_next_test ("All values in one big toplevel %d iteration\n", 1);
1795 TestTypeNode *nodes[N_VALUES];
1798 while ((nodes[i] = value_generator (&i)))
1801 run_test_nodes (nodes, N_VALUES);
1803 for (i = 0; i < N_VALUES; i++)
1804 node_destroy (nodes[i]);
1807 start_next_test ("Each value,value pair combination as toplevel, in both orders %d iterations\n",
1808 N_VALUES * N_VALUES);
1810 TestTypeNode *nodes[2];
1813 while ((nodes[0] = value_generator (&i)))
1816 while ((nodes[1] = value_generator (&j)))
1818 run_test_nodes (nodes, 2);
1820 node_destroy (nodes[1]);
1823 node_destroy (nodes[0]);
1827 start_next_test ("Each container containing each value %d iterations\n",
1828 N_CONTAINERS * N_VALUES);
1829 for (i = 0; i < N_CONTAINERS; i++)
1831 const TestTypeNodeClass *container_klass = container_nodes[i];
1833 make_and_run_values_inside_container (container_klass, 1);
1836 start_next_test ("Each container containing each value with arrays as blocks %d iterations\n",
1837 N_CONTAINERS * N_VALUES);
1838 arrays_write_fixed_in_blocks = TRUE;
1839 for (i = 0; i < N_CONTAINERS; i++)
1841 const TestTypeNodeClass *container_klass = container_nodes[i];
1843 make_and_run_values_inside_container (container_klass, 1);
1845 arrays_write_fixed_in_blocks = FALSE;
1847 start_next_test ("Each container of same container of each value %d iterations\n",
1848 N_CONTAINERS * N_VALUES);
1849 for (i = 0; i < N_CONTAINERS; i++)
1851 const TestTypeNodeClass *container_klass = container_nodes[i];
1853 make_and_run_values_inside_container (container_klass, 2);
1856 start_next_test ("Each container of same container of same container of each value %d iterations\n",
1857 N_CONTAINERS * N_VALUES);
1858 for (i = 0; i < N_CONTAINERS; i++)
1860 const TestTypeNodeClass *container_klass = container_nodes[i];
1862 make_and_run_values_inside_container (container_klass, 3);
1865 start_next_test ("Each value,value pair inside a struct %d iterations\n",
1866 N_VALUES * N_VALUES);
1868 TestTypeNode *val1, *val2;
1871 node = node_new (&struct_1_class);
1874 while ((val1 = value_generator (&i)))
1877 while ((val2 = value_generator (&j)))
1879 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
1881 node_append_child (node, val1);
1882 node_append_child (node, val2);
1884 run_test_nodes (&node, 1);
1886 _dbus_list_clear (&container->children);
1887 node_destroy (val2);
1889 node_destroy (val1);
1891 node_destroy (node);
1894 start_next_test ("All values in one big struct %d iteration\n",
1898 TestTypeNode *child;
1900 node = node_new (&struct_1_class);
1903 while ((child = value_generator (&i)))
1904 node_append_child (node, child);
1906 run_test_nodes (&node, 1);
1908 node_destroy (node);
1911 start_next_test ("Each value in a large array %d iterations\n",
1917 node = node_new (&array_9_class);
1920 while ((val = value_generator (&i)))
1922 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
1924 node_append_child (node, val);
1926 run_test_nodes (&node, 1);
1928 _dbus_list_clear (&container->children);
1932 node_destroy (node);
1935 start_next_test ("Each container of each container of each value %d iterations\n",
1936 N_CONTAINERS * N_CONTAINERS * N_VALUES);
1937 for (i = 0; i < N_CONTAINERS; i++)
1939 const TestTypeNodeClass *outer_container_klass = container_nodes[i];
1940 TestTypeNode *outer_container = node_new (outer_container_klass);
1942 for (j = 0; j < N_CONTAINERS; j++)
1944 TestTypeNode *child;
1945 const TestTypeNodeClass *inner_container_klass = container_nodes[j];
1946 TestTypeNode *inner_container = node_new (inner_container_klass);
1948 node_append_child (outer_container, inner_container);
1951 while ((child = value_generator (&m)))
1953 node_append_child (inner_container, child);
1955 run_test_nodes (&outer_container, 1);
1957 _dbus_list_clear (&((TestTypeNodeContainer*)inner_container)->children);
1958 node_destroy (child);
1960 _dbus_list_clear (&((TestTypeNodeContainer*)outer_container)->children);
1961 node_destroy (inner_container);
1963 node_destroy (outer_container);
1966 start_next_test ("Each container of each container of each container of each value %d iterations\n",
1967 N_CONTAINERS * N_CONTAINERS * N_CONTAINERS * N_VALUES);
1968 for (i = 0; i < N_CONTAINERS; i++)
1970 const TestTypeNodeClass *outer_container_klass = container_nodes[i];
1971 TestTypeNode *outer_container = node_new (outer_container_klass);
1973 for (j = 0; j < N_CONTAINERS; j++)
1975 const TestTypeNodeClass *inner_container_klass = container_nodes[j];
1976 TestTypeNode *inner_container = node_new (inner_container_klass);
1978 node_append_child (outer_container, inner_container);
1980 for (k = 0; k < N_CONTAINERS; k++)
1982 TestTypeNode *child;
1983 const TestTypeNodeClass *center_container_klass = container_nodes[k];
1984 TestTypeNode *center_container = node_new (center_container_klass);
1986 node_append_child (inner_container, center_container);
1989 while ((child = value_generator (&m)))
1991 node_append_child (center_container, child);
1993 run_test_nodes (&outer_container, 1);
1995 _dbus_list_clear (&((TestTypeNodeContainer*)center_container)->children);
1996 node_destroy (child);
1998 _dbus_list_clear (&((TestTypeNodeContainer*)inner_container)->children);
1999 node_destroy (center_container);
2001 _dbus_list_clear (&((TestTypeNodeContainer*)outer_container)->children);
2002 node_destroy (inner_container);
2004 node_destroy (outer_container);
2008 /* This one takes a really long time, so comment it out for now */
2009 start_next_test ("Each value,value,value triplet combination as toplevel, in all orders %d iterations\n",
2010 N_VALUES * N_VALUES * N_VALUES);
2012 TestTypeNode *nodes[3];
2015 while ((nodes[0] = value_generator (&i)))
2018 while ((nodes[1] = value_generator (&j)))
2021 while ((nodes[2] = value_generator (&k)))
2023 run_test_nodes (nodes, 3);
2025 node_destroy (nodes[2]);
2027 node_destroy (nodes[1]);
2029 node_destroy (nodes[0]);
2032 #endif /* #if 0 expensive test */
2034 fprintf (stderr, "%d total iterations of recursive marshaling tests\n",
2035 n_iterations_completed_total);
2036 fprintf (stderr, "each iteration ran at initial offsets 0 through %d in both big and little endian\n",
2037 MAX_INITIAL_OFFSET);
2038 fprintf (stderr, "out of memory handling %s tested\n",
2039 TEST_OOM_HANDLING ? "was" : "was not");
2043 _dbus_marshal_recursive_test (void)
2045 make_and_run_test_nodes ();
2053 * Implementations of each type node class
2058 #define MAX_MULTI_COUNT 5
2060 #define SAMPLE_INT16 1234
2061 #define SAMPLE_INT16_ALTERNATE 6785
2063 int16_from_seed (int seed)
2065 /* Generate an integer value that's predictable from seed. We could
2066 * just use seed itself, but that would only ever touch one byte of
2067 * the int so would miss some kinds of bug.
2071 v = 42; /* just to quiet compiler afaik */
2078 v = SAMPLE_INT16_ALTERNATE;
2084 v = _DBUS_INT16_MAX;
2092 v *= seed; /* wraps around eventually, which is fine */
2098 int16_write_value (TestTypeNode *node,
2100 DBusTypeWriter *writer,
2103 /* also used for uint16 */
2106 v = int16_from_seed (seed);
2108 return _dbus_type_writer_write_basic (writer,
2109 node->klass->typecode,
2114 int16_read_value (TestTypeNode *node,
2115 DBusTypeReader *reader,
2118 /* also used for uint16 */
2121 check_expected_type (reader, node->klass->typecode);
2123 _dbus_type_reader_read_basic (reader,
2124 (dbus_int16_t*) &v);
2126 _dbus_assert (v == int16_from_seed (seed));
2132 int16_set_value (TestTypeNode *node,
2133 DBusTypeReader *reader,
2134 DBusTypeReader *realign_root,
2137 /* also used for uint16 */
2140 v = int16_from_seed (seed);
2142 return _dbus_type_reader_set_basic (reader,
2148 int16_write_multi (TestTypeNode *node,
2150 DBusTypeWriter *writer,
2154 /* also used for uint16 */
2155 dbus_int16_t values[MAX_MULTI_COUNT];
2156 dbus_int16_t *v_ARRAY_INT16 = values;
2159 for (i = 0; i < count; ++i)
2160 values[i] = int16_from_seed (seed + i);
2162 return _dbus_type_writer_write_fixed_multi (writer,
2163 node->klass->typecode,
2164 &v_ARRAY_INT16, count);
2168 int16_read_multi (TestTypeNode *node,
2169 DBusTypeReader *reader,
2173 /* also used for uint16 */
2174 dbus_int16_t *values;
2178 check_expected_type (reader, node->klass->typecode);
2180 _dbus_type_reader_read_fixed_multi (reader,
2184 if (n_elements != count)
2185 _dbus_warn ("got %d elements expected %d\n", n_elements, count);
2186 _dbus_assert (n_elements == count);
2188 for (i = 0; i < count; i++)
2189 _dbus_assert (((dbus_int16_t)_dbus_unpack_uint16 (reader->byte_order,
2190 (const unsigned char*)values + (i * 2))) ==
2191 int16_from_seed (seed + i));
2197 #define SAMPLE_INT32 12345678
2198 #define SAMPLE_INT32_ALTERNATE 53781429
2200 int32_from_seed (int seed)
2202 /* Generate an integer value that's predictable from seed. We could
2203 * just use seed itself, but that would only ever touch one byte of
2204 * the int so would miss some kinds of bug.
2208 v = 42; /* just to quiet compiler afaik */
2215 v = SAMPLE_INT32_ALTERNATE;
2229 v *= seed; /* wraps around eventually, which is fine */
2235 int32_write_value (TestTypeNode *node,
2237 DBusTypeWriter *writer,
2240 /* also used for uint32 */
2243 v = int32_from_seed (seed);
2245 return _dbus_type_writer_write_basic (writer,
2246 node->klass->typecode,
2251 int32_read_value (TestTypeNode *node,
2252 DBusTypeReader *reader,
2255 /* also used for uint32 */
2258 check_expected_type (reader, node->klass->typecode);
2260 _dbus_type_reader_read_basic (reader,
2261 (dbus_int32_t*) &v);
2263 _dbus_assert (v == int32_from_seed (seed));
2269 int32_set_value (TestTypeNode *node,
2270 DBusTypeReader *reader,
2271 DBusTypeReader *realign_root,
2274 /* also used for uint32 */
2277 v = int32_from_seed (seed);
2279 return _dbus_type_reader_set_basic (reader,
2285 int32_write_multi (TestTypeNode *node,
2287 DBusTypeWriter *writer,
2291 /* also used for uint32 */
2292 dbus_int32_t values[MAX_MULTI_COUNT];
2293 dbus_int32_t *v_ARRAY_INT32 = values;
2296 for (i = 0; i < count; ++i)
2297 values[i] = int32_from_seed (seed + i);
2299 return _dbus_type_writer_write_fixed_multi (writer,
2300 node->klass->typecode,
2301 &v_ARRAY_INT32, count);
2305 int32_read_multi (TestTypeNode *node,
2306 DBusTypeReader *reader,
2310 /* also used for uint32 */
2311 dbus_int32_t *values;
2315 check_expected_type (reader, node->klass->typecode);
2317 _dbus_type_reader_read_fixed_multi (reader,
2321 if (n_elements != count)
2322 _dbus_warn ("got %d elements expected %d\n", n_elements, count);
2323 _dbus_assert (n_elements == count);
2325 for (i = 0; i < count; i++)
2326 _dbus_assert (((int)_dbus_unpack_uint32 (reader->byte_order,
2327 (const unsigned char*)values + (i * 4))) ==
2328 int32_from_seed (seed + i));
2333 #ifdef DBUS_HAVE_INT64
2335 int64_from_seed (int seed)
2340 v32 = int32_from_seed (seed);
2342 v = - (dbus_int32_t) ~ v32;
2343 v |= (((dbus_int64_t)v32) << 32);
2350 int64_write_value (TestTypeNode *node,
2352 DBusTypeWriter *writer,
2355 #ifdef DBUS_HAVE_INT64
2356 /* also used for uint64 */
2359 v = int64_from_seed (seed);
2361 return _dbus_type_writer_write_basic (writer,
2362 node->klass->typecode,
2370 int64_read_value (TestTypeNode *node,
2371 DBusTypeReader *reader,
2374 #ifdef DBUS_HAVE_INT64
2375 /* also used for uint64 */
2378 check_expected_type (reader, node->klass->typecode);
2380 _dbus_type_reader_read_basic (reader,
2381 (dbus_int64_t*) &v);
2383 _dbus_assert (v == int64_from_seed (seed));
2392 int64_set_value (TestTypeNode *node,
2393 DBusTypeReader *reader,
2394 DBusTypeReader *realign_root,
2397 #ifdef DBUS_HAVE_INT64
2398 /* also used for uint64 */
2401 v = int64_from_seed (seed);
2403 return _dbus_type_reader_set_basic (reader,
2411 #define MAX_SAMPLE_STRING_LEN 10
2413 string_from_seed (char *buf,
2420 _dbus_assert (len < MAX_SAMPLE_STRING_LEN);
2422 /* vary the length slightly, though we also have multiple string
2423 * value types for this, varying it here tests the set_value code
2437 v = (unsigned char) ('A' + seed);
2442 if (v < 'A' || v > 'z')
2455 string_write_value (TestTypeNode *node,
2457 DBusTypeWriter *writer,
2460 char buf[MAX_SAMPLE_STRING_LEN];
2461 const char *v_string = buf;
2463 string_from_seed (buf, node->klass->subclass_detail,
2466 return _dbus_type_writer_write_basic (writer,
2467 node->klass->typecode,
2472 string_read_value (TestTypeNode *node,
2473 DBusTypeReader *reader,
2477 char buf[MAX_SAMPLE_STRING_LEN];
2479 check_expected_type (reader, node->klass->typecode);
2481 _dbus_type_reader_read_basic (reader,
2482 (const char **) &v);
2484 string_from_seed (buf, node->klass->subclass_detail,
2487 if (strcmp (buf, v) != 0)
2489 _dbus_warn ("read string '%s' expected '%s'\n",
2491 _dbus_assert_not_reached ("test failed");
2498 string_set_value (TestTypeNode *node,
2499 DBusTypeReader *reader,
2500 DBusTypeReader *realign_root,
2503 char buf[MAX_SAMPLE_STRING_LEN];
2504 const char *v_string = buf;
2506 string_from_seed (buf, node->klass->subclass_detail,
2509 #if RECURSIVE_MARSHAL_WRITE_TRACE
2512 _dbus_type_reader_read_basic (reader, &old);
2513 _dbus_verbose ("SETTING new string '%s' len %d in place of '%s' len %d\n",
2514 v_string, strlen (v_string), old, strlen (old));
2518 return _dbus_type_reader_set_basic (reader,
2523 #define BOOL_FROM_SEED(seed) ((dbus_bool_t)((seed) % 2))
2526 bool_write_value (TestTypeNode *node,
2528 DBusTypeWriter *writer,
2533 v = BOOL_FROM_SEED (seed);
2535 return _dbus_type_writer_write_basic (writer,
2536 node->klass->typecode,
2541 bool_read_value (TestTypeNode *node,
2542 DBusTypeReader *reader,
2547 check_expected_type (reader, node->klass->typecode);
2549 _dbus_type_reader_read_basic (reader,
2550 (unsigned char*) &v);
2552 _dbus_assert (v == BOOL_FROM_SEED (seed));
2558 bool_set_value (TestTypeNode *node,
2559 DBusTypeReader *reader,
2560 DBusTypeReader *realign_root,
2565 v = BOOL_FROM_SEED (seed);
2567 return _dbus_type_reader_set_basic (reader,
2572 #define BYTE_FROM_SEED(seed) ((unsigned char) int32_from_seed (seed))
2575 byte_write_value (TestTypeNode *node,
2577 DBusTypeWriter *writer,
2582 v = BYTE_FROM_SEED (seed);
2584 return _dbus_type_writer_write_basic (writer,
2585 node->klass->typecode,
2590 byte_read_value (TestTypeNode *node,
2591 DBusTypeReader *reader,
2596 check_expected_type (reader, node->klass->typecode);
2598 _dbus_type_reader_read_basic (reader,
2599 (unsigned char*) &v);
2601 _dbus_assert (v == BYTE_FROM_SEED (seed));
2608 byte_set_value (TestTypeNode *node,
2609 DBusTypeReader *reader,
2610 DBusTypeReader *realign_root,
2615 v = BYTE_FROM_SEED (seed);
2617 return _dbus_type_reader_set_basic (reader,
2623 double_from_seed (int seed)
2625 return SAMPLE_INT32 * (double) seed + 0.3;
2629 double_write_value (TestTypeNode *node,
2631 DBusTypeWriter *writer,
2636 v = double_from_seed (seed);
2638 return _dbus_type_writer_write_basic (writer,
2639 node->klass->typecode,
2644 double_read_value (TestTypeNode *node,
2645 DBusTypeReader *reader,
2651 check_expected_type (reader, node->klass->typecode);
2653 _dbus_type_reader_read_basic (reader,
2656 expected = double_from_seed (seed);
2658 if (!_DBUS_DOUBLES_BITWISE_EQUAL (v, expected))
2660 #ifdef DBUS_HAVE_INT64
2661 _dbus_warn ("Expected double %g got %g\n bits = 0x%llx vs.\n bits = 0x%llx)\n",
2663 *(dbus_uint64_t*)(char*)&expected,
2664 *(dbus_uint64_t*)(char*)&v);
2666 _dbus_assert_not_reached ("test failed");
2673 double_set_value (TestTypeNode *node,
2674 DBusTypeReader *reader,
2675 DBusTypeReader *realign_root,
2680 v = double_from_seed (seed);
2682 return _dbus_type_reader_set_basic (reader,
2687 #define MAX_SAMPLE_OBJECT_PATH_LEN 10
2689 object_path_from_seed (char *buf,
2697 _dbus_assert (len < MAX_SAMPLE_OBJECT_PATH_LEN);
2699 v = (unsigned char) ('A' + seed);
2711 if (v < 'A' || v > 'z')
2727 object_path_write_value (TestTypeNode *node,
2729 DBusTypeWriter *writer,
2732 char buf[MAX_SAMPLE_OBJECT_PATH_LEN];
2733 const char *v_string = buf;
2735 object_path_from_seed (buf, seed);
2737 return _dbus_type_writer_write_basic (writer,
2738 node->klass->typecode,
2743 object_path_read_value (TestTypeNode *node,
2744 DBusTypeReader *reader,
2748 char buf[MAX_SAMPLE_OBJECT_PATH_LEN];
2750 check_expected_type (reader, node->klass->typecode);
2752 _dbus_type_reader_read_basic (reader,
2753 (const char **) &v);
2755 object_path_from_seed (buf, seed);
2757 if (strcmp (buf, v) != 0)
2759 _dbus_warn ("read object path '%s' expected '%s'\n",
2761 _dbus_assert_not_reached ("test failed");
2768 object_path_set_value (TestTypeNode *node,
2769 DBusTypeReader *reader,
2770 DBusTypeReader *realign_root,
2773 char buf[MAX_SAMPLE_OBJECT_PATH_LEN];
2774 const char *v_string = buf;
2776 object_path_from_seed (buf, seed);
2778 return _dbus_type_reader_set_basic (reader,
2783 #define MAX_SAMPLE_SIGNATURE_LEN 10
2785 signature_from_seed (char *buf,
2790 /* try to avoid ascending, descending, or alternating length to help find bugs */
2791 const char *sample_signatures[] = {
2800 s = sample_signatures[seed % _DBUS_N_ELEMENTS(sample_signatures)];
2802 for (i = 0; s[i]; i++)
2810 signature_write_value (TestTypeNode *node,
2812 DBusTypeWriter *writer,
2815 char buf[MAX_SAMPLE_SIGNATURE_LEN];
2816 const char *v_string = buf;
2818 signature_from_seed (buf, seed);
2820 return _dbus_type_writer_write_basic (writer,
2821 node->klass->typecode,
2826 signature_read_value (TestTypeNode *node,
2827 DBusTypeReader *reader,
2831 char buf[MAX_SAMPLE_SIGNATURE_LEN];
2833 check_expected_type (reader, node->klass->typecode);
2835 _dbus_type_reader_read_basic (reader,
2836 (const char **) &v);
2838 signature_from_seed (buf, seed);
2840 if (strcmp (buf, v) != 0)
2842 _dbus_warn ("read signature value '%s' expected '%s'\n",
2844 _dbus_assert_not_reached ("test failed");
2852 signature_set_value (TestTypeNode *node,
2853 DBusTypeReader *reader,
2854 DBusTypeReader *realign_root,
2857 char buf[MAX_SAMPLE_SIGNATURE_LEN];
2858 const char *v_string = buf;
2860 signature_from_seed (buf, seed);
2862 return _dbus_type_reader_set_basic (reader,
2868 struct_write_value (TestTypeNode *node,
2870 DBusTypeWriter *writer,
2873 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2874 DataBlockState saved;
2879 n_copies = node->klass->subclass_detail;
2881 _dbus_assert (container->children != NULL);
2883 data_block_save (block, &saved);
2885 if (!_dbus_type_writer_recurse (writer, DBUS_TYPE_STRUCT,
2891 while (i < n_copies)
2895 link = _dbus_list_get_first_link (&container->children);
2896 while (link != NULL)
2898 TestTypeNode *child = link->data;
2899 DBusList *next = _dbus_list_get_next_link (&container->children, link);
2901 if (!node_write_value (child, block, &sub, seed + i))
2903 data_block_restore (block, &saved);
2913 if (!_dbus_type_writer_unrecurse (writer, &sub))
2915 data_block_restore (block, &saved);
2923 struct_read_or_set_value (TestTypeNode *node,
2924 DBusTypeReader *reader,
2925 DBusTypeReader *realign_root,
2928 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2933 n_copies = node->klass->subclass_detail;
2935 check_expected_type (reader, DBUS_TYPE_STRUCT);
2937 _dbus_type_reader_recurse (reader, &sub);
2940 while (i < n_copies)
2944 link = _dbus_list_get_first_link (&container->children);
2945 while (link != NULL)
2947 TestTypeNode *child = link->data;
2948 DBusList *next = _dbus_list_get_next_link (&container->children, link);
2950 if (realign_root == NULL)
2952 if (!node_read_value (child, &sub, seed + i))
2957 if (!node_set_value (child, &sub, realign_root, seed + i))
2961 if (i == (n_copies - 1) && next == NULL)
2962 NEXT_EXPECTING_FALSE (&sub);
2964 NEXT_EXPECTING_TRUE (&sub);
2976 struct_read_value (TestTypeNode *node,
2977 DBusTypeReader *reader,
2980 return struct_read_or_set_value (node, reader, NULL, seed);
2984 struct_set_value (TestTypeNode *node,
2985 DBusTypeReader *reader,
2986 DBusTypeReader *realign_root,
2989 return struct_read_or_set_value (node, reader, realign_root, seed);
2993 struct_build_signature (TestTypeNode *node,
2996 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3001 n_copies = node->klass->subclass_detail;
3003 orig_len = _dbus_string_get_length (str);
3005 if (!_dbus_string_append_byte (str, DBUS_STRUCT_BEGIN_CHAR))
3009 while (i < n_copies)
3013 link = _dbus_list_get_first_link (&container->children);
3014 while (link != NULL)
3016 TestTypeNode *child = link->data;
3017 DBusList *next = _dbus_list_get_next_link (&container->children, link);
3019 if (!node_build_signature (child, str))
3028 if (!_dbus_string_append_byte (str, DBUS_STRUCT_END_CHAR))
3034 _dbus_string_set_length (str, orig_len);
3039 array_write_value (TestTypeNode *node,
3041 DBusTypeWriter *writer,
3044 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3045 DataBlockState saved;
3047 DBusString element_signature;
3051 TestTypeNode *child;
3053 n_copies = node->klass->subclass_detail;
3055 _dbus_assert (container->children != NULL);
3057 data_block_save (block, &saved);
3059 if (!_dbus_string_init (&element_signature))
3062 child = _dbus_list_get_first (&container->children);
3064 if (!node_build_signature (child,
3065 &element_signature))
3068 element_type = _dbus_first_type_in_signature (&element_signature, 0);
3070 if (!_dbus_type_writer_recurse (writer, DBUS_TYPE_ARRAY,
3071 &element_signature, 0,
3075 if (arrays_write_fixed_in_blocks &&
3076 _dbus_type_is_fixed (element_type) &&
3077 child->klass->write_multi)
3079 if (!node_write_multi (child, block, &sub, seed, n_copies))
3085 while (i < n_copies)
3089 link = _dbus_list_get_first_link (&container->children);
3090 while (link != NULL)
3092 TestTypeNode *child = link->data;
3093 DBusList *next = _dbus_list_get_next_link (&container->children, link);
3095 if (!node_write_value (child, block, &sub, seed + i))
3105 if (!_dbus_type_writer_unrecurse (writer, &sub))
3108 _dbus_string_free (&element_signature);
3112 data_block_restore (block, &saved);
3113 _dbus_string_free (&element_signature);
3118 array_read_or_set_value (TestTypeNode *node,
3119 DBusTypeReader *reader,
3120 DBusTypeReader *realign_root,
3123 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3127 TestTypeNode *child;
3129 n_copies = node->klass->subclass_detail;
3131 check_expected_type (reader, DBUS_TYPE_ARRAY);
3133 child = _dbus_list_get_first (&container->children);
3137 _dbus_type_reader_recurse (reader, &sub);
3139 if (realign_root == NULL && arrays_write_fixed_in_blocks &&
3140 _dbus_type_is_fixed (_dbus_type_reader_get_element_type (reader)) &&
3141 child->klass->read_multi)
3143 if (!node_read_multi (child, &sub, seed, n_copies))
3149 while (i < n_copies)
3153 link = _dbus_list_get_first_link (&container->children);
3154 while (link != NULL)
3156 TestTypeNode *child = link->data;
3157 DBusList *next = _dbus_list_get_next_link (&container->children, link);
3159 _dbus_assert (child->klass->typecode ==
3160 _dbus_type_reader_get_element_type (reader));
3162 if (realign_root == NULL)
3164 if (!node_read_value (child, &sub, seed + i))
3169 if (!node_set_value (child, &sub, realign_root, seed + i))
3173 if (i == (n_copies - 1) && next == NULL)
3174 NEXT_EXPECTING_FALSE (&sub);
3176 NEXT_EXPECTING_TRUE (&sub);
3190 array_read_value (TestTypeNode *node,
3191 DBusTypeReader *reader,
3194 return array_read_or_set_value (node, reader, NULL, seed);
3198 array_set_value (TestTypeNode *node,
3199 DBusTypeReader *reader,
3200 DBusTypeReader *realign_root,
3203 return array_read_or_set_value (node, reader, realign_root, seed);
3207 array_build_signature (TestTypeNode *node,
3210 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3213 orig_len = _dbus_string_get_length (str);
3215 if (!_dbus_string_append_byte (str, DBUS_TYPE_ARRAY))
3218 if (!node_build_signature (_dbus_list_get_first (&container->children),
3225 _dbus_string_set_length (str, orig_len);
3229 /* 10 is random just to add another seed that we use in the suite */
3230 #define VARIANT_SEED 10
3233 variant_write_value (TestTypeNode *node,
3235 DBusTypeWriter *writer,
3238 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3239 DataBlockState saved;
3241 DBusString content_signature;
3242 TestTypeNode *child;
3244 _dbus_assert (container->children != NULL);
3245 _dbus_assert (_dbus_list_length_is_one (&container->children));
3247 child = _dbus_list_get_first (&container->children);
3249 data_block_save (block, &saved);
3251 if (!_dbus_string_init (&content_signature))
3254 if (!node_build_signature (child,
3255 &content_signature))
3258 if (!_dbus_type_writer_recurse (writer, DBUS_TYPE_VARIANT,
3259 &content_signature, 0,
3263 if (!node_write_value (child, block, &sub, seed + VARIANT_SEED))
3266 if (!_dbus_type_writer_unrecurse (writer, &sub))
3269 _dbus_string_free (&content_signature);
3273 data_block_restore (block, &saved);
3274 _dbus_string_free (&content_signature);
3279 variant_read_or_set_value (TestTypeNode *node,
3280 DBusTypeReader *reader,
3281 DBusTypeReader *realign_root,
3284 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3286 TestTypeNode *child;
3288 _dbus_assert (container->children != NULL);
3289 _dbus_assert (_dbus_list_length_is_one (&container->children));
3291 child = _dbus_list_get_first (&container->children);
3293 check_expected_type (reader, DBUS_TYPE_VARIANT);
3295 _dbus_type_reader_recurse (reader, &sub);
3297 if (realign_root == NULL)
3299 if (!node_read_value (child, &sub, seed + VARIANT_SEED))
3304 if (!node_set_value (child, &sub, realign_root, seed + VARIANT_SEED))
3308 NEXT_EXPECTING_FALSE (&sub);
3314 variant_read_value (TestTypeNode *node,
3315 DBusTypeReader *reader,
3318 return variant_read_or_set_value (node, reader, NULL, seed);
3322 variant_set_value (TestTypeNode *node,
3323 DBusTypeReader *reader,
3324 DBusTypeReader *realign_root,
3327 return variant_read_or_set_value (node, reader, realign_root, seed);
3331 dict_write_value (TestTypeNode *node,
3333 DBusTypeWriter *writer,
3336 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3337 DataBlockState saved;
3339 DBusString entry_value_signature;
3340 DBusString dict_entry_signature;
3343 int entry_value_type;
3344 TestTypeNode *child;
3346 n_entries = node->klass->subclass_detail;
3348 _dbus_assert (container->children != NULL);
3350 data_block_save (block, &saved);
3352 if (!_dbus_string_init (&entry_value_signature))
3355 if (!_dbus_string_init (&dict_entry_signature))
3357 _dbus_string_free (&entry_value_signature);
3361 child = _dbus_list_get_first (&container->children);
3363 if (!node_build_signature (child,
3364 &entry_value_signature))
3367 if (!_dbus_string_append (&dict_entry_signature,
3368 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
3369 DBUS_TYPE_INT32_AS_STRING))
3372 if (!_dbus_string_copy (&entry_value_signature, 0,
3373 &dict_entry_signature,
3374 _dbus_string_get_length (&dict_entry_signature)))
3377 if (!_dbus_string_append_byte (&dict_entry_signature,
3378 DBUS_DICT_ENTRY_END_CHAR))
3381 entry_value_type = _dbus_first_type_in_signature (&entry_value_signature, 0);
3383 if (!_dbus_type_writer_recurse (writer, DBUS_TYPE_ARRAY,
3384 &dict_entry_signature, 0,
3389 while (i < n_entries)
3391 DBusTypeWriter entry_sub;
3394 if (!_dbus_type_writer_recurse (&sub, DBUS_TYPE_DICT_ENTRY,
3399 key = int32_from_seed (seed + i);
3401 if (!_dbus_type_writer_write_basic (&entry_sub,
3406 if (!node_write_value (child, block, &entry_sub, seed + i))
3409 if (!_dbus_type_writer_unrecurse (&sub, &entry_sub))
3415 if (!_dbus_type_writer_unrecurse (writer, &sub))
3418 _dbus_string_free (&entry_value_signature);
3419 _dbus_string_free (&dict_entry_signature);
3423 data_block_restore (block, &saved);
3424 _dbus_string_free (&entry_value_signature);
3425 _dbus_string_free (&dict_entry_signature);
3430 dict_read_or_set_value (TestTypeNode *node,
3431 DBusTypeReader *reader,
3432 DBusTypeReader *realign_root,
3435 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3439 TestTypeNode *child;
3441 n_entries = node->klass->subclass_detail;
3443 check_expected_type (reader, DBUS_TYPE_ARRAY);
3445 child = _dbus_list_get_first (&container->children);
3449 _dbus_type_reader_recurse (reader, &sub);
3451 check_expected_type (&sub, DBUS_TYPE_DICT_ENTRY);
3454 while (i < n_entries)
3456 DBusTypeReader entry_sub;
3458 check_expected_type (&sub, DBUS_TYPE_DICT_ENTRY);
3460 _dbus_type_reader_recurse (&sub, &entry_sub);
3462 if (realign_root == NULL)
3466 check_expected_type (&entry_sub, DBUS_TYPE_INT32);
3468 _dbus_type_reader_read_basic (&entry_sub,
3469 (dbus_int32_t*) &v);
3471 _dbus_assert (v == int32_from_seed (seed + i));
3473 NEXT_EXPECTING_TRUE (&entry_sub);
3475 if (!node_read_value (child, &entry_sub, seed + i))
3478 NEXT_EXPECTING_FALSE (&entry_sub);
3484 v = int32_from_seed (seed + i);
3486 if (!_dbus_type_reader_set_basic (&entry_sub,
3491 NEXT_EXPECTING_TRUE (&entry_sub);
3493 if (!node_set_value (child, &entry_sub, realign_root, seed + i))
3496 NEXT_EXPECTING_FALSE (&entry_sub);
3499 if (i == (n_entries - 1))
3500 NEXT_EXPECTING_FALSE (&sub);
3502 NEXT_EXPECTING_TRUE (&sub);
3512 dict_read_value (TestTypeNode *node,
3513 DBusTypeReader *reader,
3516 return dict_read_or_set_value (node, reader, NULL, seed);
3520 dict_set_value (TestTypeNode *node,
3521 DBusTypeReader *reader,
3522 DBusTypeReader *realign_root,
3525 return dict_read_or_set_value (node, reader, realign_root, seed);
3529 dict_build_signature (TestTypeNode *node,
3532 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3535 orig_len = _dbus_string_get_length (str);
3537 if (!_dbus_string_append_byte (str, DBUS_TYPE_ARRAY))
3540 if (!_dbus_string_append (str, DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_INT32_AS_STRING))
3543 if (!node_build_signature (_dbus_list_get_first (&container->children),
3547 if (!_dbus_string_append_byte (str, DBUS_DICT_ENTRY_END_CHAR))
3553 _dbus_string_set_length (str, orig_len);
3558 container_destroy (TestTypeNode *node)
3560 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3563 link = _dbus_list_get_first_link (&container->children);
3564 while (link != NULL)
3566 TestTypeNode *child = link->data;
3567 DBusList *next = _dbus_list_get_next_link (&container->children, link);
3569 node_destroy (child);
3571 _dbus_list_free_link (link);
3577 #endif /* DBUS_BUILD_TESTS */