26 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 28 #include "dbus-marshal-recursive.h" 29 #include "dbus-marshal-basic.h" 30 #include "dbus-signature.h" 31 #include "dbus-internals.h" 32 #include <dbus/dbus-test-tap.h> 35 #if !defined(PRIx64) && defined(DBUS_WIN) 40 #define RECURSIVE_MARSHAL_WRITE_TRACE 0 49 basic_value_equal (
int type,
57 return strcmp (lhs->
str, rhs->
str) == 0;
61 return lhs->
u64 == rhs->
u64;
75 if (lhs_type != rhs_type)
86 basic_value_zero (&lhs_value);
87 basic_value_zero (&rhs_value);
92 return basic_value_equal (lhs_type, &lhs_value, &rhs_value);
102 return equal_values_helper (&lhs_sub, &rhs_sub);
120 return equal_values_helper (©_lhs, ©_rhs);
125 #ifndef DOXYGEN_SHOULD_SKIP_THIS 127 #include "dbus-test.h" 128 #include "dbus-list.h" 133 #define TEST_OOM_HANDLING 0 137 #define MAX_INITIAL_OFFSET 9 143 #define MAX_ITERATIONS_FOR_EXPENSIVE_TESTS 1000 159 #define N_FENCE_BYTES 5 160 #define FENCE_BYTES_STR "abcde" 161 #define INITIAL_PADDING_BYTE '\0' 164 data_block_init (DataBlock *block,
178 INITIAL_PADDING_BYTE) ||
180 INITIAL_PADDING_BYTE) ||
189 block->byte_order = byte_order;
190 block->initial_offset = initial_offset;
196 data_block_save (DataBlock *block,
197 DataBlockState *state)
199 state->saved_sig_len = _dbus_string_get_length (&block->signature) - N_FENCE_BYTES;
200 state->saved_body_len = _dbus_string_get_length (&block->body) - N_FENCE_BYTES;
204 data_block_restore (DataBlock *block,
205 DataBlockState *state)
208 state->saved_sig_len,
209 _dbus_string_get_length (&block->signature) - state->saved_sig_len - N_FENCE_BYTES);
211 state->saved_body_len,
212 _dbus_string_get_length (&block->body) - state->saved_body_len - N_FENCE_BYTES);
216 data_block_verify (DataBlock *block)
223 offset = _dbus_string_get_length (&block->signature) - N_FENCE_BYTES - 8;
229 _dbus_string_get_length (&block->signature) - offset);
230 _dbus_test_fatal (
"block did not verify: bad bytes at end of signature");
237 offset = _dbus_string_get_length (&block->body) - N_FENCE_BYTES - 8;
243 _dbus_string_get_length (&block->body) - offset);
244 _dbus_test_fatal (
"block did not verify: bad bytes at end of body");
248 0, block->initial_offset));
250 0, block->initial_offset));
254 data_block_free (DataBlock *block)
256 data_block_verify (block);
263 data_block_reset (DataBlock *block)
265 data_block_verify (block);
268 block->initial_offset,
269 _dbus_string_get_length (&block->signature) - N_FENCE_BYTES - block->initial_offset);
271 block->initial_offset,
272 _dbus_string_get_length (&block->body) - N_FENCE_BYTES - block->initial_offset);
274 data_block_verify (block);
278 data_block_init_reader_writer (DataBlock *block,
286 block->initial_offset,
288 block->initial_offset);
294 _dbus_string_get_length (&block->signature) - N_FENCE_BYTES,
296 _dbus_string_get_length (&block->body) - N_FENCE_BYTES);
302 const char *funcname,
311 _dbus_test_fatal (
"Read wrong type: read type %s while expecting %s at %s line %d",
318 #define check_expected_type(reader, expected) real_check_expected_type (reader, expected, _DBUS_FUNCTION_NAME, __LINE__) 320 #define NEXT_EXPECTING_TRUE(reader) do { if (!_dbus_type_reader_next (reader)) \ 322 _dbus_test_fatal ("_dbus_type_reader_next() should have returned TRUE at %s %d", \ 323 _DBUS_FUNCTION_NAME, __LINE__); \ 327 #define NEXT_EXPECTING_FALSE(reader) do { if (_dbus_type_reader_next (reader)) \ 329 _dbus_test_fatal ("_dbus_type_reader_next() should have returned FALSE at %s %d", \ 330 _DBUS_FUNCTION_NAME, __LINE__); \ 332 check_expected_type (reader, DBUS_TYPE_INVALID); \ 335 typedef struct TestTypeNode TestTypeNode;
336 typedef struct TestTypeNodeClass TestTypeNodeClass;
337 typedef struct TestTypeNodeContainer TestTypeNodeContainer;
338 typedef struct TestTypeNodeContainerClass TestTypeNodeContainerClass;
342 const TestTypeNodeClass *klass;
345 struct TestTypeNodeContainer
351 struct TestTypeNodeClass
360 void (* destroy) (TestTypeNode *node);
373 dbus_bool_t (* build_signature) (TestTypeNode *node,
386 struct TestTypeNodeContainerClass
388 TestTypeNodeClass base;
396 static dbus_bool_t uint16_write_value (TestTypeNode *node,
400 static dbus_bool_t uint16_read_value (TestTypeNode *node,
403 static dbus_bool_t uint16_set_value (TestTypeNode *node,
407 static dbus_bool_t uint16_write_multi (TestTypeNode *node,
412 static dbus_bool_t uint16_read_multi (TestTypeNode *node,
416 static dbus_bool_t uint32_write_value (TestTypeNode *node,
420 static dbus_bool_t uint32_read_value (TestTypeNode *node,
423 static dbus_bool_t uint32_set_value (TestTypeNode *node,
427 static dbus_bool_t uint32_write_multi (TestTypeNode *node,
432 static dbus_bool_t uint32_read_multi (TestTypeNode *node,
436 static dbus_bool_t uint64_write_value (TestTypeNode *node,
440 static dbus_bool_t uint64_read_value (TestTypeNode *node,
443 static dbus_bool_t uint64_set_value (TestTypeNode *node,
447 static dbus_bool_t string_write_value (TestTypeNode *node,
451 static dbus_bool_t string_read_value (TestTypeNode *node,
454 static dbus_bool_t string_set_value (TestTypeNode *node,
458 static dbus_bool_t bool_write_value (TestTypeNode *node,
462 static dbus_bool_t bool_read_value (TestTypeNode *node,
465 static dbus_bool_t bool_set_value (TestTypeNode *node,
469 static dbus_bool_t byte_write_value (TestTypeNode *node,
473 static dbus_bool_t byte_read_value (TestTypeNode *node,
476 static dbus_bool_t byte_set_value (TestTypeNode *node,
480 static dbus_bool_t double_write_value (TestTypeNode *node,
484 static dbus_bool_t double_read_value (TestTypeNode *node,
487 static dbus_bool_t double_set_value (TestTypeNode *node,
491 static dbus_bool_t object_path_write_value (TestTypeNode *node,
495 static dbus_bool_t object_path_read_value (TestTypeNode *node,
498 static dbus_bool_t object_path_set_value (TestTypeNode *node,
502 static dbus_bool_t signature_write_value (TestTypeNode *node,
506 static dbus_bool_t signature_read_value (TestTypeNode *node,
509 static dbus_bool_t signature_set_value (TestTypeNode *node,
513 static dbus_bool_t struct_write_value (TestTypeNode *node,
517 static dbus_bool_t struct_read_value (TestTypeNode *node,
520 static dbus_bool_t struct_set_value (TestTypeNode *node,
524 static dbus_bool_t struct_build_signature (TestTypeNode *node,
526 static dbus_bool_t dict_write_value (TestTypeNode *node,
530 static dbus_bool_t dict_read_value (TestTypeNode *node,
533 static dbus_bool_t dict_set_value (TestTypeNode *node,
537 static dbus_bool_t dict_build_signature (TestTypeNode *node,
539 static dbus_bool_t array_write_value (TestTypeNode *node,
543 static dbus_bool_t array_read_value (TestTypeNode *node,
546 static dbus_bool_t array_set_value (TestTypeNode *node,
550 static dbus_bool_t array_build_signature (TestTypeNode *node,
552 static dbus_bool_t variant_write_value (TestTypeNode *node,
556 static dbus_bool_t variant_read_value (TestTypeNode *node,
559 static dbus_bool_t variant_set_value (TestTypeNode *node,
563 static void container_destroy (TestTypeNode *node);
567 static const TestTypeNodeClass int16_class = {
569 sizeof (TestTypeNode),
581 static const TestTypeNodeClass uint16_class = {
583 sizeof (TestTypeNode),
595 static const TestTypeNodeClass int32_class = {
597 sizeof (TestTypeNode),
609 static const TestTypeNodeClass uint32_class = {
611 sizeof (TestTypeNode),
623 static const TestTypeNodeClass int64_class = {
625 sizeof (TestTypeNode),
637 static const TestTypeNodeClass uint64_class = {
639 sizeof (TestTypeNode),
651 static const TestTypeNodeClass string_0_class = {
653 sizeof (TestTypeNode),
665 static const TestTypeNodeClass string_1_class = {
667 sizeof (TestTypeNode),
680 static const TestTypeNodeClass string_3_class = {
682 sizeof (TestTypeNode),
695 static const TestTypeNodeClass string_8_class = {
697 sizeof (TestTypeNode),
709 static const TestTypeNodeClass bool_class = {
711 sizeof (TestTypeNode),
723 static const TestTypeNodeClass byte_class = {
725 sizeof (TestTypeNode),
737 static const TestTypeNodeClass double_class = {
739 sizeof (TestTypeNode),
751 static const TestTypeNodeClass object_path_class = {
753 sizeof (TestTypeNode),
757 object_path_write_value,
758 object_path_read_value,
759 object_path_set_value,
765 static const TestTypeNodeClass signature_class = {
767 sizeof (TestTypeNode),
771 signature_write_value,
772 signature_read_value,
779 static const TestTypeNodeClass struct_1_class = {
781 sizeof (TestTypeNodeContainer),
788 struct_build_signature,
793 static const TestTypeNodeClass struct_2_class = {
795 sizeof (TestTypeNodeContainer),
802 struct_build_signature,
807 static const TestTypeNodeClass dict_1_class = {
809 sizeof (TestTypeNodeContainer),
816 dict_build_signature,
823 static const TestTypeNodeClass array_0_class = {
825 sizeof (TestTypeNodeContainer),
832 array_build_signature,
837 static const TestTypeNodeClass array_1_class = {
839 sizeof (TestTypeNodeContainer),
846 array_build_signature,
851 static const TestTypeNodeClass array_2_class = {
853 sizeof (TestTypeNodeContainer),
860 array_build_signature,
865 static const TestTypeNodeClass array_9_class = {
867 sizeof (TestTypeNodeContainer),
874 array_build_signature,
879 static const TestTypeNodeClass variant_class = {
881 sizeof (TestTypeNodeContainer),
893 static const TestTypeNodeClass*
const 911 #define N_BASICS (_DBUS_N_ELEMENTS (basic_nodes)) 913 static const TestTypeNodeClass*
const 914 container_nodes[] = {
926 #define N_CONTAINERS (_DBUS_N_ELEMENTS (container_nodes)) 929 node_new (
const TestTypeNodeClass *klass)
939 if (klass->construct)
941 if (!(* klass->construct) (node))
952 node_destroy (TestTypeNode *node)
954 if (node->klass->destroy)
955 (* node->klass->destroy) (node);
960 node_write_value (TestTypeNode *node,
967 retval = (* node->klass->write_value) (node, block, writer, seed);
971 data_block_verify (block);
978 node_read_value (TestTypeNode *node,
984 if (!(* node->klass->read_value) (node, reader, seed))
995 node_set_value (TestTypeNode *node,
1000 if (!(* node->klass->set_value) (node, reader, realign_root, seed))
1007 node_build_signature (TestTypeNode *node,
1010 if (node->klass->build_signature)
1011 return (* node->klass->build_signature) (node, str);
1017 node_append_child (TestTypeNode *node,
1018 TestTypeNode *child)
1020 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
1022 _dbus_assert (node->klass->instance_size >= (
int) sizeof (TestTypeNodeContainer));
1025 _dbus_test_fatal (
"no memory");
1031 node_write_multi (TestTypeNode *node,
1040 retval = (* node->klass->write_multi) (node, block, writer, seed, n_copies);
1044 data_block_verify (block);
1051 node_read_multi (TestTypeNode *node,
1058 if (!(* node->klass->read_multi) (node, reader, seed, n_copies))
1064 static int n_iterations_completed_total = 0;
1065 static int n_iterations_completed_this_test = 0;
1066 static int n_iterations_expected_this_test = 0;
1073 TestTypeNode **nodes;
1075 } NodeIterationData;
1078 run_test_copy (NodeIterationData *nid)
1086 _dbus_verbose (
"\n");
1092 if (!data_block_init (&dest, src->byte_order, src->initial_offset))
1095 data_block_init_reader_writer (src, &reader,
NULL);
1096 data_block_init_reader_writer (&dest,
NULL, &writer);
1102 dest.initial_offset,
'\0'))
1111 _dbus_verbose (
"SOURCE\n");
1113 _dbus_string_get_length (&src->signature));
1114 _dbus_verbose (
"DEST\n");
1116 _dbus_string_get_length (&dest.signature));
1117 _dbus_test_fatal (
"signatures did not match");
1122 _dbus_verbose (
"SOURCE\n");
1124 _dbus_string_get_length (&src->body));
1125 _dbus_verbose (
"DEST\n");
1127 _dbus_string_get_length (&dest.body));
1128 _dbus_test_fatal (
"bodies did not match");
1135 data_block_free (&dest);
1141 run_test_values_only_write (NodeIterationData *nid)
1149 _dbus_verbose (
"\n");
1153 data_block_reset (nid->block);
1155 sig_len = _dbus_string_get_length (nid->signature);
1161 _dbus_string_get_length (&nid->block->body) - N_FENCE_BYTES);
1166 nid->block->initial_offset);
1169 while (i < nid->n_nodes)
1171 if (!node_write_value (nid->nodes[i], nid->block, &writer, i))
1178 _dbus_assert (sig_len == _dbus_string_get_length (nid->signature));
1182 while (i < nid->n_nodes)
1184 if (!node_read_value (nid->nodes[i], &reader, i))
1187 if (i + 1 == nid->n_nodes)
1188 NEXT_EXPECTING_FALSE (&reader);
1190 NEXT_EXPECTING_TRUE (&reader);
1198 data_block_reset (nid->block);
1210 run_test_set_values (NodeIterationData *nid)
1217 _dbus_verbose (
"\n");
1221 data_block_init_reader_writer (nid->block,
1224 realign_root = reader;
1227 while (i < nid->n_nodes)
1229 if (!node_set_value (nid->nodes[i],
1230 &reader, &realign_root,
1234 if (i + 1 == nid->n_nodes)
1235 NEXT_EXPECTING_FALSE (&reader);
1237 NEXT_EXPECTING_TRUE (&reader);
1244 reader = realign_root;
1247 while (i < nid->n_nodes)
1249 if (!node_read_value (nid->nodes[i], &reader,
1253 if (i + 1 == nid->n_nodes)
1254 NEXT_EXPECTING_FALSE (&reader);
1256 NEXT_EXPECTING_TRUE (&reader);
1268 run_test_delete_values (NodeIterationData *nid)
1274 _dbus_verbose (
"\n");
1278 data_block_init_reader_writer (nid->block,
1303 _dbus_verbose (
"recursing into deletion loop reader.value_pos = %d array.value_pos = %d array.u.start_pos = %d\n",
1308 static int cycle = 0;
1314 if (elem == 3 || elem >= n_elements)
1315 elem = n_elements - 1;
1317 _dbus_verbose (
"deleting array element %d of %d type %s cycle %d reader pos %d elem pos %d\n",
1323 _dbus_test_fatal (
"should have had another element");
1345 data_block_init_reader_writer (nid->block,
1360 run_test_nodes_iteration (
void *data,
1363 NodeIterationData *nid = data;
1377 data_block_init_reader_writer (nid->block,
1384 nid->type_offset,
'\0'))
1388 while (i < nid->n_nodes)
1390 if (!node_write_value (nid->nodes[i], nid->block, &writer, i))
1397 &nid->block->signature, nid->type_offset))
1399 _dbus_test_fatal (
"Expected signature '%s' and got '%s' with initial offset %d",
1400 _dbus_string_get_const_data (nid->signature),
1401 _dbus_string_get_const_data_len (&nid->block->signature, nid->type_offset, 0),
1406 while (i < nid->n_nodes)
1408 if (!node_read_value (nid->nodes[i], &reader, i))
1411 if (i + 1 == nid->n_nodes)
1412 NEXT_EXPECTING_FALSE (&reader);
1414 NEXT_EXPECTING_TRUE (&reader);
1419 if (n_iterations_expected_this_test <= MAX_ITERATIONS_FOR_EXPENSIVE_TESTS)
1428 if (!run_test_set_values (nid))
1431 if (!run_test_delete_values (nid))
1434 if (!run_test_copy (nid))
1437 if (!run_test_values_only_write (nid))
1449 data_block_reset (nid->block);
1455 run_test_nodes_in_one_configuration (TestTypeNode **nodes,
1462 NodeIterationData nid;
1464 if (!data_block_init (&block, byte_order, initial_offset))
1465 _dbus_test_fatal (
"no memory");
1467 nid.signature = signature;
1469 nid.type_offset = initial_offset;
1471 nid.n_nodes = n_nodes;
1473 if (TEST_OOM_HANDLING &&
1474 n_iterations_expected_this_test <= MAX_ITERATIONS_FOR_EXPENSIVE_TESTS)
1476 _dbus_test_oom_handling (
"running test node",
1477 run_test_nodes_iteration,
1482 if (!run_test_nodes_iteration (&nid,
TRUE))
1483 _dbus_test_fatal (
"no memory");
1486 data_block_free (&block);
1490 run_test_nodes (TestTypeNode **nodes,
1497 _dbus_test_fatal (
"no memory");
1502 if (! node_build_signature (nodes[i], &signature))
1503 _dbus_test_fatal (
"no memory");
1508 _dbus_verbose (
">>> test nodes with signature '%s'\n",
1509 _dbus_string_get_const_data (&signature));
1512 while (i <= MAX_INITIAL_OFFSET)
1514 run_test_nodes_in_one_configuration (nodes, n_nodes, &signature,
1516 run_test_nodes_in_one_configuration (nodes, n_nodes, &signature,
1522 n_iterations_completed_this_test += 1;
1523 n_iterations_completed_total += 1;
1525 if (n_iterations_completed_this_test == n_iterations_expected_this_test)
1527 fprintf (stderr,
" 100%% %d this test (%d cumulative)\n",
1528 n_iterations_completed_this_test,
1529 n_iterations_completed_total);
1532 else if ((n_iterations_completed_this_test %
1533 (
int)(n_iterations_expected_this_test / 10.0)) == 1)
1535 fprintf (stderr,
" %d%% ", (
int) (n_iterations_completed_this_test / (
double) n_iterations_expected_this_test * 100));
1541 #define N_VALUES (N_BASICS * N_CONTAINERS + N_BASICS) 1543 static TestTypeNode*
1544 value_generator (
int *ip)
1547 const TestTypeNodeClass *child_klass;
1548 const TestTypeNodeClass *container_klass;
1549 TestTypeNode *child;
1558 else if (i < N_BASICS)
1560 node = node_new (basic_nodes[i]);
1574 container_klass = container_nodes[i / N_BASICS];
1575 child_klass = basic_nodes[i % N_BASICS];
1577 node = node_new (container_klass);
1578 child = node_new (child_klass);
1580 node_append_child (node, child);
1589 build_body (TestTypeNode **nodes,
1603 if (! node_build_signature (nodes[i], signature))
1604 _dbus_test_fatal (
"no memory");
1609 if (!data_block_init (&block, byte_order, 0))
1610 _dbus_test_fatal (
"no memory");
1612 data_block_init_reader_writer (&block,
1620 _dbus_test_fatal (
"no memory");
1625 if (!node_write_value (nodes[i], &block, &writer, i))
1626 _dbus_test_fatal (
"no memory");
1632 _dbus_string_get_length (&block.body) - N_FENCE_BYTES,
1634 _dbus_test_fatal (
"oom");
1636 data_block_free (&block);
1640 _dbus_test_generate_bodies (
int sequence,
1645 TestTypeNode *nodes[1];
1649 nodes[0] = value_generator (&sequence);
1651 if (nodes[0] ==
NULL)
1656 build_body (nodes, n_nodes, byte_order, signature, body);
1662 node_destroy (nodes[i]);
1670 make_and_run_values_inside_container (
const TestTypeNodeClass *container_klass,
1674 TestTypeNode *container;
1675 TestTypeNode *child;
1678 root = node_new (container_klass);
1680 for (i = 1; i < n_nested; i++)
1682 child = node_new (container_klass);
1683 node_append_child (container, child);
1690 while ((child = value_generator (&i)))
1692 node_append_child (container, child);
1694 run_test_nodes (&root, 1);
1697 node_destroy (child);
1700 node_destroy (root);
1704 start_next_test (
const char *description,
1707 n_iterations_completed_this_test = 0;
1708 n_iterations_expected_this_test = expected;
1710 fprintf (stderr,
">>> >>> %s %d iterations\n",
1712 n_iterations_expected_this_test);
1716 make_and_run_test_nodes (
void)
1752 start_next_test (
"Each value by itself", N_VALUES);
1756 while ((node = value_generator (&i)))
1758 run_test_nodes (&node, 1);
1760 node_destroy (node);
1764 start_next_test (
"Each value by itself with arrays as blocks", N_VALUES);
1765 arrays_write_fixed_in_blocks =
TRUE;
1769 while ((node = value_generator (&i)))
1771 run_test_nodes (&node, 1);
1773 node_destroy (node);
1776 arrays_write_fixed_in_blocks =
FALSE;
1778 start_next_test (
"All values in one big toplevel", 1);
1780 TestTypeNode *nodes[N_VALUES];
1784 while ((node = value_generator (&i)))
1786 nodes[i - 1] = node;
1789 run_test_nodes (nodes, N_VALUES);
1791 for (i = 0; i < N_VALUES; i++)
1792 node_destroy (nodes[i]);
1795 start_next_test (
"Each value,value pair combination as toplevel, in both orders",
1796 N_VALUES * N_VALUES);
1798 TestTypeNode *nodes[2];
1801 while ((nodes[0] = value_generator (&i)))
1804 while ((nodes[1] = value_generator (&j)))
1806 run_test_nodes (nodes, 2);
1808 node_destroy (nodes[1]);
1811 node_destroy (nodes[0]);
1815 start_next_test (
"Each container containing each value",
1816 N_CONTAINERS * N_VALUES);
1817 for (i = 0; i < N_CONTAINERS; i++)
1819 const TestTypeNodeClass *container_klass = container_nodes[i];
1821 make_and_run_values_inside_container (container_klass, 1);
1824 start_next_test (
"Each container containing each value with arrays as blocks",
1825 N_CONTAINERS * N_VALUES);
1826 arrays_write_fixed_in_blocks =
TRUE;
1827 for (i = 0; i < N_CONTAINERS; i++)
1829 const TestTypeNodeClass *container_klass = container_nodes[i];
1831 make_and_run_values_inside_container (container_klass, 1);
1833 arrays_write_fixed_in_blocks =
FALSE;
1835 start_next_test (
"Each container of same container of each value",
1836 N_CONTAINERS * N_VALUES);
1837 for (i = 0; i < N_CONTAINERS; i++)
1839 const TestTypeNodeClass *container_klass = container_nodes[i];
1841 make_and_run_values_inside_container (container_klass, 2);
1844 start_next_test (
"Each container of same container of same container of each value",
1845 N_CONTAINERS * N_VALUES);
1846 for (i = 0; i < N_CONTAINERS; i++)
1848 const TestTypeNodeClass *container_klass = container_nodes[i];
1850 make_and_run_values_inside_container (container_klass, 3);
1853 start_next_test (
"Each value,value pair inside a struct",
1854 N_VALUES * N_VALUES);
1856 TestTypeNode *val1, *val2;
1859 node = node_new (&struct_1_class);
1862 while ((val1 = value_generator (&i)))
1865 while ((val2 = value_generator (&j)))
1867 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
1869 node_append_child (node, val1);
1870 node_append_child (node, val2);
1872 run_test_nodes (&node, 1);
1875 node_destroy (val2);
1877 node_destroy (val1);
1879 node_destroy (node);
1882 start_next_test (
"All values in one big struct", 1);
1885 TestTypeNode *child;
1887 node = node_new (&struct_1_class);
1890 while ((child = value_generator (&i)))
1891 node_append_child (node, child);
1893 run_test_nodes (&node, 1);
1895 node_destroy (node);
1898 start_next_test (
"Each value in a large array", N_VALUES);
1903 node = node_new (&array_9_class);
1906 while ((val = value_generator (&i)))
1908 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
1910 node_append_child (node, val);
1912 run_test_nodes (&node, 1);
1918 node_destroy (node);
1924 fprintf (stderr,
"skipping remaining marshal-recursive tests, " 1925 "run with DBUS_TEST_SLOW=1 (or more) to enable\n");
1929 start_next_test (
"Each container of each container of each value",
1930 N_CONTAINERS * N_CONTAINERS * N_VALUES);
1931 for (i = 0; i < N_CONTAINERS; i++)
1933 const TestTypeNodeClass *outer_container_klass = container_nodes[i];
1934 TestTypeNode *outer_container = node_new (outer_container_klass);
1936 for (j = 0; j < N_CONTAINERS; j++)
1938 TestTypeNode *child;
1939 const TestTypeNodeClass *inner_container_klass = container_nodes[j];
1940 TestTypeNode *inner_container = node_new (inner_container_klass);
1942 node_append_child (outer_container, inner_container);
1945 while ((child = value_generator (&m)))
1947 node_append_child (inner_container, child);
1949 run_test_nodes (&outer_container, 1);
1952 node_destroy (child);
1955 node_destroy (inner_container);
1957 node_destroy (outer_container);
1960 start_next_test (
"Each container of each container of each container of each value",
1961 N_CONTAINERS * N_CONTAINERS * N_CONTAINERS * N_VALUES);
1962 for (i = 0; i < N_CONTAINERS; i++)
1964 const TestTypeNodeClass *outer_container_klass = container_nodes[i];
1965 TestTypeNode *outer_container = node_new (outer_container_klass);
1967 for (j = 0; j < N_CONTAINERS; j++)
1969 const TestTypeNodeClass *inner_container_klass = container_nodes[j];
1970 TestTypeNode *inner_container = node_new (inner_container_klass);
1972 node_append_child (outer_container, inner_container);
1974 for (k = 0; k < N_CONTAINERS; k++)
1976 TestTypeNode *child;
1977 const TestTypeNodeClass *center_container_klass = container_nodes[k];
1978 TestTypeNode *center_container = node_new (center_container_klass);
1980 node_append_child (inner_container, center_container);
1983 while ((child = value_generator (&m)))
1985 node_append_child (center_container, child);
1987 run_test_nodes (&outer_container, 1);
1990 node_destroy (child);
1993 node_destroy (center_container);
1996 node_destroy (inner_container);
1998 node_destroy (outer_container);
2005 fprintf (stderr,
"skipping really slow marshal-recursive test, " 2006 "run with DBUS_TEST_SLOW=2 (or more) to enable\n");
2010 start_next_test (
"Each value,value,value triplet combination as toplevel, in all orders",
2011 N_VALUES * N_VALUES * N_VALUES);
2013 TestTypeNode *nodes[3];
2016 while ((nodes[0] = value_generator (&i)))
2019 while ((nodes[1] = value_generator (&j)))
2022 while ((nodes[2] = value_generator (&k)))
2024 run_test_nodes (nodes, 3);
2026 node_destroy (nodes[2]);
2028 node_destroy (nodes[1]);
2030 node_destroy (nodes[0]);
2035 fprintf (stderr,
"%d total iterations of recursive marshaling tests\n",
2036 n_iterations_completed_total);
2037 fprintf (stderr,
"each iteration ran at initial offsets 0 through %d in both big and little endian\n",
2038 MAX_INITIAL_OFFSET);
2039 fprintf (stderr,
"out of memory handling %s tested\n",
2040 TEST_OOM_HANDLING ?
"was" :
"was not");
2044 _dbus_marshal_recursive_test (
void)
2046 make_and_run_test_nodes ();
2059 #define MAX_MULTI_COUNT 5 2061 #define SAMPLE_INT16 1234 2062 #define SAMPLE_INT16_ALTERNATE 6785 2063 static dbus_uint16_t
2064 uint16_from_seed (
unsigned int seed)
2070 static const dbus_uint16_t v_of_seed[5] = {
2072 SAMPLE_INT16_ALTERNATE,
2087 uint16_write_value (TestTypeNode *node,
2095 v = uint16_from_seed (seed);
2098 node->klass->typecode,
2103 uint16_read_value (TestTypeNode *node,
2110 check_expected_type (reader, node->klass->typecode);
2120 uint16_set_value (TestTypeNode *node,
2128 v = uint16_from_seed (seed);
2136 uint16_write_multi (TestTypeNode *node,
2143 dbus_uint16_t values[MAX_MULTI_COUNT];
2144 dbus_uint16_t *v_ARRAY_UINT16 = values;
2149 for (i = 0; i < count; ++i)
2150 values[i] = uint16_from_seed (seed + i);
2153 node->klass->typecode,
2154 &v_ARRAY_UINT16, count);
2158 uint16_read_multi (TestTypeNode *node,
2164 dbus_uint16_t *values;
2168 check_expected_type (reader, node->klass->typecode);
2174 if (n_elements != count)
2175 _dbus_warn (
"got %d elements expected %d", n_elements, count);
2178 for (i = 0; i < count; i++)
2180 (
const unsigned char*)values + (i * 2))) ==
2181 uint16_from_seed (seed + i));
2187 #define SAMPLE_INT32 12345678 2188 #define SAMPLE_INT32_ALTERNATE 53781429 2189 static dbus_uint32_t
2190 uint32_from_seed (
unsigned int seed)
2196 static const dbus_uint32_t v_of_seed[5] = {
2198 SAMPLE_INT32_ALTERNATE,
2213 uint32_write_value (TestTypeNode *node,
2221 v = uint32_from_seed (seed);
2224 node->klass->typecode,
2229 uint32_read_value (TestTypeNode *node,
2236 check_expected_type (reader, node->klass->typecode);
2246 uint32_set_value (TestTypeNode *node,
2254 v = uint32_from_seed (seed);
2262 uint32_write_multi (TestTypeNode *node,
2269 dbus_uint32_t values[MAX_MULTI_COUNT];
2270 dbus_uint32_t *v_ARRAY_UINT32 = values;
2275 for (i = 0; i < count; ++i)
2276 values[i] = uint32_from_seed (seed + i);
2279 node->klass->typecode,
2280 &v_ARRAY_UINT32, count);
2284 uint32_read_multi (TestTypeNode *node,
2290 dbus_uint32_t *values;
2294 check_expected_type (reader, node->klass->typecode);
2300 if (n_elements != count)
2301 _dbus_warn (
"got %d elements expected %d", n_elements, count);
2304 for (i = 0; i < count; i++)
2306 (
const unsigned char*)values + (i * 4))) ==
2307 uint32_from_seed (seed + i));
2312 static dbus_uint64_t
2313 uint64_from_seed (
unsigned int seed)
2318 v32 = uint32_from_seed (seed);
2323 v = (v32 + 1) & 0xFFFFFFFF;
2325 v |= (((dbus_uint64_t) v32) << 32);
2331 uint64_write_value (TestTypeNode *node,
2339 v = uint64_from_seed (seed);
2342 node->klass->typecode,
2347 uint64_read_value (TestTypeNode *node,
2354 check_expected_type (reader, node->klass->typecode);
2364 uint64_set_value (TestTypeNode *node,
2372 v = uint64_from_seed (seed);
2379 #define MAX_SAMPLE_STRING_LEN 10 2381 string_from_seed (
char *buf,
2411 v = (
unsigned char) (
'A' + seed);
2416 if (v < 'A' || v >
'z')
2429 string_write_value (TestTypeNode *node,
2434 char buf[MAX_SAMPLE_STRING_LEN + 1]=
"";
2435 const char *v_string = buf;
2438 string_from_seed (buf, node->klass->subclass_detail,
2442 node->klass->typecode,
2447 string_read_value (TestTypeNode *node,
2452 char buf[MAX_SAMPLE_STRING_LEN + 1];
2455 check_expected_type (reader, node->klass->typecode);
2458 (
const char **) &v);
2460 string_from_seed (buf, node->klass->subclass_detail,
2463 if (strcmp (buf, v) != 0)
2464 _dbus_test_fatal (
"read string '%s' expected '%s'", v, buf);
2470 string_set_value (TestTypeNode *node,
2475 char buf[MAX_SAMPLE_STRING_LEN + 1];
2476 const char *v_string = buf;
2478 string_from_seed (buf, node->klass->subclass_detail,
2481 #if RECURSIVE_MARSHAL_WRITE_TRACE 2485 _dbus_verbose (
"SETTING new string '%s' len %d in place of '%s' len %d\n",
2486 v_string, strlen (v_string), old, strlen (old));
2495 #define BOOL_FROM_SEED(seed) ((dbus_bool_t)((seed) % 2)) 2498 bool_write_value (TestTypeNode *node,
2505 v = BOOL_FROM_SEED (seed);
2508 node->klass->typecode,
2513 bool_read_value (TestTypeNode *node,
2519 check_expected_type (reader, node->klass->typecode);
2522 (
unsigned char*) &v);
2530 bool_set_value (TestTypeNode *node,
2537 v = BOOL_FROM_SEED (seed);
2544 #define BYTE_FROM_SEED(seed) ((unsigned char) uint32_from_seed (seed)) 2547 byte_write_value (TestTypeNode *node,
2554 v = BYTE_FROM_SEED (seed);
2557 node->klass->typecode,
2562 byte_read_value (TestTypeNode *node,
2568 check_expected_type (reader, node->klass->typecode);
2571 (
unsigned char*) &v);
2580 byte_set_value (TestTypeNode *node,
2587 v = BYTE_FROM_SEED (seed);
2595 double_from_seed (
unsigned int seed)
2597 return SAMPLE_INT32 * ((double) (
int) seed) + 0.3;
2601 double_write_value (TestTypeNode *node,
2608 v = double_from_seed (seed);
2611 node->klass->typecode,
2616 double_read_value (TestTypeNode *node,
2623 check_expected_type (reader, node->klass->typecode);
2627 expected = double_from_seed (seed);
2630 _dbus_test_fatal (
"Expected double %g got %g\n bits = 0x%" PRIx64
" vs.\n bits = 0x%" PRIx64,
2632 *(dbus_uint64_t*)(
char*)&expected,
2633 *(dbus_uint64_t*)(
char*)&v);
2639 double_set_value (TestTypeNode *node,
2646 v = double_from_seed (seed);
2653 #define MAX_SAMPLE_OBJECT_PATH_LEN 10 2655 object_path_from_seed (
char *buf,
2665 v = (
unsigned char) (
'A' + seed);
2677 if (v < 'A' || v >
'z')
2693 object_path_write_value (TestTypeNode *node,
2698 char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
2699 const char *v_string = buf;
2701 object_path_from_seed (buf, seed);
2704 node->klass->typecode,
2709 object_path_read_value (TestTypeNode *node,
2714 char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
2716 check_expected_type (reader, node->klass->typecode);
2720 object_path_from_seed (buf, seed);
2722 if (strcmp (buf, v) != 0)
2723 _dbus_test_fatal (
"read object path '%s' expected '%s'", v, buf);
2729 object_path_set_value (TestTypeNode *node,
2734 char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
2735 const char *v_string = buf;
2737 object_path_from_seed (buf, seed);
2744 #define MAX_SAMPLE_SIGNATURE_LEN 10 2746 signature_from_seed (
char *buf,
2750 const char *sample_signatures[] = {
2759 strcpy (buf, sample_signatures[seed %
_DBUS_N_ELEMENTS(sample_signatures)]);
2763 signature_write_value (TestTypeNode *node,
2768 char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
2769 const char *v_string = buf;
2771 signature_from_seed (buf, seed);
2774 node->klass->typecode,
2779 signature_read_value (TestTypeNode *node,
2784 char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
2786 check_expected_type (reader, node->klass->typecode);
2790 signature_from_seed (buf, seed);
2792 if (strcmp (buf, v) != 0)
2793 _dbus_test_fatal (
"read signature value '%s' expected '%s'", v, buf);
2800 signature_set_value (TestTypeNode *node,
2805 char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
2806 const char *v_string = buf;
2808 signature_from_seed (buf, seed);
2816 struct_write_value (TestTypeNode *node,
2821 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2822 DataBlockState saved;
2827 n_copies = node->klass->subclass_detail;
2831 data_block_save (block, &saved);
2839 while (i < n_copies)
2844 while (link !=
NULL)
2846 TestTypeNode *child = link->
data;
2849 if (!node_write_value (child, block, &sub, seed + i))
2851 data_block_restore (block, &saved);
2863 data_block_restore (block, &saved);
2871 struct_read_or_set_value (TestTypeNode *node,
2876 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2881 n_copies = node->klass->subclass_detail;
2888 while (i < n_copies)
2893 while (link !=
NULL)
2895 TestTypeNode *child = link->
data;
2898 if (realign_root ==
NULL)
2900 if (!node_read_value (child, &sub, seed + i))
2905 if (!node_set_value (child, &sub, realign_root, seed + i))
2909 if (i == (n_copies - 1) && next ==
NULL)
2910 NEXT_EXPECTING_FALSE (&sub);
2912 NEXT_EXPECTING_TRUE (&sub);
2924 struct_read_value (TestTypeNode *node,
2928 return struct_read_or_set_value (node, reader,
NULL, seed);
2932 struct_set_value (TestTypeNode *node,
2937 return struct_read_or_set_value (node, reader, realign_root, seed);
2941 struct_build_signature (TestTypeNode *node,
2944 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2949 n_copies = node->klass->subclass_detail;
2951 orig_len = _dbus_string_get_length (str);
2957 while (i < n_copies)
2962 while (link !=
NULL)
2964 TestTypeNode *child = link->
data;
2967 if (!node_build_signature (child, str))
2987 array_write_value (TestTypeNode *node,
2992 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2993 DataBlockState saved;
2999 TestTypeNode *child;
3001 n_copies = node->klass->subclass_detail;
3005 data_block_save (block, &saved);
3012 if (!node_build_signature (child,
3013 &element_signature))
3019 &element_signature, 0,
3023 if (arrays_write_fixed_in_blocks &&
3025 child->klass->write_multi)
3027 if (!node_write_multi (child, block, &sub, seed, n_copies))
3033 while (i < n_copies)
3038 while (link !=
NULL)
3040 TestTypeNode *child2 = link->
data;
3043 if (!node_write_value (child2, block, &sub, seed + i))
3060 data_block_restore (block, &saved);
3066 array_read_or_set_value (TestTypeNode *node,
3071 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3075 TestTypeNode *child;
3077 n_copies = node->klass->subclass_detail;
3087 if (realign_root ==
NULL && arrays_write_fixed_in_blocks &&
3089 child->klass->read_multi)
3091 if (!node_read_multi (child, &sub, seed, n_copies))
3097 while (i < n_copies)
3102 while (link !=
NULL)
3104 TestTypeNode *child2 = link->
data;
3110 if (realign_root ==
NULL)
3112 if (!node_read_value (child2, &sub, seed + i))
3117 if (!node_set_value (child2, &sub, realign_root, seed + i))
3121 if (i == (n_copies - 1) && next ==
NULL)
3122 NEXT_EXPECTING_FALSE (&sub);
3124 NEXT_EXPECTING_TRUE (&sub);
3138 array_read_value (TestTypeNode *node,
3142 return array_read_or_set_value (node, reader,
NULL, seed);
3146 array_set_value (TestTypeNode *node,
3151 return array_read_or_set_value (node, reader, realign_root, seed);
3155 array_build_signature (TestTypeNode *node,
3158 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3161 orig_len = _dbus_string_get_length (str);
3178 #define VARIANT_SEED 10 3181 variant_write_value (TestTypeNode *node,
3186 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3187 DataBlockState saved;
3190 TestTypeNode *child;
3197 data_block_save (block, &saved);
3202 if (!node_build_signature (child,
3203 &content_signature))
3207 &content_signature, 0,
3211 if (!node_write_value (child, block, &sub, seed + VARIANT_SEED))
3221 data_block_restore (block, &saved);
3227 variant_read_or_set_value (TestTypeNode *node,
3232 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3234 TestTypeNode *child;
3245 if (realign_root ==
NULL)
3247 if (!node_read_value (child, &sub, seed + VARIANT_SEED))
3252 if (!node_set_value (child, &sub, realign_root, seed + VARIANT_SEED))
3256 NEXT_EXPECTING_FALSE (&sub);
3262 variant_read_value (TestTypeNode *node,
3266 return variant_read_or_set_value (node, reader,
NULL, seed);
3270 variant_set_value (TestTypeNode *node,
3275 return variant_read_or_set_value (node, reader, realign_root, seed);
3279 dict_write_value (TestTypeNode *node,
3284 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3285 DataBlockState saved;
3291 TestTypeNode *child;
3293 n_entries = node->klass->subclass_detail;
3297 data_block_save (block, &saved);
3310 if (!node_build_signature (child,
3311 &entry_value_signature))
3320 &dict_entry_signature,
3321 _dbus_string_get_length (&dict_entry_signature)))
3329 &dict_entry_signature, 0,
3334 while (i < n_entries)
3344 key = (dbus_int32_t) uint32_from_seed (seed + i);
3351 if (!node_write_value (child, block, &entry_sub, seed + i))
3368 data_block_restore (block, &saved);
3375 dict_read_or_set_value (TestTypeNode *node,
3380 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3384 TestTypeNode *child;
3386 n_entries = node->klass->subclass_detail;
3399 while (i < n_entries)
3407 if (realign_root ==
NULL)
3415 _dbus_assert (v == (dbus_int32_t) uint32_from_seed (seed + i));
3417 NEXT_EXPECTING_TRUE (&entry_sub);
3419 if (!node_read_value (child, &entry_sub, seed + i))
3422 NEXT_EXPECTING_FALSE (&entry_sub);
3428 v = (dbus_int32_t) uint32_from_seed (seed + i);
3435 NEXT_EXPECTING_TRUE (&entry_sub);
3437 if (!node_set_value (child, &entry_sub, realign_root, seed + i))
3440 NEXT_EXPECTING_FALSE (&entry_sub);
3443 if (i == (n_entries - 1))
3444 NEXT_EXPECTING_FALSE (&sub);
3446 NEXT_EXPECTING_TRUE (&sub);
3456 dict_read_value (TestTypeNode *node,
3460 return dict_read_or_set_value (node, reader,
NULL, seed);
3464 dict_set_value (TestTypeNode *node,
3469 return dict_read_or_set_value (node, reader, realign_root, seed);
3473 dict_build_signature (TestTypeNode *node,
3476 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3479 orig_len = _dbus_string_get_length (str);
3502 container_destroy (TestTypeNode *node)
3504 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3508 while (link !=
NULL)
3510 TestTypeNode *child = link->
data;
3513 node_destroy (child);
dbus_bool_t dbus_type_is_fixed(int typecode)
Tells you whether values of this type can change length if you set them to some other value...
dbus_bool_t _dbus_string_insert_bytes(DBusString *str, int i, int n_bytes, unsigned char byte)
Inserts a number of bytes of a given value at the given position.
void _dbus_type_reader_read_fixed_multi(const DBusTypeReader *reader, void *value, int *n_elements)
Reads a block of fixed-length basic values, from the current point in an array to the end of the arra...
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
#define DBUS_TYPE_UINT16
Type code marking a 16-bit unsigned integer.
#define _DBUS_UINT16_MAX
Maximum value of type "uint16".
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t _dbus_string_equal(const DBusString *a, const DBusString *b)
Tests two DBusString for equality.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
int _dbus_first_type_in_signature(const DBusString *str, int pos)
Get the first type in the signature.
The type writer is an iterator for writing to a block of values.
dbus_bool_t _dbus_list_length_is_one(DBusList **list)
Check whether length is exactly one.
void _dbus_type_reader_recurse(DBusTypeReader *reader, DBusTypeReader *sub)
Initialize a new reader pointing to the first type and corresponding value that's a child of the curr...
#define DBUS_TYPE_STRUCT
STRUCT and DICT_ENTRY are sort of special since their codes can't appear in a type string...
#define DBUS_TYPE_DICT_ENTRY
Type code used to represent a dict entry; however, this type code does not appear in type signatures...
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
void * data
Data stored at this element.
#define DBUS_TYPE_BYTE
Type code marking an 8-bit unsigned integer.
dbus_bool_t _dbus_type_writer_write_basic(DBusTypeWriter *writer, int type, const void *value)
Writes out a basic type.
dbus_uint64_t u64
as int64
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
char * str
as char* (string, object path or signature)
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that's copied to the d...
#define DBUS_STRUCT_END_CHAR
Code marking the end of a struct type in a type signature.
#define DBUS_TYPE_DOUBLE
Type code marking an 8-byte double in IEEE 754 format.
dbus_bool_t _dbus_string_ends_with_c_str(const DBusString *a, const char *c_str)
Returns whether a string ends with the given suffix.
void * _dbus_list_get_first(DBusList **list)
Gets the first data in the list.
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
#define DBUS_TYPE_ARRAY
Type code marking a D-Bus array type.
#define DBUS_TYPE_INT64
Type code marking a 64-bit signed integer.
dbus_uint32_t _dbus_unpack_uint32(int byte_order, const unsigned char *data)
Unpacks a 32 bit unsigned integer from a data pointer.
dbus_bool_t _dbus_type_reader_delete(DBusTypeReader *reader, const DBusTypeReader *realign_root)
Recursively deletes any value pointed to by the reader, leaving the reader valid to continue reading...
void _dbus_type_writer_init_values_only(DBusTypeWriter *writer, int byte_order, const DBusString *type_str, int type_pos, DBusString *value_str, int value_pos)
Like _dbus_type_writer_init(), except the type string passed in should correspond to an existing sign...
dbus_bool_t _dbus_type_reader_set_basic(DBusTypeReader *reader, const void *value, const DBusTypeReader *realign_root)
Sets a new value for the basic type value pointed to by the reader, leaving the reader valid to conti...
dbus_bool_t _dbus_type_writer_unrecurse(DBusTypeWriter *writer, DBusTypeWriter *sub)
Closes a container created by _dbus_type_writer_recurse() and writes any additional information to th...
dbus_bool_t dbus_type_is_basic(int typecode)
A "basic type" is a somewhat arbitrary concept, but the intent is to include those types that are ful...
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_type_reader_read_basic(const DBusTypeReader *reader, void *value)
Reads a basic-typed value, as with _dbus_marshal_read_basic().
#define _DBUS_UINT32_MAX
Maximum value of type "uint32".
#define DBUS_TYPE_INT32_AS_STRING
DBUS_TYPE_INT32 as a string literal instead of a int literal
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
void _dbus_string_delete(DBusString *str, int start, int len)
Deletes a segment of a DBusString with length len starting at start.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
dbus_uint16_t _dbus_unpack_uint16(int byte_order, const unsigned char *data)
Unpacks a 16 bit unsigned integer from a data pointer.
#define DBUS_TYPE_INT32
Type code marking a 32-bit signed integer.
dbus_bool_t _dbus_type_reader_next(DBusTypeReader *reader)
Skip to the next value on this "level".
#define DBUS_BIG_ENDIAN
Code marking MSB-first byte order in the wire protocol.
#define DBUS_TYPE_SIGNATURE
Type code marking a D-Bus type signature.
dbus_bool_t _dbus_string_equal_substring(const DBusString *a, int a_start, int a_len, const DBusString *b, int b_start)
Tests two sub-parts of two DBusString for equality.
#define DBUS_TYPE_UINT64
Type code marking a 64-bit unsigned integer.
#define DBUS_STRUCT_BEGIN_CHAR
Code marking the start of a struct type in a type signature.
#define DBUS_TYPE_VARIANT
Type code marking a D-Bus variant type.
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
#define DBUS_TYPE_UINT32
Type code marking a 32-bit unsigned integer.
dbus_uint32_t byte_order
byte order of the block
dbus_bool_t _dbus_string_insert_byte(DBusString *str, int i, unsigned char byte)
Inserts a single byte at the given position.
dbus_bool_t _dbus_string_append_byte(DBusString *str, unsigned char byte)
Appends a single byte to the string, returning FALSE if not enough memory.
dbus_uint32_t byte_order
byte order to write values with
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
The type reader is an iterator for reading values from a block of values.
#define TRUE
Expands to "1".
#define DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
DBUS_DICT_ENTRY_BEGIN_CHAR as a string literal instead of a int literal
void _dbus_list_free_link(DBusList *link)
Frees a linked list node allocated with _dbus_list_alloc_link.
#define DBUS_TYPE_OBJECT_PATH
Type code marking a D-Bus object path.
dbus_bool_t _dbus_type_writer_write_reader(DBusTypeWriter *writer, DBusTypeReader *reader)
Iterate through all values in the given reader, writing a copy of each value to the writer...
#define DBUS_TYPE_INVALID
Type code that is never equal to a legitimate type code.
void _dbus_type_reader_init(DBusTypeReader *reader, int byte_order, const DBusString *type_str, int type_pos, const DBusString *value_str, int value_pos)
Initializes a type reader.
union DBusTypeReader::@1 u
class-specific data
#define DBUS_TYPE_INT16
Type code marking a 16-bit signed integer.
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
int _dbus_type_reader_get_element_type(const DBusTypeReader *reader)
Gets the type of an element of the array the reader is currently pointing to.
void _dbus_type_writer_init(DBusTypeWriter *writer, int byte_order, DBusString *type_str, int type_pos, DBusString *value_str, int value_pos)
Initialize a write iterator, which is used to write out values in serialized D-Bus format...
A simple value union that lets you access bytes as if they were various types; useful when dealing wi...
#define _DBUS_INT32_MAX
Maximum value of type "int32".
dbus_bool_t _dbus_string_validate_nul(const DBusString *str, int start, int len)
Checks that the given range of the string is all nul bytes.
int _dbus_type_reader_get_current_type(const DBusTypeReader *reader)
Gets the type of the value the reader is currently pointing to; or for a types-only reader gets the t...
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
#define FALSE
Expands to "0".
#define DBUS_DICT_ENTRY_END_CHAR
Code marking the end of a dict entry type in a type signature.
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
const char * _dbus_type_to_string(int typecode)
Returns a string describing the given type.
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
void * dbus_malloc0(size_t bytes)
Allocates the given number of bytes, as with standard malloc(), but all bytes are initialized to zero...
dbus_bool_t _dbus_type_writer_write_fixed_multi(DBusTypeWriter *writer, int element_type, const void *value, int n_elements)
Writes a block of fixed-length basic values, i.e.
DBUS_PRIVATE_EXPORT void _dbus_verbose_bytes_of_string(const DBusString *str, int start, int len)
Dump the given part of the string to verbose log.
#define _DBUS_INT16_MAX
Maximum value of type "int16".
int value_pos
current position in values
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
dbus_bool_t _dbus_type_writer_recurse(DBusTypeWriter *writer, int container_type, const DBusString *contained_type, int contained_type_start, DBusTypeWriter *sub)
Opens a new container and writes out the initial information for that container.
#define _DBUS_DOUBLES_BITWISE_EQUAL(a, b)
On x86 there is an 80-bit FPU, and if you do "a == b" it may have a or b in an 80-bit register...
void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.
#define DBUS_LITTLE_ENDIAN
Code marking LSB-first byte order in the wire protocol.