X-Git-Url: http://git.maemo.org/git/?p=mafwsubrenderer;a=blobdiff_plain;f=qmafw-gst-subtitles-renderer%2Funittests%2Fut_GstScreenshot%2Fut_GstScreenshot.cpp;fp=qmafw-gst-subtitles-renderer%2Funittests%2Fut_GstScreenshot%2Fut_GstScreenshot.cpp;h=9bf94a4a8a548031dffd1ad746e916cbfd25eda1;hp=0000000000000000000000000000000000000000;hb=226d35244df85a27c332d3a3ded1b25b3c7f4951;hpb=57ba96e291a055f69dbfd4ae9f1ae2390e36986e diff --git a/qmafw-gst-subtitles-renderer/unittests/ut_GstScreenshot/ut_GstScreenshot.cpp b/qmafw-gst-subtitles-renderer/unittests/ut_GstScreenshot/ut_GstScreenshot.cpp new file mode 100644 index 0000000..9bf94a4 --- /dev/null +++ b/qmafw-gst-subtitles-renderer/unittests/ut_GstScreenshot/ut_GstScreenshot.cpp @@ -0,0 +1,209 @@ +/* + * This file is part of QMAFW + * + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights + * reserved. + * + * Contact: Visa Smolander + * + * This software, including documentation, is protected by copyright controlled + * by Nokia Corporation. All rights are reserved. Copying, including + * reproducing, storing, adapting or translating, any or all of this material + * requires the prior written consent of Nokia Corporation. This material also + * contains confidential information which may not be disclosed to others + * without the prior written consent of Nokia. + * + */ + +#include + +#include +#include +#include + +#include "MafwGstScreenshot.h" +#include "ut_GstScreenshot.h" + +static gchar *global_failing_gst_element = NULL; + +/* START OF STUB DEFINITIONS */ +GstElement *gst_element_factory_make(const gchar *factoryname, const gchar *name) +{ + + GstElementFactory *factory; + + qDebug() << __PRETTY_FUNCTION__ << factoryname; + + if (global_failing_gst_element != NULL && + g_str_equal(factoryname, global_failing_gst_element)) + { + qDebug() << "SIMULATED FAIL OF gst_element_factory_make()"; + return NULL; + } + else + { + factory = gst_element_factory_find(factoryname); + return gst_element_factory_create(factory, name); + } + +} +/* END OF STUB DEFINITIONS */ + +void ut_GstScreenshot::testFailures() +{ + gint width = 1024; + gint height = 1024; + gint size = width * height + width * height / 2; + GstBuffer *buf = gst_buffer_new_and_alloc(size); + QCOMPARE(GST_OBJECT_REFCOUNT_VALUE(buf), 1); + + memset(GST_BUFFER_DATA(buf), 0, size); + + /* no caps set, returns false */ + QVERIFY(m_screenshot->savePauseFrame(buf, + "/dev/null") == FALSE); + + buf = gst_buffer_new_and_alloc(size); + memset(GST_BUFFER_DATA(buf), 0, size); + + GstCaps *caps; + caps = gst_caps_new_simple("video/x-raw-yuv", + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I','4','2','0'), + "framerate", GST_TYPE_FRACTION, 25, 1, + "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, + NULL); + gst_buffer_set_caps(buf, caps); + + /* fakesrc creation fails, returns false */ + global_failing_gst_element = g_strdup("fakesrc"); + QVERIFY(m_screenshot->savePauseFrame(buf, + "/dev/null") == FALSE); + + gst_caps_unref(caps); + + /* TODO: Gst pipeline errors are difficult to test... */ +} + +void ut_GstScreenshot::testConvert() +{ + gint width = 1024; + gint height = 512; + gint size = width * height + width * height / 2; + GstBuffer *buf = gst_buffer_new_and_alloc(size); + memset(GST_BUFFER_DATA(buf), 0, size); + + /* set caps, returns true */ + GstCaps *caps; + caps = gst_caps_new_simple("video/x-raw-yuv", + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I','4','2','0'), + "framerate", GST_TYPE_FRACTION, 25, 1, + "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, + NULL); + gst_buffer_set_caps(buf, caps); + QVERIFY(m_screenshot->savePauseFrame(buf, + "/dev/null") == TRUE); + + QTest::qWait(500); + QVERIFY(m_gotScreenshotSignal == TRUE); + + gst_caps_unref(caps); +} + + +void ut_GstScreenshot::testCancel() +{ + gint width = 1024; + gint height = 512; + gint size = width * height + width * height / 2; + GstBuffer *buf = gst_buffer_new_and_alloc(size); + memset(GST_BUFFER_DATA(buf), 0, size); + + QFETCH(uint, timeout); + + /* set caps, returns true */ + GstCaps *caps; + caps = gst_caps_new_simple("video/x-raw-yuv", + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I','4','2','0'), + "framerate", GST_TYPE_FRACTION, 25, 1, + "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, + NULL); + gst_buffer_set_caps(buf, caps); + + QVERIFY(m_screenshot->savePauseFrame(buf, + "/dev/null") == TRUE); + QTest::qWait(timeout); + if (m_gotScreenshotSignal == false ) + { + m_screenshot->cancelPauseFrame(); + QVERIFY(m_gotCancelSignal == TRUE); + } +} + +void ut_GstScreenshot::testCancel_data() +{ + QTest::addColumn("timeout"); + QTest::newRow("0 ms") << (uint)0; + QTest::newRow("1 ms") << (uint)1; + QTest::newRow("5 ms") << (uint)5; + QTest::newRow("10 ms") << (uint)10; + QTest::newRow("20 ms") << (uint)20; + QTest::newRow("35 ms") << (uint)35; + QTest::newRow("50 ms") << (uint)50; + QTest::newRow("100 ms") << (uint)100; +} + +void ut_GstScreenshot::slotScreenshot(char *location, GError *error) +{ + qDebug() << __PRETTY_FUNCTION__; + Q_UNUSED(location); + Q_UNUSED(error); + m_gotScreenshotSignal = TRUE; +} + +void ut_GstScreenshot::slotCancelScreenshot() +{ + qDebug() << __PRETTY_FUNCTION__; + + m_gotCancelSignal = TRUE; +} + +void ut_GstScreenshot::init() +{ + + qDebug() << __PRETTY_FUNCTION__; + + gst_init(0, 0); + + m_gotScreenshotSignal = FALSE; + m_gotCancelSignal = FALSE; + + m_screenshot = new MafwGstScreenshot(this); + connect(m_screenshot, SIGNAL(screenshotTaken(char*,GError*)), this, SLOT(slotScreenshot(char*,GError*))); + connect(m_screenshot, SIGNAL(screenshotCancelled()), this, SLOT(slotCancelScreenshot())); + + global_failing_gst_element = NULL; + +} + +void ut_GstScreenshot::cleanup() +{ + + qDebug() << __PRETTY_FUNCTION__; + g_free(global_failing_gst_element); + + while(QCoreApplication::hasPendingEvents()) + { + QCoreApplication::sendPostedEvents(); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::processEvents(); + } + delete m_screenshot; +} + +QTEST_MAIN(ut_GstScreenshot)