libepc r219 - in trunk: . tests



Author: hasselmm
Date: Mon Apr  7 21:54:52 2008
New Revision: 219
URL: http://svn.gnome.org/viewvc/libepc?rev=219&view=rev

Log:
Upgrade the test suite to handle multiple active network interfaces.

* tests/framework.c, tests/framework.h (EpcIfTestStatus,
  epc_test_list_ifaces(), _epc_test_match_any(), _epc_test_match_one(),
  _epc_test_pass_once_per_iface(), epc_test_pass_once_for_each_iface(),
  epc_test_pass_once_per_iface()): Provide infrastructure for handling
  tests, that match once for each active network interface.

* tests/test-dispatcher-rename.c (service_browser_cb()),
  tests/test-dispatcher-reset.c (service_browser_cb()),
  tests/test-publisher-bookmarks.c (service_browser_cb()),
  tests/test-publisher-change-name.c (service_browser_cb()):
  Replace epc_test_pass_once() by epc_test_pass_once_per_iface()
  were needed.

* tests/test-dispatcher-unique.c (service_found_cb()),
  tests/test-publisher-unique.c (contents_handler_cb(),
  service_found_cb()): Replace epc_test_pass_once() by
  epc_test_pass_once_for_each_iface() were needed.


Added:
   trunk/tests/test-publisher-authentication.c
Modified:
   trunk/ChangeLog
   trunk/tests/framework.c
   trunk/tests/framework.h
   trunk/tests/test-dispatcher-rename.c
   trunk/tests/test-dispatcher-reset.c
   trunk/tests/test-dispatcher-unique.c
   trunk/tests/test-publisher-bookmarks.c
   trunk/tests/test-publisher-change-name.c
   trunk/tests/test-publisher-unique.c

Modified: trunk/tests/framework.c
==============================================================================
--- trunk/tests/framework.c	(original)
+++ trunk/tests/framework.c	Mon Apr  7 21:54:52 2008
@@ -24,6 +24,21 @@
 #include <avahi-client/client.h>
 #include <avahi-common/error.h>
 
+#include <net/if.h>
+#include <sys/ioctl.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+typedef struct _EpcIfTestStatus EpcIfTestStatus;
+
+struct _EpcIfTestStatus
+{
+  guint  ifidx;
+  gchar *name;
+  gint   mask;
+};
+
 static GSList *epc_test_service_browsers = NULL;
 static GMainLoop *epc_test_loop = NULL;
 static guint epc_test_timeout = 0;
@@ -121,6 +136,159 @@
     epc_test_quit ();
 }
 
