[farsight2/master] Factor out the utility func to find multicast addresses
Olivier Crête
olivier.crete at collabora.co.uk
Thu Apr 23 14:48:35 PDT 2009
---
tests/check/Makefile.am | 4 +-
tests/check/testutils.c | 80 +++++++++++++++++++++++++++++++++++
tests/check/testutils.h | 32 ++++++++++++++
tests/check/transmitter/multicast.c | 59 +------------------------
4 files changed, 118 insertions(+), 57 deletions(-)
create mode 100644 tests/check/testutils.c
create mode 100644 tests/check/testutils.h
diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index 75a934c..26653c0 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -81,11 +81,13 @@ transmitter_rawudp_SOURCES = \
transmitter_multicast_CFLAGS = $(AM_CFLAGS)
transmitter_multicast_SOURCES = \
check-threadsafe.h \
+ testutils.c \
+ testutils.h \
transmitter/generic.c \
transmitter/generic.h \
transmitter/fake-filter.c \
transmitter/fake-filter.h \
- transmitter/multicast.c
+ transmitter/multicast.c
transmitter_nice_CFLAGS = $(FS2_INTERNAL_CFLAGS) $(CFLAGS) $(AM_CFLAGS)
transmitter_nice_SOURCES = \
diff --git a/tests/check/testutils.c b/tests/check/testutils.c
new file mode 100644
index 0000000..8fa4e18
--- /dev/null
+++ b/tests/check/testutils.c
@@ -0,0 +1,80 @@
+/* Farsight 2 unit tests generic utilities
+ *
+ * Copyright (C) 2007 Collabora, Nokia
+ * @author: Olivier Crete <olivier.crete at collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "testutils.h"
+
+#ifdef HAVE_GETIFADDRS
+ #include <sys/socket.h>
+ #include <ifaddrs.h>
+ #include <net/if.h>
+ #include <arpa/inet.h>
+#endif
+
+gchar *
+find_multicast_capable_address (void)
+{
+#ifdef HAVE_GETIFADDRS
+ gchar *retval = NULL;
+ struct ifaddrs *ifa, *results;
+
+ if (getifaddrs (&results) < 0)
+ return NULL;
+
+ for (ifa = results; ifa; ifa = ifa->ifa_next) {
+ /* no ip address from interface that is down */
+ if ((ifa->ifa_flags & IFF_UP) == 0)
+ continue;
+
+ if ((ifa->ifa_flags & IFF_MULTICAST) == 0)
+ continue;
+
+ if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET)
+ continue;
+
+ if (retval)
+ {
+ g_free (retval);
+ retval = NULL;
+ g_debug ("Disabling test, more than one multicast capable interface");
+ break;
+ }
+
+ retval = g_strdup (
+ inet_ntoa (((struct sockaddr_in *) ifa->ifa_addr)->sin_addr));
+ g_debug ("Sending from %s on interface %s", retval, ifa->ifa_name);
+ }
+
+ freeifaddrs (results);
+
+ if (retval == NULL)
+ g_message ("Skipping multicast transmitter tests, "
+ "no multicast capable interface found");
+ return retval;
+
+#else
+ g_message ("This system does not have getifaddrs,"
+ " this test will be disabled");
+ return NULL;
+#endif
+}
diff --git a/tests/check/testutils.h b/tests/check/testutils.h
new file mode 100644
index 0000000..c199f67
--- /dev/null
+++ b/tests/check/testutils.h
@@ -0,0 +1,32 @@
+/* Farsight 2 unit tests generic utilities
+ *
+ * Copyright (C) 2007 Collabora, Nokia
+ * @author: Olivier Crete <olivier.crete at collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef __UTILS_H__
+#define __UTILS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gchar *find_multicast_capable_address (void);
+
+G_END_DECLS
+
+#endif /* __UTILS_H__ */
diff --git a/tests/check/transmitter/multicast.c b/tests/check/transmitter/multicast.c
index d091521..58afded 100644
--- a/tests/check/transmitter/multicast.c
+++ b/tests/check/transmitter/multicast.c
@@ -26,16 +26,10 @@
#include <gst/farsight/fs-transmitter.h>
#include <gst/farsight/fs-conference-iface.h>
-#ifdef HAVE_GETIFADDRS
- #include <sys/socket.h>
- #include <ifaddrs.h>
- #include <net/if.h>
- #include <arpa/inet.h>
-#endif
-
#include "check-threadsafe.h"
#include "generic.h"
#include "fake-filter.h"
+#include "testutils.h"
gint buffer_count[2] = {0, 0};
GMainLoop *loop = NULL;
@@ -227,60 +221,13 @@ GST_START_TEST (test_multicasttransmitter_run)
}
GST_END_TEST;
-static gchar *
-_find_multicast_capable_address (void)
-{
-#ifdef HAVE_GETIFADDRS
- gchar *retval = NULL;
- struct ifaddrs *ifa, *results;
-
- if (getifaddrs (&results) < 0)
- return NULL;
-
- for (ifa = results; ifa; ifa = ifa->ifa_next) {
- /* no ip address from interface that is down */
- if ((ifa->ifa_flags & IFF_UP) == 0)
- continue;
-
- if ((ifa->ifa_flags & IFF_MULTICAST) == 0)
- continue;
-
- if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET)
- continue;
-
- if (retval)
- {
- g_free (retval);
- retval = NULL;
- g_debug ("Disabling test, more than one multicast capable interface");
- break;
- }
-
- retval = g_strdup (
- inet_ntoa (((struct sockaddr_in *) ifa->ifa_addr)->sin_addr));
- g_debug ("Sending from %s on interface %s", retval, ifa->ifa_name);
- }
-
- freeifaddrs (results);
-
- if (retval == NULL)
- g_message ("Skipping multicast transmitter tests, "
- "no multicast capable interface found");
- return retval;
-
-#else
- g_message ("This system does not have getifaddrs,"
- " this test will be disabled");
- return NULL;
-#endif
-}
GST_START_TEST (test_multicasttransmitter_run_local_candidates)
{
GParameter params[1];
GList *list = NULL;
FsCandidate *candidate;
- gchar *address = _find_multicast_capable_address ();
+ gchar *address = find_multicast_capable_address ();
if (address == NULL)
return;
@@ -334,7 +281,7 @@ multicasttransmitter_suite (void)
GLogLevelFlags fatal_mask;
gchar *tmp_addr;
- tmp_addr = _find_multicast_capable_address ();
+ tmp_addr = find_multicast_capable_address ();
if (!tmp_addr)
return s;
--
1.5.6.5
More information about the farsight-commits
mailing list