[farsight2/master] Add upnp test to the rawudp transmitter

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:25:18 PST 2008


---
 tests/check/Makefile.am               |    9 ++-
 tests/check/transmitter/rawudp-upnp.c |  152 +++++++++++++++++++++++++++++++++
 tests/check/transmitter/rawudp-upnp.h |   27 ++++++
 tests/check/transmitter/rawudp.c      |   36 ++++++++
 4 files changed, 222 insertions(+), 2 deletions(-)
 create mode 100644 tests/check/transmitter/rawudp-upnp.c
 create mode 100644 tests/check/transmitter/rawudp-upnp.h

diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index a1c298f..b0d7a10 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -58,12 +58,17 @@ LDADD = \
 	$(GST_CHECK_LIBS) \
 	$(GST_LIBS)
 
-transmitter_rawudp_CFLAGS = $(AM_CFLAGS)
+transmitter_rawudp_CFLAGS = $(AM_CFLAGS) $(GUPNP_CFLAGS)
+transmitter_rawudp_LDADD = $(LDADD) \
+	$(GUPNP_LIBS)
 transmitter_rawudp_SOURCES = \
 	check-threadsafe.h  \
 	transmitter/generic.c \
 	transmitter/generic.h \
-	transmitter/rawudp.c 
+	transmitter/rawudp.c \
+	transmitter/rawudp-upnp.c \
+	transmitter/rawudp-upnp.h
+
 
 transmitter_multicast_CFLAGS = $(AM_CFLAGS)
 transmitter_multicast_SOURCES = \
diff --git a/tests/check/transmitter/rawudp-upnp.c b/tests/check/transmitter/rawudp-upnp.c
new file mode 100644
index 0000000..f0b7918
--- /dev/null
+++ b/tests/check/transmitter/rawudp-upnp.c
@@ -0,0 +1,152 @@
+/* Farsight 2 unit tests for FsRawUdpTransmitter UPnP code
+ *
+ * Copyright (C) 2009 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 "check-threadsafe.h"
+
+#ifdef HAVE_GUPNP
+
+#include <libgupnp/gupnp.h>
+
+
+static void
+get_external_ip_address_cb (GUPnPService *service,
+    GUPnPServiceAction *action,
+    gpointer user_data)
+{
+  gupnp_service_action_set (action,
+      "NewExternalIPAddress", G_TYPE_STRING, "127.0.0.1",
+      NULL);
+  gupnp_service_action_return (action);
+
+}
+
+static void
+add_port_mapping_cb (GUPnPService *service,
+    GUPnPServiceAction *action,
+    gpointer user_data)
+{
+  gchar *remote_host = NULL;
+  guint external_port = 0;
+  gchar *proto = NULL;
+  guint internal_port = 0;
+  gchar *internal_client = NULL;
+  gboolean enabled = -1;
+  gchar *desc = NULL;
+  guint lease = 0;
+
+  gupnp_service_action_get (action,
+      "NewRemoteHost", G_TYPE_STRING, &remote_host,
+      "NewExternalPort", G_TYPE_UINT, &external_port,
+      "NewProtocol", G_TYPE_STRING, &proto,
+      "NewInternalPort", G_TYPE_UINT, &internal_port,
+      "NewInternalClient", G_TYPE_STRING, &internal_client,
+      "NewEnabled", G_TYPE_BOOLEAN, &enabled,
+      "NewPortMappingDescription", G_TYPE_STRING, &desc,
+      "NewLeaseDuration", G_TYPE_UINT, &lease,
+      NULL);
+
+  ts_fail_unless (remote_host && !strcmp (remote_host, ""), "Remote host invalid");
+  ts_fail_unless (external_port == internal_port, "External and internal ports different");
+  ts_fail_unless (proto && (!strcmp (proto, "UDP") || !strcmp (proto, "TCP")));
+  ts_fail_unless (enabled == TRUE, "enable is not true");
+  ts_fail_unless (desc != NULL, "no desc");
+
+  gupnp_service_action_return (action);
+}
+
+
+static void
+delete_port_mapping_cb (GUPnPService *service,
+    GUPnPServiceAction *action,
+    gpointer user_data)
+{
+  gchar *remote_host = NULL;
+  guint external_port = 0;
+  gchar *proto = NULL;
+
+  gupnp_service_action_get (action,
+      "NewRemoteHost", G_TYPE_STRING, &remote_host,
+      "NewExternalPort", G_TYPE_UINT, &external_port,
+      "NewProtocol", G_TYPE_STRING, &proto,
+      NULL);
+
+  ts_fail_if (remote_host == NULL, "remote host NULL on remove");
+  ts_fail_unless (external_port, "external port wrong on remove");
+  ts_fail_unless (proto && !strcmp (proto, "UDP"), "proto wrong on remove");
+
+  gupnp_service_action_return (action);
+}
+
+
+GObject *
+start_upnp_server (void)
+{
+  GUPnPContext *context;
+  GUPnPRootDevice *dev;
+  GUPnPServiceInfo *service;
+  GUPnPDeviceInfo *subdev1;
+  GUPnPDeviceInfo *subdev2;
+
+  context = gupnp_context_new (NULL, NULL, 0, NULL);
+  ts_fail_if (context == NULL, "Can't get gupnp context");
+
+  gupnp_context_host_path (context, "upnp/InternetGatewayDevice.xml", "/InternetGatewayDevice.xml");
+  gupnp_context_host_path (context, "upnp/WANIPConnection.xml", "/WANIPConnection.xml");
+
+  dev = gupnp_root_device_new (context, "/InternetGatewayDevice.xml");
+  ts_fail_if (dev == NULL, "could not get root dev");
+
+  subdev1 = gupnp_device_info_get_device (GUPNP_DEVICE_INFO (dev),
+      "urn:schemas-upnp-org:device:WANDevice:1");
+  ts_fail_if (subdev1 == NULL, "Could not get WANDevice");
+
+  subdev2 = gupnp_device_info_get_device (subdev1,
+      "urn:schemas-upnp-org:device:WANConnectionDevice:1");
+  ts_fail_if (subdev2 == NULL, "Could not get WANConnectionDevice");
+
+  service = gupnp_device_info_get_service (subdev2,
+      "urn:schemas-upnp-org:service:WANIPConnection:1");
+  ts_fail_if (service == NULL, "Could not get WANIPConnection");
+
+  g_signal_connect (service, "action-invoked::GetExternalIPAddress",
+      G_CALLBACK (get_external_ip_address_cb), NULL);
+  g_signal_connect (service, "action-invoked::AddPortMapping",
+      G_CALLBACK (add_port_mapping_cb), NULL);
+  g_signal_connect (service, "action-invoked::DeletePortMapping",
+      G_CALLBACK (delete_port_mapping_cb), NULL);
+
+  gupnp_root_device_set_available (dev, TRUE);
+
+  return G_OBJECT (context);
+}
+
+#else
+
+GObject *
+start_upnp_server (void)
+{
+  return NULL;
+}
+
+#endif
diff --git a/tests/check/transmitter/rawudp-upnp.h b/tests/check/transmitter/rawudp-upnp.h
new file mode 100644
index 0000000..d1bb2ee
--- /dev/null
+++ b/tests/check/transmitter/rawudp-upnp.h
@@ -0,0 +1,27 @@
+/* Farsight 2 unit tests for FsRawUdpTransmitter UPnP code
+ *
+ * Copyright (C) 2008 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 __RAWUDP_UPNP_H__
+#define __RAWUDP_UPNP_H__
+
+GObject *start_upnp_server (void);
+
+#endif /* __RAWUDP_UPNP_H__ */
diff --git a/tests/check/transmitter/rawudp.c b/tests/check/transmitter/rawudp.c
index 184628a..db0a6b3 100644
--- a/tests/check/transmitter/rawudp.c
+++ b/tests/check/transmitter/rawudp.c
@@ -31,6 +31,7 @@
 
 #include "check-threadsafe.h"
 #include "generic.h"
