2 * This file is part of QMAFW
4 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
7 * Contact: Visa Smolander <visa.smolander@nokia.com>
9 * This software, including documentation, is protected by copyright controlled
10 * by Nokia Corporation. All rights are reserved. Copying, including
11 * reproducing, storing, adapting or translating, any or all of this material
12 * requires the prior written consent of Nokia Corporation. This material also
13 * contains confidential information which may not be disclosed to others
14 * without the prior written consent of Nokia.
24 #include "MafwGstScreenshot.h"
25 #include "ut_GstScreenshot.h"
27 static gchar *global_failing_gst_element = NULL;
29 /* START OF STUB DEFINITIONS */
30 GstElement *gst_element_factory_make(const gchar *factoryname, const gchar *name)
33 GstElementFactory *factory;
35 qDebug() << __PRETTY_FUNCTION__ << factoryname;
37 if (global_failing_gst_element != NULL &&
38 g_str_equal(factoryname, global_failing_gst_element))
40 qDebug() << "SIMULATED FAIL OF gst_element_factory_make()";
45 factory = gst_element_factory_find(factoryname);
46 return gst_element_factory_create(factory, name);
50 /* END OF STUB DEFINITIONS */
52 void ut_GstScreenshot::testFailures()
56 gint size = width * height + width * height / 2;
57 GstBuffer *buf = gst_buffer_new_and_alloc(size);
58 QCOMPARE(GST_OBJECT_REFCOUNT_VALUE(buf), 1);
60 memset(GST_BUFFER_DATA(buf), 0, size);
62 /* no caps set, returns false */
63 QVERIFY(m_screenshot->savePauseFrame(buf,
64 "/dev/null") == FALSE);
66 buf = gst_buffer_new_and_alloc(size);
67 memset(GST_BUFFER_DATA(buf), 0, size);
70 caps = gst_caps_new_simple("video/x-raw-yuv",
71 "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I','4','2','0'),
72 "framerate", GST_TYPE_FRACTION, 25, 1,
73 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
74 "width", G_TYPE_INT, width,
75 "height", G_TYPE_INT, height,
77 gst_buffer_set_caps(buf, caps);
79 /* fakesrc creation fails, returns false */
80 global_failing_gst_element = g_strdup("fakesrc");
81 QVERIFY(m_screenshot->savePauseFrame(buf,
82 "/dev/null") == FALSE);
86 /* TODO: Gst pipeline errors are difficult to test... */
89 void ut_GstScreenshot::testConvert()
93 gint size = width * height + width * height / 2;
94 GstBuffer *buf = gst_buffer_new_and_alloc(size);
95 memset(GST_BUFFER_DATA(buf), 0, size);
97 /* set caps, returns true */
99 caps = gst_caps_new_simple("video/x-raw-yuv",
100 "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I','4','2','0'),
101 "framerate", GST_TYPE_FRACTION, 25, 1,
102 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
103 "width", G_TYPE_INT, width,
104 "height", G_TYPE_INT, height,
106 gst_buffer_set_caps(buf, caps);
107 QVERIFY(m_screenshot->savePauseFrame(buf,
108 "/dev/null") == TRUE);
111 QVERIFY(m_gotScreenshotSignal == TRUE);
113 gst_caps_unref(caps);
117 void ut_GstScreenshot::testCancel()
121 gint size = width * height + width * height / 2;
122 GstBuffer *buf = gst_buffer_new_and_alloc(size);
123 memset(GST_BUFFER_DATA(buf), 0, size);
125 QFETCH(uint, timeout);
127 /* set caps, returns true */
129 caps = gst_caps_new_simple("video/x-raw-yuv",
130 "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I','4','2','0'),
131 "framerate", GST_TYPE_FRACTION, 25, 1,
132 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
133 "width", G_TYPE_INT, width,
134 "height", G_TYPE_INT, height,
136 gst_buffer_set_caps(buf, caps);
138 QVERIFY(m_screenshot->savePauseFrame(buf,
139 "/dev/null") == TRUE);
140 QTest::qWait(timeout);
141 if (m_gotScreenshotSignal == false )
143 m_screenshot->cancelPauseFrame();
144 QVERIFY(m_gotCancelSignal == TRUE);
148 void ut_GstScreenshot::testCancel_data()
150 QTest::addColumn<uint>("timeout");
151 QTest::newRow("0 ms") << (uint)0;
152 QTest::newRow("1 ms") << (uint)1;
153 QTest::newRow("5 ms") << (uint)5;
154 QTest::newRow("10 ms") << (uint)10;
155 QTest::newRow("20 ms") << (uint)20;
156 QTest::newRow("35 ms") << (uint)35;
157 QTest::newRow("50 ms") << (uint)50;
158 QTest::newRow("100 ms") << (uint)100;
161 void ut_GstScreenshot::slotScreenshot(char *location, GError *error)
163 qDebug() << __PRETTY_FUNCTION__;
166 m_gotScreenshotSignal = TRUE;
169 void ut_GstScreenshot::slotCancelScreenshot()
171 qDebug() << __PRETTY_FUNCTION__;
173 m_gotCancelSignal = TRUE;
176 void ut_GstScreenshot::init()
179 qDebug() << __PRETTY_FUNCTION__;
183 m_gotScreenshotSignal = FALSE;
184 m_gotCancelSignal = FALSE;
186 m_screenshot = new MafwGstScreenshot(this);
187 connect(m_screenshot, SIGNAL(screenshotTaken(char*,GError*)), this, SLOT(slotScreenshot(char*,GError*)));
188 connect(m_screenshot, SIGNAL(screenshotCancelled()), this, SLOT(slotCancelScreenshot()));
190 global_failing_gst_element = NULL;
194 void ut_GstScreenshot::cleanup()
197 qDebug() << __PRETTY_FUNCTION__;
198 g_free(global_failing_gst_element);
200 while(QCoreApplication::hasPendingEvents())
202 QCoreApplication::sendPostedEvents();
203 QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
204 QCoreApplication::processEvents();
209 QTEST_MAIN(ut_GstScreenshot)