on xenial help sign in
improve Audio mock, drop testfiles
b7306c7Michael Zanetti
tests/mocks/QtMultimedia/audio.cpp+38−3
@@ -22,6 +22,9 @@ Audio::Audio(QObject* parent):
22 QObject(parent),
22 QObject(parent),
23 m_playbackState(StoppedState)
23 m_playbackState(StoppedState)
24{
24{
25+ qsrand(time(NULL));
26+ m_timer.setInterval(1000);
27+ connect(&m_timer, SIGNAL(timeout()), SLOT(timerEvent()));
25}
28}
26
29
27QUrl Audio::source() const
30QUrl Audio::source() const
@@ -34,6 +37,12 @@ void Audio::setSource(const QUrl &source)
34 if (m_source != source) {
37 if (m_source != source) {
35 m_source = source;
38 m_source = source;
36 Q_EMIT sourceChanged(source);
39 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);
37 }
46 }
38}
47}
39
48
@@ -42,6 +51,16 @@ Audio::PlaybackState Audio::playbackState() const
42 return m_playbackState;
51 return m_playbackState;
43}
52}
44
53
54+int Audio::position() const
55+{
56+ return m_position;
57+}
58+
59+int Audio::duration() const
60+{
61+ return m_duration;
62+}
63+
45QString Audio::errorString() const
64QString Audio::errorString() const
46{
65{
47 return QString();
66 return QString();
@@ -51,7 +70,8 @@ void Audio::pause()
51{
70{
52 if (m_playbackState == PlayingState) {
71 if (m_playbackState == PlayingState) {
53 m_playbackState = PausedState;
72 m_playbackState = PausedState;
54− Q_EMIT playbackStateChanged();
73+ Q_EMIT playbackStateChanged(m_playbackState);
74+ m_timer.stop();
55 }
75 }
56}
76}
57
77
@@ -59,7 +79,9 @@ void Audio::play()
59{
79{
60 if (m_playbackState != PlayingState && m_source.isValid()) {
80 if (m_playbackState != PlayingState && m_source.isValid()) {
61 m_playbackState = PlayingState;
81 m_playbackState = PlayingState;
62− Q_EMIT playbackStateChanged();
82+ Q_EMIT playbackStateChanged(m_playbackState);
83+
84+ m_timer.start();
63 }
85 }
64}
86}
65
87
@@ -67,6 +89,19 @@ void Audio::stop()
67{
89{
68 if (m_playbackState != StoppedState) {
90 if (m_playbackState != StoppedState) {
69 m_playbackState = StoppedState;
91 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();
71 }
106 }
72}
107}
tests/mocks/QtMultimedia/audio.h+16−1
@@ -21,6 +21,7 @@
21
21
22#include <QObject>
22#include <QObject>
23#include <QUrl>
23#include <QUrl>
24+#include <QTimer>
24
25
25class Audio: public QObject
26class Audio: public QObject
26{
27{
@@ -28,6 +29,8 @@ class Audio: public QObject
28 Q_ENUMS(PlaybackState)
29 Q_ENUMS(PlaybackState)
29 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
30 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
30 Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
31 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)
31 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
34 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
32public:
35public:
33 enum PlaybackState {
36 enum PlaybackState {
@@ -43,6 +46,10 @@ public:
43
46
44 PlaybackState playbackState() const;
47 PlaybackState playbackState() const;
45
48
49+ int position() const;
50+
51+ int duration() const;
52+
46 QString errorString() const;
53 QString errorString() const;
47
54
48public Q_SLOTS:
55public Q_SLOTS:
@@ -52,12 +59,20 @@ public Q_SLOTS:
52
59
53Q_SIGNALS:
60Q_SIGNALS:
54 void sourceChanged(const QUrl &source);
61 void sourceChanged(const QUrl &source);
55− void playbackStateChanged();
62+ void playbackStateChanged(PlaybackState playbackState);
63+ void positionChanged(int position);
64+ void durationChanged(int duration);
56 void errorStringChanged(const QString &errorString);
65 void errorStringChanged(const QString &errorString);
57
66
67+private Q_SLOTS:
68+ void timerEvent();
69+
58private:
70private:
59 QUrl m_source;
71 QUrl m_source;
60 PlaybackState m_playbackState;
72 PlaybackState m_playbackState;
73+ QTimer m_timer;
74+ int m_position;
75+ int m_duration;
61};
76};
62
77
63#endif
78#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.