Merge lp:~ahayzen/music-app/qml-unit-test-filenames into lp:music-app

Proposed by Andrew Hayzen
Status: Needs review
Proposed branch: lp:~ahayzen/music-app/qml-unit-test-filenames
Merge into: lp:music-app
Diff against target: 292 lines (+231/-0)
9 files modified
README.unittests (+47/-0)
app/components/Player.qml (+1/-0)
debian/changelog (+3/-0)
tests/CMakeLists.txt (+1/-0)
tests/unit/CMakeLists.txt (+6/-0)
tests/unit/generate_files.sh (+16/-0)
tests/unit/setup_run_locally.sh (+17/-0)
tests/unit/setup_run_on_device.sh (+24/-0)
tests/unit/tst_filenames.qml (+116/-0)
To merge this branch: bzr merge lp:~ahayzen/music-app/qml-unit-test-filenames
Reviewer Review Type Date Requested Status
Jenkins Bot continuous-integration Approve
Victor Thompson Needs Fixing
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+270512@code.launchpad.net

Commit message

* Add qml unit tests for different filenames with media-hub and mediascanner

Description of the change

* Add qml unit tests for different filenames with media-hub and mediascanner

This add a set of qml unit tests, which can be run manually to test that all the possible filenames in the ascii table can be played/found. (Plan is to add this to the manual tests list once that is in the repo).

To post a comment you must log in.
892. By Andrew Hayzen

* Merge of trunk

893. By Andrew Hayzen

* Update code comments

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :

PASSED: Continuous integration, rev:892
http://91.189.93.70:8080/job/music-app-ci/1379/
Executed test runs:
    SUCCESS: http://91.189.93.70:8080/job/music-app-vivid-amd64-ci/231

Click here to trigger a rebuild:
http://91.189.93.70:8080/job/music-app-ci/1379/rebuild

review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :

PASSED: Continuous integration, rev:893
http://91.189.93.70:8080/job/music-app-ci/1380/
Executed test runs:
    SUCCESS: http://91.189.93.70:8080/job/music-app-vivid-amd64-ci/232

Click here to trigger a rebuild:
http://91.189.93.70:8080/job/music-app-ci/1380/rebuild

review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

Just briefly looking this over. I think we should also add a README.unittests with instructions on running the tests. Also, if we have a script to run on the device, would it also make sense to have a script that runs all the tests locally?

review: Needs Fixing
894. By Andrew Hayzen

* Add README.unittests and setup_run_locally.sh files

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

* Add README.unittests and setup_run_locally.sh files

Please retest :-)

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :

PASSED: Continuous integration, rev:894
http://91.189.93.70:8080/job/music-app-ci/1384/
Executed test runs:
    SUCCESS: http://91.189.93.70:8080/job/music-app-vivid-amd64-ci/236

Click here to trigger a rebuild:
http://91.189.93.70:8080/job/music-app-ci/1384/rebuild

review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

Things to fix:

1. Please update to UC 1.3.
2. I also experienced your FIXME when running on the device. I think it's because the password isn't echoed back through adb--my password shows up in the terminal. There should be a way to echo it back.

Things to consider:

1. Oh dear that tone for the test files is kind of annoying. :)
2. Will it still make sense to have this run locally to test mh3 bg playlists? I think we might need to update the installation requirements before running the tests to install media hub. The unit tests fail locally on Xenial for me.
3. Is there a way to have the Ubuntu Application Test close after the unit tests run?

review: Needs Fixing
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Unmerged revisions

894. By Andrew Hayzen

* Add README.unittests and setup_run_locally.sh files

893. By Andrew Hayzen

* Update code comments

892. By Andrew Hayzen

* Merge of trunk

891. By Andrew Hayzen

* Tweaks to test files

890. By Andrew Hayzen

* Merge of trunk

889. By Andrew Hayzen

* Skip invalid file paths
* Test metadata from mediascanner is correct
* Improve init and how data is exposed

888. By Andrew Hayzen

