Added qmafw-gst-subtitles-renderer-0.0.55 for Meego Harmattan 1.2
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / unittests / ut_MafwGstRendererSeeker / ut_MafwGstRendererSeeker.cpp
1 /*
2  * This file is part of QMAFW
3  *
4  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights
5  * reserved.
6  *
7  * Contact: Visa Smolander <visa.smolander@nokia.com>
8  *
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.
15  *
16  */
17
18 #include "ut_MafwGstRendererSeeker.h"
19
20 #include <QDebug>
21
22 Q_DECLARE_METATYPE(QList<qint64>);
23
24 extern gint64 g_currentPosition;
25 extern gint64 g_duration;
26 extern gint64 g_seekRequested;
27 extern gint g_seeksCalled;
28
29 void Ut_MafwGstRendererSeeker::initTestCase()
30 {
31     g_type_init();
32 }
33
34 void Ut_MafwGstRendererSeeker::cleanupTestCase()
35 {
36 }
37
38 void Ut_MafwGstRendererSeeker::init()
39 {
40     m_seeker = mafw_gst_renderer_seeker_new();
41     mafw_gst_renderer_seeker_set_pipeline(m_seeker, (GstElement*)(313));
42 }
43
44 void Ut_MafwGstRendererSeeker::cleanup()
45 {
46     mafw_gst_renderer_seeker_free(m_seeker);
47
48     g_currentPosition = -1;
49     g_duration = -1;
50     g_seekRequested = -1;
51     g_seeksCalled = 0;
52 }
53
54
55
56 void Ut_MafwGstRendererSeeker::testSeekSuccess()
57 {
58     QFETCH(qint64, startPosition);
59     QFETCH(qint64, seekTo);
60     QFETCH(qint64, seekGoesTo);
61     QFETCH(qint64, mediaDuration);
62
63     g_duration = mediaDuration;
64     g_currentPosition = startPosition;
65
66     mafw_gst_renderer_seeker_seek_to(m_seeker, seekTo);
67     QCOMPARE(g_seekRequested, seekTo);
68
69     g_currentPosition = seekGoesTo;
70
71     gint64 newSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
72
73     // only one seek operation should be called when successful
74     QCOMPARE(g_seeksCalled, 1);
75     QCOMPARE(newSeekPos, -1ll);
76 }
77
78 void Ut_MafwGstRendererSeeker::testSeekSuccess_data()
79 {
80     QTest::addColumn<qint64>("startPosition");
81     QTest::addColumn<qint64>("seekTo");
82     QTest::addColumn<qint64>("seekGoesTo");
83     QTest::addColumn<qint64>("mediaDuration");
84
85     QTest::newRow("1") << 0ll << 20ll << 21ll << 30ll;
86     QTest::newRow("1a") << 0ll << 19ll << 21ll << 30ll;
87     QTest::newRow("2") << 5ll << 1ll << 2ll << 10ll;
88     QTest::newRow("3") << 100ll << 150ll << 119ll << 120ll;
89
90     //intentionally messed values
91     QTest::newRow("weird1") << 4ll <<  1ll << 1ll << 2ll;
92     QTest::newRow("weird2") << -13ll << 13ll <<  12ll << 0ll;
93     QTest::newRow("weird2") << 10ll << 5ll << 4ll << 1ll;
94 }
95
96
97 void Ut_MafwGstRendererSeeker::testSeekFails()
98 {
99     QFETCH(qint64, startPosition);
100     QFETCH(qint64, seekTo);
101     QFETCH(QList<qint64>, processedSeekRequests);
102     QFETCH(QList<qint64>, seekGoesTo);
103     QFETCH(qint64, mediaDuration);
104
105     g_duration = mediaDuration;
106     g_currentPosition = startPosition;
107
108     mafw_gst_renderer_seeker_seek_to(m_seeker, seekTo);
109     QCOMPARE(g_seekRequested, seekTo);
110
111     qint64 newSeekPos = 0;
112     int i = 0;
113
114     while( true )
115     {
116         g_currentPosition = seekGoesTo.at(i);
117         newSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
118
119         if( newSeekPos == -1 )
120         {
121             break;
122         }
123
124         QCOMPARE(newSeekPos, processedSeekRequests.at(i));
125         QCOMPARE(g_seekRequested, processedSeekRequests.at(i));
126         ++i;
127     }
128
129     qint64 lastSeekPos = mafw_gst_renderer_seeker_process(m_seeker);
130     QCOMPARE( lastSeekPos, -1ll);
131     QCOMPARE( g_seeksCalled, seekGoesTo.size());
132 }
133
134 void Ut_MafwGstRendererSeeker::testSeekFails_data()
135 {
136     QTest::addColumn<qint64>("startPosition");
137     QTest::addColumn<qint64>("seekTo");
138     QTest::addColumn<QList<qint64> >("processedSeekRequests");
139     QTest::addColumn<QList<qint64> >("seekGoesTo");
140     QTest::addColumn<qint64>("mediaDuration");
141
142     QTest::newRow("Second seek is close enough")
143                        << 0ll // position where seeking start
144                        << 20ll // the seek request
145                        << (QList<qint64>() << 30 ) // list of processed seek request affected by the seekGoesTo list
146                        << (QList<qint64>() << 1 << 31 ) // list of resulting seeks to gst_element_seek()
147                        << 35ll; //affects when seek processing should stop
148
149     QTest::newRow("Fourth seek forward required")
150                        << 5ll // position where seeking start
151                        << 20ll // the seek request
152                        << (QList<qint64>() << 30 << 40 << 50 ) // list of processed seek request affected by the seekGoesTo list
153                        << (QList<qint64>() << 1 << 2 << 6 << 15 ) // list of resulting positions after calling gst_element_seek()
154                        << 70ll; //affects when seek processing should stop
155
156     // backward seeks assume that key_frame seeks will always seek at least to the requested position most likely earlier
157     // such backward seeks that would not reach at least the required position succeed anyway
158     QTest::newRow("backward seek fails")
159                        << 20ll // position where seeking start
160                        << 10ll // the seek request
161                        << (QList<qint64>() ) // list of processed seek request affected by the seekGoesTo list
162                        << (QList<qint64>() << 0 ) // list of resulting positions after calling gst_element_seek()
163                        << 70ll; //affects when seek processing should stop
164
165     QTest::newRow("backward seek fails 2")
166                        << 20ll // position where seeking start
167                        << 10ll // the seek request
168                        << (QList<qint64>() ) // list of processed seek request affected by the seekGoesTo list
169                        << (QList<qint64>() << 15 ) // list of resulting positions after calling gst_element_seek()
170                        << 70ll; //affects when seek processing should stop
171
172     QTest::newRow("Seek over media duration cancelled when processing")
173                        << 5ll // position where seeking start
174                        << 20ll // the seek request
175                        << (QList<qint64>()) // list of processed seek request affected by the seekGoesTo list
176                        << (QList<qint64>() << 5 ) // list of resulting positions after calling gst_element_seek()
177                        << 25ll; //affects when seek processing should stop
178
179     QTest::newRow("Test accuracy, first fails just by an inch")
180                        << 5ll // position where seeking start
181                        << 20ll // the seek request
182                        << (QList<qint64>() << 30) // list of processed seek request affected by the seekGoesTo list
183                        << (QList<qint64>() << 6 << 7) // list of resulting positions after calling gst_element_seek()
184                        << 35ll; //affects when seek processing should stop
185
186     QTest::newRow("Test accuracy 1, first fails just by an inch")
187                        << 5ll // position where seeking start
188                        << 20ll // the seek request
189                        << (QList<qint64>() << 30) // list of processed seek request affected by the seekGoesTo list
190                        << (QList<qint64>() << 6 << 7) // list of resulting seeks to gst_element_seek()
191                        << 35ll; //affects when seek processing should stop
192
193 }
194
195
196 QTEST_MAIN(Ut_MafwGstRendererSeeker)