1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Window
import QtTest
import QtQuick.Templates as T
import QtQuick.Controls
import QtQuick.Controls.Imagine
import QtQuick.Controls.Imagine.impl
TestCase {
id: testCase
width: 200
height: 200
visible: true
when: windowShown
name: "Imagine"
Component {
id: buttonComponent
Button {}
}
Component {
id: implicitQrcButtonComponent
Button {
Imagine.path: ":/control-assets"
}
}
Component {
id: explicitQrcButtonComponent
Button {
Imagine.path: "qrc:/control-assets"
}
}
function test_qrcPaths_data() {
return [
{ tag: ":/control-assets", component: implicitQrcButtonComponent },
{ tag: "qrc:/control-assets", component: explicitQrcButtonComponent }
]
}
function test_qrcPaths(data) {
if (Qt.platform.pluginName === "offscreen")
skip("grabImage() is not functional on the offscreen platform (QTBUG-63185)")
var control = createTemporaryObject(data.component, testCase)
verify(control)
compare(control.Imagine.path, data.tag)
var image = grabImage(control)
compare(image.pixel(control.width / 2, control.height / 2), "#ff0000")
}
function test_fontFromConfigFile() {
var control = createTemporaryObject(buttonComponent, testCase)
verify(control)
compare(control.font.pixelSize, 80)
}
Component {
id: ninePatchImageComponent
NinePatchImage {
property alias mouseArea: mouseArea
MouseArea {
id: mouseArea
anchors.fill: parent
// The name of the images isn't important; we just want to check that
// going from regular to 9-patch to regular to regular works without crashing.
onPressed: parent.source = "qrc:/control-assets/button-background.9.png"
onReleased: parent.source = "qrc:/test-assets/button-background-1.png"
onClicked: parent.source = "qrc:/test-assets/button-background-2.png"
}
}
}
Component {
id: signalSpyComponent
SignalSpy {}
}
// QTBUG-78790
function test_switchBetween9PatchAndRegular() {
var ninePatchImage = createTemporaryObject(ninePatchImageComponent, testCase,
{ source: "qrc:/test-assets/button-background-1.png" })
verify(ninePatchImage)
var clickSpy = signalSpyComponent.createObject(ninePatchImage,
{ target: ninePatchImage.mouseArea, signalName: "clicked" })
verify(clickSpy.valid)
var afterRenderingSpy = signalSpyComponent.createObject(ninePatchImage,
{ target: testCase.Window.window, signalName: "afterRendering" })
verify(afterRenderingSpy.valid)
mousePress(ninePatchImage)
// Wait max 1 second - in reality it should take a handful of milliseconds.
afterRenderingSpy.wait(1000)
mouseRelease(ninePatchImage)
compare(clickSpy.count, 1)
// Shouldn't result in a crash.
afterRenderingSpy.wait(1000)
}
Component {
id: invalidNinePatchImageProvider
Item {
width: 200
height: 200
property alias ninePatchImage: np
NinePatchImage {
id: np
source : "qrc:/test-assets/button-background-1.png"
cache: false
visible: false
}
ShaderEffect {
width: 200
height: 200
property variant source: np
property real amplitude: 0.04
property real frequency: 20
property real time: 0
fragmentShader: "qrc:/test-assets/wobble.frag.qsb"
}
}
}
// QTBUG-100508
function test_invalidNinePatchImageProvider() {
var container = createTemporaryObject(invalidNinePatchImageProvider, testCase)
verify(container);
var afterRenderingSpy = signalSpyComponent.createObject(null,
{ target: testCase.Window.window, signalName: "afterRendering" })
verify(afterRenderingSpy.valid)
afterRenderingSpy.wait(1000)
container.ninePatchImage.source = ""
// Shouldn't result in a crash.
afterRenderingSpy.wait(1000)
}
}
|