2006-10-23 David Zeuthen <davidz@redhat.com>
[platform/upstream/dbus.git] / bus / dispatch.c
index e1dd001..185d7f8 100644 (file)
@@ -581,7 +581,7 @@ check_service_owner_changed_foreach (DBusConnection *connection,
           || (d->expected_kind == OWNER_CHANGED   && (!old_owner[0] || !new_owner[0]))
           || (d->expected_kind == SERVICE_DELETED && (!old_owner[0] ||  new_owner[0])))
         {
-          _dbus_warn ("inconsistent NameOwnerChanged arguments");
+          _dbus_warn ("inconsistent NameOwnerChanged arguments\n");
           goto out;
         }
 
@@ -1479,7 +1479,7 @@ check_hello_connection (BusContext *context)
 
   dbus_error_init (&error);
 
-  connection = dbus_connection_open ("debug-pipe:name=test-server", &error);
+  connection = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
   if (connection == NULL)
     {
       _DBUS_ASSERT_ERROR_IS_SET (&error);
@@ -2359,7 +2359,7 @@ check_got_service_info (DBusMessage *message)
             }
           else
             {
-              _dbus_warn ("unexpected arguments for NameOwnerChanged message");
+              _dbus_warn ("unexpected arguments for NameOwnerChanged message\n");
               message_kind = GOT_SOMETHING_ELSE;
             }
         }
@@ -2556,12 +2556,13 @@ check_existent_service_no_auto_start (BusContext     *context,
             if (message_kind != GOT_ERROR)
               {
                 block_connection_until_message_from_bus (context, connection, "error about service exiting");
-              
+               
                 /* and process everything again */
                 bus_test_run_everything (context);
               
                 if (!check_got_error (context, connection,
                                       DBUS_ERROR_SPAWN_CHILD_EXITED,
+                                     DBUS_ERROR_NO_MEMORY,
                                       NULL))
                   goto out;
               }
@@ -2941,6 +2942,87 @@ check_existent_ping (BusContext     *context,
  * but the correct thing may include OOM errors.
  */
 static dbus_bool_t
+check_existent_get_machine_id (BusContext     *context,
+                               DBusConnection *connection)
+{
+  DBusMessage *message;
+  dbus_uint32_t serial;
+  const char *machine_id;
+  
+  message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME,
+                                          "/org/freedesktop/TestSuite",
+                                          "org.freedesktop.DBus.Peer",
+                                          "GetMachineId");
+  
+  if (message == NULL)
+    return TRUE;
+
+  if (!dbus_connection_send (connection, message, &serial))
+    {
+      dbus_message_unref (message);
+      return TRUE;
+    }
+
+  dbus_message_unref (message);
+  message = NULL;
+
+  bus_test_run_everything (context);
+
+  /* Note: if this test is run in OOM mode, it will block when the bus
+   * doesn't send a reply due to OOM.
+   */
+  block_connection_until_message_from_bus (context, connection, "reply from running GetMachineId");
+      
+  message = pop_message_waiting_for_memory (connection);
+  if (message == NULL)
+    {
+      _dbus_warn ("Failed to pop message! Should have been reply from GetMachineId message\n");
+      return FALSE;
+    }
+
+  if (dbus_message_get_reply_serial (message) != serial)
+    {
+      _dbus_warn ("Wrong reply serial\n");
+      dbus_message_unref (message);
+      return FALSE;
+    }
+
+  if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_RETURN)
+    {
+      _dbus_warn ("Unexpected message return during GetMachineId\n");
+      dbus_message_unref (message);
+      return FALSE;
+    }
+
+  machine_id = NULL;
+  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &machine_id, DBUS_TYPE_INVALID))
+    {
+      _dbus_warn ("Did not get a machine ID in reply to GetMachineId\n");
+      dbus_message_unref (message);
+      return FALSE;
+    }
+
+  if (machine_id == NULL || strlen (machine_id) != 32)
+    {
+      _dbus_warn ("Machine id looks bogus: '%s'\n", machine_id ? machine_id : "null");
+      dbus_message_unref (message);
+      return FALSE;
+    }
+  
+  /* We can't check that the machine id is correct because during make check it is
+   * just made up for each process separately
+   */
+  
+  dbus_message_unref (message);
+  message = NULL;
+      
+  return TRUE;
+}
+
+/* returns TRUE if the correct thing happens,
+ * but the correct thing may include OOM errors.
+ */
+static dbus_bool_t
 check_existent_service_auto_start (BusContext     *context,
                                    DBusConnection *connection)
 {
@@ -3028,7 +3110,7 @@ check_existent_service_auto_start (BusContext     *context,
       if (message == NULL)
         {
           _dbus_warn ("No message after auto activation "
-                      "(should be a service announcement)");
+                      "(should be a service announcement)\n");
           dbus_connection_return_message (connection, message);
           message = NULL;
           goto out;
@@ -3115,6 +3197,9 @@ check_existent_service_auto_start (BusContext     *context,
   if (!check_existent_ping (context, connection))
     goto out;
 
+  if (!check_existent_get_machine_id (context, connection))
+    goto out;
+  
   if (!check_existent_hello_from_self (context, connection))
     goto out;
 
@@ -3314,7 +3399,7 @@ check_shell_service_success_auto_start (BusContext     *context,
       if (message == NULL)
         {
           _dbus_warn ("No message after auto activation "
-                      "(should be a service announcement)");
+                      "(should be a service announcement)\n");
           dbus_connection_return_message (connection, message);
           message = NULL;
           goto out;
@@ -3405,7 +3490,7 @@ check_shell_service_success_auto_start (BusContext     *context,
                                        DBUS_TYPE_STRING, &argv[6],
                                        DBUS_TYPE_INVALID))
     {
-      _dbus_warn ("Error getting arguments from return");
+      _dbus_warn ("Error getting arguments from return\n");
       goto out;
     }
 
@@ -3414,42 +3499,42 @@ check_shell_service_success_auto_start (BusContext     *context,
    */
   if (strcmp("-test", argv[1]) != 0)
     {
-      _dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)", 
+      _dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)\n", 
                   "-test", argv[1]);
       goto out;
     } 
 
   if (strcmp("that", argv[2]) != 0)
     {
-      _dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)", 
+      _dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)\n", 
                    "that", argv[2]);
       goto out;
     } 
 
   if (strcmp("we get", argv[3]) != 0)
     {
-      _dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)", 
+      _dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)\n", 
                    "we get", argv[3]);
       goto out;
     } 
    
   if (strcmp("back", argv[4]) != 0)
     {
-      _dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)", 
+      _dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)\n", 
                    "back", argv[4]);
       goto out;
     } 
 
   if (strcmp("--what", argv[5]) != 0)
     {
-      _dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)", 
+      _dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)\n", 
                    "--what", argv[5]);
       goto out;
     } 
 
   if (strcmp("we put in", argv[6]) != 0)
     {
-      _dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)", 
+      _dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)\n", 
                    "we put in", argv[6]);
       goto out;
     } 
