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
=== added file 'README.unittests'
--- README.unittests 1970-01-01 00:00:00 +0000
+++ README.unittests 2015-09-25 11:15:25 +0000
@@ -0,0 +1,47 @@
1QML Unit Tests
2==============
3
4QML Unit Tests help with testing the internal working of components while
5autopilot tests help with testing the UI workflow as experience by the user.
6
7If you are submitting your bugfix/patch to the music app, please follow the
8following steps below to check whether that all tests pass before proposing a
9merge request.
10
11Note that these tests use the folder ~/Music/QMLTest and any content inside
12will be removed.
13
14Also the application currently crashes on exit, so the test pass or fail lines
15are a few lines back up the console.
16
17Running QML Unit Tests on device
18================================
19
20Use the tests/unit/setup_run_on_device.sh note that some commands may have to
21be run manually.
22
23Running QML Unit Tests on desktop
24=================================
25
26Note that you need the mediascanner2 service to be running.
27
28Run the setup_run_locally.sh
29
30$ cd tests/unit/
31$ ./setup_run_locally.sh
32
33Running individual test cases
34=============================
35
36To run individual tests firstly created the mocked environment
37$ ./generate_files.sh
38$ cp -r files/generated ~/Music/QMLTest
39
40Then ensure that all requirements are installed
41$ sudo apt-get install ubuntu-app-test qtdeclarative5-dev-tools qml-module-qttest -y
42
43Navigate to the unit tests directory
44$ cd tests/unit
45
46Run the test by providing its filename
47$ qmltestrunner -input tst_filenames.qml
048
=== modified file 'app/components/Player.qml'
--- app/components/Player.qml 2015-06-28 03:06:49 +0000
+++ app/components/Player.qml 2015-09-25 11:15:25 +0000
@@ -40,6 +40,7 @@
40 property int currentIndex: -140 property int currentIndex: -1
41 property int duration: 141 property int duration: 1
42 readonly property bool isPlaying: player.playbackState === MediaPlayer.PlayingState42 readonly property bool isPlaying: player.playbackState === MediaPlayer.PlayingState
43 readonly property bool loaded: mediaPlayerLoader.status == Loader.Ready
43 readonly property var playbackState: mediaPlayerLoader.status == Loader.Ready ? mediaPlayerLoader.item.playbackState : MediaPlayer.StoppedState44 readonly property var playbackState: mediaPlayerLoader.status == Loader.Ready ? mediaPlayerLoader.item.playbackState : MediaPlayer.StoppedState
44 property int position: 045 property int position: 0
45 property alias repeat: settings.repeat46 property alias repeat: settings.repeat
4647
=== modified file 'debian/changelog'
--- debian/changelog 2015-09-25 08:11:22 +0000
+++ debian/changelog 2015-09-25 11:15:25 +0000
@@ -1,5 +1,8 @@
1music-app (2.2ubuntu2) UNRELEASED; urgency=medium1music-app (2.2ubuntu2) UNRELEASED; urgency=medium
22
3 [ Andrew Hayzen ]
4 * Add qml unit tests for different filenames with media-hub and mediascanner
5
3 [ Bartosz Kosiorek ]6 [ Bartosz Kosiorek ]
4 * Reduce size of images (with tinypng.com) to decrease click size and improve performance7 * Reduce size of images (with tinypng.com) to decrease click size and improve performance
58
69
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2014-01-31 20:43:59 +0000
+++ tests/CMakeLists.txt 2015-09-25 11:15:25 +0000
@@ -1,1 +1,2 @@
1add_subdirectory(autopilot)1add_subdirectory(autopilot)
2add_subdirectory(unit)
23
=== added directory 'tests/unit'
=== added file 'tests/unit/CMakeLists.txt'
--- tests/unit/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/unit/CMakeLists.txt 2015-09-25 11:15:25 +0000
@@ -0,0 +1,6 @@
1# make the emulator files visible on qtcreator
2file(GLOB QML_UNIT_TEST_FILES
3 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
4 *.qml *.sh)
5
6add_custom_target(com_ubuntu_music_QMLUNITTESTFiles ALL SOURCES ${QML_UNIT_TEST_FILES})
07
=== added directory 'tests/unit/files'
=== added directory 'tests/unit/files/original'
=== added file 'tests/unit/files/original/1.ogg'
1Binary 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 differ8Binary 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
=== added file 'tests/unit/generate_files.sh'
--- tests/unit/generate_files.sh 1970-01-01 00:00:00 +0000
+++ tests/unit/generate_files.sh 2015-09-25 11:15:25 +0000
@@ -0,0 +1,16 @@
1#!/bin/bash
2
3mkdir files/generated
4
5for i in {32..126} # from 'Space' to '~'
6do
7 if [ $i -eq 46 ] || [ $i -eq 47 ] # skip '.' and '/'
8 then
9 continue
10 else
11 chr=$(printf \\$(printf '%03o' $i))
12
13 echo "Creating file $chr.ogg from 1.ogg"
14 cp "files/original/1.ogg" "files/generated/$chr.ogg"
15 fi
16done
017
=== added file 'tests/unit/setup_run_locally.sh'
--- tests/unit/setup_run_locally.sh 1970-01-01 00:00:00 +0000
+++ tests/unit/setup_run_locally.sh 2015-09-25 11:15:25 +0000
@@ -0,0 +1,17 @@
1#!/bin/sh
2
3# Generate files
4./generate_files.sh
5
6# Copy files to device
7cp -r files/generated ~/Music/QMLTest
8
9# Install requirements
10sudo apt-get install ubuntu-app-test qtdeclarative5-dev-tools qml-module-qttest -y
11
12# Run qmltestrunner
13ubuntu-app-test qmltestrunner -silent -eventdelay 500
14
15# Clean up
16rm -rf ~/Music/QMLTest
17rm -rf files/generated
018
=== added file 'tests/unit/setup_run_on_device.sh'
--- tests/unit/setup_run_on_device.sh 1970-01-01 00:00:00 +0000
+++ tests/unit/setup_run_on_device.sh 2015-09-25 11:15:25 +0000
@@ -0,0 +1,24 @@
1#!/bin/sh
2
3# Copy music app to device
4adb push ../../. /tmp/music-app-unit-test
5
6# Generate files
7./generate_files.sh
8
9# Copy files to device
10adb push files/generated /home/phablet/Music/QMLTest
11
12# TODO: make writeable ?
13
14# Install requirements
15# FIXME: I have to adb into the device and run manually?
16adb shell "sudo apt-get install ubuntu-app-test qtdeclarative5-dev-tools qml-module-qttest -y"
17
18# Run qmltestrunner
19adb shell "cd /tmp/music-app-unit-test/tests/unit && ubuntu-app-test qmltestrunner -silent -eventdelay 500"
20
21# Clean up
22adb shell "rm -rf /home/phablet/Music/QMLTest"
23adb shell "rm -rf /tmp/music-app-unit-test"
24rm -rf files/generated
025
=== added file 'tests/unit/tst_filenames.qml'
--- tests/unit/tst_filenames.qml 1970-01-01 00:00:00 +0000
+++ tests/unit/tst_filenames.qml 2015-09-25 11:15:25 +0000
@@ -0,0 +1,116 @@
1
2import QtTest 1.0
3import QtQuick 2.4
4import Ubuntu.Components 1.2
5import Ubuntu.MediaScanner 0.1
6import Ubuntu.Test 1.0
7
8import "../../app/components"
9
10MainView {
11 // Wrapper function around decodeURIComponent() to prevent exceptions
12 // from bubbling up to the app.
13 function decodeFileURI(filename)
14 {
15 var newFilename = "";
16 try {
17 newFilename = decodeURIComponent(filename);
18 } catch (e) {
19 newFilename = filename;
20 console.log("Unicode decoding error:", filename, e.message)
21 }
22
23 return newFilename;
24 }
25
26 Item {
27 id: trackQueue
28
29 property ListModel model: ListModel {
30
31 }
32 }
33
34 /* Mediahub */
35 Player {
36 id: player
37 }
38
39 /* Mediascanner */
40 SongsModel {
41 id: songsModel
42 store: MediaStore {
43 id: musicStore
44 }
45 }
46
47 /* UnitTests */
48 UbuntuTestCase {
49 property var filepaths: [
50
51 ]
52
53 function init() {
54 // Wait for the async MediaPlayer to load
55 tryCompare(player, "loaded", true, 250, "Player has not loaded");
56 }
57
58 function init_data() {
59 return filepaths;
60 }
61
62 function initTestCase() {
63 // Build up filenames to test
64 var blacklist = [46, 47]; // '.', '/'
65
66 for (var i=32; i < 127; i++) {
67 if (blacklist.indexOf(i) > -1) {
68 continue;
69 } else {
70 var chr = String.fromCharCode(i);
71 filepaths.push({ filepath: "/home/phablet/Music/QMLTest/" + chr + ".ogg", tag: chr });
72 }
73 }
74 }
75
76 function test_mediascanner(data) {
77 var filepath = decodeFileURI(data.filepath);
78 var msResult = musicStore.lookup(filepath);
79
80 // Check lookup from ms2 returned something
81 verify(msResult !== null, "Mediascanner2 could not find track - " + filepath);
82
83 compare(msResult.title, "Test Sound", "Mediascanner title is not the same - " + filepath);
84 compare(msResult.album, "Test Album", "Mediascanner album is not the same - " + filepath);
85 compare(msResult.author, "Test Artist", "Mediascanner author is not the same - " + filepath);
86 compare(msResult.art, "image://albumart/artist=Test%20Artist&album=Test%20Album", "Mediascanner art is not the same - " + filepath);
87 }
88
89 function test_media_hub(data) {
90 if (data.tag === "#") { // manually skip otherwise media-hub crashes
91 // FIXME: MediaHub won't play '#' due to http://pad.lv/1449790
92 // expectFail("#", "MediaHub won't play '#' due to http://pad.lv/1449790")
93
94 /*
95 // FIXME: Not sure why this doesn't work, it should only skip this data row but it skips the test
96 if (data.tag === "#") {
97 skip("MediaHub won't play '#' due to http://pad.lv/1449790")
98 }
99 */
100 } else {
101 var filepath = data.filepath;
102
103 player.setSource(filepath);
104 player.play();
105
106 wait(1100); // Wait for the track to reach > 1s
107
108 // Check that track is playing and the position has changed
109 compare(player.isPlaying, true, "MediaHub is not playing the track - " + filepath);
110 verify(player.position > 0, "MediaHub position has not changed - " + filepath + " - " + player.position);
111
112 player.pause();
113 }
114 }
115 }
116}

Subscribers

People subscribed via source and target branches