on xenial help sign in
mock QtMultimedia Audio element
d735966Michael Zanetti
tests/mocks/CMakeLists.txt+1
@@ -7,6 +7,7 @@ add_subdirectory(Powerd)
7add_subdirectory(QMenuModel)
7add_subdirectory(QMenuModel)
8add_subdirectory(Ubuntu)
8add_subdirectory(Ubuntu)
9add_subdirectory(Unity)
9add_subdirectory(Unity)
10+add_subdirectory(QtMultimedia)
10
11
11install(
12install(
12 DIRECTORY data
13 DIRECTORY data
tests/mocks/QtMultimedia/CMakeLists.txtnew file+19
@@ -0,0 +1,19 @@
1+add_library(QtMultimedia-qml MODULE
2+ plugin.cpp
3+ audio.cpp
4+ )
5+
6+qt5_use_modules(QtMultimedia-qml Qml)
7+
8+# copy qmldir file into build directory for shadow builds
9+file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
10+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
11+ )
12+
13+install(TARGETS QtMultimedia-qml
14+ DESTINATION ${SHELL_PRIVATE_LIBDIR}/qml/mocks/QtMultimedia
15+ )
16+
17+install(FILES qmldir
18+ DESTINATION ${SHELL_PRIVATE_LIBDIR}/qml/mocks/QtMultimedia
19+ )
tests/mocks/QtMultimedia/audio.cppnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Author: Michael Zanetti <michael.zanetti@canonical.com>
17+ */
18+
19+#include "audio.h"
20+
21+Audio::Audio(QObject* parent):
22+ QObject(parent),
23+ m_playbackState(StoppedState)
24+{
25+}
26+
27+QUrl Audio::source() const
28+{
29+ return m_source;
30+}
31+
32+void Audio::setSource(const QUrl &source)
33+{
34+ if (m_source != source) {
35+ m_source = source;
36+ Q_EMIT sourceChanged(source);
37+ }
38+}
39+
40+Audio::PlaybackState Audio::playbackState() const
41+{
42+ return m_playbackState;
43+}
44+
45+QString Audio::errorString() const
46+{
47+ return QString();
48+}
49+
50+void Audio::pause()
51+{
52+ if (m_playbackState == PlayingState) {
53+ m_playbackState = PausedState;
54+ Q_EMIT playbackStateChanged();
55+ }
56+}
57+
58+void Audio::play()
59+{
60+ if (m_playbackState != PlayingState && m_source.isValid()) {
61+ m_playbackState = PlayingState;
62+ Q_EMIT playbackStateChanged();
63+ }
64+}
65+
66+void Audio::stop()
67+{
68+ if (m_playbackState != StoppedState) {
69+ m_playbackState = StoppedState;
70+ Q_EMIT playbackStateChanged();
71+ }
72+}
tests/mocks/QtMultimedia/audio.hnew file+63
@@ -0,0 +1,63 @@
1+/*
2+ * Copyright (C) 2012,2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17+ */
18+
19+#ifndef MOCK_AUDIO_H
20+#define MOCK_AUDIO_H
21+
22+#include <QObject>
23+#include <QUrl>
24+
25+class Audio: public QObject
26+{
27+ Q_OBJECT
28+ Q_ENUMS(PlaybackState)
29+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
30+ Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
31+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
32+public:
33+ enum PlaybackState {
34+ PlayingState,
35+ PausedState,
36+ StoppedState
37+ };
38+
39+ explicit Audio(QObject *parent = 0);
40+
41+ QUrl source() const;
42+ void setSource(const QUrl &source);
43+
44+ PlaybackState playbackState() const;
45+
46+ QString errorString() const;
47+
48+public Q_SLOTS:
49+ void pause();
50+ void play();
51+ void stop();
52+
53+Q_SIGNALS:
54+ void sourceChanged(const QUrl &source);
55+ void playbackStateChanged();
56+ void errorStringChanged(const QString &errorString);
57+
58+private:
59+ QUrl m_source;
60+ PlaybackState m_playbackState;
61+};
62+
63+#endif
tests/mocks/QtMultimedia/plugin.cppnew file+28
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2012,2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17+ */
18+
19+#include "plugin.h"
20+#include "audio.h"
21+
22+#include <QtQml/qqml.h>
23+
24+void MockQtMultimediaPlugin::registerTypes(const char *uri)
25+{
26+ Q_ASSERT(uri == QLatin1String("QtMultimedia"));
27+ qmlRegisterType<Audio>(uri, 5, 0, "Audio");
28+}
tests/mocks/QtMultimedia/plugin.hnew file+34
@@ -0,0 +1,34 @@
1+/*
2+ * Copyright (C) 2012,2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17+ */
18+
19+#ifndef MOCK_QTMULTIMEDIA_PLUGIN_H
20+#define MOCK_QTMULTIMEDIA_PLUGIN_H
21+
22+#include <QtQml/QQmlEngine>
23+#include <QtQml/QQmlExtensionPlugin>
24+
25+class MockQtMultimediaPlugin : public QQmlExtensionPlugin
26+{
27+ Q_OBJECT
28+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29+
30+public:
31+ void registerTypes(const char *uri);
32+};
33+
34+#endif
tests/mocks/QtMultimedia/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module QtMultimedia
2+plugin QtMultimedia-qml
tests/qmltests/Dash/Music/tst_MusicPreview.qml−2
@@ -41,8 +41,6 @@ Rectangle {
41 { id: 123, displayName: "Play"},
41 { id: 123, displayName: "Play"},
42 { id: 456, displayName: "Show in folder"}
42 { id: 456, displayName: "Show in folder"}
43 ]
43 ]
44− property var execute: fake_callback
45−
46 property var tracks: tracksModel2
44 property var tracks: tracksModel2
47 }
45 }
48 }
46 }