summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2016-08-22 12:02:44 +0200
committerOndrej Holy <oholy@redhat.com>2016-08-23 08:37:13 +0200
commit4b29a94a71317ffa9df282fef7f7be126687343a (patch)
treea686b7f2968d794fd134ad9cfe0f4658aea65cf6
parent76e12748bd0e519caeeefd6e1ac7ce8086e63059 (diff)
downloadlibgdata-4b29a94a71317ffa9df282fef7f7be126687343a.tar.gz
tests: Add one more test for GDataBuffer
This test reproduces bug 769727. https://bugzilla.gnome.org/show_bug.cgi?id=769727
-rw-r--r--gdata/tests/buffer.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gdata/tests/buffer.c b/gdata/tests/buffer.c
index 02012d6c..c4e9d133 100644
--- a/gdata/tests/buffer.c
+++ b/gdata/tests/buffer.c
@@ -74,6 +74,41 @@ test_buffer_instant_eof (Fixture *f, gconstpointer user_data)
gdata_buffer_free (buffer);
}
+static gpointer
+test_buffer_thread_eof_func (gpointer user_data)
+{
+ GDataBuffer *buffer = user_data;
+
+ /* HACK: Wait for a while to be sure that gdata_buffer_pop_data() has
+ * been already called. */
+ g_usleep (G_USEC_PER_SEC / 2);
+
+ g_assert_false (gdata_buffer_push_data (buffer, NULL, 0));
+
+ return NULL;
+}
+
+/* The test needs to call gdata_buffer_push_data() from another thread only
+ * once gdata_buffer_pop_data() has reached its blocking loop. */
+static void
+test_buffer_thread_eof (Fixture *f, gconstpointer user_data)
+{
+ GDataBuffer *buffer = NULL; /* owned */
+ gboolean reached_eof = FALSE;
+ guint8 buf[1];
+
+ g_test_bug ("769727");
+
+ buffer = gdata_buffer_new ();
+
+ g_thread_new (NULL, test_buffer_thread_eof_func, buffer);
+ g_assert_cmpuint (gdata_buffer_pop_data (buffer, buf, sizeof (buf),
+ &reached_eof, NULL), ==, 0);
+ g_assert_true (reached_eof);
+
+ gdata_buffer_free (buffer);
+}
+
static void
test_buffer_basic (Fixture *f, gconstpointer user_data)
{
@@ -121,6 +156,8 @@ main (int argc, char *argv[])
set_up, test_buffer_construction, tear_down);
g_test_add ("/buffer/instant-eof", Fixture, NULL,
set_up, test_buffer_instant_eof, tear_down);
+ g_test_add ("/buffer/thread-eof", Fixture, NULL,
+ set_up, test_buffer_thread_eof, tear_down);
g_test_add ("/buffer/basic", Fixture, NULL,
set_up, test_buffer_basic, tear_down);