on xenial help sign in
improve Audio mock, drop testfiles
commitb7306c7fe374bd8b7ba9dd160307533ea506f497 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 14 Nov 2013, 13:12 (13 years ago) parentd735966
5 files changed+54−4
tests/mocks/QtMultimedia/audio.cpp+38−3 tests/mocks/QtMultimedia/audio.h+16−1 tests/qmltests/Dash/Music/data/testsound1.ogg tests/qmltests/Dash/Music/data/testsound2.ogg tests/qmltests/Dash/Music/data/testsound3.ogg
tests/mocks/QtMultimedia/audio.cpp+38−3
@@ -22,6 +22,9 @@ Audio::Audio(QObject* parent):
2222 QObject(parent),
2323 m_playbackState(StoppedState)
2424{
25+ qsrand(time(NULL));
26+ m_timer.setInterval(1000);
27+ connect(&m_timer, SIGNAL(timeout()), SLOT(timerEvent()));
2528}
2629
2730QUrl Audio::source() const
@@ -34,6 +37,12 @@ void Audio::setSource(const QUrl &source)
3437 if (m_source != source) {
3538 m_source = source;
3639 Q_EMIT sourceChanged(source);
40+
41+ m_position = 0;
42+ Q_EMIT positionChanged(m_position);
43+
44+ m_duration = (qrand() % 20000) + 10000;
45+ Q_EMIT durationChanged(m_duration);
3746 }
3847}
3948
@@ -42,6 +51,16 @@ Audio::PlaybackState Audio::playbackState() const
4251 return m_playbackState;
4352}
4453
54+int Audio::position() const
55+{
56+ return m_position;
57+}
58+
59+int Audio::duration() const
60+{
61+ return m_duration;
62+}
63+
4564QString Audio::errorString() const
4665{
4766 return QString();
@@ -51,7 +70,8 @@ void Audio::pause()
5170{
5271 if (m_playbackState == PlayingState) {
5372 m_playbackState = PausedState;
54− Q_EMIT playbackStateChanged();
73+ Q_EMIT playbackStateChanged(m_playbackState);
74+ m_timer.stop();
5575 }
5676}
5777
@@ -59,7 +79,9 @@ void Audio::play()
5979{
6080 if (m_playbackState != PlayingState && m_source.isValid()) {
6181 m_playbackState = PlayingState;
62− Q_EMIT playbackStateChanged();
82+ Q_EMIT playbackStateChanged(m_playbackState);
83+
84+ m_timer.start();
6385 }
6486}
6587
@@ -67,6 +89,19 @@ void Audio::stop()
6789{
6890 if (m_playbackState != StoppedState) {
6991 m_playbackState = StoppedState;
70− Q_EMIT playbackStateChanged();
92+ Q_EMIT playbackStateChanged(m_playbackState);
93+ m_timer.stop();
94+ m_position = 0;
95+ Q_EMIT positionChanged(m_position);
96+ }
97+}
98+
99+void Audio::timerEvent()
100+{
101+ if (m_position + 1000 < m_duration) {
102+ m_position += 1000;
103+ Q_EMIT positionChanged(m_position);
104+ } else {
105+ stop();
71106 }
72107}
tests/mocks/QtMultimedia/audio.h+16−1
@@ -21,6 +21,7 @@
2121
2222#include <QObject>
2323#include <QUrl>
24+#include <QTimer>
2425
2526class Audio: public QObject
2627{
@@ -28,6 +29,8 @@ class Audio: public QObject
2829 Q_ENUMS(PlaybackState)
2930 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
3031 Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
32+ Q_PROPERTY(int position READ position NOTIFY positionChanged)
33+ Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
3134 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
3235public:
3336 enum PlaybackState {
@@ -43,6 +46,10 @@ public:
4346
4447 PlaybackState playbackState() const;
4548
49+ int position() const;
50+
51+ int duration() const;
52+
4653 QString errorString() const;
4754
4855public Q_SLOTS:
@@ -52,12 +59,20 @@ public Q_SLOTS:
5259
5360Q_SIGNALS:
5461 void sourceChanged(const QUrl &source);
55− void playbackStateChanged();
62+ void playbackStateChanged(PlaybackState playbackState);
63+ void positionChanged(int position);
64+ void durationChanged(int duration);
5665 void errorStringChanged(const QString &errorString);
5766
67+private Q_SLOTS:
68+ void timerEvent();
69+
5870private:
5971 QUrl m_source;
6072 PlaybackState m_playbackState;
73+ QTimer m_timer;
74+ int m_position;
75+ int m_duration;
6176};
6277
6378#endif
tests/qmltests/Dash/Music/data/testsound1.oggdeleted

Binary file not shown.

tests/qmltests/Dash/Music/data/testsound2.oggdeleted

Binary file not shown.

tests/qmltests/Dash/Music/data/testsound3.oggdeleted

Binary file not shown.