4779
4780
dbus_shutdown ();
4784
/* Check that the code to demarshal a D-Bus file descriptor into an
4785
* int is correctly generated and returned as an allocated string.
4787
TEST_FEATURE ("with file descriptor");
4789
nih_list_init (&outputs);
4790
nih_list_init (&locals);
4791
nih_list_init (&structs);
4793
dbus_signature_iter_init (&signature,
4794
DBUS_TYPE_UNIX_FD_AS_STRING);
4796
str = demarshal (NULL, &signature,
4797
"parent", "iter", "value",
4801
"my", NULL, "unix_fd", "value",
4804
if (test_alloc_failed) {
4805
TEST_EQ_P (str, NULL);
4806
TEST_LIST_EMPTY (&outputs);
4807
TEST_LIST_EMPTY (&locals);
4808
TEST_LIST_EMPTY (&structs);
4812
TEST_EQ_STR (str, ("/* Demarshal a int from the message */\n"
4813
"if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UNIX_FD) {\n"
4817
"dbus_message_iter_get_basic (&iter, &value);\n"
4819
"dbus_message_iter_next (&iter);\n"));
4821
TEST_LIST_NOT_EMPTY (&outputs);
4823
var = (TypeVar *)outputs.next;
4824
TEST_ALLOC_SIZE (var, sizeof (TypeVar));
4825
TEST_ALLOC_PARENT (var, str);
4826
TEST_EQ_STR (var->type, "int");
4827
TEST_ALLOC_PARENT (var->type, var);
4828
TEST_EQ_STR (var->name, "value");
4829
TEST_ALLOC_PARENT (var->name, var);
4832
TEST_LIST_EMPTY (&outputs);
4834
TEST_LIST_EMPTY (&locals);
4836
TEST_LIST_EMPTY (&structs);
4842
/* Check that the generated code takes the value from the D-Bus
4843
* file descriptor in the message we pass and stores it in the int
4844
* pointer, which should have the right value.
4846
TEST_FEATURE ("with file descriptor (generated code)");
4849
message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
4851
dbus_message_iter_init_append (message, &iter);
4854
dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD,
4860
ret = my_unix_fd_demarshal (NULL, message, &unix_fd_value);
4862
if (test_alloc_failed) {
4865
dbus_message_unref (message);
4871
TEST_GT (unix_fd_value, 2); // duplicated by dbus
4873
dbus_message_unref (message);
4874
close (unix_fd_value);
4880
/* Check that when a file descriptor is expected, but a different
4881
* type is found, the type error code is run and the function returns
4882
* without modifying the pointer.
4884
TEST_FEATURE ("with wrong type for file descriptor (generated code)");
4887
message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
4889
dbus_message_iter_init_append (message, &iter);
4891
double_value = 3.14;
4892
dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE,
4898
ret = my_unix_fd_demarshal (NULL, message, &unix_fd_value);
4900
if (test_alloc_failed) {
4903
dbus_message_unref (message);
4909
TEST_EQ (unix_fd_value, -1);
4911
dbus_message_unref (message);