+static EpcIfTestStatus*
+epc_test_list_ifaces (void)
+{
+  EpcIfTestStatus *ifaces = NULL;
+  gsize n_ifaces = 0, i, j;
+  struct ifconf ifc;
+  char buf[4096];
+  gint fd = -1;
+
+  fd = socket (AF_INET, SOCK_DGRAM, 0);
+
+  if (fd < 0)
+    {
+      g_warning ("%s: socket(AF_INET, SOCK_DGRAM): %s",
+                 G_STRLOC, g_strerror (errno));
+      goto out;
+    }
+
+  ifc.ifc_buf = buf;
+  ifc.ifc_len = sizeof buf;
+
+  if (ioctl (fd, SIOCGIFCONF, &ifc) < 0)
+    {
+      g_warning ("%s: ioctl(SIOCGIFCONF): %s",
+                 G_STRLOC, g_strerror (errno));
+      goto out;
+    }
+
+  n_ifaces = ifc.ifc_len / sizeof(struct ifreq);
+  ifaces = g_new0 (EpcIfTestStatus, n_ifaces + 1);
+
+  for (i = 0, j = 0; i < n_ifaces; ++i)
+    {
+      struct ifreq *req = &ifc.ifc_req[i];
+
+      ifaces[j].name = g_strdup (req->ifr_name);
+
+      if (ioctl (fd, SIOCGIFFLAGS, req) < 0)
+        {
+          g_warning ("%s: ioctl(SIOCGIFFLAGS): %s",
+                     G_STRLOC, g_strerror (errno));
+          goto out;
+        }
+
+      if (req->ifr_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))
+        {
+          g_free (ifaces[j].name);
+          ifaces[j].name = NULL;
+          continue;
+        }
+
+      if (ioctl (fd, SIOCGIFINDEX, req) < 0)
+        {
+          g_warning ("%s: ioctl(SIOCGIFINDEX): %s",
+                     G_STRLOC, g_strerror (errno));
+          goto out;
+        }
+
+      ifaces[j].ifidx = req->ifr_ifindex;
+      ifaces[j].mask = epc_test_result;
+
+      g_print ("%s: name=%s, ifidx=%u, \n",
+               G_STRLOC, ifaces[j].name,
+               ifaces[j].ifidx);
+
+      ++j;
+    }
+
+out:
+  if (fd >= 0)
+    close (fd);
+
+  return ifaces;
+}
+
+static gboolean
+_epc_test_match_any (const gchar           *strloc,
+                     const EpcIfTestStatus *status,
+                     gint                   ifidx,
+                     gint                   i)
+{
+  const gint mask = (1 << i);
+
+  if (!(status->mask & mask))
+    return FALSE;
+
+  g_print ("%s: Test #%d passed for some network interface\n", strloc, i + 1);
+  return TRUE;
+}
+
+static gboolean
+_epc_test_match_one (const gchar           *strloc,
+                     const EpcIfTestStatus *status,
+                     gint                   ifidx,
+                     gint                   i)
+{
+  if (status->ifidx != ifidx)
+    return FALSE;
+
+  g_print ("%s: Test #%d passed for %s\n", strloc, i + 1, status->name);
+  return TRUE;
+}
+
+void
+_epc_test_pass_once_per_iface (const gchar *strloc,
+                               gint         mask,
+                               guint        ifidx,
+                               gboolean     any)
+{
+  gboolean (*match)(const gchar           *strloc,
+                    const EpcIfTestStatus *status,
+                    gint                   ifidx,
+                    gint                   i);
+
+  static EpcIfTestStatus *ifaces = NULL;
+  gint pending;
+  guint i, j;
+
+  if (!ifaces)
+    ifaces = epc_test_list_ifaces ();
+
+  g_assert (NULL != ifaces);
+  mask &= EPC_TEST_MASK_USER;
+
+  if (any)
+    match = _epc_test_match_any;
+  else
+    match = _epc_test_match_one;
+
+  for (i = 0; (1 << i) < EPC_TEST_MASK_USER; ++i)
+    {
+      if (0 == (mask & (1 << i)))
+        continue;
+
+      pending = 0;
+
+      for (j = 0; ifaces[j].name; ++j)
+        {
+          if (match (strloc, &ifaces[j], ifidx, i))
+            {
+              ifaces[j].mask &= ~(1 << i);
+              break;
+            }
+        }
+
+      for (j = 0; ifaces[j].name; ++j)
+        pending |= (ifaces[j].mask & (1 << i));
+
+      if (!pending)
+        _epc_test_pass (strloc, TRUE, 1 << i);
+    }
+}
+
 gboolean
 epc_test_init_service_browser (const gchar                 *service,
                                AvahiServiceBrowserCallback  callback,

Modified: trunk/tests/framework.h
==============================================================================
--- trunk/tests/framework.h	(original)
+++ trunk/tests/framework.h	Mon Apr  7 21:54:52 2008
@@ -26,9 +26,16 @@
 
 G_BEGIN_DECLS
 
-#define epc_test_pass_many(mask) (_epc_test_pass (G_STRLOC, FALSE, (mask)))
-#define epc_test_pass_once(mask) (_epc_test_pass (G_STRLOC, TRUE, (mask)))
-#define epc_test_quit()          (_epc_test_quit (G_STRLOC))
+#define epc_test_pass_many(mask) \
+  (_epc_test_pass (G_STRLOC, FALSE, (mask)))
+#define epc_test_pass_once(mask) \
+  (_epc_test_pass (G_STRLOC, TRUE, (mask)))
+#define epc_test_pass_once_per_iface(mask, ifidx) \
+  (_epc_test_pass_once_per_iface (G_STRLOC, (mask), (ifidx), FALSE))
+#define epc_test_pass_once_for_each_iface(mask) \
+  (_epc_test_pass_once_per_iface (G_STRLOC, (mask), 0, TRUE))
+#define epc_test_quit() \
+  (_epc_test_quit (G_STRLOC))
 
 #define epc_test_goto_if_fail(Test, Label) G_STMT_START{        \
   if (!(Test))                                                  \
@@ -42,7 +49,7 @@
 {
   EPC_TEST_MASK_INIT = 128,
   EPC_TEST_MASK_USER = 127,
-  EPC_TEST_MASK_ALL = 255
+  EPC_TEST_MASK_ALL  = 255
 };
 
 gboolean epc_test_init                 (gint                         tests);
@@ -56,6 +63,11 @@
                                         gboolean                     once,
                                         gint                         mask);
 
