26 #include "dbus-internals.h" 27 #include "dbus-test.h" 28 #include "dbus-message-private.h" 29 #include "dbus-marshal-recursive.h" 30 #include "dbus-string.h" 31 #ifdef HAVE_UNIX_FD_PASSING 32 #include "dbus-sysdeps-unix.h" 34 #include <dbus/dbus-test-tap.h> 38 #include <sys/types.h> 58 #ifdef HAVE_UNIX_FD_PASSING 59 return message->n_unix_fds;
65 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 87 _dbus_return_val_if_fail (iter !=
NULL,
FALSE);
88 _dbus_return_val_if_error_is_set (error,
FALSE);
90 va_start (var_args, first_arg_type);
100 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 101 #include "dbus-test.h" 102 #include "dbus-message-factory.h" 114 static int validities_seen[DBUS_VALIDITY_LAST + _DBUS_NEGATIVE_VALIDITY_COUNT];
117 reset_validities_seen (
void)
123 validities_seen[i] = 0;
131 validities_seen[validity + _DBUS_NEGATIVE_VALIDITY_COUNT] += 1;
141 if ((i - _DBUS_NEGATIVE_VALIDITY_COUNT) == DBUS_VALIDITY_UNKNOWN ||
142 (i - _DBUS_NEGATIVE_VALIDITY_COUNT) == DBUS_INVALID_FOR_UNKNOWN_REASON)
144 else if ((not_seen && validities_seen[i] == 0) ||
145 (!not_seen && validities_seen[i] > 0))
146 _dbus_test_diag (
"validity %3d seen %d times",
147 i - _DBUS_NEGATIVE_VALIDITY_COUNT,
154 check_memleaks (
void)
158 if (_dbus_get_malloc_blocks_outstanding () != 0)
160 _dbus_test_fatal (
"%d dbus_malloc blocks were not freed in %s",
161 _dbus_get_malloc_blocks_outstanding (), __FILE__);
166 struct DBusInitialFDs {
172 _dbus_check_fdleaks_enter (
void)
179 fds = malloc (
sizeof (DBusInitialFDs));
184 if ((d = opendir (
"/proc/self/fd")))
188 while ((de = readdir(d)))
194 if (de->d_name[0] ==
'.')
198 l = strtol (de->d_name, &e, 10);
209 if (fd >= FD_SETSIZE)
211 _dbus_verbose (
"FD %d unexpectedly large; cannot track whether " 212 "it is leaked\n", fd);
216 FD_SET (fd, &fds->set);
229 _dbus_check_fdleaks_leave (DBusInitialFDs *fds)
236 if ((d = opendir (
"/proc/self/fd")))
240 while ((de = readdir(d)))
246 if (de->d_name[0] ==
'.')
250 l = strtol (de->d_name, &e, 10);
261 if (fd >= FD_SETSIZE)
263 _dbus_verbose (
"FD %d unexpectedly large; cannot track whether " 264 "it is leaked\n", fd);
268 if (FD_ISSET (fd, &fds->set))
271 _dbus_test_fatal (
"file descriptor %i leaked in %s.", fd, __FILE__);
294 _dbus_warn (
"loader corrupted on message that was expected to be valid; invalid reason %d",
302 _dbus_warn (
"didn't load message that was expected to be valid (message not popped)");
306 if (_dbus_string_get_length (&loader->
data) > 0)
308 _dbus_warn (
"had leftover bytes from expected-to-be-valid single message");
318 if (!check_message_handling (message))
343 _dbus_warn (
"loader not corrupted on message that was expected to be invalid");
349 if (expected_validity != DBUS_INVALID_FOR_UNKNOWN_REASON &&
352 _dbus_warn (
"expected message to be corrupted for reason %d and was corrupted for %d instead",
374 _dbus_warn (
"loader corrupted on message that was expected to be valid (but incomplete), corruption reason %d",
382 _dbus_warn (
"loaded message that was expected to be incomplete");
386 record_validity_seen (DBUS_VALID_BUT_INCOMPLETE);
400 _dbus_test_fatal (
"no memory to queue messages");
403 return check_have_valid_message (loader);
404 else if (expected_validity == DBUS_VALID_BUT_INCOMPLETE)
405 return check_incomplete_message (loader);
406 else if (expected_validity == DBUS_VALIDITY_UNKNOWN)
418 return check_invalid_message (loader, expected_validity);
429 load_message_file (
const DBusString *filename,
437 _dbus_verbose (
"Loading raw %s\n", _dbus_string_get_const_data (filename));
440 _dbus_warn (
"Could not load message file %s: %s",
441 _dbus_string_get_const_data (filename),
474 _dbus_test_fatal (
"could not allocate string");
476 if (!load_message_file (filename, &data))
479 retval = try_message_data (&data, expected_validity);
485 if (_dbus_string_get_length (&data) > 0)
487 _dbus_string_get_length (&data));
489 _dbus_warn (
"Failed message loader test on %s",
490 _dbus_string_get_const_data (filename));
528 len = _dbus_string_get_length (data);
529 for (i = 0; i < len; i++)
535 _dbus_string_get_byte (data, i)))
540 if (!check_loader_results (loader, expected_validity))
557 _dbus_string_get_length (buffer)))
562 if (!check_loader_results (loader, expected_validity))
574 len = _dbus_string_get_length (data);
575 for (i = 0; i < len; i += 2)
581 _dbus_string_get_byte (data, i)))
587 _dbus_string_get_byte (data, i+1)))
594 if (!check_loader_results (loader, expected_validity))
611 process_test_subdir (
const DBusString *test_base_dir,
614 DBusForeachMessageFileFunc
function,
627 _dbus_test_fatal (
"didn't allocate test_directory");
633 _dbus_test_fatal (
"couldn't copy test_base_dir to test_directory");
636 _dbus_test_fatal (
"couldn't allocate full path");
640 _dbus_test_fatal (
"didn't allocate filename string");
646 _dbus_string_get_const_data (&test_directory),
652 _dbus_test_diag (
"Testing %s:", subdir);
660 _dbus_test_fatal (
"couldn't init string");
663 _dbus_test_fatal (
"couldn't copy dir to full_path");
666 _dbus_test_fatal (
"couldn't concat file to dir");
672 _dbus_verbose (
"Skipping non-.message-raw file %s\n",
673 _dbus_string_get_const_data (&filename));
678 _dbus_test_diag (
" %s",
679 _dbus_string_get_const_data (&filename));
681 if (! (*
function) (&full_path,
682 expected_validity, user_data))
693 _dbus_warn (
"Could not get next file in %s: %s",
694 _dbus_string_get_const_data (&test_directory),
722 foreach_message_file (
const char *test_data_dir,
723 DBusForeachMessageFileFunc func,
733 if (!process_test_subdir (&test_directory,
"invalid-messages",
734 DBUS_INVALID_FOR_UNKNOWN_REASON, func, user_data))
749 #define GET_AND_CHECK(iter, typename, literal) \ 751 if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_##typename) \ 752 _dbus_test_fatal ("got wrong argument type from message iter"); \ 753 dbus_message_iter_get_basic (&iter, &v_##typename); \ 754 if (v_##typename != literal) \ 755 _dbus_test_fatal ("got wrong value from message iter"); \ 758 #define GET_AND_CHECK_STRCMP(iter, typename, literal) \ 760 if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_##typename) \ 761 _dbus_test_fatal ("got wrong argument type from message iter"); \ 762 dbus_message_iter_get_basic (&iter, &v_##typename); \ 763 if (strcmp (v_##typename, literal) != 0) \ 764 _dbus_test_fatal ("got wrong value from message iter"); \ 767 #define GET_AND_CHECK_AND_NEXT(iter, typename, literal) \ 769 GET_AND_CHECK(iter, typename, literal); \ 770 if (!dbus_message_iter_next (&iter)) \ 771 _dbus_test_fatal ("failed to move iter to next"); \ 774 #define GET_AND_CHECK_STRCMP_AND_NEXT(iter, typename, literal) \ 776 GET_AND_CHECK_STRCMP(iter, typename, literal); \ 777 if (!dbus_message_iter_next (&iter)) \ 778 _dbus_test_fatal ("failed to move iter to next"); \ 785 const char *v_STRING;
787 dbus_int16_t v_INT16;
788 dbus_uint16_t v_UINT16;
789 dbus_int32_t v_INT32;
790 dbus_uint32_t v_UINT32;
791 dbus_int64_t v_INT64;
792 dbus_uint64_t v_UINT64;
793 unsigned char v_BYTE;
796 const dbus_int32_t *our_int_array;
801 GET_AND_CHECK_STRCMP_AND_NEXT (iter, STRING,
"Test string");
802 GET_AND_CHECK_AND_NEXT (iter, INT32, -0x12345678);
803 GET_AND_CHECK_AND_NEXT (iter, UINT32, 0xedd1e);
804 GET_AND_CHECK_AND_NEXT (iter, DOUBLE, 3.14159);
807 _dbus_test_fatal (
"Argument type not an array");
810 _dbus_test_fatal (
"Array type not double");
814 GET_AND_CHECK_AND_NEXT (array, DOUBLE, 1.5);
815 GET_AND_CHECK (array, DOUBLE, 2.5);
818 _dbus_test_fatal (
"Didn't reach end of array");
821 _dbus_test_fatal (
"Reached end of arguments");
823 GET_AND_CHECK_AND_NEXT (iter, BYTE, 0xF0);
826 _dbus_test_fatal (
"no array");
829 _dbus_test_fatal (
"Array type not int32");
835 _dbus_test_fatal (
"Didn't reach end of array");
838 _dbus_test_fatal (
"Reached end of arguments");
840 GET_AND_CHECK (iter, BYTE, 0xF0);
843 _dbus_test_fatal (
"Didn't reach end of arguments");
852 dbus_int16_t our_int16;
853 dbus_uint16_t our_uint16;
854 dbus_int32_t our_int;
855 dbus_uint32_t our_uint;
860 unsigned char our_byte_1, our_byte_2;
861 const dbus_uint32_t *our_uint32_array = (
void*)0xdeadbeef;
862 int our_uint32_array_len;
863 dbus_int32_t *our_int32_array = (
void*)0xdeadbeef;
864 int our_int32_array_len;
865 dbus_int64_t our_int64;
866 dbus_uint64_t our_uint64;
867 dbus_int64_t *our_uint64_array = (
void*)0xdeadbeef;
868 int our_uint64_array_len;
869 const dbus_int64_t *our_int64_array = (
void*)0xdeadbeef;
870 int our_int64_array_len;
871 const double *our_double_array = (
void*)0xdeadbeef;
872 int our_double_array_len;
873 const unsigned char *our_byte_array = (
void*)0xdeadbeef;
874 int our_byte_array_len;
875 const dbus_bool_t *our_boolean_array = (
void*)0xdeadbeef;
876 int our_boolean_array_len;
877 char **our_string_array;
878 int our_string_array_len;
882 if (!dbus_message_iter_get_args (&iter, &error,
895 &our_uint32_array, &our_uint32_array_len,
897 &our_int32_array, &our_int32_array_len,
899 &our_uint64_array, &our_uint64_array_len,
901 &our_int64_array, &our_int64_array_len,
903 &our_double_array, &our_double_array_len,
905 &our_byte_array, &our_byte_array_len,
907 &our_boolean_array, &our_boolean_array_len,
909 &our_string_array, &our_string_array_len,
912 _dbus_test_fatal (
"Could not get arguments: %s - %s", error.
name,
916 if (our_int16 != -0x123)
917 _dbus_test_fatal (
"16-bit integers differ!");
919 if (our_uint16 != 0x123)
920 _dbus_test_fatal (
"16-bit uints differ!");
922 if (our_int != -0x12345678)
923 _dbus_test_fatal (
"integers differ!");
925 if (our_uint != 0x12300042)
926 _dbus_test_fatal (
"uints differ!");
928 if (our_int64 != DBUS_INT64_CONSTANT (-0x123456789abcd))
929 _dbus_test_fatal (
"64-bit integers differ!");
930 if (our_uint64 != DBUS_UINT64_CONSTANT (0x123456789abcd))
931 _dbus_test_fatal (
"64-bit unsigned integers differ!");
935 _dbus_test_fatal (
"doubles differ!");
937 if (strcmp (our_str,
"Test string") != 0)
938 _dbus_test_fatal (
"strings differ!");
941 _dbus_test_fatal (
"booleans differ");
943 if (our_byte_1 != 42)
944 _dbus_test_fatal (
"bytes differ!");
946 if (our_byte_2 != 24)
947 _dbus_test_fatal (
"bytes differ!");
949 if (our_uint32_array_len != 4 ||
950 our_uint32_array[0] != 0x12345678 ||
951 our_uint32_array[1] != 0x23456781 ||
952 our_uint32_array[2] != 0x34567812 ||
953 our_uint32_array[3] != 0x45678123)
954 _dbus_test_fatal (
"uint array differs");
956 if (our_int32_array_len != 4 ||
957 our_int32_array[0] != 0x12345678 ||
958 our_int32_array[1] != -0x23456781 ||
959 our_int32_array[2] != 0x34567812 ||
960 our_int32_array[3] != -0x45678123)
961 _dbus_test_fatal (
"int array differs");
963 if (our_uint64_array_len != 4 ||
964 our_uint64_array[0] != 0x12345678 ||
965 our_uint64_array[1] != 0x23456781 ||
966 our_uint64_array[2] != 0x34567812 ||
967 our_uint64_array[3] != 0x45678123)
968 _dbus_test_fatal (
"uint64 array differs");
970 if (our_int64_array_len != 4 ||
971 our_int64_array[0] != 0x12345678 ||
972 our_int64_array[1] != -0x23456781 ||
973 our_int64_array[2] != 0x34567812 ||
974 our_int64_array[3] != -0x45678123)
975 _dbus_test_fatal (
"int64 array differs");
977 if (our_double_array_len != 3)
978 _dbus_test_fatal (
"double array had wrong length");
985 _dbus_test_fatal (
"double array had wrong values");
986 v_DOUBLE = 9876.54321;
988 _dbus_test_fatal (
"double array had wrong values");
991 _dbus_test_fatal (
"double array had wrong values");
993 if (our_byte_array_len != 4)
994 _dbus_test_fatal (
"byte array had wrong length");
996 if (our_byte_array[0] !=
'a' ||
997 our_byte_array[1] !=
'b' ||
998 our_byte_array[2] !=
'c' ||
999 our_byte_array[3] != 234)
1000 _dbus_test_fatal (
"byte array had wrong values");
1002 if (our_boolean_array_len != 5)
1003 _dbus_test_fatal (
"bool array had wrong length");
1005 if (our_boolean_array[0] !=
TRUE ||
1006 our_boolean_array[1] !=
FALSE ||
1007 our_boolean_array[2] !=
TRUE ||
1008 our_boolean_array[3] !=
TRUE ||
1009 our_boolean_array[4] !=
FALSE)
1010 _dbus_test_fatal (
"bool array had wrong values");
1012 if (our_string_array_len != 4)
1013 _dbus_test_fatal (
"string array was wrong length");
1015 if (strcmp (our_string_array[0],
"Foo") != 0 ||
1016 strcmp (our_string_array[1],
"bar") != 0 ||
1017 strcmp (our_string_array[2],
"") != 0 ||
1018 strcmp (our_string_array[3],
"woo woo woo woo") != 0)
1019 _dbus_test_fatal (
"string array had wrong values");
1024 _dbus_test_fatal (
"Didn't reach end of arguments");
1028 verify_test_message_args_ignored (
DBusMessage *message)
1032 dbus_uint32_t our_uint;
1033 DBusInitialFDs *initial_fds;
1035 initial_fds = _dbus_check_fdleaks_enter ();
1039 if (!dbus_message_iter_get_args (&iter, &error,
1048 _dbus_verbose (
"arguments ignored.\n");
1053 if (!dbus_message_iter_get_args (&iter, &error,
1063 _dbus_verbose (
"arguments ignored.\n");
1066 _dbus_check_fdleaks_leave (initial_fds);
1070 verify_test_message_memleak (
DBusMessage *message)
1074 dbus_uint32_t our_uint1;
1075 dbus_uint32_t our_uint2;
1076 dbus_uint32_t our_uint3;
1077 char **our_string_array1;
1078 int our_string_array_len1;
1079 char **our_string_array2;
1080 int our_string_array_len2;
1081 #ifdef HAVE_UNIX_FD_PASSING 1085 DBusInitialFDs *initial_fds;
1087 initial_fds = _dbus_check_fdleaks_enter ();
1092 if (!dbus_message_iter_get_args (&iter, &error,
1095 &our_string_array1, &our_string_array_len1,
1096 #ifdef HAVE_UNIX_FD_PASSING
1100 DBUS_TYPE_UINT32, &our_uint3,
1103 _dbus_verbose (
"expected error: %s - %s\n", error.
name,
1107 #ifdef HAVE_UNIX_FD_PASSING 1113 _dbus_test_fatal (
"error: parse with wrong signature: 'uashuu'.");
1119 if (!dbus_message_iter_get_args (&iter, &error,
1120 DBUS_TYPE_UINT32, &our_uint1,
1122 &our_string_array1, &our_string_array_len1,
1123 #ifdef HAVE_UNIX_FD_PASSING
1124 DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1126 DBUS_TYPE_UINT32, &our_uint2,
1128 &our_string_array2, &our_string_array_len2,
1129 #ifdef HAVE_UNIX_FD_PASSING
1130 DBUS_TYPE_UNIX_FD, &our_unix_fd2,
1132 DBUS_TYPE_UINT32, &our_uint3,
1135 _dbus_verbose (
"expected error: %s - %s\n", error.
name,
1140 #ifdef HAVE_UNIX_FD_PASSING 1147 _dbus_test_fatal (
"error: parse with wrong signature: 'uashuashu'.");
1153 if (!dbus_message_iter_get_args (&iter, &error,
1154 DBUS_TYPE_UINT32, &our_uint1,
1156 &our_string_array1, &our_string_array_len1,
1157 #ifdef HAVE_UNIX_FD_PASSING
1158 DBUS_TYPE_UNIX_FD, &our_unix_fd1,
1160 DBUS_TYPE_UINT32, &our_uint2,
1162 &our_string_array2, &our_string_array_len2,
1163 #ifdef HAVE_UNIX_FD_PASSING
1164 DBUS_TYPE_UNIX_FD, &our_unix_fd2,
1168 _dbus_test_fatal (
"Could not get arguments: %s - %s", error.
name,
1175 #ifdef HAVE_UNIX_FD_PASSING 1180 _dbus_check_fdleaks_leave (initial_fds);
1190 _dbus_message_test (
const char *test_data_dir)
1199 const dbus_uint32_t our_uint32_array[] =
1200 { 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
1201 const dbus_int32_t our_int32_array[] =
1202 { 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
1203 const dbus_uint32_t *v_ARRAY_UINT32 = our_uint32_array;
1204 const dbus_int32_t *v_ARRAY_INT32 = our_int32_array;
1205 const dbus_uint64_t our_uint64_array[] =
1206 { 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
1207 const dbus_int64_t our_int64_array[] =
1208 { 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
1209 const dbus_uint64_t *v_ARRAY_UINT64 = our_uint64_array;
1210 const dbus_int64_t *v_ARRAY_INT64 = our_int64_array;
1211 const char *our_string_array[] = {
"Foo",
"bar",
"",
"woo woo woo woo" };
1212 const char *our_string_array1[] = {
"foo",
"Bar",
"",
"Woo woo Woo woo" };
1213 const char **v_ARRAY_STRING = our_string_array;
1214 const char **v1_ARRAY_STRING = our_string_array1;
1215 const double our_double_array[] = { 0.1234, 9876.54321, -300.0 };
1216 const double *v_ARRAY_DOUBLE = our_double_array;
1217 const unsigned char our_byte_array[] = {
'a',
'b',
'c', 234 };
1218 const unsigned char *v_ARRAY_BYTE = our_byte_array;
1220 const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array;
1223 const char *v_STRING;
1225 dbus_int16_t v_INT16;
1226 dbus_uint16_t v_UINT16;
1227 dbus_int32_t v_INT32;
1228 dbus_uint32_t v_UINT32;
1229 dbus_uint32_t v1_UINT32;
1230 dbus_int64_t v_INT64;
1231 dbus_uint64_t v_UINT64;
1232 unsigned char v_BYTE;
1233 unsigned char v2_BYTE;
1236 #ifdef HAVE_UNIX_FD_PASSING 1241 DBusInitialFDs *initial_fds;
1254 initial_fds = _dbus_check_fdleaks_enter ();
1257 "/org/freedesktop/TestPath",
1258 "Foo.TestInterface",
1264 "/org/freedesktop/TestPath") == 0);
1269 _dbus_test_fatal (
"out of memory");
1275 _dbus_string_get_length (&message->
header.
data));
1277 _dbus_string_get_length (&message->
body));
1280 _dbus_test_fatal (
"out of memory");
1284 _dbus_string_get_length (&message->
header.
data));
1286 _dbus_string_get_length (&message->
body));
1303 _dbus_test_fatal (
"out of memory");
1308 _dbus_test_fatal (
"out of memory");
1310 "/org/freedesktop/DBus/Containers1/c42") == 0);
1313 _dbus_test_fatal (
"out of memory");
1318 _dbus_test_fatal (
"out of memory");
1324 _dbus_test_fatal (
"out of memory");
1329 _dbus_test_fatal (
"out of memory");
1331 "org.Foo.Bar") == 0);
1334 _dbus_test_fatal (
"out of memory");
1341 _dbus_test_fatal (
"out of memory");
1346 _dbus_test_fatal (
"out of memory");
1351 _dbus_test_fatal (
"out of memory");
1387 "/org/freedesktop/TestPath",
1388 "Foo.TestInterface",
1395 v_INT32 = -0x12345678;
1396 v_UINT32 = 0x12300042;
1397 v_INT64 = DBUS_INT64_CONSTANT (-0x123456789abcd);
1398 v_UINT64 = DBUS_UINT64_CONSTANT (0x123456789abcd);
1399 v_STRING =
"Test string";
1404 #ifdef HAVE_UNIX_FD_PASSING 1471 #ifdef HAVE_UNIX_FD_PASSING 1481 _dbus_verbose (
"HEADER\n");
1483 _dbus_string_get_length (&message->
header.
data));
1484 _dbus_verbose (
"BODY\n");
1486 _dbus_string_get_length (&message->
body));
1488 _dbus_verbose (
"Signature expected \"%s\" actual \"%s\"\n",
1496 verify_test_message (message);
1505 _dbus_string_get_length (©->
header.
data));
1508 _dbus_string_get_length (©->
body));
1510 verify_test_message (copy);
1533 data = _dbus_string_get_const_data (&message->
header.
data);
1534 for (i = 0; i < _dbus_string_get_length (&message->
header.
data); i++)
1544 data = _dbus_string_get_const_data (&message->
body);
1545 for (i = 0; i < _dbus_string_get_length (&message->
body); i++)
1554 #ifdef HAVE_UNIX_FD_PASSING 1557 unsigned n_unix_fds;
1559 _dbus_message_loader_get_unix_fds(loader, &unix_fds, &n_unix_fds);
1564 _dbus_message_loader_return_unix_fds(loader, unix_fds, 1);
1572 _dbus_test_fatal (
"no memory to queue messages");
1575 _dbus_test_fatal (
"message loader corrupted");
1579 _dbus_test_fatal (
"received a NULL message");
1582 _dbus_test_fatal (
"reply serial fields differ");
1591 verify_test_message (message_without_unix_fds);
1598 char *marshalled =
NULL;
1603 _dbus_test_fatal (
"failed to marshal message");
1613 verify_test_message (message2);
1645 _dbus_check_fdleaks_leave (initial_fds);
1646 initial_fds = _dbus_check_fdleaks_enter ();
1649 for (i = strlen (basic_types) - 1; i > 0; i--)
1655 signature[0] = basic_types[i];
1656 s =
"SomeThingToSay";
1657 memset (&val,
'\0',
sizeof (val));
1660 "/de/ende/test",
"de.ende.Test",
"ArtistName");
1664 signature, &array_iter);
1665 for (some = 0; some < 3; some++)
1680 "/de/ende/test",
"de.ende.Test",
"ArtistName");
1688 NULL, &struct_iter);
1700 "/org/freedesktop/TestPath",
1701 "Foo.TestInterface",
1710 DBUS_STRUCT_END_CHAR_AS_STRING),
1714 NULL, &struct_iter);
1729 "/org/freedesktop/TestPath",
1730 "Foo.TestInterface",
1738 #ifdef HAVE_UNIX_FD_PASSING
1744 #ifdef HAVE_UNIX_FD_PASSING
1745 DBUS_TYPE_UNIX_FD, &v1_UNIX_FD,
1754 #ifdef HAVE_UNIX_FD_PASSING 1760 #ifdef HAVE_UNIX_FD_PASSING 1767 verify_test_message_args_ignored (message);
1768 verify_test_message_memleak (message);
1774 DBusMessageDataIter diter;
1775 DBusMessageData mdata;
1778 reset_validities_seen ();
1781 _dbus_message_data_iter_init (&diter);
1783 while (_dbus_message_data_iter_get_and_next (&diter,
1786 if (!try_message_data (&mdata.data, mdata.expected_validity))
1788 _dbus_test_fatal (
"expected validity %d and did not get it",
1789 mdata.expected_validity);
1792 _dbus_message_data_free (&mdata);
1797 _dbus_test_diag (
"%d sample messages tested", count);
1799 print_validities_seen (FALSE);
1800 print_validities_seen (
TRUE);
1804 _dbus_check_fdleaks_leave (initial_fds);
1807 if (test_data_dir ==
NULL)
1810 initial_fds = _dbus_check_fdleaks_enter ();
1812 if (!foreach_message_file (test_data_dir, try_message_file,
NULL))
1813 _dbus_test_fatal (
"foreach_message_file test failed");
1815 _dbus_check_fdleaks_leave (initial_fds);
#define DBUS_TYPE_UINT16
Type code marking a 16-bit unsigned integer.
void dbus_message_lock(DBusMessage *message)
Locks a message.
const char * message
public error message field
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t dbus_message_is_method_call(DBusMessage *message, const char *iface, const char *method)
Checks whether the message is a method call with the given interface and member fields.
void dbus_message_set_no_reply(DBusMessage *message, dbus_bool_t no_reply)
Sets a flag indicating that the message does not want a reply; if this flag is set, the other end of the connection may (but is not required to) optimize by not sending method return or error replies.
int dbus_message_iter_get_arg_type(DBusMessageIter *iter)
Returns the argument type of the argument that the message iterator points to.
DBUS_PRIVATE_EXPORT void _dbus_message_loader_return_buffer(DBusMessageLoader *loader, DBusString *buffer)
Returns a buffer obtained from _dbus_message_loader_get_buffer(), indicating to the loader how many b...
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
dbus_uint32_t dbus_message_get_serial(DBusMessage *message)
Returns the serial of a message or 0 if none has been specified.
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING
DBUS_STRUCT_BEGIN_CHAR as a string literal instead of a int literal
void dbus_message_iter_recurse(DBusMessageIter *iter, DBusMessageIter *sub)
Recurses into a container value when reading values from a message, initializing a sub-iterator to us...
DBUS_PRIVATE_EXPORT DBusMessage * _dbus_message_loader_pop_message(DBusMessageLoader *loader)
Pops a loaded message (passing ownership of the message to the caller).
dbus_bool_t dbus_message_set_interface(DBusMessage *message, const char *iface)
Sets the interface this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or the interface...
dbus_bool_t dbus_message_iter_close_container(DBusMessageIter *iter, DBusMessageIter *sub)
Closes a container-typed value appended to the message; may write out more information to the message...
#define DBUS_TYPE_STRUCT
STRUCT and DICT_ENTRY are sort of special since their codes can't appear in a type string...
void _dbus_directory_close(DBusDirIter *iter)
Closes a directory iteration.
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_iter_get_args_valist(DBusMessageIter *iter, DBusError *error, int first_arg_type, va_list var_args)
Implementation of the varargs arg-getting functions.
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
DBusString body
Body network data.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_directory_get_next_file(DBusDirIter *iter, DBusString *filename, DBusError *error)
Get next file in the directory.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
const char * dbus_message_get_signature(DBusMessage *message)
Gets the type signature of the message, i.e.
void dbus_message_iter_init_append(DBusMessage *message, DBusMessageIter *iter)
Initializes a DBusMessageIter for appending arguments to the end of a message.
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
#define DBUS_TYPE_BYTE
Type code marking an 8-bit unsigned integer.
dbus_bool_t _dbus_file_get_contents(DBusString *str, const DBusString *filename, DBusError *error)
Appends the contents of the given file to the string, returning error code.
DBUS_PRIVATE_EXPORT void _dbus_message_loader_unref(DBusMessageLoader *loader)
Decrements the reference count of the loader and finalizes the loader when the count reaches zero...
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
const char * dbus_message_get_path(DBusMessage *message)
Gets the object path this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or being emitt...
DBusDirIter * _dbus_directory_open(const DBusString *filename, DBusError *error)
Open a directory to iterate over.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
int _dbus_dup(int fd, DBusError *error)
Duplicates a file descriptor.
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...
DBusValidity
This is primarily used in unit testing, so we can verify that each invalid message is invalid for the...
DBusMessageIter struct; contains no public fields.
#define DBUS_TYPE_DOUBLE
Type code marking an 8-byte double in IEEE 754 format.
dbus_bool_t dbus_message_iter_init(DBusMessage *message, DBusMessageIter *iter)
Initializes a DBusMessageIter for reading the arguments of the message passed in. ...
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.
#define DBUS_TYPE_ARRAY
Type code marking a D-Bus array type.
#define DBUS_TYPE_INT64
Type code marking a 64-bit signed integer.
Internals of directory iterator.
const char * dbus_message_get_member(DBusMessage *message)
Gets the interface member being invoked (DBUS_MESSAGE_TYPE_METHOD_CALL) or emitted (DBUS_MESSAGE_TYPE...
Internals of DBusMessage.
#define DBUS_MINIMUM_HEADER_SIZE
The smallest header size that can occur.
const char * dbus_message_get_container_instance(DBusMessage *message)
Gets the container instance this message was sent from, or NULL if none.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
DBusHeader header
Header network data and associated cache.
dbus_bool_t dbus_message_set_sender(DBusMessage *message, const char *sender)
Sets the message sender.
DBusString data
Buffered data.
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_ref(DBusMessageLoader *loader)
Increments the reference count of the loader.
dbus_bool_t dbus_message_get_path_decomposed(DBusMessage *message, char ***path)
Gets the object path this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or being emitt...
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
dbus_bool_t dbus_message_set_path(DBusMessage *message, const char *object_path)
Sets the object path this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or the one a s...
#define DBUS_TYPE_INT32
Type code marking a 32-bit signed integer.
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
dbus_bool_t dbus_message_set_container_instance(DBusMessage *message, const char *object_path)
Sets the container instance this message was sent from.
Object representing an exception.
int dbus_message_iter_get_element_count(DBusMessageIter *iter)
Returns the number of elements in the array-typed value pointed to by the iterator.
dbus_bool_t dbus_message_append_args(DBusMessage *message, int first_arg_type,...)
Appends fields to a message given a variable argument list.
#define DBUS_TYPE_UINT64
Type code marking a 64-bit unsigned integer.
dbus_uint32_t dbus_message_get_reply_serial(DBusMessage *message)
Returns the serial that the message is a reply to or 0 if none.
dbus_bool_t dbus_message_has_signature(DBusMessage *message, const char *signature)
Checks whether the message has the given signature; see dbus_message_get_signature() for more details...
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_get_is_corrupted(DBusMessageLoader *loader)
Checks whether the loader is confused due to bad data.
#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.
DBusMessage * dbus_message_new_method_call(const char *destination, const char *path, const char *iface, const char *method)
Constructs a new message to invoke a method on a remote object.
dbus_bool_t dbus_message_has_destination(DBusMessage *message, const char *name)
Checks whether the message was sent to the given name.
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.
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...
#define TRUE
Expands to "1".
dbus_bool_t dbus_message_marshal(DBusMessage *msg, char **marshalled_data_p, int *len_p)
Turn a DBusMessage into the marshalled form as described in the D-Bus specification.
DBusMessage * dbus_message_copy(const DBusMessage *message)
Creates a new message that is an exact replica of the message specified, except that its refcount is ...
int dbus_message_iter_get_element_type(DBusMessageIter *iter)
Returns the element type of the array that the message iterator points to.
const char * name
public error name field
DBusMessage * dbus_message_demarshal(const char *str, int len, DBusError *error)
Demarshal a D-Bus message from the format described in the D-Bus specification.
#define DBUS_TYPE_UNIX_FD
Type code marking a unix file descriptor.
unsigned int _dbus_message_get_n_unix_fds(DBusMessage *message)
Gets the number of unix fds attached to this message.
const char * dbus_message_get_interface(DBusMessage *message)
Gets the interface this message is being sent to (for DBUS_MESSAGE_TYPE_METHOD_CALL) or being emitted...
#define DBUS_TYPE_INVALID
Type code that is never equal to a legitimate type code.
dbus_bool_t dbus_message_set_reply_serial(DBusMessage *message, dbus_uint32_t reply_serial)
Sets the reply serial of a message (the serial of the message this is a reply to).
dbus_bool_t dbus_message_has_sender(DBusMessage *message, const char *name)
Checks whether the message has the given unique name as its sender.
dbus_bool_t dbus_message_iter_next(DBusMessageIter *iter)
Moves the iterator to the next field, if any.
dbus_bool_t dbus_message_get_no_reply(DBusMessage *message)
Returns TRUE if the message does not expect a reply.
#define DBUS_TYPE_INT16
Type code marking a 16-bit signed integer.
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
#define DBUS_STRUCT_END_CHAR_AS_STRING
DBUS_STRUCT_END_CHAR a string literal instead of a int literal
dbus_bool_t dbus_message_iter_open_container(DBusMessageIter *iter, int type, const char *contained_signature, DBusMessageIter *sub)
Appends a container-typed value to the message.
A simple value union that lets you access bytes as if they were various types; useful when dealing wi...
#define DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_STRING as a string literal instead of a int literal
dbus_bool_t dbus_message_iter_append_basic(DBusMessageIter *iter, int type, const void *value)
Appends a basic-typed value to the message.
dbus_bool_t _dbus_close(int fd, DBusError *error)
Closes a file descriptor.
void dbus_shutdown(void)
Frees all memory allocated internally by libdbus and reverses the effects of dbus_threads_init().
#define FALSE
Expands to "0".
DBUS_PRIVATE_EXPORT void _dbus_message_loader_get_buffer(DBusMessageLoader *loader, DBusString **buffer, int *max_to_read, dbus_bool_t *may_read_unix_fds)
Gets the buffer to use for reading data from the network.
int dbus_message_demarshal_bytes_needed(const char *buf, int len)
Returns the number of bytes required to be in the buffer to demarshal a D-Bus message.
void dbus_message_iter_abandon_container(DBusMessageIter *iter, DBusMessageIter *sub)
Abandons creation of a contained-typed value and frees resources created by dbus_message_iter_open_co...
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.
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_queue_messages(DBusMessageLoader *loader)
Converts buffered data into messages, if we have enough data.
char * _dbus_strdup(const char *str)
Duplicates a string.
DBusValidity corruption_reason
why we were corrupted
dbus_bool_t dbus_message_set_member(DBusMessage *message, const char *member)
Sets the interface member being invoked (DBUS_MESSAGE_TYPE_METHOD_CALL) or emitted (DBUS_MESSAGE_TYPE...
void dbus_message_unref(DBusMessage *message)
Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0...
Implementation details of DBusMessageLoader.
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
#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_message_set_serial(DBusMessage *message, dbus_uint32_t serial)
Sets the serial number of a message.