fix whitespace
authorHavoc Pennington <hp@redhat.com>
Thu, 26 Jul 2007 22:32:09 +0000 (22:32 +0000)
committerHavoc Pennington <hp@redhat.com>
Thu, 26 Jul 2007 22:32:09 +0000 (22:32 +0000)
test/name-test/test-names.c

index 506ed26..48dfe74 100644 (file)
 #define EXISTS DBUS_REQUEST_NAME_REPLY_EXISTS
 #define ALREADY_OWNER DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER
 
-#define RELEASED DBUS_RELEASE_NAME_REPLY_RELEASED 
+#define RELEASED DBUS_RELEASE_NAME_REPLY_RELEASED
 #define NON_EXISTANT DBUS_RELEASE_NAME_REPLY_NON_EXISTENT
 #define NOT_OWNER DBUS_RELEASE_NAME_REPLY_NOT_OWNER
 
-#define NUM_CONN 4 
+#define NUM_CONN 4
 #define TEST_NAME "org.freedesktop.DBus.TestSuite.NameTest"
 #define NUM_TRIES_TIL_FAIL 15
 
 typedef struct {
   int command;
-  
-  int connection_number; 
+
+  int connection_number;
   dbus_uint32_t flags;
 
   dbus_uint32_t expected_result;
@@ -37,42 +37,42 @@ typedef struct {
   int expected_queue[NUM_CONN];
 } CommandAndResult;
 
-CommandAndResult test_data[] = { 
-        {ADD_CONNECTION, 0, ALLOW_REPLACEMENT | REPLACE_EXISTING, 
-       PRIMARY_OWNER, {0,-1,-1,-1}},
-       {ADD_CONNECTION, 0, REPLACE_EXISTING,
-       ALREADY_OWNER, {0,-1,-1,-1}},
-       {ADD_CONNECTION, 1, ALLOW_REPLACEMENT | REPLACE_EXISTING,
-       IN_QUEUE, {0,1,-1,-1}},
-       {REMOVE_CONNECTION, 0, 0,
-       RELEASED, {1,-1,-1,-1}},
-       {ADD_CONNECTION, 0, REPLACE_EXISTING | DO_NOT_QUEUE,
-       PRIMARY_OWNER, {0,1,-1,-1}},
-       {ADD_CONNECTION, 2, ALLOW_REPLACEMENT,
-       IN_QUEUE, {0,1,2,-1}},
-       {ADD_CONNECTION, 2, ALLOW_REPLACEMENT | REPLACE_EXISTING,
-       IN_QUEUE, {0,2,1,-1}},
-       {ADD_CONNECTION, 0, ALLOW_REPLACEMENT | DO_NOT_QUEUE,
-       ALREADY_OWNER, {0,2,1,-1}},
-       {ADD_CONNECTION, 1, ALLOW_REPLACEMENT | REPLACE_EXISTING,
-       PRIMARY_OWNER, {1,2,-1,-1}},
-       {ADD_CONNECTION, 0, REPLACE_EXISTING,
-       PRIMARY_OWNER, {0,1,2,-1}},
-       {ADD_CONNECTION, 2, DO_NOT_QUEUE,
-       EXISTS, {0,1,-1,-1}},
-       {REMOVE_CONNECTION, 2, 0,
-       NOT_OWNER, {0,1,-1,-1}},
-       {ADD_CONNECTION, 3, 0,
-       IN_QUEUE, {0,1,3,-1}},
-       {ADD_CONNECTION, 0, ALLOW_REPLACEMENT,
-       ALREADY_OWNER, {0,1,3,-1}},
-       {ADD_CONNECTION, 2, ALLOW_REPLACEMENT,
-       IN_QUEUE, {0,1,3,2}}
+CommandAndResult test_data[] = {
+  {ADD_CONNECTION, 0, ALLOW_REPLACEMENT | REPLACE_EXISTING,
+   PRIMARY_OWNER, {0,-1,-1,-1}},
+  {ADD_CONNECTION, 0, REPLACE_EXISTING,
+   ALREADY_OWNER, {0,-1,-1,-1}},
+  {ADD_CONNECTION, 1, ALLOW_REPLACEMENT | REPLACE_EXISTING,
+   IN_QUEUE, {0,1,-1,-1}},
+  {REMOVE_CONNECTION, 0, 0,
+   RELEASED, {1,-1,-1,-1}},
+  {ADD_CONNECTION, 0, REPLACE_EXISTING | DO_NOT_QUEUE,
+   PRIMARY_OWNER, {0,1,-1,-1}},
+  {ADD_CONNECTION, 2, ALLOW_REPLACEMENT,
+   IN_QUEUE, {0,1,2,-1}},
+  {ADD_CONNECTION, 2, ALLOW_REPLACEMENT | REPLACE_EXISTING,
+   IN_QUEUE, {0,2,1,-1}},
+  {ADD_CONNECTION, 0, ALLOW_REPLACEMENT | DO_NOT_QUEUE,
+   ALREADY_OWNER, {0,2,1,-1}},
+  {ADD_CONNECTION, 1, ALLOW_REPLACEMENT | REPLACE_EXISTING,
+   PRIMARY_OWNER, {1,2,-1,-1}},
+  {ADD_CONNECTION, 0, REPLACE_EXISTING,
+   PRIMARY_OWNER, {0,1,2,-1}},
+  {ADD_CONNECTION, 2, DO_NOT_QUEUE,
+   EXISTS, {0,1,-1,-1}},
+  {REMOVE_CONNECTION, 2, 0,
+   NOT_OWNER, {0,1,-1,-1}},
+  {ADD_CONNECTION, 3, 0,
+   IN_QUEUE, {0,1,3,-1}},
+  {ADD_CONNECTION, 0, ALLOW_REPLACEMENT,
+   ALREADY_OWNER, {0,1,3,-1}},
+  {ADD_CONNECTION, 2, ALLOW_REPLACEMENT,
+   IN_QUEUE, {0,1,3,2}}
 };
 
 static dbus_bool_t
-check_connection (DBusConnection *conn, 
-                  int iteration, 
+check_connection (DBusConnection *conn,
+                  int iteration,
                   DBusConnection *uniq_conn[NUM_CONN])
 {
   DBusMessage *reply;
@@ -89,7 +89,7 @@ check_connection (DBusConnection *conn,
   dbus_error_init (&error);
 
   name = TEST_NAME;
-  method = dbus_message_new_method_call (DBUS_SERVICE_DBUS, 
+  method = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
                                          DBUS_PATH_DBUS,
                                          DBUS_INTERFACE_DBUS,
                                          "ListQueuedOwners");
@@ -97,8 +97,8 @@ check_connection (DBusConnection *conn,
   if (method == NULL)
     goto out;
 
-  if (!dbus_message_append_args (method, 
-                                 DBUS_TYPE_STRING, &name, 
+  if (!dbus_message_append_args (method,
+                                 DBUS_TYPE_STRING, &name,
                                  DBUS_TYPE_INVALID))
     {
       fprintf (stderr, "Error appending args\n") ;
@@ -118,10 +118,10 @@ check_connection (DBusConnection *conn,
     }
 
 
-  if (!dbus_message_get_args (reply, 
-                              &error, 
-                              DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, 
+
+  if (!dbus_message_get_args (reply,
+                              &error,
+                              DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
                               &list, &len,
                               DBUS_TYPE_INVALID))
     {
@@ -135,12 +135,12 @@ check_connection (DBusConnection *conn,
   if (len > NUM_CONN)
     {
       fprintf (stderr, "There are %i connections in the queue,"
-                       " we are only expecting up to %i connections!\n",
-                      len,
-                      NUM_CONN);
+               " we are only expecting up to %i connections!\n",
+               len,
+               NUM_CONN);
       goto out;
     }
-  
+
   for (i = 0; i < len; i++)
     {
       int expected_conn_num;
@@ -155,33 +155,33 @@ check_connection (DBusConnection *conn,
 
       if (expected_conn_num == -1)
         {
-          fprintf (stderr, 
-                   "\nDid not expect this last connection" 
+          fprintf (stderr,
+                   "\nDid not expect this last connection"
                    " to be in the queue!\n");
           goto out;
         }
 
-      expected_uname = 
-             dbus_bus_get_unique_name (uniq_conn[expected_conn_num]);
+      expected_uname =
+        dbus_bus_get_unique_name (uniq_conn[expected_conn_num]);
 
       if (strcmp (list[i], expected_uname) != 0)
         {
-          fprintf (stderr, 
+          fprintf (stderr,
                    "\n%s expected but %s is in the queue!\n",
-                   expected_uname, 
+                   expected_uname,
                    list[i]);
 
           goto out;
         }
     }
-  
+
   printf ("\n");
 
   dbus_message_unref (method);
   dbus_message_unref (reply);
   dbus_free_string_array (list);
   return TRUE;
+
  out:
   if (method != NULL)
     dbus_message_unref (method);
@@ -191,7 +191,7 @@ check_connection (DBusConnection *conn,
 
   if (list != NULL)
     dbus_free_string_array (list);
-  
+
   return FALSE;
 }
 
@@ -214,9 +214,9 @@ match_acquired_or_lost_signal (DBusConnection *conn, const char *member, const c
       msg = dbus_connection_pop_message (conn);
       if (msg != NULL)
         {
-          if (dbus_message_is_signal (msg, 
-              interface,
-              member))
+          if (dbus_message_is_signal (msg,
+                                      interface,
+                                      member))
             {
               const char *n;
               DBusError error;
@@ -234,7 +234,7 @@ match_acquired_or_lost_signal (DBusConnection *conn, const char *member, const c
 
               if (strcmp (n, name) == 0)
                 {
-                  dbus_message_unref (msg); 
+                  dbus_message_unref (msg);
                   break;
                 }
             }
@@ -244,10 +244,10 @@ match_acquired_or_lost_signal (DBusConnection *conn, const char *member, const c
 
   if (tries == NUM_TRIES_TIL_FAIL)
     {
-      fprintf (stderr, "Did not recive the expected %s.%s signal!!!\n", interface, member);
+      fprintf (stderr, "Did not receive the expected %s.%s signal!!!\n", interface, member);
       return FALSE;
     }
-  
+
   return TRUE;
 }
 
@@ -256,7 +256,7 @@ match_name_owner_changed_signal (DBusConnection *conn, const char *bus_name, con
 {
   int tries;
   DBusMessage *msg;
+
   for (tries = 0; tries < NUM_TRIES_TIL_FAIL; tries++)
     {
       _dbus_connection_lock (conn);
@@ -267,12 +267,12 @@ match_name_owner_changed_signal (DBusConnection *conn, const char *bus_name, con
                                               0);
       _dbus_connection_unlock (conn);
       msg = dbus_connection_pop_message (conn);
-    
+
       if (msg != NULL)
         {
-          if (dbus_message_is_signal (msg, 
-              "org.freedesktop.DBus",
-              "NameOwnerChanged"))
+          if (dbus_message_is_signal (msg,
+                                      "org.freedesktop.DBus",
+                                      "NameOwnerChanged"))
             {
               const char *n;
               const char *ln;
@@ -293,12 +293,12 @@ match_name_owner_changed_signal (DBusConnection *conn, const char *bus_name, con
               if (strcmp (n, bus_name) == 0)
                 {
                   if ((lost_name == NULL && strcmp (ln, "") == 0)
-                        || strcmp (lost_name, ln) == 0)
+                      || strcmp (lost_name, ln) == 0)
                     {
                       if ((acquired_name == NULL && strcmp (an, "") == 0)
-                            || strcmp (acquired_name, an) == 0)
+                          || strcmp (acquired_name, an) == 0)
                         {
-                          dbus_message_unref (msg); 
+                          dbus_message_unref (msg);
                           break;
                         }
                       else
@@ -325,12 +325,12 @@ match_name_owner_changed_signal (DBusConnection *conn, const char *bus_name, con
       fprintf (stderr, "Did not recive the expected NameOwnerChanged signal!!!\n");
       return FALSE;
     }
-  
+
   return TRUE;
 }
 
 
-static dbus_bool_t 
+static dbus_bool_t
 check_signals (DBusConnection *monitor,
                int iteration,
                DBusConnection *conn[NUM_CONN])
@@ -339,7 +339,7 @@ check_signals (DBusConnection *monitor,
   DBusConnection *acquired_conn = NULL;
   const char *lost_name;
   const char *acquired_name;
-  
+
   if (iteration == 0)
     {
       int i;
@@ -365,32 +365,32 @@ check_signals (DBusConnection *monitor,
         acquired_conn = lost_conn = NULL;
     }
 
-    lost_name = lost_conn == NULL? NULL : 
-                         dbus_bus_get_unique_name (lost_conn);
-
-    acquired_name = acquired_conn == NULL? NULL :
-                         dbus_bus_get_unique_name (acquired_conn);
-
-    if (lost_name != NULL)
-      if (!match_acquired_or_lost_signal (lost_conn,
-                                         "NameLost",
-                                         TEST_NAME))
-        return FALSE;
-
-    if (acquired_name != NULL)
-      if (!match_acquired_or_lost_signal (acquired_conn,
-                                         "NameAcquired",
-                                         TEST_NAME))
-        return FALSE;
-
-    if (acquired_name != NULL || lost_name != NULL)
-      if (!match_name_owner_changed_signal (monitor,
-                                            TEST_NAME,
-                                            lost_name,
-                                            acquired_name))
-        return FALSE;
-    
-    return TRUE;
+  lost_name = lost_conn == NULL? NULL :
+    dbus_bus_get_unique_name (lost_conn);
+
+  acquired_name = acquired_conn == NULL? NULL :
+    dbus_bus_get_unique_name (acquired_conn);
+
+  if (lost_name != NULL)
+    if (!match_acquired_or_lost_signal (lost_conn,
+                                        "NameLost",
+                                        TEST_NAME))
+      return FALSE;
+
+  if (acquired_name != NULL)
+    if (!match_acquired_or_lost_signal (acquired_conn,
+                                        "NameAcquired",
+                                        TEST_NAME))
+      return FALSE;
+
+  if (acquired_name != NULL || lost_name != NULL)
+    if (!match_name_owner_changed_signal (monitor,
+                                          TEST_NAME,
+                                          lost_name,
+                                          acquired_name))
+      return FALSE;
+
+  return TRUE;
 }
 
 int
@@ -403,7 +403,7 @@ main (int argc, char *argv[])
   int test_data_len;
 
   test_data_len = sizeof (test_data) / sizeof (CommandAndResult);
-  
+
   dbus_error_init (&error);
 
   conn[0] = dbus_bus_get_private (DBUS_BUS_SESSION, &error);
@@ -414,12 +414,12 @@ main (int argc, char *argv[])
       dbus_error_free (&error);
       return 1;
     }
-  
+
   if (!match_acquired_or_lost_signal (conn[0],
-                                "NameAcquired",
-                                dbus_bus_get_unique_name (conn[0])))
+                                      "NameAcquired",
+                                      dbus_bus_get_unique_name (conn[0])))
     return 1;
-  
+
   conn[1] = dbus_bus_get_private (DBUS_BUS_SESSION, &error);
   if (dbus_error_is_set (&error))
     {
@@ -430,8 +430,8 @@ main (int argc, char *argv[])
     }
 
   if (!match_acquired_or_lost_signal (conn[1],
-                                "NameAcquired",
-                                dbus_bus_get_unique_name (conn[1])))
+                                      "NameAcquired",
+                                      dbus_bus_get_unique_name (conn[1])))
     return 1;
 
 
@@ -445,8 +445,8 @@ main (int argc, char *argv[])
     }
 
   if (!match_acquired_or_lost_signal (conn[2],
-                                "NameAcquired",
-                                dbus_bus_get_unique_name (conn[2])))
+                                      "NameAcquired",
+                                      dbus_bus_get_unique_name (conn[2])))
     return 1;
 
 
@@ -460,8 +460,8 @@ main (int argc, char *argv[])
     }
 
   if (!match_acquired_or_lost_signal (conn[3],
-                                "NameAcquired",
-                                dbus_bus_get_unique_name (conn[3])))
+                                      "NameAcquired",
+                                      dbus_bus_get_unique_name (conn[3])))
     return 1;
 
 
@@ -475,8 +475,8 @@ main (int argc, char *argv[])
     }
 
   if (!match_acquired_or_lost_signal (monitor,
-                                "NameAcquired",
-                                dbus_bus_get_unique_name (monitor)))
+                                      "NameAcquired",
+                                      dbus_bus_get_unique_name (monitor)))
     return 1;
 
   dbus_bus_add_match (monitor, "", &error);
@@ -489,7 +489,7 @@ main (int argc, char *argv[])
     }
 
 
-  for (i = 0; i < NUM_CONN; i++) 
+  for (i = 0; i < NUM_CONN; i++)
     dbus_connection_set_exit_on_disconnect (conn[i], FALSE);
 
   for (i = 0; i < test_data_len; i++)
@@ -499,8 +499,8 @@ main (int argc, char *argv[])
 
       if (test_data[i].command == ADD_CONNECTION)
         {
-          result = dbus_bus_request_name (conn[test_data[i].connection_number], 
-                                          TEST_NAME, 
+          result = dbus_bus_request_name (conn[test_data[i].connection_number],
+                                          TEST_NAME,
                                           test_data[i].flags,
                                           &error);
 
@@ -510,12 +510,12 @@ main (int argc, char *argv[])
               dbus_error_free (&error);
               return 1;
             }
-        } 
+        }
       else if (test_data[i].command == REMOVE_CONNECTION)
         {
-          result = dbus_bus_release_name (conn[test_data[i].connection_number], 
-                                          TEST_NAME, 
-                                          &error);  
+          result = dbus_bus_release_name (conn[test_data[i].connection_number],
+                                          TEST_NAME,
+                                          &error);
           if (dbus_error_is_set (&error))
             {
               fprintf (stderr, "*** Failed to remove connection %i in iteration %i: %s\n",
@@ -555,5 +555,5 @@ main (int argc, char *argv[])
         }
     }
 
-    return 0;
+  return 0;
 }