[farsight2/master] Add stun alternate-server tests
Olivier Crête
olivier.crete at collabora.co.uk
Tue Apr 7 17:29:04 PDT 2009
---
tests/check/transmitter/generic.c | 60 ++++++++++++++++++++++++++
tests/check/transmitter/generic.h | 7 +++
tests/check/transmitter/rawudp.c | 84 +++++++++++++++++++++++++++++++++++++
3 files changed, 151 insertions(+), 0 deletions(-)
diff --git a/tests/check/transmitter/generic.c b/tests/check/transmitter/generic.c
index 9029204..f20aa55 100644
--- a/tests/check/transmitter/generic.c
+++ b/tests/check/transmitter/generic.c
@@ -241,3 +241,63 @@ teardown_stund (void)
g_spawn_close_pid (stund_pid);
stund_pid = 0;
}
+
+
+GPid stunalternd_pid = 0;
+
+static void
+setup_stunalternd_internal (gchar *argv[])
+{
+ GError *error = NULL;
+
+ stunalternd_pid = 0;
+
+ if (!g_spawn_async (NULL, argv, NULL,
+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+ NULL, NULL, &stunalternd_pid, &error))
+ {
+ g_debug ("Could not spawn stunalternd, skipping stun testing: %s",
+ error->message);
+ g_clear_error (&error);
+ return;
+ }
+}
+
+void
+setup_stunalternd_valid (void)
+{
+ gchar *argv[] = {"stunalternd", "127.0.0.1", "3478", "3480", NULL};
+ setup_stunalternd_internal (argv);
+}
+
+void
+setup_stunalternd_loop (void)
+{
+ gchar *argv[] = {"stunalternd", "127.0.0.1", "3480", "3480", NULL};
+ setup_stunalternd_internal (argv);
+}
+
+void
+teardown_stunalternd (void)
+{
+ if (!stunalternd_pid)
+ return;
+
+ kill (stunalternd_pid, SIGTERM);
+ waitpid (stunalternd_pid, NULL, 0);
+ g_spawn_close_pid (stunalternd_pid);
+ stunalternd_pid = 0;
+}
+
+void setup_stund_stunalternd (void)
+{
+ setup_stund ();
+ setup_stunalternd_valid ();
+}
+
+
+void teardown_stund_stunalternd (void)
+{
+ teardown_stund ();
+ teardown_stunalternd ();
+}
diff --git a/tests/check/transmitter/generic.h b/tests/check/transmitter/generic.h
index be0612a..642a2c4 100644
--- a/tests/check/transmitter/generic.h
+++ b/tests/check/transmitter/generic.h
@@ -39,9 +39,16 @@ gboolean bus_error_callback (GstBus *bus, GstMessage *message,
void test_transmitter_creation (gchar *transmitter_name);
extern GPid stund_pid;
+extern GPid stunalternd_pid;
void setup_stund (void);
void teardown_stund (void);
+void setup_stunalternd_valid (void);
+void setup_stunalternd_loop (void);
+void teardown_stunalternd (void);
+
+void setup_stund_stunalternd (void);
+void teardown_stund_stunalternd (void);
#endif /* __GENERIC_H__ */
diff --git a/tests/check/transmitter/rawudp.c b/tests/check/transmitter/rawudp.c
index 071faee..ea60015 100644
--- a/tests/check/transmitter/rawudp.c
+++ b/tests/check/transmitter/rawudp.c
@@ -804,6 +804,69 @@ GST_START_TEST (test_rawudptransmitter_sending_half)
}
GST_END_TEST;
+
+GST_START_TEST (test_rawudptransmitter_run_stunalternd)
+{
+ GParameter params[4];
+
+ if (stund_pid <= 0 || stunalternd_pid <= 0)
+ return;
+
+ memset (params, 0, sizeof (GParameter) * 4);
+
+ params[0].name = "stun-ip";
+ g_value_init (¶ms[0].value, G_TYPE_STRING);
+ g_value_set_static_string (¶ms[0].value, "127.0.0.1");
+
+ params[1].name = "stun-port";
+ g_value_init (¶ms[1].value, G_TYPE_UINT);
+ g_value_set_uint (¶ms[1].value, 3480);
+
+ params[2].name = "stun-timeout";
+ g_value_init (¶ms[2].value, G_TYPE_UINT);
+ g_value_set_uint (¶ms[2].value, 5);
+
+ params[3].name = "upnp-discovery";
+ g_value_init (¶ms[3].value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (¶ms[3].value, FALSE);
+
+
+ run_rawudp_transmitter_test (3, params, FLAG_HAS_STUN);
+}
+GST_END_TEST;
+
+
+GST_START_TEST (test_rawudptransmitter_run_stun_altern_to_nowhere)
+{
+ GParameter params[3];
+
+ if (stunalternd_pid <= 0)
+ return;
+
+ /*
+ * Hopefully not one is runing a stun server on local port 3478
+ */
+
+ memset (params, 0, sizeof (GParameter) * 3);
+
+ params[0].name = "stun-ip";
+ g_value_init (¶ms[0].value, G_TYPE_STRING);
+ g_value_set_static_string (¶ms[0].value, "127.0.0.1");
+
+ params[1].name = "stun-port";
+ g_value_init (¶ms[1].value, G_TYPE_UINT);
+ g_value_set_uint (¶ms[1].value, 3480);
+
+ params[2].name = "stun-timeout";
+ g_value_init (¶ms[2].value, G_TYPE_UINT);
+ g_value_set_uint (¶ms[2].value, 10);
+
+ run_rawudp_transmitter_test (3, params, 0);
+
+}
+GST_END_TEST;
+
+
static Suite *
rawudptransmitter_suite (void)
{
@@ -869,6 +932,27 @@ rawudptransmitter_suite (void)
tcase_add_test (tc_chain, test_rawudptransmitter_sending_half);
suite_add_tcase (s, tc_chain);
+ tc_chain = tcase_create ("rawudptransmitter-stunalternd");
+ tcase_set_timeout (tc_chain, 5);
+ tcase_add_checked_fixture (tc_chain, setup_stund_stunalternd,
+ teardown_stund_stunalternd);
+ tcase_add_test (tc_chain, test_rawudptransmitter_run_stunalternd);
+ suite_add_tcase (s, tc_chain);
+
+ tc_chain = tcase_create ("rawudptransmitter-stunalternd-to-nowhere");
+ tcase_set_timeout (tc_chain, 12);
+ tcase_add_checked_fixture (tc_chain, setup_stunalternd_valid,
+ teardown_stunalternd);
+ tcase_add_test (tc_chain, test_rawudptransmitter_run_stun_altern_to_nowhere);
+ suite_add_tcase (s, tc_chain);
+
+ tc_chain = tcase_create ("rawudptransmitter-stunalternd-loop");
+ tcase_set_timeout (tc_chain, 12);
+ tcase_add_checked_fixture (tc_chain, setup_stunalternd_loop,
+ teardown_stunalternd);
+ tcase_add_test (tc_chain, test_rawudptransmitter_run_stun_altern_to_nowhere);
+ suite_add_tcase (s, tc_chain);
+
return s;
}
--
1.5.6.5
More information about the farsight-commits
mailing list