+void    _epc_test_pass_once_per_iface  (const gchar                 *strloc,
+                                        gint                         mask,
+                                        guint                        ifidx,
+                                        gboolean                     any);
+
 G_END_DECLS
 
 #endif /* __EPC_TEST_FRAMEWORK_H__ */

Modified: trunk/tests/test-dispatcher-rename.c
==============================================================================
--- trunk/tests/test-dispatcher-rename.c	(original)
+++ trunk/tests/test-dispatcher-rename.c	Mon Apr  7 21:54:52 2008
@@ -31,7 +31,7 @@
 
 static void
 service_browser_cb (AvahiServiceBrowser     *browser G_GNUC_UNUSED,
-                    AvahiIfIndex             interface G_GNUC_UNUSED,
+                    AvahiIfIndex             interface,
                     AvahiProtocol            protocol G_GNUC_UNUSED,
                     AvahiBrowserEvent        event,
                     const char              *name G_GNUC_UNUSED,
@@ -49,27 +49,27 @@
           case AVAHI_BROWSER_NEW:
             if (g_str_equal (name, first_name))
               {
-                epc_test_pass_once (1 << 0);
+                epc_test_pass_once_per_iface (1 << 0, interface);
                 epc_dispatcher_set_name (dispatcher, second_name);
               }
 
             if (g_str_equal (name, second_name))
               {
-                epc_test_pass_once (1 << 2);
+                epc_test_pass_once_per_iface (1 << 2, interface);
                 epc_dispatcher_set_name (dispatcher, third_name);
               }
 
             if (g_str_equal (name, third_name))
-              epc_test_pass_once (1 << 4);
+              epc_test_pass_once_per_iface (1 << 4, interface);
 
             break;
 
           case AVAHI_BROWSER_REMOVE:
             if (g_str_equal (name, first_name))
-              epc_test_pass_once (1 << 1);
+              epc_test_pass_once_per_iface (1 << 1, interface);
 
             if (g_str_equal (name, second_name))
-              epc_test_pass_once (1 << 3);
+              epc_test_pass_once_per_iface (1 << 3, interface);
 
             break;
 

Modified: trunk/tests/test-dispatcher-reset.c
==============================================================================
--- trunk/tests/test-dispatcher-reset.c	(original)
+++ trunk/tests/test-dispatcher-reset.c	Mon Apr  7 21:54:52 2008
@@ -29,7 +29,7 @@
 
 static void
 service_browser_cb (AvahiServiceBrowser     *browser G_GNUC_UNUSED,
-                    AvahiIfIndex             interface G_GNUC_UNUSED,
+                    AvahiIfIndex             interface,
                     AvahiProtocol            protocol G_GNUC_UNUSED,
                     AvahiBrowserEvent        event,
                     const char              *name,
@@ -45,12 +45,12 @@
     {
       if (AVAHI_BROWSER_NEW == event)
         {
-          epc_test_pass_once (1);
+          epc_test_pass_once_per_iface (1, interface);
           epc_dispatcher_reset (dispatcher);
         }
 
       if (AVAHI_BROWSER_REMOVE == event)
-        epc_test_pass_once (2);
+        epc_test_pass_once_per_iface (2, interface);
     }
 }
 

Modified: trunk/tests/test-dispatcher-unique.c
==============================================================================
--- trunk/tests/test-dispatcher-unique.c	(original)
+++ trunk/tests/test-dispatcher-unique.c	Mon Apr  7 21:54:52 2008
@@ -61,7 +61,8 @@
       cookie && g_str_equal (cookie, test_cookie1) &&
       dispatcher && g_str_equal (dispatcher, "dispatcher1"))
     {
-      epc_test_pass_once (1 << 3);
+g_debug ("%s", epc_service_info_get_interface (info));
+      epc_test_pass_once_for_each_iface (1 << 3);
       g_timeout_add (500, stop_dispatcher_cb, NULL);
     }
 
