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" 34 #if !defined(PRIx64) && defined(DBUS_WIN) 45 basic_value_equal (
int type,
53 return strcmp (lhs->
str, rhs->
str) == 0;
57 return lhs->
u64 == rhs->
u64;
71 if (lhs_type != rhs_type)
82 basic_value_zero (&lhs_value);
83 basic_value_zero (&rhs_value);
88 return basic_value_equal (lhs_type, &lhs_value, &rhs_value);
98 return equal_values_helper (&lhs_sub, &rhs_sub);
116 return equal_values_helper (©_lhs, ©_rhs);
121 #ifndef DOXYGEN_SHOULD_SKIP_THIS 123 #include "dbus-test.h" 124 #include "dbus-list.h" 129 #define TEST_OOM_HANDLING 0 133 #define MAX_INITIAL_OFFSET 9 139 #define MAX_ITERATIONS_FOR_EXPENSIVE_TESTS 1000 155 #define N_FENCE_BYTES 5 156 #define FENCE_BYTES_STR "abcde" 157 #define INITIAL_PADDING_BYTE '\0' 160 data_block_init (DataBlock *block,
174 INITIAL_PADDING_BYTE) ||
176 INITIAL_PADDING_BYTE) ||
185 block->byte_order = byte_order;
186 block->initial_offset = initial_offset;
192 data_block_save (DataBlock *block,
193 DataBlockState *state)
195 state->saved_sig_len = _dbus_string_get_length (&block->signature) - N_FENCE_BYTES;
196 state->saved_body_len = _dbus_string_get_length (&block->body) - N_FENCE_BYTES;
200 data_block_restore (DataBlock *block,
201 DataBlockState *state)
204 state->saved_sig_len,
205 _dbus_string_get_length (&block->signature) - state->saved_sig_len - N_FENCE_BYTES);
207 state->saved_body_len,
208 _dbus_string_get_length (&block->body) - state->saved_body_len - N_FENCE_BYTES);
212 data_block_verify (DataBlock *block)
219 offset = _dbus_string_get_length (&block->signature) - N_FENCE_BYTES - 8;
225 _dbus_string_get_length (&block->signature) - offset);
233 offset = _dbus_string_get_length (&block->body) - N_FENCE_BYTES - 8;
239 _dbus_string_get_length (&block->body) - offset);
244 0, block->initial_offset));
246 0, block->initial_offset));
250 data_block_free (DataBlock *block)
252 data_block_verify (block);
259 data_block_reset (DataBlock *block)
261 data_block_verify (block);
264 block->initial_offset,
265 _dbus_string_get_length (&block->signature) - N_FENCE_BYTES - block->initial_offset);
267 block->initial_offset,
268 _dbus_string_get_length (&block->body) - N_FENCE_BYTES - block->initial_offset);
270 data_block_verify (block);
274 data_block_init_reader_writer (DataBlock *block,
282 block->initial_offset,
284 block->initial_offset);
290 _dbus_string_get_length (&block->signature) - N_FENCE_BYTES,
292 _dbus_string_get_length (&block->body) - N_FENCE_BYTES);
298 const char *funcname,
307 _dbus_warn (
"Read type %s while expecting %s at %s line %d",
316 #define check_expected_type(reader, expected) real_check_expected_type (reader, expected, _DBUS_FUNCTION_NAME, __LINE__) 318 #define NEXT_EXPECTING_TRUE(reader) do { if (!_dbus_type_reader_next (reader)) \ 320 _dbus_warn ("_dbus_type_reader_next() should have returned TRUE at %s %d", \ 321 _DBUS_FUNCTION_NAME, __LINE__); \ 322 _dbus_assert_not_reached ("test failed"); \ 326 #define NEXT_EXPECTING_FALSE(reader) do { if (_dbus_type_reader_next (reader)) \ 328 _dbus_warn ("_dbus_type_reader_next() should have returned FALSE at %s %d", \ 329 _DBUS_FUNCTION_NAME, __LINE__); \ 330 _dbus_assert_not_reached ("test failed"); \ 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 int16_write_value (TestTypeNode *node,
400 static dbus_bool_t int16_read_value (TestTypeNode *node,
403 static dbus_bool_t int16_set_value (TestTypeNode *node,
407 static dbus_bool_t int16_write_multi (TestTypeNode *node,
412 static dbus_bool_t int16_read_multi (TestTypeNode *node,
416 static dbus_bool_t int32_write_value (TestTypeNode *node,
420 static dbus_bool_t int32_read_value (TestTypeNode *node,
423 static dbus_bool_t int32_set_value (TestTypeNode *node,
427 static dbus_bool_t int32_write_multi (TestTypeNode *node,
432 static dbus_bool_t int32_read_multi (TestTypeNode *node,
436 static dbus_bool_t int64_write_value (TestTypeNode *node,
440 static dbus_bool_t int64_read_value (TestTypeNode *node,
443 static dbus_bool_t int64_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));
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));
1122 _dbus_verbose (
"SOURCE\n");
1124 _dbus_string_get_length (&src->body));
1125 _dbus_verbose (
"DEST\n");
1127 _dbus_string_get_length (&dest.body));
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",
1345 data_block_init_reader_writer (nid->block,
1360 run_test_nodes_iteration (
void *data)
1362 NodeIterationData *nid = data;
1376 data_block_init_reader_writer (nid->block,
1383 nid->type_offset,
'\0'))
1387 while (i < nid->n_nodes)
1389 if (!node_write_value (nid->nodes[i], nid->block, &writer, i))
1396 &nid->block->signature, nid->type_offset))
1398 _dbus_warn (
"Expected signature '%s' and got '%s' with initial offset %d",
1399 _dbus_string_get_const_data (nid->signature),
1400 _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))
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))
1486 data_block_free (&block);
1490 run_test_nodes (TestTypeNode **nodes,
1502 if (! node_build_signature (nodes[i], &signature))
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))
1609 if (!data_block_init (&block, byte_order, 0))
1612 data_block_init_reader_writer (&block,
1625 if (!node_write_value (nodes[i], &block, &writer, i))
1632 _dbus_string_get_length (&block.body) - N_FENCE_BYTES,
1636 data_block_free (&block);
1640 dbus_internal_do_not_use_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 *format,
1707 n_iterations_completed_this_test = 0;
1708 n_iterations_expected_this_test = expected;
1710 fprintf (stderr,
">>> >>> ");
1711 fprintf (stderr, format,
1712 n_iterations_expected_this_test);
1716 make_and_run_test_nodes (
void)
1752 start_next_test (
"Each value by itself %d iterations\n", 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 %d iterations\n", 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 %d iteration\n", 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 %d iterations\n",
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 %d iterations\n",
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 %d iterations\n",
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 %d iterations\n",
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 %d iterations\n",
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 %d iterations\n",
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 %d iteration\n",
1886 TestTypeNode *child;
1888 node = node_new (&struct_1_class);
1891 while ((child = value_generator (&i)))
1892 node_append_child (node, child);
1894 run_test_nodes (&node, 1);
1896 node_destroy (node);
1899 start_next_test (
"Each value in a large array %d iterations\n",
1905 node = node_new (&array_9_class);
1908 while ((val = value_generator (&i)))
1910 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
1912 node_append_child (node, val);
1914 run_test_nodes (&node, 1);
1920 node_destroy (node);
1926 fprintf (stderr,
"skipping remaining marshal-recursive tests, " 1927 "run with DBUS_TEST_SLOW=1 (or more) to enable\n");
1931 start_next_test (
"Each container of each container of each value %d iterations\n",
1932 N_CONTAINERS * N_CONTAINERS * N_VALUES);
1933 for (i = 0; i < N_CONTAINERS; i++)
1935 const TestTypeNodeClass *outer_container_klass = container_nodes[i];
1936 TestTypeNode *outer_container = node_new (outer_container_klass);
1938 for (j = 0; j < N_CONTAINERS; j++)
1940 TestTypeNode *child;
1941 const TestTypeNodeClass *inner_container_klass = container_nodes[j];
1942 TestTypeNode *inner_container = node_new (inner_container_klass);
1944 node_append_child (outer_container, inner_container);
1947 while ((child = value_generator (&m)))
1949 node_append_child (inner_container, child);
1951 run_test_nodes (&outer_container, 1);
1954 node_destroy (child);
1957 node_destroy (inner_container);
1959 node_destroy (outer_container);
1962 start_next_test (
"Each container of each container of each container of each value %d iterations\n",
1963 N_CONTAINERS * N_CONTAINERS * N_CONTAINERS * N_VALUES);
1964 for (i = 0; i < N_CONTAINERS; i++)
1966 const TestTypeNodeClass *outer_container_klass = container_nodes[i];
1967 TestTypeNode *outer_container = node_new (outer_container_klass);
1969 for (j = 0; j < N_CONTAINERS; j++)
1971 const TestTypeNodeClass *inner_container_klass = container_nodes[j];
1972 TestTypeNode *inner_container = node_new (inner_container_klass);
1974 node_append_child (outer_container, inner_container);
1976 for (k = 0; k < N_CONTAINERS; k++)
1978 TestTypeNode *child;
1979 const TestTypeNodeClass *center_container_klass = container_nodes[k];
1980 TestTypeNode *center_container = node_new (center_container_klass);
1982 node_append_child (inner_container, center_container);
1985 while ((child = value_generator (&m)))
1987 node_append_child (center_container, child);
1989 run_test_nodes (&outer_container, 1);
1992 node_destroy (child);
1995 node_destroy (center_container);
1998 node_destroy (inner_container);
2000 node_destroy (outer_container);
2007 fprintf (stderr,
"skipping really slow marshal-recursive test, " 2008 "run with DBUS_TEST_SLOW=2 (or more) to enable\n");
2012 start_next_test (
"Each value,value,value triplet combination as toplevel, in all orders %d iterations\n",
2013 N_VALUES * N_VALUES * N_VALUES);
2015 TestTypeNode *nodes[3];
2018 while ((nodes[0] = value_generator (&i)))
2021 while ((nodes[1] = value_generator (&j)))
2024 while ((nodes[2] = value_generator (&k)))
2026 run_test_nodes (nodes, 3);
2028 node_destroy (nodes[2]);
2030 node_destroy (nodes[1]);
2032 node_destroy (nodes[0]);
2037 fprintf (stderr,
"%d total iterations of recursive marshaling tests\n",
2038 n_iterations_completed_total);
2039 fprintf (stderr,
"each iteration ran at initial offsets 0 through %d in both big and little endian\n",
2040 MAX_INITIAL_OFFSET);
2041 fprintf (stderr,
"out of memory handling %s tested\n",
2042 TEST_OOM_HANDLING ?
"was" :
"was not");
2046 _dbus_marshal_recursive_test (
void)
2048 make_and_run_test_nodes ();
2061 #define MAX_MULTI_COUNT 5 2063 #define SAMPLE_INT16 1234 2064 #define SAMPLE_INT16_ALTERNATE 6785 2066 int16_from_seed (
int seed)
2081 v = SAMPLE_INT16_ALTERNATE;
2101 int16_write_value (TestTypeNode *node,
2109 v = int16_from_seed (seed);
2112 node->klass->typecode,
2117 int16_read_value (TestTypeNode *node,
2124 check_expected_type (reader, node->klass->typecode);
2127 (dbus_int16_t*) &v);
2135 int16_set_value (TestTypeNode *node,
2143 v = int16_from_seed (seed);
2151 int16_write_multi (TestTypeNode *node,
2158 dbus_int16_t values[MAX_MULTI_COUNT];
2159 dbus_int16_t *v_ARRAY_INT16 = values;
2162 for (i = 0; i < count; ++i)
2163 values[i] = int16_from_seed (seed + i);
2166 node->klass->typecode,
2167 &v_ARRAY_INT16, count);
2171 int16_read_multi (TestTypeNode *node,
2177 dbus_int16_t *values;
2181 check_expected_type (reader, node->klass->typecode);
2187 if (n_elements != count)
2188 _dbus_warn (
"got %d elements expected %d", n_elements, count);
2191 for (i = 0; i < count; i++)
2193 (
const unsigned char*)values + (i * 2))) ==
2194 int16_from_seed (seed + i));
2200 #define SAMPLE_INT32 12345678 2201 #define SAMPLE_INT32_ALTERNATE 53781429 2203 int32_from_seed (
int seed)
2218 v = SAMPLE_INT32_ALTERNATE;
2238 int32_write_value (TestTypeNode *node,
2246 v = int32_from_seed (seed);
2249 node->klass->typecode,
2254 int32_read_value (TestTypeNode *node,
2261 check_expected_type (reader, node->klass->typecode);
2264 (dbus_int32_t*) &v);
2272 int32_set_value (TestTypeNode *node,
2280 v = int32_from_seed (seed);
2288 int32_write_multi (TestTypeNode *node,
2295 dbus_int32_t values[MAX_MULTI_COUNT];
2296 dbus_int32_t *v_ARRAY_INT32 = values;
2299 for (i = 0; i < count; ++i)
2300 values[i] = int32_from_seed (seed + i);
2303 node->klass->typecode,
2304 &v_ARRAY_INT32, count);
2308 int32_read_multi (TestTypeNode *node,
2314 dbus_int32_t *values;
2318 check_expected_type (reader, node->klass->typecode);
2324 if (n_elements != count)
2325 _dbus_warn (
"got %d elements expected %d", n_elements, count);
2328 for (i = 0; i < count; i++)
2330 (
const unsigned char*)values + (i * 4))) ==
2331 int32_from_seed (seed + i));
2337 int64_from_seed (
int seed)
2342 v32 = int32_from_seed (seed);
2344 v = - (dbus_int32_t) ~ v32;
2345 v |= (((dbus_int64_t)v32) << 32);
2351 int64_write_value (TestTypeNode *node,
2359 v = int64_from_seed (seed);
2362 node->klass->typecode,
2367 int64_read_value (TestTypeNode *node,
2374 check_expected_type (reader, node->klass->typecode);
2377 (dbus_int64_t*) &v);
2385 int64_set_value (TestTypeNode *node,
2393 v = int64_from_seed (seed);
2400 #define MAX_SAMPLE_STRING_LEN 10 2402 string_from_seed (
char *buf,
2426 v = (
unsigned char) (
'A' + seed);
2431 if (v < 'A' || v >
'z')
2444 string_write_value (TestTypeNode *node,
2449 char buf[MAX_SAMPLE_STRING_LEN + 1]=
"";
2450 const char *v_string = buf;
2453 string_from_seed (buf, node->klass->subclass_detail,
2457 node->klass->typecode,
2462 string_read_value (TestTypeNode *node,
2467 char buf[MAX_SAMPLE_STRING_LEN + 1];
2470 check_expected_type (reader, node->klass->typecode);
2473 (
const char **) &v);
2475 string_from_seed (buf, node->klass->subclass_detail,
2478 if (strcmp (buf, v) != 0)
2480 _dbus_warn (
"read string '%s' expected '%s'",
2489 string_set_value (TestTypeNode *node,
2494 char buf[MAX_SAMPLE_STRING_LEN + 1];
2495 const char *v_string = buf;
2497 string_from_seed (buf, node->klass->subclass_detail,
2500 #if RECURSIVE_MARSHAL_WRITE_TRACE 2504 _dbus_verbose (
"SETTING new string '%s' len %d in place of '%s' len %d\n",
2505 v_string, strlen (v_string), old, strlen (old));
2514 #define BOOL_FROM_SEED(seed) ((dbus_bool_t)((seed) % 2)) 2517 bool_write_value (TestTypeNode *node,
2524 v = BOOL_FROM_SEED (seed);
2527 node->klass->typecode,
2532 bool_read_value (TestTypeNode *node,
2538 check_expected_type (reader, node->klass->typecode);
2541 (
unsigned char*) &v);
2549 bool_set_value (TestTypeNode *node,
2556 v = BOOL_FROM_SEED (seed);
2563 #define BYTE_FROM_SEED(seed) ((unsigned char) int32_from_seed (seed)) 2566 byte_write_value (TestTypeNode *node,
2573 v = BYTE_FROM_SEED (seed);
2576 node->klass->typecode,
2581 byte_read_value (TestTypeNode *node,
2587 check_expected_type (reader, node->klass->typecode);
2590 (
unsigned char*) &v);
2599 byte_set_value (TestTypeNode *node,
2606 v = BYTE_FROM_SEED (seed);
2614 double_from_seed (
int seed)
2616 return SAMPLE_INT32 * (double) seed + 0.3;
2620 double_write_value (TestTypeNode *node,
2627 v = double_from_seed (seed);
2630 node->klass->typecode,
2635 double_read_value (TestTypeNode *node,
2642 check_expected_type (reader, node->klass->typecode);
2647 expected = double_from_seed (seed);
2651 _dbus_warn (
"Expected double %g got %g\n bits = 0x%" PRIx64
" vs.\n bits = 0x%" PRIx64,
2653 *(dbus_uint64_t*)(
char*)&expected,
2654 *(dbus_uint64_t*)(
char*)&v);
2662 double_set_value (TestTypeNode *node,
2669 v = double_from_seed (seed);
2676 #define MAX_SAMPLE_OBJECT_PATH_LEN 10 2678 object_path_from_seed (
char *buf,
2688 v = (
unsigned char) (
'A' + seed);
2700 if (v < 'A' || v >
'z')
2716 object_path_write_value (TestTypeNode *node,
2721 char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
2722 const char *v_string = buf;
2724 object_path_from_seed (buf, seed);
2727 node->klass->typecode,
2732 object_path_read_value (TestTypeNode *node,
2737 char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
2739 check_expected_type (reader, node->klass->typecode);
2742 (
const char **) &v);
2744 object_path_from_seed (buf, seed);
2746 if (strcmp (buf, v) != 0)
2748 _dbus_warn (
"read object path '%s' expected '%s'",
2757 object_path_set_value (TestTypeNode *node,
2762 char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
2763 const char *v_string = buf;
2765 object_path_from_seed (buf, seed);
2772 #define MAX_SAMPLE_SIGNATURE_LEN 10 2774 signature_from_seed (
char *buf,
2778 const char *sample_signatures[] = {
2787 strcpy (buf, sample_signatures[seed %
_DBUS_N_ELEMENTS(sample_signatures)]);
2791 signature_write_value (TestTypeNode *node,
2796 char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
2797 const char *v_string = buf;
2799 signature_from_seed (buf, seed);
2802 node->klass->typecode,
2807 signature_read_value (TestTypeNode *node,
2812 char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
2814 check_expected_type (reader, node->klass->typecode);
2817 (
const char **) &v);
2819 signature_from_seed (buf, seed);
2821 if (strcmp (buf, v) != 0)
2823 _dbus_warn (
"read signature value '%s' expected '%s'",
2833 signature_set_value (TestTypeNode *node,
2838 char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
2839 const char *v_string = buf;
2841 signature_from_seed (buf, seed);
2849 struct_write_value (TestTypeNode *node,
2854 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2855 DataBlockState saved;
2860 n_copies = node->klass->subclass_detail;
2864 data_block_save (block, &saved);
2872 while (i < n_copies)
2877 while (link !=
NULL)
2879 TestTypeNode *child = link->
data;
2882 if (!node_write_value (child, block, &sub, seed + i))
2884 data_block_restore (block, &saved);
2896 data_block_restore (block, &saved);
2904 struct_read_or_set_value (TestTypeNode *node,
2909 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2914 n_copies = node->klass->subclass_detail;
2921 while (i < n_copies)
2926 while (link !=
NULL)
2928 TestTypeNode *child = link->
data;
2931 if (realign_root ==
NULL)
2933 if (!node_read_value (child, &sub, seed + i))
2938 if (!node_set_value (child, &sub, realign_root, seed + i))
2942 if (i == (n_copies - 1) && next ==
NULL)
2943 NEXT_EXPECTING_FALSE (&sub);
2945 NEXT_EXPECTING_TRUE (&sub);
2957 struct_read_value (TestTypeNode *node,
2961 return struct_read_or_set_value (node, reader,
NULL, seed);
2965 struct_set_value (TestTypeNode *node,
2970 return struct_read_or_set_value (node, reader, realign_root, seed);
2974 struct_build_signature (TestTypeNode *node,
2977 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
2982 n_copies = node->klass->subclass_detail;
2984 orig_len = _dbus_string_get_length (str);
2990 while (i < n_copies)
2995 while (link !=
NULL)
2997 TestTypeNode *child = link->
data;
3000 if (!node_build_signature (child, str))
3020 array_write_value (TestTypeNode *node,
3025 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3026 DataBlockState saved;
3032 TestTypeNode *child;
3034 n_copies = node->klass->subclass_detail;
3038 data_block_save (block, &saved);
3045 if (!node_build_signature (child,
3046 &element_signature))
3052 &element_signature, 0,
3056 if (arrays_write_fixed_in_blocks &&
3058 child->klass->write_multi)
3060 if (!node_write_multi (child, block, &sub, seed, n_copies))
3066 while (i < n_copies)
3071 while (link !=
NULL)
3073 TestTypeNode *child = link->
data;
3076 if (!node_write_value (child, block, &sub, seed + i))
3093 data_block_restore (block, &saved);
3099 array_read_or_set_value (TestTypeNode *node,
3104 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3108 TestTypeNode *child;
3110 n_copies = node->klass->subclass_detail;
3120 if (realign_root ==
NULL && arrays_write_fixed_in_blocks &&
3122 child->klass->read_multi)
3124 if (!node_read_multi (child, &sub, seed, n_copies))
3130 while (i < n_copies)
3135 while (link !=
NULL)
3137 TestTypeNode *child = link->
data;
3143 if (realign_root ==
NULL)
3145 if (!node_read_value (child, &sub, seed + i))
3150 if (!node_set_value (child, &sub, realign_root, seed + i))
3154 if (i == (n_copies - 1) && next ==
NULL)
3155 NEXT_EXPECTING_FALSE (&sub);
3157 NEXT_EXPECTING_TRUE (&sub);
3171 array_read_value (TestTypeNode *node,
3175 return array_read_or_set_value (node, reader,
NULL, seed);
3179 array_set_value (TestTypeNode *node,
3184 return array_read_or_set_value (node, reader, realign_root, seed);
3188 array_build_signature (TestTypeNode *node,
3191 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3194 orig_len = _dbus_string_get_length (str);
3211 #define VARIANT_SEED 10 3214 variant_write_value (TestTypeNode *node,
3219 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3220 DataBlockState saved;
3223 TestTypeNode *child;
3230 data_block_save (block, &saved);
3235 if (!node_build_signature (child,
3236 &content_signature))
3240 &content_signature, 0,
3244 if (!node_write_value (child, block, &sub, seed + VARIANT_SEED))
3254 data_block_restore (block, &saved);
3260 variant_read_or_set_value (TestTypeNode *node,
3265 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3267 TestTypeNode *child;
3278 if (realign_root ==
NULL)
3280 if (!node_read_value (child, &sub, seed + VARIANT_SEED))
3285 if (!node_set_value (child, &sub, realign_root, seed + VARIANT_SEED))
3289 NEXT_EXPECTING_FALSE (&sub);
3295 variant_read_value (TestTypeNode *node,
3299 return variant_read_or_set_value (node, reader,
NULL, seed);
3303 variant_set_value (TestTypeNode *node,
3308 return variant_read_or_set_value (node, reader, realign_root, seed);
3312 dict_write_value (TestTypeNode *node,
3317 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3318 DataBlockState saved;
3324 TestTypeNode *child;
3326 n_entries = node->klass->subclass_detail;
3330 data_block_save (block, &saved);
3343 if (!node_build_signature (child,
3344 &entry_value_signature))
3353 &dict_entry_signature,
3354 _dbus_string_get_length (&dict_entry_signature)))
3362 &dict_entry_signature, 0,
3367 while (i < n_entries)
3377 key = int32_from_seed (seed + i);
3384 if (!node_write_value (child, block, &entry_sub, seed + i))
3401 data_block_restore (block, &saved);
3408 dict_read_or_set_value (TestTypeNode *node,
3413 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3417 TestTypeNode *child;
3419 n_entries = node->klass->subclass_detail;
3432 while (i < n_entries)
3440 if (realign_root ==
NULL)
3447 (dbus_int32_t*) &v);
3451 NEXT_EXPECTING_TRUE (&entry_sub);
3453 if (!node_read_value (child, &entry_sub, seed + i))
3456 NEXT_EXPECTING_FALSE (&entry_sub);
3462 v = int32_from_seed (seed + i);
3469 NEXT_EXPECTING_TRUE (&entry_sub);
3471 if (!node_set_value (child, &entry_sub, realign_root, seed + i))
3474 NEXT_EXPECTING_FALSE (&entry_sub);
3477 if (i == (n_entries - 1))
3478 NEXT_EXPECTING_FALSE (&sub);
3480 NEXT_EXPECTING_TRUE (&sub);
3490 dict_read_value (TestTypeNode *node,
3494 return dict_read_or_set_value (node, reader,
NULL, seed);
3498 dict_set_value (TestTypeNode *node,
3503 return dict_read_or_set_value (node, reader, realign_root, seed);
3507 dict_build_signature (TestTypeNode *node,
3510 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3513 orig_len = _dbus_string_get_length (str);
3536 container_destroy (TestTypeNode *node)
3538 TestTypeNodeContainer *container = (TestTypeNodeContainer*) node;
3542 while (link !=
NULL)
3544 TestTypeNode *child = link->
data;
3547 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 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_INT_MAX
Maximum value of type "int".
#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_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().
The type reader is an iterator for reading values from a block of values.
#define TRUE
Expands to "1".
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
#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...
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.