+#include "transmitter/rawudp-upnp.h"
 
 gint buffer_count[2] = {0, 0};
 GMainLoop *loop = NULL;
@@ -645,6 +646,35 @@ GST_START_TEST (test_rawudptransmitter_stop_stream)
 }
 GST_END_TEST;
 
+#ifdef HAVE_GUPNP
+
+
+
+GST_START_TEST (test_rawudptransmitter_run_upnp_discovery)
+{
+  GParameter params[2];
+  GObject *context;
+
+  memset (params, 0, sizeof (GParameter) * 2);
+
+  params[0].name = "associate-on-source";
+  g_value_init (&params[0].value, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&params[0].value, TRUE);
+
+  params[1].name = "upnp-discovery";
+  g_value_init (&params[1].value, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&params[1].value, TRUE);
+
+  context = start_upnp_server ();
+
+  run_rawudp_transmitter_test (2, params, 0);
+
+  g_object_unref (context);
+}
+GST_END_TEST;
+
+
+#endif
 
 static Suite *
 rawudptransmitter_suite (void)
@@ -687,6 +717,12 @@ rawudptransmitter_suite (void)
   tcase_add_test (tc_chain, test_rawudptransmitter_stop_stream);
   suite_add_tcase (s, tc_chain);
 
+#ifdef HAVE_GUPNP
+  tc_chain = tcase_create ("rawudptransmitter-upnp-discovery");
+  tcase_add_test (tc_chain, test_rawudptransmitter_run_upnp_discovery);
+  suite_add_tcase (s, tc_chain);
+#endif
+
   return s;
 }
 
-- 
1.5.6.5




More information about the farsight-commits mailing list