From 23ae8c0d515dd3346ca0e1fb2dc268adf602bb93 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Mon, 4 May 2020 18:04:53 +0300
Subject: [PATCH] tests/si-softdsp-endpoint: add tests for streams

---
 tests/modules/si-audio-softdsp-endpoint.c | 68 ++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 2 deletions(-)

diff --git a/tests/modules/si-audio-softdsp-endpoint.c b/tests/modules/si-audio-softdsp-endpoint.c
index 50f1d332..47037fed 100644
--- a/tests/modules/si-audio-softdsp-endpoint.c
+++ b/tests/modules/si-audio-softdsp-endpoint.c
@@ -64,6 +64,7 @@ static void
 test_si_audio_softdsp_endpoint_configure_activate (TestFixture * f,
     gconstpointer user_data)
 {
+  guint requested_streams = GPOINTER_TO_UINT (user_data);
   g_autoptr (WpNode) node = NULL;
   g_autoptr (WpSessionItem) adapter = NULL;
   g_autoptr (WpSessionItem) endpoint = NULL;
@@ -143,6 +144,29 @@ test_si_audio_softdsp_endpoint_configure_activate (TestFixture * f,
     g_assert_cmpuint (adapter_i, ==, (guint64) adapter);
   }
 
+  if (requested_streams > 1) {
+    for (guint i = 0; i < requested_streams; i++) {
+      g_autoptr (WpSessionItem) stream =
+          wp_session_item_make (f->base.core, "si-convert");
+      g_assert_nonnull (stream);
+      g_assert_true (WP_IS_SI_STREAM (stream));
+
+      {
+        g_auto (GVariantBuilder) b =
+            G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
+        g_variant_builder_add (&b, "{sv}", "target",
+            g_variant_new_uint64 ((guint64) adapter));
+        g_variant_builder_add (&b, "{sv}", "name",
+            g_variant_new_printf ("stream-%u", i));
+        g_assert_true (
+            wp_session_item_configure (stream, g_variant_builder_end (&b)));
+      }
+
+      g_assert_true (wp_session_bin_add (WP_SESSION_BIN (endpoint),
+              g_steal_pointer (&stream)));
+    }
+  }
+
   /* activate audio softdsp endpoint */
   {
     wp_session_item_activate (endpoint,
@@ -154,6 +178,35 @@ test_si_audio_softdsp_endpoint_configure_activate (TestFixture * f,
       WP_SI_FLAG_CONFIGURED | WP_SI_FLAG_ACTIVE);
   g_assert_cmphex (wp_session_item_get_flags (adapter), ==,
       WP_SI_FLAG_CONFIGURED | WP_SI_FLAG_ACTIVE);
+  g_assert_cmphex (wp_proxy_get_features (WP_PROXY (node)), ==,
+      WP_NODE_FEATURES_STANDARD);
+
+  /* check streams */
+
+  g_assert_cmpuint (wp_si_endpoint_get_n_streams (WP_SI_ENDPOINT (endpoint)),
+      ==, requested_streams);
+  if (requested_streams == 1) {
+    WpSiStream *stream =
+        wp_si_endpoint_get_stream (WP_SI_ENDPOINT (endpoint), 0);
+    g_autoptr (GVariant) info = wp_si_stream_get_registration_info (stream);
+    const gchar *stream_name;
+
+    g_variant_get (info, "(&sa{ss})", &stream_name, NULL);
+    g_assert_cmpstr (stream_name, ==, "default");
+    g_assert_true ((gpointer) stream == (gpointer) adapter);
+  } else {
+    for (guint i = 0; i < requested_streams; i++) {
+      WpSiStream *stream =
+          wp_si_endpoint_get_stream (WP_SI_ENDPOINT (endpoint), i);
+      g_autoptr (GVariant) info = wp_si_stream_get_registration_info (stream);
+      g_autofree gchar *expected_name = g_strdup_printf ("stream-%u", i);
+      const gchar *stream_name;
+
+      g_variant_get (info, "(&sa{ss})", &stream_name, NULL);
+      g_assert_cmpstr (stream_name, ==, expected_name);
+      g_assert_true ((gpointer) stream != (gpointer) adapter);
+    }
+  }
 
   /* deactivate - configuration should not be altered  */
 
@@ -258,6 +311,11 @@ test_si_audio_softdsp_endpoint_export (TestFixture * f, gconstpointer user_data)
       (GAsyncReadyCallback) test_si_export_finish_cb, f);
   g_main_loop_run (f->base.loop);
 
+  g_assert_cmphex (wp_session_item_get_flags (item), ==,
+      WP_SI_FLAG_CONFIGURED | WP_SI_FLAG_ACTIVE | WP_SI_FLAG_EXPORTED);
+  g_assert_cmphex (wp_session_item_get_flags (adapter), ==,
+      WP_SI_FLAG_CONFIGURED | WP_SI_FLAG_ACTIVE);
+
   {
     g_autoptr (WpEndpoint) ep = NULL;
     g_autoptr (WpProperties) props = NULL;
@@ -299,8 +357,14 @@ main (gint argc, gchar *argv[])
 
   /* configure-activate */
 
-  g_test_add ("/modules/si-audio-softdsp-endpoint/configure-activate",
-      TestFixture, NULL,
+  g_test_add ("/modules/si-audio-softdsp-endpoint/configure-activate/single-stream",
+      TestFixture, GUINT_TO_POINTER (1),
+      test_si_audio_softdsp_endpoint_setup,
+      test_si_audio_softdsp_endpoint_configure_activate,
+      test_si_audio_softdsp_endpoint_teardown);
+
+  g_test_add ("/modules/si-audio-softdsp-endpoint/configure-activate/multi-stream",
+      TestFixture, GUINT_TO_POINTER (5),
       test_si_audio_softdsp_endpoint_setup,
       test_si_audio_softdsp_endpoint_configure_activate,
       test_si_audio_softdsp_endpoint_teardown);
-- 
GitLab