From: Florin Apostol Date: Tue, 20 Oct 2015 16:21:00 +0000 (+0100) Subject: adaptivedemux: tests: added test for fragment download error X-Git-Tag: 1.19.3~507^2~7689 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77f4776acb919391e7b3e3c2c57ebe7817bfe535;p=platform%2Fupstream%2Fgstreamer.git adaptivedemux: tests: added test for fragment download error https://bugzilla.gnome.org/show_bug.cgi?id=757361 --- diff --git a/tests/check/elements/dash_demux.c b/tests/check/elements/dash_demux.c index 60e0fa1..b83e2f2 100644 --- a/tests/check/elements/dash_demux.c +++ b/tests/check/elements/dash_demux.c @@ -1284,6 +1284,112 @@ GST_START_TEST (testDownloadError) GST_END_TEST; +/* generate error message on adaptive demux pipeline */ +static gboolean +testFragmentDownloadErrorCheckDataReceived (GstDashDemuxTestData * testData, + GstDashDemuxTestOutputStreamData * testOutputStreamData, GstBuffer * buffer) +{ + checkDataReceived (testData, testOutputStreamData, buffer); + + if (testOutputStreamData->scratchData->segmentReceivedSize > 2000) { + GstPad *fakeHttpSrcPad; + GstObject *fakeHttpSrcElement; + + /* tell fake soup http src to post an error on the adaptive demux bus */ + fakeHttpSrcPad = + gst_pad_get_peer (testOutputStreamData->scratchData->internalPad); + fakeHttpSrcElement = gst_pad_get_parent (fakeHttpSrcPad); + + gst_fake_soup_http_src_simulate_download_error ((GstFakeSoupHTTPSrc *) + fakeHttpSrcElement, 404); + + gst_object_unref (fakeHttpSrcPad); + gst_object_unref (fakeHttpSrcElement); + + testData->expectError = TRUE; + } + + return TRUE; +} + +/* function to check total size of data received by AppSink + * will be called when AppSink receives eos. + */ +static gboolean +testFragmentDownloadErrorCheckSizeOfDataReceived (GstDashDemuxTestData * + testData, GstDashDemuxTestOutputStreamData * testOutputStreamData) +{ + /* expect to receive more than 0 */ + fail_unless (testOutputStreamData->scratchData->totalReceivedSize > 0, + "size validation failed for %s, expected > 0, received %d", + testOutputStreamData->name, + testOutputStreamData->scratchData->totalReceivedSize); + + /* expect to receive less than file size */ + fail_unless (testOutputStreamData->scratchData->totalReceivedSize < + testOutputStreamData->expectedSize, + "size validation failed for %s, expected < %d received %d", + testOutputStreamData->name, testOutputStreamData->expectedSize, + testOutputStreamData->scratchData->totalReceivedSize); + + return TRUE; +} + +/* + * Test fragment download error + * Let the adaptive demux download a few bytes, then instruct the fake soup http + * src element to generate an error. + */ +GST_START_TEST (testFragmentDownloadError) +{ + const gchar *mpd = + "" + "" + " " + " " + " " + " " + " audio.webm" + " " + " " + " " + " "; + + const GstFakeHttpSrcInputData inputTestData[] = { + {"http://unit.test/test.mpd", mpd, 0}, + {"http://unit.test/audio.webm", NULL, 5000}, + {NULL, NULL, 0}, + }; + + GstDashDemuxTestOutputStreamData outputTestData[] = { + {"audio_00", 5000, NULL}, + }; + + Callbacks cb = { 0 }; + cb.appSinkGotDataCallback = testFragmentDownloadErrorCheckDataReceived; + cb.appSinkGotEosCallback = testFragmentDownloadErrorCheckSizeOfDataReceived; + + runTest (inputTestData, outputTestData, + sizeof (outputTestData) / sizeof (outputTestData[0]), &cb); +} + +GST_END_TEST; + /* generate queries to adaptive demux */ static gboolean testQueryCheckDataReceived (GstDashDemuxTestData * testData, @@ -1408,6 +1514,7 @@ dash_demux_suite (void) tcase_add_test (tc_basicTest, testParameters); tcase_add_test (tc_basicTest, testSeek); tcase_add_test (tc_basicTest, testDownloadError); + tcase_add_test (tc_basicTest, testFragmentDownloadError); tcase_add_test (tc_basicTest, testQuery); tcase_add_unchecked_fixture (tc_basicTest, test_setup, test_teardown); diff --git a/tests/check/elements/fake_http_src.c b/tests/check/elements/fake_http_src.c index b45ef48..b9c2a54 100644 --- a/tests/check/elements/fake_http_src.c +++ b/tests/check/elements/fake_http_src.c @@ -55,6 +55,9 @@ typedef struct _GstFakeSoupHTTPSrc guint64 position; /* index immediately after the last byte from the segment to be retrieved */ guint64 segment_end; + + /* download error code to simulate during create function */ + guint downloadErrorCode; } GstFakeSoupHTTPSrc; typedef struct _GstFakeSoupHTTPSrcClass @@ -138,6 +141,7 @@ gst_fake_soup_http_src_init (GstFakeSoupHTTPSrc * src) src->position = 0; src->size = 0; src->segment_end = 0; + src->downloadErrorCode = 0; gst_base_src_set_blocksize (GST_BASE_SRC (src), GST_FAKE_SOUP_HTTP_SRC_MAX_BUF_SIZE); } @@ -163,7 +167,8 @@ gst_fake_soup_http_src_start (GstBaseSrc * basesrc) src = GST_FAKE_SOUP_HTTP_SRC (basesrc); if (!src->uri) { - GST_WARNING ("gst_fake_soup_http_src_start without location"); + GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (("No URL set.")), + ("Missing location property")); return FALSE; } @@ -176,6 +181,7 @@ gst_fake_soup_http_src_start (GstBaseSrc * basesrc) else src->size = input[i].size; src->segment_end = src->size; + src->downloadErrorCode = 0; gst_base_src_set_dynamic_size (basesrc, FALSE); return TRUE; } @@ -295,6 +301,13 @@ gst_fake_soup_http_src_create (GstBaseSrc * basesrc, guint64 offset, GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM); return GST_FLOW_ERROR; } + if (src->downloadErrorCode) { + GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, ("%s", + "Generated requested error"), ("%s (%d), URL: %s, Redirect to: %s", + "Generated requested error", src->downloadErrorCode, src->uri, + GST_STR_NULL (NULL))); + return GST_FLOW_ERROR; + } bytes_read = MIN ((src->segment_end - src->position), GST_FAKE_SOUP_HTTP_SRC_MAX_BUF_SIZE); @@ -431,3 +444,10 @@ gst_fake_soup_http_src_set_input_data (const GstFakeHttpSrcInputData * input) { gst_fake_soup_http_src_inputData = input; } + +void +gst_fake_soup_http_src_simulate_download_error (GstFakeSoupHTTPSrc * + fakeSoupHTTPSrc, guint downloadErrorCode) +{ + fakeSoupHTTPSrc->downloadErrorCode = downloadErrorCode; +} diff --git a/tests/check/elements/fake_http_src.h b/tests/check/elements/fake_http_src.h index 5ddbfa0..abcaa16 100644 --- a/tests/check/elements/fake_http_src.h +++ b/tests/check/elements/fake_http_src.h @@ -43,6 +43,8 @@ typedef struct _GstFakeHttpSrcInputData guint64 size; } GstFakeHttpSrcInputData; +typedef struct _GstFakeSoupHTTPSrc GstFakeSoupHTTPSrc; + /* GstFakeSoupHTTPSrc will send buffers up to this size */ #define GST_FAKE_SOUP_HTTP_SRC_MAX_BUF_SIZE (1024) @@ -51,3 +53,9 @@ GType gst_fake_soup_http_src_get_type (void); gboolean gst_fake_soup_http_src_register_plugin (GstRegistry * registry, const gchar * name); void gst_fake_soup_http_src_set_input_data (const GstFakeHttpSrcInputData *input); + +/* TODO: use SoupKnownStatusCode. But it requires makefile support to include + * + */ +void gst_fake_soup_http_src_simulate_download_error ( + GstFakeSoupHTTPSrc *fakeSoupHTTPSrc, guint downloadErrorCode);