Added qmafw-gst-subtitles-renderer-0.0.55 for Meego Harmattan 1.2
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / unittests / ut_MafwGstRendererSeeker / ut_MafwGstRendererSeeker.cpp
diff --git a/qmafw-gst-subtitles-renderer/unittests/ut_MafwGstRendererSeeker/ut_MafwGstRendererSeeker.cpp b/qmafw-gst-subtitles-renderer/unittests/ut_MafwGstRendererSeeker/ut_MafwGstRendererSeeker.cpp
new file mode 100644 (file)
index 0000000..8d34d64
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * This file is part of QMAFW
+ *
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights
+ * reserved.
+ *
+ * Contact: Visa Smolander <visa.smolander@nokia.com>
+ *
+ * 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 "ut_MafwGstRendererSeeker.h"
+
+#include <QDebug>
+
+Q_DECLARE_METATYPE(QList<qint64>);
+
+extern gint64 g_currentPosition;
+extern gint64 g_duration;
+extern gint64 g_seekRequested;
+extern gint g_seeksCalled;
+
+void Ut_MafwGstRendererSeeker::initTestCase()
+{
+    g_type_init();
+}
+
+void Ut_MafwGstRendererSeeker::cleanupTestCase()
+{
+}
+
+void Ut_MafwGstRendererSeeker::init()
+{
+    m_seeker = mafw_gst_renderer_seeker_new();
+    mafw_gst_renderer_seeker_set_pipeline(m_seeker, (GstElement*)(313));
+}
+
+void Ut_MafwGstRendererSeeker::cleanup()
+{
+    mafw_gst_renderer_seeker_free(m_seeker);
+
+    g_currentPosition = -1;
+    g_duration = -1;
+    g_seekRequested = -1;
+    g_seeksCalled = 0;
+}
+
+
+
+void Ut_MafwGstRendererSeeker::testSeekSuccess()
+{
+    QFETCH(qint64, startPosition);
+    QFETCH(qint64, seekTo);
+    QFETCH(qint64, seekGoesTo);
+    QFETCH(qint64, mediaDuration);
+
+    g_duration = mediaDuration;
+    g_currentPosition = startPosition;
+
+    mafw_gst_renderer_seeker_seek_to(m_seeker, seekTo);
+    QCOMPARE(g_seekRequested, seekTo);
+
+    g_currentPosition = seekGoesTo;
+
+    gint64 newSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
+
+    // only one seek operation should be called when successful
+    QCOMPARE(g_seeksCalled, 1);
+    QCOMPARE(newSeekPos, -1ll);
+}
+
+void Ut_MafwGstRendererSeeker::testSeekSuccess_data()
+{
+    QTest::addColumn<qint64>("startPosition");
+    QTest::addColumn<qint64>("seekTo");
+    QTest::addColumn<qint64>("seekGoesTo");
+    QTest::addColumn<qint64>("mediaDuration");
+
+    QTest::newRow("1") << 0ll << 20ll << 21ll << 30ll;
+    QTest::newRow("1a") << 0ll << 19ll << 21ll << 30ll;
+    QTest::newRow("2") << 5ll << 1ll << 2ll << 10ll;
+    QTest::newRow("3") << 100ll << 150ll << 119ll << 120ll;
+
+    //intentionally messed values
+    QTest::newRow("weird1") << 4ll <<  1ll << 1ll << 2ll;
+    QTest::newRow("weird2") << -13ll << 13ll <<  12ll << 0ll;
+    QTest::newRow("weird2") << 10ll << 5ll << 4ll << 1ll;
+}
+
+
+void Ut_MafwGstRendererSeeker::testSeekFails()
+{
+    QFETCH(qint64, startPosition);
+    QFETCH(qint64, seekTo);
+    QFETCH(QList<qint64>, processedSeekRequests);
+    QFETCH(QList<qint64>, seekGoesTo);
+    QFETCH(qint64, mediaDuration);
+
+    g_duration = mediaDuration;
+    g_currentPosition = startPosition;
+
+    mafw_gst_renderer_seeker_seek_to(m_seeker, seekTo);
+    QCOMPARE(g_seekRequested, seekTo);
+
+    qint64 newSeekPos = 0;
+    int i = 0;
+
+    while( true )
+    {
+        g_currentPosition = seekGoesTo.at(i);
+        newSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
+
+        if( newSeekPos == -1 )
+        {
+            break;
+        }
+
+        QCOMPARE(newSeekPos, processedSeekRequests.at(i));
+        QCOMPARE(g_seekRequested, processedSeekRequests.at(i));
+        ++i;
+    }
+
+    qint64 lastSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
+    QCOMPARE( lastSeekPos, -1ll);
+    QCOMPARE( g_seeksCalled, seekGoesTo.size());
+}
+
+void Ut_MafwGstRendererSeeker::testSeekFails_data()
+{
+    QTest::addColumn<qint64>("startPosition");
+    QTest::addColumn<qint64>("seekTo");
+    QTest::addColumn<QList<qint64> >("processedSeekRequests");
+    QTest::addColumn<QList<qint64> >("seekGoesTo");
+    QTest::addColumn<qint64>("mediaDuration");
+
+    QTest::newRow("Second seek is close enough")
+                       << 0ll // position where seeking start
+                       << 20ll // the seek request
+                       << (QList<qint64>() << 30 ) // list of processed seek request affected by the seekGoesTo list
+                       << (QList<qint64>() << 1 << 31 ) // list of resulting seeks to gst_element_seek()
+                       << 35ll; //affects when seek processing should stop
+
+    QTest::newRow("Fourth seek forward required")
+                       << 5ll // position where seeking start
+                       << 20ll // the seek request
+                       << (QList<qint64>() << 30 << 40 << 50 ) // list of processed seek request affected by the seekGoesTo list
+                       << (QList<qint64>() << 1 << 2 << 6 << 15 ) // list of resulting positions after calling gst_element_seek()
+                       << 70ll; //affects when seek processing should stop
+
+    // backward seeks assume that key_frame seeks will always seek at least to the requested position most likely earlier
+    // such backward seeks that would not reach at least the required position succeed anyway
+    QTest::newRow("backward seek fails")
+                       << 20ll // position where seeking start
+                       << 10ll // the seek request
+                       << (QList<qint64>() ) // list of processed seek request affected by the seekGoesTo list
+                       << (QList<qint64>() << 0 ) // list of resulting positions after calling gst_element_seek()
+                       << 70ll; //affects when seek processing should stop
+
+    QTest::newRow("backward seek fails 2")
+                       << 20ll // position where seeking start
+                       << 10ll // the seek request
+                       << (QList<qint64>() ) // list of processed seek request affected by the seekGoesTo list
+                       << (QList<qint64>() << 15 ) // list of resulting positions after calling gst_element_seek()
+                       << 70ll; //affects when seek processing should stop
+
+    QTest::newRow("Seek over media duration cancelled when processing")
+                       << 5ll // position where seeking start
+                       << 20ll // the seek request
+                       << (QList<qint64>()) // list of processed seek request affected by the seekGoesTo list
+                       << (QList<qint64>() << 5 ) // list of resulting positions after calling gst_element_seek()
+                       << 25ll; //affects when seek processing should stop
+
+    QTest::newRow("Test accuracy, first fails just by an inch")
+                       << 5ll // position where seeking start
+                       << 20ll // the seek request
+                       << (QList<qint64>() << 30) // list of processed seek request affected by the seekGoesTo list
+                       << (QList<qint64>() << 6 << 7) // list of resulting positions after calling gst_element_seek()
+                       << 35ll; //affects when seek processing should stop
+
+    QTest::newRow("Test accuracy 1, first fails just by an inch")
+                       << 5ll // position where seeking start
+                       << 20ll // the seek request
+                       << (QList<qint64>() << 30) // list of processed seek request affected by the seekGoesTo list
+                       << (QList<qint64>() << 6 << 7) // list of resulting seeks to gst_element_seek()
+                       << 35ll; //affects when seek processing should stop
+
+}
+
+
+QTEST_MAIN(Ut_MafwGstRendererSeeker)