27cb75fd3004ebd026146dbdeace55ecda2431e7
[profile/ivi/qtdeclarative.git] / tests / auto / qmltest / borderimage / tst_borderimage.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 2.0
43 import QtTest 1.0
44
45 Item {
46     id: top
47
48     BorderImage {
49         id: noSource
50         source: ""
51     }
52
53     property string srcImage: "colors.png"
54
55     BorderImage {
56         id: clearSource
57         source: srcImage
58     }
59
60     BorderImage {
61         id: resized
62         source: "colors.png"
63         width: 300
64         height: 300
65     }
66
67     BorderImage {
68         id: smooth
69         source: "colors.png"
70         smooth: true
71         width: 300
72         height: 300
73     }
74
75     BorderImage {
76         id: tileModes1
77         source: "colors.png"
78         width: 100
79         height: 300
80         horizontalTileMode: BorderImage.Repeat
81         verticalTileMode: BorderImage.Repeat
82     }
83
84     BorderImage {
85         id: tileModes2
86         source: "colors.png"
87         width: 300
88         height: 150
89         horizontalTileMode: BorderImage.Round
90         verticalTileMode: BorderImage.Round
91     }
92
93     TestCase {
94         name: "BorderImage"
95
96         function test_noSource() {
97             compare(noSource.source, "")
98             compare(noSource.width, 0)
99             compare(noSource.height, 0)
100             compare(noSource.horizontalTileMode, BorderImage.Stretch)
101             compare(noSource.verticalTileMode, BorderImage.Stretch)
102         }
103
104         function test_imageSource_data() {
105             return [
106                 {
107                     tag: "local",
108                     source: "colors.png",
109                     remote: false,
110                     error: ""
111                 },
112                 {
113                     tag: "local not found",
114                     source: "no-such-file.png",
115                     remote: false,
116                     error: "SUBinline:1:21: QML BorderImage: Cannot open: SUBno-such-file.png"
117                 }
118                 // TODO: remote tests that need to use http
119             ]
120         }
121
122         function test_imageSource(row) {
123             var expectError = (row.error.length != 0)
124             if (expectError) {
125                 var parentUrl = Qt.resolvedUrl(".")
126                 ignoreWarning(row.error.replace(/SUB/g, parentUrl))
127             }
128
129             var img = Qt.createQmlObject
130                 ('import QtQuick 1.0; BorderImage { source: "' +
131                     row.source + '" }', top)
132
133             if (row.remote)
134                 tryCompare(img, "status", BorderImage.Loading)
135
136             if (!expectError) {
137                 tryCompare(img, "status", BorderImage.Ready)
138                 compare(img.width, 120)
139                 compare(img.height, 120)
140                 compare(img.horizontalTileMode, BorderImage.Stretch)
141                 compare(img.verticalTileMode, BorderImage.Stretch)
142             } else {
143                 tryCompare(img, "status", BorderImage.Error)
144             }
145
146             img.destroy()
147         }
148
149         function test_clearSource() {
150             compare(clearSource.source, Qt.resolvedUrl("colors.png"))
151             compare(clearSource.width, 120)
152             compare(clearSource.height, 120)
153
154             srcImage = ""
155             compare(clearSource.source, "")
156             compare(clearSource.width, 0)
157             compare(clearSource.height, 0)
158         }
159
160         function test_resized() {
161             compare(resized.width, 300)
162             compare(resized.height, 300)
163             compare(resized.horizontalTileMode, BorderImage.Stretch)
164             compare(resized.verticalTileMode, BorderImage.Stretch)
165         }
166
167         function test_smooth() {
168             compare(smooth.smooth, true)
169             compare(smooth.width, 300)
170             compare(smooth.height, 300)
171             compare(smooth.horizontalTileMode, BorderImage.Stretch)
172             compare(smooth.verticalTileMode, BorderImage.Stretch)
173         }
174
175         function test_tileModes() {
176             compare(tileModes1.width, 100)
177             compare(tileModes1.height, 300)
178             compare(tileModes1.horizontalTileMode, BorderImage.Repeat)
179             compare(tileModes1.verticalTileMode, BorderImage.Repeat)
180
181             compare(tileModes2.width, 300)
182             compare(tileModes2.height, 150)
183             compare(tileModes2.horizontalTileMode, BorderImage.Round)
184             compare(tileModes2.verticalTileMode, BorderImage.Round)
185         }
186
187         function test_sciSource_data() {
188             return [
189                 {
190                     tag: "local",
191                     source: "colors-round.sci",
192                     remote: false,
193                     valid: true
194                 },
195                 {
196                     tag: "local not found",
197                     source: "no-such-file.sci",
198                     remote: false,
199                     valid: false
200                 }
201                 // TODO: remote tests that need to use http
202             ]
203         }
204
205         function test_sciSource(row) {
206             var img = Qt.createQmlObject
207                 ('import QtQuick 1.0; BorderImage { source: "' +
208                     row.source + '"; width: 300; height: 300 }', top)
209
210             if (row.remote)
211                 tryCompare(img, "status", BorderImage.Loading)
212
213             compare(img.source, Qt.resolvedUrl(row.source))
214             compare(img.width, 300)
215             compare(img.height, 300)
216
217             if (row.valid) {
218                 tryCompare(img, "status", BorderImage.Ready)
219                 compare(img.border.left, 10)
220                 compare(img.border.top, 20)
221                 compare(img.border.right, 30)
222                 compare(img.border.bottom, 40)
223                 compare(img.horizontalTileMode, BorderImage.Round)
224                 compare(img.verticalTileMode, BorderImage.Repeat)
225             } else {
226                 tryCompare(img, "status", BorderImage.Error)
227             }
228
229             img.destroy()
230         }
231
232
233         function test_invalidSciFile() {
234             ignoreWarning("QQuickGridScaledImage: Invalid tile rule specified. Using Stretch.") // for "Roun"
235             ignoreWarning("QQuickGridScaledImage: Invalid tile rule specified. Using Stretch.") // for "Repea"
236
237             var component = Qt.createComponent("InvalidSciFile.qml")
238             var invalidSciFile = component.createObject(top)
239
240             compare(invalidSciFile.status, Image.Error)
241             compare(invalidSciFile.width, 300)
242             compare(invalidSciFile.height, 300)
243             compare(invalidSciFile.horizontalTileMode, BorderImage.Stretch)
244             compare(invalidSciFile.verticalTileMode, BorderImage.Stretch)
245         }
246     }
247 }