@@ -73,7 +74,7 @@
   if (g_str_equal (name, test_name2) &&
       cookie && g_str_equal (cookie, test_cookie2) &&
       dispatcher && g_str_equal (dispatcher, "dispatcher3"))
-    epc_test_pass_once (1 << 5);
+    epc_test_pass_once_for_each_iface (1 << 5);
 }
 
 int

Added: trunk/tests/test-publisher-authentication.c
==============================================================================
--- (empty file)
+++ trunk/tests/test-publisher-authentication.c	Mon Apr  7 21:54:52 2008
@@ -0,0 +1,8 @@
+
+
+int
+main (int    argc,
+      char **argv[])
+{
+  return 1;
+}

Modified: trunk/tests/test-publisher-bookmarks.c
==============================================================================
--- trunk/tests/test-publisher-bookmarks.c	(original)
+++ trunk/tests/test-publisher-bookmarks.c	Mon Apr  7 21:54:52 2008
@@ -31,7 +31,7 @@
 
 static void
 service_browser_cb (AvahiServiceBrowser     *browser G_GNUC_UNUSED,
-                    AvahiIfIndex             interface G_GNUC_UNUSED,
+                    AvahiIfIndex             interface,
                     AvahiProtocol            protocol G_GNUC_UNUSED,
                     AvahiBrowserEvent        event,
                     const char              *name,
@@ -47,15 +47,15 @@
       if (g_str_equal (name, first_name))
         {
           if (g_str_equal (type, EPC_SERVICE_TYPE_HTTP))
-            epc_test_pass_once (1 << 1);
+            epc_test_pass_once_per_iface (1 << 1, interface);
           if (g_str_equal (type, "_http._tcp"))
-            epc_test_pass_once (1 << 2);
+            epc_test_pass_once_per_iface (1 << 2, interface);
         }
 
       if (g_str_equal (name, second_name))
         {
           if (g_str_equal (type, "_http._tcp"))
-            epc_test_pass_once (1 << 3);
+            epc_test_pass_once_per_iface (1 << 3, interface);
         }
     }
 }

Modified: trunk/tests/test-publisher-change-name.c
==============================================================================
--- trunk/tests/test-publisher-change-name.c	(original)
+++ trunk/tests/test-publisher-change-name.c	Mon Apr  7 21:54:52 2008
@@ -29,7 +29,7 @@
 
 static void
 service_browser_cb (AvahiServiceBrowser     *browser G_GNUC_UNUSED,
-                    AvahiIfIndex             interface G_GNUC_UNUSED,
+                    AvahiIfIndex             interface,
                     AvahiProtocol            protocol G_GNUC_UNUSED,
                     AvahiBrowserEvent        event,
                     const char              *name,
@@ -46,12 +46,12 @@
     {
       if (g_str_equal (name, first_name))
         {
-          epc_test_pass_once (1 << 1);
+          epc_test_pass_once_per_iface (1 << 1, interface);
           epc_publisher_set_service_name (publisher, second_name);
         }
 
       if (g_str_equal (name, second_name))
-        epc_test_pass_once (1 << 2);
+        epc_test_pass_once_per_iface (1 << 2, interface);
     }
 }
 

Modified: trunk/tests/test-publisher-unique.c
==============================================================================
--- trunk/tests/test-publisher-unique.c	(original)
+++ trunk/tests/test-publisher-unique.c	Mon Apr  7 21:54:52 2008
@@ -52,9 +52,9 @@
       value = epc_consumer_lookup (consumer, "id", NULL, &error);
 
       if (value && g_str_equal (value, test_value1))
-        epc_test_pass_once (1 << 4);
+        epc_test_pass_once_for_each_iface (1 << 4);
       if (value && g_str_equal (value, test_value2))
-        epc_test_pass_once (1 << 6);
+        epc_test_pass_once_for_each_iface (1 << 6);
       if (error)
         g_warning ("%s: %s", G_STRLOC, error->message);
 
@@ -80,9 +80,9 @@
                      gpointer      data)
 {
   if (data == test_value1)
-    epc_test_pass_once (1 << 3);
+    epc_test_pass_once_for_each_iface (1 << 3);
   if (data == test_value2)
-    epc_test_pass_once (1 << 5);
+    epc_test_pass_once_for_each_iface (1 << 5);
 
   g_timeout_add (250, quit_publisher_cb, g_object_ref (publisher));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]