Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
47c733bb
Commit
47c733bb
authored
Oct 21, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(InvertedMouseArea): add spec file to test emitted signals
parent
521b9681
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
189 additions
and
25 deletions
+189
-25
test_qml
tests/tools/test_qml
+5
-2
ListForm.qml
tests/ui/modules/Common/Form/ListForm.qml
+0
-1
InvertedMouseArea.qml
tests/ui/modules/Common/InvertedMouseArea.qml
+4
-5
InvertedMouseArea.spec.qml
tests/ui/modules/Common/InvertedMouseArea.spec.qml
+84
-0
SearchBox.qml
tests/ui/modules/Common/SearchBox.qml
+1
-3
utils.js
tests/ui/scripts/Utils/utils.js
+37
-9
utils.spec.qml
tests/ui/scripts/Utils/utils.spec.qml
+58
-5
No files found.
tests/tools/test_qml
View file @
47c733bb
...
...
@@ -4,10 +4,13 @@
# Tool to run unit tests on all `*.spec.qml` files.
# ====================================================================
RESOURCES_FILE
=
'resources.qrc'
TEST_RUNNER
=
'qmltestrunner-qt5'
RESOURCES_FILE
=
'resources.qrc'
TEST_FILE_EXTENSION
=
'spec.qml'
MODULES_PATH
=
'./ui/modules'
SCRIPTS_PATH
=
'./ui/scripts'
RED
=
'\e[1;31m'
GREEN
=
'\e[1;32m'
...
...
@@ -43,7 +46,7 @@ do
if
[
-f
$spec_qml_file
]
;
then
printf
"
${
BLUE
}
Running unit qml tests of '
${
qml_file
}
'...
${
NC
}
\n
"
$TEST_RUNNER
-import
$MODULES_PATH
-input
"
$spec_qml_file
"
$TEST_RUNNER
-import
$MODULES_PATH
-i
mport
$SCRIPTS_PATH
-i
nput
"
$spec_qml_file
"
if
[[
$?
==
0
]]
;
then
printf
"
${
GREEN
}
All unit tests have succeeded for '
${
spec_qml_file
}
'.
\n
"
...
...
tests/ui/modules/Common/Form/ListForm.qml
View file @
47c733bb
...
...
@@ -122,7 +122,6 @@ RowLayout {
InvertedMouseArea
{
enabled
:
textEdit
.
activeFocus
height
:
textEdit
.
height
parent
:
parent
width
:
textEdit
.
width
onPressed
:
textEdit
.
focus
=
false
...
...
tests/ui/modules/Common/InvertedMouseArea.qml
View file @
47c733bb
...
...
@@ -41,8 +41,8 @@ Item {
return
(
point
.
x
>=
item
.
x
&&
point
.
y
>=
item
.
y
&&
point
.
x
<
=
item
.
x
+
item
.
width
&&
point
.
y
<
=
item
.
y
+
item
.
height
point
.
x
<
item
.
x
+
item
.
width
&&
point
.
y
<
item
.
y
+
item
.
height
)
}
...
...
@@ -50,9 +50,8 @@ Item {
// See: http://doc.qt.io/qt-5/qml-qtqml-component.html#completed-signal
//
// The creation order of components in a view is undefined,
// so the mouse area must be created only when `enabled === true`.
//
// In the first render, `enabled` must be equal to false.
// so the mouse area must be created only when the target component
// was completed.
Component.onCompleted
:
enabled
&&
_createMouseArea
()
Component.onDestruction
:
_deleteMouseArea
()
...
...
tests/ui/modules/Common/InvertedMouseArea.spec.qml
0 → 100644
View file @
47c733bb
import
QtQuick
2.7
import
QtTest
1.1
import
Utils
1.0
// ===================================================================
Rectangle
{
id
:
root
color
:
'
violet
'
height
:
200
width
:
300
Rectangle
{
id
:
item
color
:
'
pink
'
height
:
80
width
:
100
x
:
120
y
:
100
InvertedMouseArea
{
id
:
invertedMouseArea
anchors.fill
:
parent
}
}
SignalSpy
{
id
:
spy
signalName
:
'
pressed
'
}
TestCase
{
when
:
windowShown
function
test_randomInsideMouseArea
()
{
var
failFun
=
function
()
{
fail
(
'
`pressed` signal was emitted.
'
)
}
invertedMouseArea
.
pressed
.
connect
(
failFun
)
Utils
.
times
(
100
,
function
()
{
var
x
=
Math
.
floor
(
Utils
.
genRandomNumber
(
item
.
x
,
item
.
x
+
width
))
var
y
=
Math
.
floor
(
Utils
.
genRandomNumber
(
item
.
y
,
item
.
y
+
height
))
mouseClick
(
root
,
x
,
y
)
})
wait
(
100
)
invertedMouseArea
.
pressed
.
disconnect
(
failFun
)
}
function
test_randomOutsideMouseArea
()
{
spy
.
target
=
invertedMouseArea
Utils
.
times
(
50
,
function
()
{
var
x
=
Math
.
floor
(
Utils
.
genRandomNumberBetweenIntervals
([
[
0
,
item
.
x
],
[
item
.
x
+
item
.
width
,
root
.
width
]
]))
var
y
=
Math
.
floor
(
Utils
.
genRandomNumberBetweenIntervals
([
[
0
,
item
.
y
],
[
item
.
y
+
item
.
height
,
root
.
height
]
]))
mouseClick
(
root
,
x
,
y
)
spy
.
wait
(
100
)
})
Utils
.
times
(
50
,
function
()
{
var
x
=
Math
.
floor
(
Utils
.
genRandomNumber
(
item
.
x
,
item
.
x
+
item
.
width
))
var
y
=
Math
.
floor
(
Utils
.
genRandomNumberBetweenIntervals
([
[
0
,
item
.
y
],
[
item
.
y
+
item
.
height
,
root
.
height
]
]))
mouseClick
(
root
,
x
,
y
)
spy
.
wait
(
100
)
})
}
}
}
tests/ui/modules/Common/SearchBox.qml
View file @
47c733bb
...
...
@@ -79,10 +79,8 @@ Item {
}
InvertedMouseArea
{
anchors.fill
:
parent
enabled
:
menu
.
visible
height
:
parent
.
height
parent
:
parent
width
:
parent
.
width
onPressed
:
_hideMenu
()
}
...
...
tests/ui/scripts/Utils/utils.js
View file @
47c733bb
...
...
@@ -30,15 +30,7 @@ function openWindow (window, parent, options) {
object
=
component
.
createObject
(
parent
)
}
console
.
debug
(
'
Open window.
'
)
object
.
closing
.
connect
(
function
()
{
console
.
debug
(
'
Destroy window.
'
)
object
.
destroy
()
})
object
.
exitStatus
.
connect
(
function
(
status
)
{
console
.
debug
(
'
Exit status:
'
+
status
)
})
object
.
closing
.
connect
(
object
.
destroy
.
bind
(
object
))
if
(
options
&&
options
.
exitHandler
)
{
object
.
exitStatus
.
connect
(
...
...
@@ -135,3 +127,39 @@ function times (n, cb, context) {
function
isString
(
string
)
{
return
typeof
string
===
'
string
'
||
string
instanceof
String
}
// -------------------------------------------------------------------
// Generate a random number in the [min, max[ interval.
// Uniform distrib.
function
genRandomNumber
(
min
,
max
)
{
return
Math
.
random
()
*
(
max
-
min
)
+
min
}
// -------------------------------------------------------------------
// Generate a random number between a set of intervals.
// The `intervals` param must be orderer like this:
// `[ [ 1, 4 ], [ 8, 16 ], [ 22, 25 ] ]`
function
genRandomNumberBetweenIntervals
(
intervals
)
{
// Compute the number of values.
var
size
=
0
intervals
.
forEach
(
function
(
interval
)
{
size
+=
interval
[
1
]
-
interval
[
0
]
})
// Generate a value in the interval: `[0, size[`
var
n
=
genRandomNumber
(
0
,
size
)
// Map the value in the right interval.
n
+=
intervals
[
0
][
0
]
for
(
var
i
=
0
;
i
<
intervals
.
length
-
1
;
i
++
)
{
if
(
n
<
intervals
[
i
][
1
])
{
break
}
n
+=
intervals
[
i
+
1
][
0
]
-
intervals
[
i
][
1
]
}
return
n
}
tests/ui/scripts/Utils/utils.spec.qml
View file @
47c733bb
...
...
@@ -99,11 +99,6 @@ TestCase {
failed
=
true
})
// Simulate time
Utils
.
times
(
500000
,
function
(
i
)
{
// Nothing.
})
if
(
failed
)
{
fail
(
'
`setTimeout` callback was called before `wait`.
'
)
}
...
...
@@ -160,4 +155,62 @@ TestCase {
function
test_isString
(
data
)
{
compare
(
Utils
.
isString
(
data
.
input
),
data
.
output
)
}
// -----------------------------------------------------------------
function
test_genRandomNumber_data
()
{
return
[
{
min
:
42
,
max
:
3600
},
{
min
:
10
,
max
:
100
},
{
min
:
58
,
max
:
61
},
{
min
:
2
,
max
:
3
}
]
}
function
test_genRandomNumber
(
data
)
{
Utils
.
times
(
10
,
function
()
{
var
n
=
Utils
.
genRandomNumber
(
data
.
min
,
data
.
max
)
compare
(
n
>=
data
.
min
&&
n
<
data
.
max
,
true
)
})
}
function
test_genRandomNumberId
()
{
compare
(
Utils
.
genRandomNumber
(
42
,
42
),
42
)
}
// -----------------------------------------------------------------
function
test_genRandomNumberBetweenIntervals_data
()
{
return
[
{
intervals
:
[
[
1
,
5
]
]
},
{
intervals
:
[
[
8
,
9
],
[
10
,
15
]
]
},
{
intervals
:
[
[
1
,
4
],
[
8
,
16
],
[
22
,
25
]
]
},
{
intervals
:
[
[
11
,
12
],
[
50
,
80
],
[
92
,
93
],
[
1000
,
1100
]
]
},
{
intervals
:
[
[
-
5
,
-
2
]
]
},
{
intervals
:
[
[
-
5
,
-
2
],
[
12
,
14
]
]
},
{
intervals
:
[
[
-
127
,
-
111
],
[
-
35
,
-
14
],
[
1256
,
1270
],
[
10000
,
10020
]
]
}
]
}
function
test_genRandomNumberBetweenIntervals
(
data
)
{
var
intervals
=
data
.
intervals
Utils
.
times
(
10
,
function
()
{
var
n
=
Utils
.
genRandomNumberBetweenIntervals
(
intervals
)
var
soFarSoGood
=
false
for
(
var
i
=
0
;
i
<
intervals
.
length
;
i
++
)
{
if
(
n
>=
intervals
[
i
][
0
]
&&
n
<
intervals
[
i
][
1
])
{
soFarSoGood
=
true
break
}
}
compare
(
soFarSoGood
,
true
,
'
The generated number cannot be found in a interval.
'
)
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment