[gupnp/wip/context-manager-tests: 3/3] wip: Test common context manager functionality
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp/wip/context-manager-tests: 3/3] wip: Test common context manager functionality
- Date: Tue, 14 Jun 2022 20:57:14 +0000 (UTC)
commit cd9f4e87b5154061ad45c0924709d6c39956b606
Author: Jens Georg <mail jensge org>
Date: Tue Jun 14 22:56:28 2022 +0200
wip: Test common context manager functionality
tests/meson.build | 2 +-
tests/test-context-manager.c | 133 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 134 insertions(+), 1 deletion(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index 3e656d2..701f901 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,4 +1,4 @@
-foreach program : ['context', 'bugs', 'service', 'acl', 'service-proxy', 'context-filter']
+foreach program : ['context', 'bugs', 'service', 'acl', 'service-proxy', 'context-filter', 'context-manager']
test(
program,
executable(
diff --git a/tests/test-context-manager.c b/tests/test-context-manager.c
new file mode 100644
index 0000000..3bc987e
--- /dev/null
+++ b/tests/test-context-manager.c
@@ -0,0 +1,133 @@
+#include <config.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "libgupnp/gupnp-context-manager.h"
+
+#define TEST_CONTEXT_MANAGER (test_context_manager_get_type ())
+
+struct _TestContextManager {
+ GUPnPContextManager parent;
+};
+typedef struct _TestContextManager TestContextManager;
+
+struct _TestContextManagerClass {
+ GUPnPContextManagerClass parent_class;
+};
+typedef struct _TestContextManagerClass TestContextManagerClass;
+
+G_DEFINE_TYPE (TestContextManager,
+ test_context_manager,
+ GUPNP_TYPE_CONTEXT_MANAGER)
+static void
+test_context_manager_class_init (TestContextManagerClass *klass)
+{
+}
+static void
+test_context_manager_init (TestContextManager *self)
+{
+}
+
+void
+test_context_manager_manage ()
+{
+ GError *error = NULL;
+
+ GUPnPContext *ctx = gupnp_context_new ("lo", 0, &error);
+ g_assert_null (error);
+
+ GUPnPControlPoint *cp =
+ gupnp_control_point_new (ctx, "upnp::rootdevice");
+ gpointer weak = cp;
+
+ g_object_add_weak_pointer (G_OBJECT (cp), &weak);
+
+ TestContextManager *cm =
+ g_object_new (test_context_manager_get_type (), NULL);
+
+ gupnp_context_manager_manage_control_point (GUPNP_CONTEXT_MANAGER (cm),
+ cp);
+ g_object_unref (cp);
+
+ // Check that the context manager has kept a reference on cp
+ g_assert_nonnull (weak);
+
+ g_signal_emit_by_name (cm, "context-unavailable", ctx, NULL);
+
+ // Check that the context manager dropped the reference if the
+ // context is gone
+ g_assert_null (weak);
+
+ GUPnPRootDevice *rd = gupnp_root_device_new (ctx,
+ "TestDevice.xml",
+ DATA_PATH,
+ &error);
+
+ weak = rd;
+ g_object_add_weak_pointer (G_OBJECT (rd), &weak);
+ gupnp_context_manager_manage_root_device (GUPNP_CONTEXT_MANAGER (cm),
+ rd);
+ g_object_unref (rd);
+
+ // Check that the context manager has kept a reference on cp
+ g_assert_nonnull (weak);
+
+ g_signal_emit_by_name (cm, "context-unavailable", ctx, NULL);
+
+ // Check that the context manager dropped the reference if the
+ // context is gone
+ g_assert_null (weak);
+
+ g_object_unref (cm);
+ g_object_unref (ctx);
+}
+
+
+
+void
+test_context_manager_filter_enable_disable ()
+{
+ GError *error = NULL;
+
+ GUPnPContext *ctx = g_initable_new (GUPNP_TYPE_CONTEXT,
+ NULL,
+ &error,
+ "host-ip",
+ "127.0.0.1",
+
+ "network",
+ "Free WiFi!",
+
+ "active",
+ FALSE,
+ NULL);
+
+ TestContextManager *cm =
+ g_object_new (test_context_manager_get_type (), NULL);
+
+ g_signal_connect (cm, "context-available", on_)
+
+ const char *iface = gssdp_client_get_interface (GSSDP_CLIENT (ctx));
+
+ g_assert_no_error (error);
+ g_assert_nonnull (ctx);
+
+ g_signal_emit_by_name ()
+
+ g_clear_object (&ctx);
+ g_clear_error (&error);
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/context-manager/manage",
+ test_context_manager_manage);
+ g_test_add_func ("/context_manager/filter/enable_disable",
+ test_context_manager_filter_enable_disable);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]