@@ -3796,7 +3881,7 @@ check_list_services (BusContext     *context,
        case GOT_ERROR:
        case GOT_SERVICE_DELETED:
          _dbus_warn ("Unexpected message after ActivateService "
-                     "(should be an error or a service announcement");
+                     "(should be an error or a service announcement)\n");
          goto out;
 
        case GOT_SERVICE_CREATED:
@@ -3871,7 +3956,7 @@ check_oom_check2_func (void *data)
   
   if (!check_no_leftovers (d->context))
     {
-      _dbus_warn ("Messages were left over, should be covered by test suite");
+      _dbus_warn ("Messages were left over, should be covered by test suite\n");
       return FALSE;
     }
 
@@ -3914,7 +3999,7 @@ bus_dispatch_test (const DBusString *test_data_dir)
   if (context == NULL)
     return FALSE;
   
-  foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
+  foo = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
   if (foo == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -3932,7 +4017,7 @@ bus_dispatch_test (const DBusString *test_data_dir)
   if (!check_add_match_all (context, foo))
     _dbus_assert_not_reached ("AddMatch message failed");
   
-  bar = dbus_connection_open ("debug-pipe:name=test-server", &error);
+  bar = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
   if (bar == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -3947,7 +4032,7 @@ bus_dispatch_test (const DBusString *test_data_dir)
   if (!check_add_match_all (context, bar))
     _dbus_assert_not_reached ("AddMatch message failed");
   
-  baz = dbus_connection_open ("debug-pipe:name=test-server", &error);
+  baz = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
   if (baz == NULL)
     _dbus_assert_not_reached ("could not alloc connection");
 
@@ -3973,7 +4058,7 @@ bus_dispatch_test (const DBusString *test_data_dir)
   
   if (!check_no_leftovers (context))
     {
-      _dbus_warn ("Messages were left over after setting up initial connections");
+      _dbus_warn ("Messages were left over after setting up initial connections\n");
       _dbus_assert_not_reached ("initial connection setup failed");
     }
   
@@ -4041,7 +4126,7 @@ bus_dispatch_sha1_test (const DBusString *test_data_dir)
   if (context == NULL)
     return FALSE;
 
-  foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
+  foo = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
   if (foo == NULL)
     _dbus_assert_not_reached ("could not alloc connection");