[farsight2/master] Compile tests for upnp stuff

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


---
 .gitignore                      |    2 +
 configure.ac                    |    1 +
 gst-libs/ext/fsupnp/Makefile.am |    2 +-
 tests/Makefile.am               |    4 +-
 tests/commandline/test-thread.c |   85 ---------------------------------
 tests/commandline/test.c        |   98 ---------------------------------------
 tests/upnp/Makefile.am          |   13 +++++
 tests/upnp/test-thread.c        |   85 +++++++++++++++++++++++++++++++++
 tests/upnp/test.c               |   98 +++++++++++++++++++++++++++++++++++++++
 9 files changed, 202 insertions(+), 186 deletions(-)
 delete mode 100644 tests/commandline/test-thread.c
 delete mode 100644 tests/commandline/test.c
 create mode 100644 tests/upnp/Makefile.am
 create mode 100644 tests/upnp/test-thread.c
 create mode 100644 tests/upnp/test.c

diff --git a/.gitignore b/.gitignore
index 0ec44be..da3a337 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,6 +53,8 @@ tests/check/rtp/sendcodecs
 tests/check/utils/binadded
 tests/rtp/codec-discovery
 tests/commandline/simple-call
+tests/upnp/test
+tests/upnp/test-thread
 tests/gui/*.pyo
 tests/gui/*.pyc
 
diff --git a/configure.ac b/configure.ac
index 496fb55..dde054e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -416,6 +416,7 @@ tests/check/Makefile
 tests/rtp/Makefile
 tests/gui/Makefile
 tests/commandline/Makefile
+tests/upnp/Makefile
 docs/Makefile
 docs/libs/Makefile
 docs/version.entities
diff --git a/gst-libs/ext/fsupnp/Makefile.am b/gst-libs/ext/fsupnp/Makefile.am
index ed95aaf..d5433be 100644
--- a/gst-libs/ext/fsupnp/Makefile.am
+++ b/gst-libs/ext/fsupnp/Makefile.am
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libfsupnp.la
 
-fsupnpincludedir = $(includedir)/gstreamer- at GST_MAJORMINOR@/gst/fsupnp
+fsupnpincludedir = $(includedir)/gstreamer- at GST_MAJORMINOR@/ext/fsupnp
 
 fsupnpinclude_HEADERS = \
 	fs-upnp-simple-igd.h \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dd4f823..ca83c4d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,6 +4,6 @@ else
 SUBDIRS_CHECK =
 endif
 
-SUBDIRS = $(SUBDIRS_CHECK) rtp gui commandline
+SUBDIRS = $(SUBDIRS_CHECK) rtp gui commandline upnp
 
-DIST_SUBDIRS = check rtp gui commandline
+DIST_SUBDIRS = check rtp gui commandline upnp
diff --git a/tests/commandline/test-thread.c b/tests/commandline/test-thread.c
deleted file mode 100644
index 546f46b..0000000
--- a/tests/commandline/test-thread.c
+++ /dev/null
@@ -1,85 +0,0 @@
-
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <glib.h>
-
-#include "fs-upnp-simple-igd-thread.h"
-
-static void
-_mapped_external_port (FsUpnpSimpleIgd *igd, gchar *proto,
-    gchar *external_ip, gchar *replaces_external_ip, guint external_port,
-    gchar *local_ip, guint local_port,
-    gchar *description, gpointer user_data)
-{
-  g_debug ("proto:%s ex:%s oldex:%s exp:%u local:%s localp:%u desc:%s",
-      proto, external_ip, replaces_external_ip, external_port, local_ip,
-      local_port, description);
-
-}
-
-
-
-static void
-_error_mapping_external_port (FsUpnpSimpleIgd *igd, GError *error,
-    gchar *proto, guint external_port,
-    gchar *description, gpointer user_data)
-{
-  g_error ("proto:%s port:%u desc:%s error: %s", proto, external_port,
-      description, error->message);
-}
-
-
-static void
-_error (FsUpnpSimpleIgd *igd, GError *error, gpointer user_data)
-{
-  g_error ("error: %s", error->message);
-}
-
-int
-main (int argc, char **argv)
-{
-  FsUpnpSimpleIgdThread *igd = NULL;
-  guint external_port, internal_port;
-
-
-  if (argc != 5)
-  {
-    g_print ("Usage: %s <external port> <local ip> <local port> <description>\n",
-        argv[0]);
-    return 0;
-  }
-
-  external_port = atoi (argv[1]);
-  internal_port = atoi (argv[3]);
-  g_return_val_if_fail (external_port && internal_port, 1);
-
-  g_type_init ();
-  g_thread_init (NULL);
-
-  igd = fs_upnp_simple_igd_thread_new ();
-
-  g_signal_connect (igd, "mapped-external-port",
-      G_CALLBACK (_mapped_external_port),
-      NULL);
-  g_signal_connect (igd, "error", G_CALLBACK (_error),
-      NULL);
-  g_signal_connect (igd, "error-mapping-port",
-      G_CALLBACK (_error_mapping_external_port),
-      NULL);
-
-  fs_upnp_simple_igd_add_port (FS_UPNP_SIMPLE_IGD (igd),
-      "TCP", external_port, argv[2],
-      internal_port, 20, argv[4]);
-
-  sleep (30);
-
-  fs_upnp_simple_igd_remove_port (FS_UPNP_SIMPLE_IGD (igd), "TCP",
-      external_port);
-
-  sleep (5);
-
-  g_object_unref (igd);
-
-  return 0;
-}
diff --git a/tests/commandline/test.c b/tests/commandline/test.c
deleted file mode 100644
index 19d58c0..0000000
--- a/tests/commandline/test.c
+++ /dev/null
@@ -1,98 +0,0 @@
-
-#include <stdlib.h>
-
-#include <glib.h>
-
-#include "fs-upnp-simple-igd.h"
-
-GMainContext *ctx = NULL;
-GMainLoop *loop = NULL;
-FsUpnpSimpleIgd *igd = NULL;
-guint external_port, internal_port;
-
-static gboolean
-_remove_port (gpointer user_data)
-{
-  g_debug ("removing port");
-  fs_upnp_simple_igd_remove_port (igd, "TCP", external_port);
-
-  return FALSE;
-}
-
-static void
-_mapped_external_port (FsUpnpSimpleIgd *igd, gchar *proto,
-    gchar *external_ip, gchar *replaces_external_ip, guint external_port,
-    gchar *local_ip, guint local_port,
-    gchar *description, gpointer user_data)
-{
-  GSource *src;
-
-  g_debug ("proto:%s ex:%s oldex:%s exp:%u local:%s localp:%u desc:%s",
-      proto, external_ip, replaces_external_ip, external_port, local_ip,
-      local_port, description);
-
-  src = g_timeout_source_new_seconds (30);
-  g_source_set_callback (src, _remove_port, user_data, NULL);
-  g_source_attach (src, ctx);
-}
-
-
-
-static void
-_error_mapping_external_port (FsUpnpSimpleIgd *igd, GError *error,
-    gchar *proto, guint external_port,
-    gchar *description, gpointer user_data)
-{
-  g_error ("proto:%s port:%u desc:%s error: %s", proto, external_port,
-      description, error->message);
-}
-
-
-static void
-_error (FsUpnpSimpleIgd *igd, GError *error, gpointer user_data)
-{
-  g_error ("error: %s", error->message);
-}
-int
-main (int argc, char **argv)
-{
-
-  if (argc != 5)
-  {
-    g_print ("Usage: %s <external port> <local ip> <local port> <description>\n",
-        argv[0]);
-    return 0;
-  }
-
-  external_port = atoi (argv[1]);
-  internal_port = atoi (argv[3]);
-  g_return_val_if_fail (external_port && internal_port, 1);
-
-  g_type_init ();
-  g_thread_init (NULL);
-
-  ctx = g_main_context_new ();
-  loop = g_main_loop_new (ctx, FALSE);
-
-  igd = fs_upnp_simple_igd_new (ctx);
-
-  g_signal_connect (igd, "mapped-external-port",
-      G_CALLBACK (_mapped_external_port),
-      NULL);
-  g_signal_connect (igd, "error", G_CALLBACK (_error),
-      NULL);
-  g_signal_connect (igd, "error-mapping-port",
-      G_CALLBACK (_error_mapping_external_port),
-      NULL);
-
-  fs_upnp_simple_igd_add_port (igd, "TCP", external_port, argv[2],
-      internal_port, 20, argv[4]);
-
-  g_main_loop_run (loop);
-
-  g_object_unref (igd);
-  g_main_loop_unref (loop);
-  g_main_context_unref (ctx);
-
-  return 0;
-}
diff --git a/tests/upnp/Makefile.am b/tests/upnp/Makefile.am
new file mode 100644
index 0000000..c936067
--- /dev/null
+++ b/tests/upnp/Makefile.am
@@ -0,0 +1,13 @@
+
+noinst_PROGRAMS = test test-thread
+
+
+LDADD = \
+	$(top_builddir)/gst-libs/ext/fsupnp/libfsupnp.la \
+	$(GUPNP_LIBS) 
+
+test_CFLAGS = $(GUPNP_CFLAGS) \
+	-I$(top_srcdir)/gst-libs
+
+test_thread_CFLAGS = $(GUPNP_CFLAGS) \
+	-I$(top_srcdir)/gst-libs
diff --git a/tests/upnp/test-thread.c b/tests/upnp/test-thread.c
new file mode 100644
index 0000000..a97c021
--- /dev/null
+++ b/tests/upnp/test-thread.c
@@ -0,0 +1,85 @@
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include <ext/fsupnp/fs-upnp-simple-igd-thread.h>
+
+static void
+_mapped_external_port (FsUpnpSimpleIgd *igd, gchar *proto,
+    gchar *external_ip, gchar *replaces_external_ip, guint external_port,
+    gchar *local_ip, guint local_port,
+    gchar *description, gpointer user_data)
+{
+  g_debug ("proto:%s ex:%s oldex:%s exp:%u local:%s localp:%u desc:%s",
+      proto, external_ip, replaces_external_ip, external_port, local_ip,
+      local_port, description);
+
+}
+
+
+
+static void
+_error_mapping_external_port (FsUpnpSimpleIgd *igd, GError *error,
+    gchar *proto, guint external_port,
+    gchar *description, gpointer user_data)
+{
+  g_error ("proto:%s port:%u desc:%s error: %s", proto, external_port,
+      description, error->message);
+}
+
+
+static void
+_error (FsUpnpSimpleIgd *igd, GError *error, gpointer user_data)
+{
+  g_error ("error: %s", error->message);
+}
+
+int
+main (int argc, char **argv)
+{
+  FsUpnpSimpleIgdThread *igd = NULL;
+  guint external_port, internal_port;
+
+
+  if (argc != 5)
+  {
+    g_print ("Usage: %s <external port> <local ip> <local port> <description>\n",
+        argv[0]);
+    return 0;
+  }
+
+  external_port = atoi (argv[1]);
+  internal_port = atoi (argv[3]);
+  g_return_val_if_fail (external_port && internal_port, 1);
+
+  g_type_init ();
+  g_thread_init (NULL);
+
+  igd = fs_upnp_simple_igd_thread_new ();
+
+  g_signal_connect (igd, "mapped-external-port",
+      G_CALLBACK (_mapped_external_port),
+      NULL);
+  g_signal_connect (igd, "error", G_CALLBACK (_error),
+      NULL);
+  g_signal_connect (igd, "error-mapping-port",
+      G_CALLBACK (_error_mapping_external_port),
+      NULL);
+
+  fs_upnp_simple_igd_add_port (FS_UPNP_SIMPLE_IGD (igd),
+      "TCP", external_port, argv[2],
+      internal_port, 20, argv[4]);
+
+  sleep (30);
+
+  fs_upnp_simple_igd_remove_port (FS_UPNP_SIMPLE_IGD (igd), "TCP",
+      external_port);
+
+  sleep (5);
+
+  g_object_unref (igd);
+
+  return 0;
+}
diff --git a/tests/upnp/test.c b/tests/upnp/test.c
new file mode 100644
index 0000000..b979631
--- /dev/null
+++ b/tests/upnp/test.c
@@ -0,0 +1,98 @@
+
+#include <stdlib.h>
+
+#include <glib.h>
+
+#include <ext/fsupnp/fs-upnp-simple-igd.h>
+
+GMainContext *ctx = NULL;
+GMainLoop *loop = NULL;
+FsUpnpSimpleIgd *igd = NULL;
+guint external_port, internal_port;
+
+static gboolean
+_remove_port (gpointer user_data)
+{
+  g_debug ("removing port");
+  fs_upnp_simple_igd_remove_port (igd, "TCP", external_port);
+
+  return FALSE;
+}
+
+static void
+_mapped_external_port (FsUpnpSimpleIgd *igd, gchar *proto,
+    gchar *external_ip, gchar *replaces_external_ip, guint external_port,
+    gchar *local_ip, guint local_port,
+    gchar *description, gpointer user_data)
+{
+  GSource *src;
+
+  g_debug ("proto:%s ex:%s oldex:%s exp:%u local:%s localp:%u desc:%s",
+      proto, external_ip, replaces_external_ip, external_port, local_ip,
+      local_port, description);
+
+  src = g_timeout_source_new_seconds (30);
+  g_source_set_callback (src, _remove_port, user_data, NULL);
+  g_source_attach (src, ctx);
+}
+
+
+
+static void
+_error_mapping_external_port (FsUpnpSimpleIgd *igd, GError *error,
+    gchar *proto, guint external_port,
+    gchar *description, gpointer user_data)
+{
+  g_error ("proto:%s port:%u desc:%s error: %s", proto, external_port,
+      description, error->message);
+}
+
+
+static void
+_error (FsUpnpSimpleIgd *igd, GError *error, gpointer user_data)
+{
+  g_error ("error: %s", error->message);
+}
+int
+main (int argc, char **argv)
+{
+
+  if (argc != 5)
+  {
+    g_print ("Usage: %s <external port> <local ip> <local port> <description>\n",
+        argv[0]);
+    return 0;
+  }
+
+  external_port = atoi (argv[1]);
+  internal_port = atoi (argv[3]);
+  g_return_val_if_fail (external_port && internal_port, 1);
+
+  g_type_init ();
+  g_thread_init (NULL);
+
+  ctx = g_main_context_new ();
+  loop = g_main_loop_new (ctx, FALSE);
+
+  igd = fs_upnp_simple_igd_new (ctx);
+
+  g_signal_connect (igd, "mapped-external-port",
+      G_CALLBACK (_mapped_external_port),
+      NULL);
+  g_signal_connect (igd, "error", G_CALLBACK (_error),
+      NULL);
+  g_signal_connect (igd, "error-mapping-port",
+      G_CALLBACK (_error_mapping_external_port),
+      NULL);
+
+  fs_upnp_simple_igd_add_port (igd, "TCP", external_port, argv[2],
+      internal_port, 20, argv[4]);
+
+  g_main_loop_run (loop);
+
+  g_object_unref (igd);
+  g_main_loop_unref (loop);
+  g_main_context_unref (ctx);
+
+  return 0;
+}
-- 
1.5.6.5




More information about the farsight-commits mailing list