637
670
_dbus_wait_for_memory ();
639
672
dbus_connection_ref (connection);
641
674
/* kick in the disconnect handler that unrefs the connection */
642
675
dbus_connection_close (connection);
644
677
bus_test_run_everything (context);
646
679
_dbus_assert (bus_test_client_listed (connection));
648
681
/* Run disconnect handler in test.c */
649
682
if (bus_connection_dispatch_one_message (connection))
650
683
_dbus_assert_not_reached ("something received on connection being killed other than the disconnect");
652
685
_dbus_assert (!dbus_connection_get_is_connected (connection));
653
686
dbus_connection_unref (connection);
654
687
connection = NULL;
655
688
_dbus_assert (!bus_test_client_listed (connection));
657
690
socd.expected_kind = SERVICE_DELETED;
658
691
socd.expected_service_name = base_service;
659
692
socd.failed = FALSE;
660
693
socd.skip_connection = NULL;
662
695
bus_test_clients_foreach (check_service_owner_changed_foreach,
665
698
dbus_free (base_service);
668
701
_dbus_assert_not_reached ("didn't get the expected NameOwnerChanged (deletion) messages");
670
703
if (!check_no_leftovers (context))
671
704
_dbus_assert_not_reached ("stuff left in message queues after disconnecting a client");
3927
/* don't worry about arg[0] as it may be different
3959
/* don't worry about arg[0] as it may be different
3928
3960
depending on the path to the tests
3930
3962
if (strcmp("-test", argv[1]) != 0)
3932
_dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)\n",
3964
_dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)\n",
3933
3965
"-test", argv[1]);
3937
3969
if (strcmp("that", argv[2]) != 0)
3939
_dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)\n",
3971
_dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)\n",
3940
3972
"that", argv[2]);
3944
3976
if (strcmp("we get", argv[3]) != 0)
3946
_dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)\n",
3978
_dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)\n",
3947
3979
"we get", argv[3]);
3951
3983
if (strcmp("back", argv[4]) != 0)
3953
_dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)\n",
3985
_dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)\n",
3954
3986
"back", argv[4]);
3958
3990
if (strcmp("--what", argv[5]) != 0)
3960
_dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)\n",
3992
_dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)\n",
3961
3993
"--what", argv[5]);
3965
3997
if (strcmp("we put in", argv[6]) != 0)
3967
_dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)\n",
3999
_dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)\n",
3968
4000
"we put in", argv[6]);
3972
4004
dbus_message_unref (message);
3973
4005
message = NULL;
3975
4007
if (!check_send_exit_to_service (context, connection,
3976
4008
SHELL_SUCCESS_SERVICE_NAME,
4509
4542
_dbus_assert_not_reached ("could not set up connection");
4511
4544
spin_connection_until_authenticated (context, baz);
4513
4546
if (!check_hello_message (context, baz))
4514
4547
_dbus_assert_not_reached ("hello message failed");
4516
4549
if (!check_add_match_all (context, baz))
4517
4550
_dbus_assert_not_reached ("AddMatch message failed");
4552
#ifdef DBUS_WIN_FIXME
4553
_dbus_warn("TODO: testing of GetConnectionUnixUser message skipped for now\n");
4554
_dbus_warn("TODO: testing of GetConnectionUnixProcessID message skipped for now\n");
4519
4556
if (!check_get_connection_unix_user (context, baz))
4520
4557
_dbus_assert_not_reached ("GetConnectionUnixUser message failed");
4522
4559
if (!check_get_connection_unix_process_id (context, baz))
4523
4560
_dbus_assert_not_reached ("GetConnectionUnixProcessID message failed");
4525
4563
if (!check_list_services (context, baz))
4526
4564
_dbus_assert_not_reached ("ListActivatableNames message failed");
4528
4566
if (!check_no_leftovers (context))
4530
4568
_dbus_warn ("Messages were left over after setting up initial connections\n");
4531
4569
_dbus_assert_not_reached ("initial connection setup failed");
4534
4572
check1_try_iterations (context, "create_and_hello",
4535
4573
check_hello_connection);
4537
4575
check2_try_iterations (context, foo, "nonexistent_service_no_auto_start",
4538
4576
check_nonexistent_service_no_auto_start);
4767
#ifdef HAVE_UNIX_FD_PASSING
4770
bus_unix_fds_passing_test(const DBusString *test_data_dir)
4772
BusContext *context;
4773
DBusConnection *foo, *bar;
4777
int one[2], two[2], x, y, z;
4780
dbus_error_init (&error);
4782
context = bus_context_new_test (test_data_dir, "valid-config-files/debug-allow-all.conf");
4783
if (context == NULL)
4784
_dbus_assert_not_reached ("could not alloc context");
4786
foo = dbus_connection_open_private (TEST_CONNECTION, &error);
4788
_dbus_assert_not_reached ("could not alloc connection");
4790
if (!bus_setup_debug_client (foo))
4791
_dbus_assert_not_reached ("could not set up connection");
4793
spin_connection_until_authenticated (context, foo);
4795
if (!check_hello_message (context, foo))
4796
_dbus_assert_not_reached ("hello message failed");
4798
if (!check_add_match_all (context, foo))
4799
_dbus_assert_not_reached ("AddMatch message failed");
4801
bar = dbus_connection_open_private (TEST_CONNECTION, &error);
4803
_dbus_assert_not_reached ("could not alloc connection");
4805
if (!bus_setup_debug_client (bar))
4806
_dbus_assert_not_reached ("could not set up connection");
4808
spin_connection_until_authenticated (context, bar);
4810
if (!check_hello_message (context, bar))
4811
_dbus_assert_not_reached ("hello message failed");
4813
if (!check_add_match_all (context, bar))
4814
_dbus_assert_not_reached ("AddMatch message failed");
4816
if (!(m = dbus_message_new_signal("/", "a.b.c", "d")))
4817
_dbus_assert_not_reached ("could not alloc message");
4819
if (!(_dbus_full_duplex_pipe(one, one+1, TRUE, &error)))
4820
_dbus_assert_not_reached("Failed to allocate pipe #1");
4822
if (!(_dbus_full_duplex_pipe(two, two+1, TRUE, &error)))
4823
_dbus_assert_not_reached("Failed to allocate pipe #2");
4825
if (!dbus_message_append_args(m,
4826
DBUS_TYPE_UNIX_FD, one,
4827
DBUS_TYPE_UNIX_FD, two,
4828
DBUS_TYPE_UNIX_FD, two,
4830
_dbus_assert_not_reached("Failed to attach fds.");
4832
if (!_dbus_close(one[0], &error))
4833
_dbus_assert_not_reached("Failed to close pipe #1 ");
4834
if (!_dbus_close(two[0], &error))
4835
_dbus_assert_not_reached("Failed to close pipe #2 ");
4837
if (!(dbus_connection_can_send_type(foo, DBUS_TYPE_UNIX_FD)))
4838
_dbus_assert_not_reached("Connection cannot do fd passing");
4840
if (!(dbus_connection_can_send_type(bar, DBUS_TYPE_UNIX_FD)))
4841
_dbus_assert_not_reached("Connection cannot do fd passing");
4843
if (!dbus_connection_send (foo, m, NULL))
4844
_dbus_assert_not_reached("Failed to send fds");
4846
dbus_message_unref(m);
4848
bus_test_run_clients_loop (SEND_PENDING (foo));
4850
bus_test_run_everything (context);
4852
block_connection_until_message_from_bus (context, foo, "unix fd reception on foo");
4854
if (!(m = pop_message_waiting_for_memory (foo)))
4855
_dbus_assert_not_reached("Failed to receive msg");
4857
if (!dbus_message_is_signal(m, "a.b.c", "d"))
4858
_dbus_assert_not_reached("bogus message received");
4860
dbus_message_unref(m);
4862
block_connection_until_message_from_bus (context, bar, "unix fd reception on bar");
4864
if (!(m = pop_message_waiting_for_memory (bar)))
4865
_dbus_assert_not_reached("Failed to receive msg");
4867
if (!dbus_message_is_signal(m, "a.b.c", "d"))
4868
_dbus_assert_not_reached("bogus message received");
4870
if (!dbus_message_get_args(m,
4872
DBUS_TYPE_UNIX_FD, &x,
4873
DBUS_TYPE_UNIX_FD, &y,
4874
DBUS_TYPE_UNIX_FD, &z,
4876
_dbus_assert_not_reached("Failed to parse fds.");
4878
dbus_message_unref(m);
4880
if (write(x, "X", 1) != 1)
4881
_dbus_assert_not_reached("Failed to write to pipe #1");
4882
if (write(y, "Y", 1) != 1)
4883
_dbus_assert_not_reached("Failed to write to pipe #2");
4884
if (write(z, "Z", 1) != 1)
4885
_dbus_assert_not_reached("Failed to write to pipe #2/2nd fd");
4887
if (!_dbus_close(x, &error))
4888
_dbus_assert_not_reached("Failed to close pipe #1/other side ");
4889
if (!_dbus_close(y, &error))
4890
_dbus_assert_not_reached("Failed to close pipe #2/other side ");
4891
if (!_dbus_close(z, &error))
4892
_dbus_assert_not_reached("Failed to close pipe #2/other size 2nd fd ");
4894
if (read(one[1], &r, 1) != 1 || r != 'X')
4895
_dbus_assert_not_reached("Failed to read value from pipe.");
4896
if (read(two[1], &r, 1) != 1 || r != 'Y')
4897
_dbus_assert_not_reached("Failed to read value from pipe.");
4898
if (read(two[1], &r, 1) != 1 || r != 'Z')
4899
_dbus_assert_not_reached("Failed to read value from pipe.");
4901
if (!_dbus_close(one[1], &error))
4902
_dbus_assert_not_reached("Failed to close pipe #1 ");
4903
if (!_dbus_close(two[1], &error))
4904
_dbus_assert_not_reached("Failed to close pipe #2 ");
4906
_dbus_verbose ("Disconnecting foo\n");
4907
kill_client_connection_unchecked (foo);
4909
_dbus_verbose ("Disconnecting bar\n");
4910
kill_client_connection_unchecked (bar);
4912
bus_context_unref (context);
4725
4918
#endif /* DBUS_BUILD_TESTS */