* First round of changes for unit tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'README.unittests'
2--- README.unittests 1970-01-01 00:00:00 +0000
3+++ README.unittests 2015-09-25 11:15:25 +0000
4@@ -0,0 +1,47 @@
5+QML Unit Tests
6+==============
7+
8+QML Unit Tests help with testing the internal working of components while
9+autopilot tests help with testing the UI workflow as experience by the user.
10+
11+If you are submitting your bugfix/patch to the music app, please follow the
12+following steps below to check whether that all tests pass before proposing a
13+merge request.
14+
15+Note that these tests use the folder ~/Music/QMLTest and any content inside
16+will be removed.
17+
18+Also the application currently crashes on exit, so the test pass or fail lines
19+are a few lines back up the console.
20+
21+Running QML Unit Tests on device
22+================================
23+
24+Use the tests/unit/setup_run_on_device.sh note that some commands may have to
25+be run manually.
26+
27+Running QML Unit Tests on desktop
28+=================================
29+
30+Note that you need the mediascanner2 service to be running.
31+
32+Run the setup_run_locally.sh
33+
34+$ cd tests/unit/
35+$ ./setup_run_locally.sh
36+
37+Running individual test cases
38+=============================
39+
40+To run individual tests firstly created the mocked environment
41+$ ./generate_files.sh
42+$ cp -r files/generated ~/Music/QMLTest
43+
44+Then ensure that all requirements are installed
45+$ sudo apt-get install ubuntu-app-test qtdeclarative5-dev-tools qml-module-qttest -y
46+
47+Navigate to the unit tests directory
48+$ cd tests/unit
49+
50+Run the test by providing its filename
51+$ qmltestrunner -input tst_filenames.qml
52
53=== modified file 'app/components/Player.qml'
54--- app/components/Player.qml 2015-06-28 03:06:49 +0000
55+++ app/components/Player.qml 2015-09-25 11:15:25 +0000
56@@ -40,6 +40,7 @@
57 property int currentIndex: -1
58 property int duration: 1
59 readonly property bool isPlaying: player.playbackState === MediaPlayer.PlayingState
60+ readonly property bool loaded: mediaPlayerLoader.status == Loader.Ready
61 readonly property var playbackState: mediaPlayerLoader.status == Loader.Ready ? mediaPlayerLoader.item.playbackState : MediaPlayer.StoppedState
62 property int position: 0
63 property alias repeat: settings.repeat
64
65=== modified file 'debian/changelog'
66--- debian/changelog 2015-09-25 08:11:22 +0000
67+++ debian/changelog 2015-09-25 11:15:25 +0000
68@@ -1,5 +1,8 @@
69 music-app (2.2ubuntu2) UNRELEASED; urgency=medium
70
71+ [ Andrew Hayzen ]
72+ * Add qml unit tests for different filenames with media-hub and mediascanner
73+
74 [ Bartosz Kosiorek ]
75 * Reduce size of images (with tinypng.com) to decrease click size and improve performance
76
77
78=== modified file 'tests/CMakeLists.txt'
79--- tests/CMakeLists.txt 2014-01-31 20:43:59 +0000
80+++ tests/CMakeLists.txt 2015-09-25 11:15:25 +0000
81@@ -1,1 +1,2 @@
82 add_subdirectory(autopilot)
83+add_subdirectory(unit)
84
85=== added directory 'tests/unit'
86=== added file 'tests/unit/CMakeLists.txt'
87--- tests/unit/CMakeLists.txt 1970-01-01 00:00:00 +0000
88+++ tests/unit/CMakeLists.txt 2015-09-25 11:15:25 +0000
89@@ -0,0 +1,6 @@
90+# make the emulator files visible on qtcreator
91+file(GLOB QML_UNIT_TEST_FILES
92+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
93+ *.qml *.sh)
94+
95+add_custom_target(com_ubuntu_music_QMLUNITTESTFiles ALL SOURCES ${QML_UNIT_TEST_FILES})
96
97=== added directory 'tests/unit/files'
98=== added directory 'tests/unit/files/original'
99=== added file 'tests/unit/files/original/1.ogg'
100Binary files tests/unit/files/original/1.ogg 1970-01-01 00:00:00 +0000 and tests/unit/files/original/1.ogg 2015-09-25 11:15:25 +0000 differ
101=== added file 'tests/unit/generate_files.sh'
102--- tests/unit/generate_files.sh 1970-01-01 00:00:00 +0000
103+++ tests/unit/generate_files.sh 2015-09-25 11:15:25 +0000
104@@ -0,0 +1,16 @@
105+#!/bin/bash
106+
107+mkdir files/generated
108+
109+for i in {32..126} # from 'Space' to '~'
110+do
111+ if [ $i -eq 46 ] || [ $i -eq 47 ] # skip '.' and '/'
112+ then
113+ continue
114+ else
115+ chr=$(printf \\$(printf '%03o' $i))
116+
117+ echo "Creating file $chr.ogg from 1.ogg"
118+ cp "files/original/1.ogg" "files/generated/$chr.ogg"
119+ fi
120+done
121
122=== added file 'tests/unit/setup_run_locally.sh'
123--- tests/unit/setup_run_locally.sh 1970-01-01 00:00:00 +0000
124+++ tests/unit/setup_run_locally.sh 2015-09-25 11:15:25 +0000
125@@ -0,0 +1,17 @@
126+#!/bin/sh
127+
128+# Generate files
129+./generate_files.sh
130+
131+# Copy files to device
132+cp -r files/generated ~/Music/QMLTest
133+
134+# Install requirements
135+sudo apt-get install ubuntu-app-test qtdeclarative5-dev-tools qml-module-qttest -y
136+
137+# Run qmltestrunner
138+ubuntu-app-test qmltestrunner -silent -eventdelay 500
139+
140+# Clean up
141+rm -rf ~/Music/QMLTest
142+rm -rf files/generated
143
144=== added file 'tests/unit/setup_run_on_device.sh'
145--- tests/unit/setup_run_on_device.sh 1970-01-01 00:00:00 +0000
146+++ tests/unit/setup_run_on_device.sh 2015-09-25 11:15:25 +0000
147@@ -0,0 +1,24 @@
148+#!/bin/sh
149+
150+# Copy music app to device
151+adb push ../../. /tmp/music-app-unit-test
152+
153+# Generate files
154+./generate_files.sh
155+
156+# Copy files to device
157+adb push files/generated /home/phablet/Music/QMLTest
158+
159+# TODO: make writeable ?
160+
161+# Install requirements
162+# FIXME: I have to adb into the device and run manually?
163+adb shell "sudo apt-get install ubuntu-app-test qtdeclarative5-dev-tools qml-module-qttest -y"
164+
165+# Run qmltestrunner
166+adb shell "cd /tmp/music-app-unit-test/tests/unit && ubuntu-app-test qmltestrunner -silent -eventdelay 500"
167+
168+# Clean up
169+adb shell "rm -rf /home/phablet/Music/QMLTest"
170+adb shell "rm -rf /tmp/music-app-unit-test"
171+rm -rf files/generated
172
173=== added file 'tests/unit/tst_filenames.qml'
174--- tests/unit/tst_filenames.qml 1970-01-01 00:00:00 +0000
175+++ tests/unit/tst_filenames.qml 2015-09-25 11:15:25 +0000
176@@ -0,0 +1,116 @@
177+
178+import QtTest 1.0
179+import QtQuick 2.4
180+import Ubuntu.Components 1.2
181+import Ubuntu.MediaScanner 0.1
182+import Ubuntu.Test 1.0
183+
184+import "../../app/components"
185+
186+MainView {
187+ // Wrapper function around decodeURIComponent() to prevent exceptions
188+ // from bubbling up to the app.
189+ function decodeFileURI(filename)
190+ {
191+ var newFilename = "";
192+ try {
193+ newFilename = decodeURIComponent(filename);
194+ } catch (e) {
195+ newFilename = filename;
196+ console.log("Unicode decoding error:", filename, e.message)
197+ }
198+
199+ return newFilename;
200+ }
201+
202+ Item {
203+ id: trackQueue
204+
205+ property ListModel model: ListModel {
206+
207+ }
208+ }
209+
210+ /* Mediahub */
211+ Player {
212+ id: player
213+ }
214+
215+ /* Mediascanner */
216+ SongsModel {
217+ id: songsModel
218+ store: MediaStore {
219+ id: musicStore
220+ }
221+ }
222+
223+ /* UnitTests */
224+ UbuntuTestCase {
225+ property var filepaths: [
226+
227+ ]
228+
229+ function init() {
230+ // Wait for the async MediaPlayer to load
231+ tryCompare(player, "loaded", true, 250, "Player has not loaded");
232+ }
233+
234+ function init_data() {
235+ return filepaths;
236+ }
237+
238+ function initTestCase() {
239+ // Build up filenames to test
240+ var blacklist = [46, 47]; // '.', '/'
241+
242+ for (var i=32; i < 127; i++) {
243+ if (blacklist.indexOf(i) > -1) {
244+ continue;
245+ } else {
246+ var chr = String.fromCharCode(i);
247+ filepaths.push({ filepath: "/home/phablet/Music/QMLTest/" + chr + ".ogg", tag: chr });
248+ }
249+ }
250+ }
251+
252+ function test_mediascanner(data) {
253+ var filepath = decodeFileURI(data.filepath);
254+ var msResult = musicStore.lookup(filepath);
255+
256+ // Check lookup from ms2 returned something
257+ verify(msResult !== null, "Mediascanner2 could not find track - " + filepath);
258+
259+ compare(msResult.title, "Test Sound", "Mediascanner title is not the same - " + filepath);
260+ compare(msResult.album, "Test Album", "Mediascanner album is not the same - " + filepath);
261+ compare(msResult.author, "Test Artist", "Mediascanner author is not the same - " + filepath);
262+ compare(msResult.art, "image://albumart/artist=Test%20Artist&album=Test%20Album", "Mediascanner art is not the same - " + filepath);
263+ }
264+
265+ function test_media_hub(data) {
266+ if (data.tag === "#") { // manually skip otherwise media-hub crashes
267+ // FIXME: MediaHub won't play '#' due to http://pad.lv/1449790
268+ // expectFail("#", "MediaHub won't play '#' due to http://pad.lv/1449790")
269+
270+ /*
271+ // FIXME: Not sure why this doesn't work, it should only skip this data row but it skips the test
272+ if (data.tag === "#") {
273+ skip("MediaHub won't play '#' due to http://pad.lv/1449790")
274+ }
275+ */
276+ } else {
277+ var filepath = data.filepath;
278+
279+ player.setSource(filepath);
280+ player.play();
281+
282+ wait(1100); // Wait for the track to reach > 1s
283+
284+ // Check that track is playing and the position has changed
285+ compare(player.isPlaying, true, "MediaHub is not playing the track - " + filepath);
286+ verify(player.position > 0, "MediaHub position has not changed - " + filepath + " - " + player.position);
287+
288+ player.pause();
289+ }
290+ }
291+ }
292+}

Subscribers

People subscribed via source and target branches