[libsoup] http2: use a mock parent stream for SoupBodyInputStreamHttp2 in tests



commit 5c6a3b10707a6ebcbff2cf17324211df53a58f62
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu May 20 17:41:56 2021 +0200

    http2: use a mock parent stream for SoupBodyInputStreamHttp2 in tests
    
    And stop allowing a null parent stream in SoupBodyInputStreamHttp2

 libsoup/http2/soup-body-input-stream-http2.c | 12 ++++--------
 tests/http2-body-stream-test.c               | 12 +++++++++---
 tests/http2-test.c                           |  4 +++-
 3 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/libsoup/http2/soup-body-input-stream-http2.c b/libsoup/http2/soup-body-input-stream-http2.c
index c1ed2249..2c8ea356 100644
--- a/libsoup/http2/soup-body-input-stream-http2.c
+++ b/libsoup/http2/soup-body-input-stream-http2.c
@@ -77,10 +77,11 @@ soup_body_input_stream_http2_new (GPollableInputStream *parent_stream)
         GInputStream *stream;
         SoupBodyInputStreamHttp2Private *priv;
 
+        g_assert (G_IS_POLLABLE_INPUT_STREAM (parent_stream));
+
         stream = g_object_new (SOUP_TYPE_BODY_INPUT_STREAM_HTTP2, NULL);
         priv = soup_body_input_stream_http2_get_instance_private (SOUP_BODY_INPUT_STREAM_HTTP2 (stream));
-        if (parent_stream)
-                priv->parent_stream = g_object_ref (parent_stream);
+        priv->parent_stream = g_object_ref (parent_stream);
 
         return stream;
 }
@@ -440,12 +441,7 @@ soup_body_input_stream_http2_create_source (GPollableInputStream *stream,
        SoupMemoryStreamSource *stream_source = (SoupMemoryStreamSource *)source;
         stream_source->stream = g_object_ref (SOUP_BODY_INPUT_STREAM_HTTP2 (stream));
 
-        GSource *child_source;
-        if (priv->parent_stream)
-                child_source = g_pollable_input_stream_create_source (priv->parent_stream, cancellable);
-        else
-                child_source = g_cancellable_source_new (cancellable);
-
+        GSource *child_source = g_pollable_input_stream_create_source (priv->parent_stream, cancellable);
         g_source_set_dummy_callback (child_source);
         g_source_add_child_source (source, child_source);
         g_source_unref (child_source);
diff --git a/tests/http2-body-stream-test.c b/tests/http2-body-stream-test.c
index f86507f2..e5aa3007 100644
--- a/tests/http2-body-stream-test.c
+++ b/tests/http2-body-stream-test.c
@@ -26,7 +26,8 @@ do_large_data_test (void)
 #define CHUNK_SIZE (gsize)1024 * 1024 * 512 // 512 MiB
 #define TEST_SIZE CHUNK_SIZE * 20 // 10 GiB
 
-        GInputStream *stream = soup_body_input_stream_http2_new (NULL);
+        GInputStream *parent_stream = g_memory_input_stream_new ();
+        GInputStream *stream = soup_body_input_stream_http2_new (G_POLLABLE_INPUT_STREAM (parent_stream));
         SoupBodyInputStreamHttp2 *mem_stream = SOUP_BODY_INPUT_STREAM_HTTP2 (stream);
         gsize data_needed = TEST_SIZE;
         guint8 *memory_chunk = g_new (guint8, CHUNK_SIZE); 
@@ -57,13 +58,15 @@ do_large_data_test (void)
 
         g_free (trash_buffer);
         g_free (memory_chunk);
+        g_object_unref (parent_stream);
         g_object_unref (stream);
 }
 
 static void
 do_multiple_chunk_test (void)
 {
-        GInputStream *stream = soup_body_input_stream_http2_new (NULL);
+        GInputStream *parent_stream = g_memory_input_stream_new ();
+        GInputStream *stream = soup_body_input_stream_http2_new (G_POLLABLE_INPUT_STREAM (parent_stream));
         SoupBodyInputStreamHttp2 *mem_stream = SOUP_BODY_INPUT_STREAM_HTTP2 (stream);
         const char * const chunks[] = {
                 "1234", "5678", "9012", "hell", "owor", "ld..",
@@ -82,6 +85,7 @@ do_multiple_chunk_test (void)
                 g_assert_cmpstr (buffer, ==, chunks[i]);
         }
 
+        g_object_unref (parent_stream);
         g_object_unref (stream);
 }
 
@@ -100,7 +104,8 @@ on_skip_ready (GInputStream *stream, GAsyncResult *res, GMainLoop *loop)
 static void
 do_skip_async_test (void)
 {
-        GInputStream *stream = soup_body_input_stream_http2_new (NULL);
+        GInputStream *parent_stream = g_memory_input_stream_new ();
+        GInputStream *stream = soup_body_input_stream_http2_new (G_POLLABLE_INPUT_STREAM (parent_stream));
         SoupBodyInputStreamHttp2 *bistream = SOUP_BODY_INPUT_STREAM_HTTP2 (stream);
         GMainLoop *loop = g_main_loop_new (NULL, FALSE);
 
@@ -109,6 +114,7 @@ do_skip_async_test (void)
         g_input_stream_skip_async (stream, 2, G_PRIORITY_DEFAULT, NULL, (GAsyncReadyCallback)on_skip_ready, 
loop);
 
         g_main_loop_run (loop);
+        g_object_unref (parent_stream);
         g_object_unref (stream);
         g_main_loop_unref (loop);
 }
diff --git a/tests/http2-test.c b/tests/http2-test.c
index 26d2b5c9..e483b679 100644
--- a/tests/http2-test.c
+++ b/tests/http2-test.c
@@ -292,7 +292,8 @@ do_post_blocked_async_test (Test *test, gconstpointer data)
 {
         GMainContext *async_context = g_main_context_ref_thread_default ();
 
-        GInputStream *in_stream = soup_body_input_stream_http2_new (NULL);
+        GInputStream *parent_stream = g_memory_input_stream_new ();
+        GInputStream *in_stream = soup_body_input_stream_http2_new (G_POLLABLE_INPUT_STREAM (parent_stream));
         soup_body_input_stream_http2_add_data (SOUP_BODY_INPUT_STREAM_HTTP2 (in_stream), (guint8*)"Part 1 
-", 8);
 
         test->msg = soup_message_new (SOUP_METHOD_POST, "https://127.0.0.1:5000/echo_post";);
@@ -317,6 +318,7 @@ do_post_blocked_async_test (Test *test, gconstpointer data)
                 g_main_context_iteration (async_context, FALSE);
 
         g_bytes_unref (response);
+        g_object_unref (parent_stream);
         g_object_unref (in_stream);
         g_main_context_unref (async_context);
         g_object_unref (test->msg);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]