Debian Codegraph @

tests/unit/components13/tst_label13.qml

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import QtTest 1.0
19 import Lomiri.Components 1.3
20
21 TestCase {
22 name: "Label13API"
23
24 function cleanup() {
25 textCustom.fontSize = "medium";
26 textCustom.font.weight = Font.Light;
27 }
28
29 function initTestCase() {
30 compare(textCustom.font.family, "Ubuntu", "Default font family");
31 compare(textCustom.font.weight, Font.Light, "Default font weight");
32 compare(textCustom.fontSize, "medium", "fontSize is 'medium' by default")
33 compare(textCustom.textSize, Label.Medium, "fontSize is 'medium' by default")
34 }
35
36 function test_fontSize_data() {
37 return [
38 {tag: "xx-small"},
39 {tag: "x-small"},
40 {tag: "small"},
41 {tag: "medium"},
42 {tag: "large"},
43 {tag: "x-large"},
44 ];
45 }
46 function test_fontSize(data) {
47 textCustom.fontSize = data.tag;
48 compare(textCustom.fontSize, data.tag, "Can set/get " + data.tag)
49 }
50
51 function test_textSize_data() {
52 return [
53 {tag: "XxSmall", size: Label.XxSmall},
54 {tag: "XSmall", size: Label.XSmall},
55 {tag: "Small", size: Label.Small},
56 {tag: "Medium", size: Label.Medium},
57 {tag: "Large", size: Label.Large},
58 {tag: "XLarge", size: Label.XLarge},
59 ];
60 }
61 function test_textSize(data) {
62 textCustom.textSize = data.tag;
63 compare(textCustom.textSize, data.size, "Can set/get " + data.tag)
64 }
65
66 // this must be executed on a Label which is tested only by this function
67 function test_textSize_suppresses_fontSize() {
68 textSizeTest.textSize = Label.XLarge;
69 textSizeTest.fontSize = "xx-small";
70 compare(textSizeTest.textSize, Label.XLarge, "fontSize overruled textSize!");
71 }
72
73 function test_fontSize_equals_textSize_data() {
74 return [
75 {tag: "xx-small", size: Label.XxSmall},
76 {tag: "x-small", size: Label.XSmall},
77 {tag: "small", size: Label.Small},
78 {tag: "medium", size: Label.Medium},
79 {tag: "large", size: Label.Large},
80 {tag: "x-large", size: Label.XLarge},
81 ];
82 }
83 function test_fontSize_equals_textSize(data) {
84 textFontSize.textSize = data.size;
85 fuzzyCompare(textFontSize.font.pixelSize, FontUtils.sizeToPixels(data.tag), 0.999, "pixelSize differs for " + data.tag);
86 }
87
88 function test_fontWeight_data() {
89 return [
90 {tag: "Light", weight: Font.Light},
91 {tag: "Normal", weight: Font.Normal},
92 {tag: "DemiBold", weight: Font.DemiBold},
93 {tag: "Bold", weight: Font.Bold},
94 {tag: "Black", weight: Font.Black},
95 ];
96 }
97 function test_fontWeight(data) {
98 textCustom.font.weight = data.weight
99 compare(textCustom.font.weight, data.weight, "can set/get " + data.weight);
100 }
101
102 function test_boldWeightConflict() {
103 compare(lightLabel.font.weight, Font.Light, "font.weight is not overriden by font.bold")
104 }
105
106 function test_weightPrecedence() {
107 compare(lightLabel2.font.weight, Font.Light, "font.weight takes precedence over font.bold")
108 }
109
110
111 function verifyAutomaticRenderType(label) {
112 if (units.gridUnit <= 10) {
113 compare(label.renderType, Text.NativeRendering,
114 "On low dpi screen renderType is Text.NativeRendering by default");
115 } else {
116 compare(label.renderType, Text.QtRendering,
117 "On high dpi screen renderType is Text.QtRendering by default");
118 }
119 }
120
121 function verifyManualRenderType(label, renderType) {
122 compare(label.renderType, renderType,
123 "renderType was set manually, no automatic change should happen to it");
124 }
125
126 function test_renderTypeDefault_data() {
127 return [
128 {tag: "Default", gridUnit: 8.0},
129 {tag: "HighDPI", gridUnit: 16.0},
130 {tag: "LowDPI", gridUnit: 10.0},
131 ];
132 }
133
134 function test_renderTypeDefault(data) {
135 verifyAutomaticRenderType(textRenderTypeDefault);
136 units.gridUnit = data.gridUnit;
137 verifyAutomaticRenderType(textRenderTypeDefault);
138 }
139
140 function test_presetRenderType_data() {
141 return test_renderTypeDefault_data();
142 }
143
144 function test_setRenderType() {
145 units.gridUnit = 8;
146 verifyAutomaticRenderType(textSetRenderType);
147 units.gridUnit = 16;
148 verifyAutomaticRenderType(textSetRenderType);
149
150 // set renderType manually
151 textSetRenderType.renderType = Text.NativeRendering;
152 verifyManualRenderType(textSetRenderType, Text.NativeRendering);
153
154 units.gridUnit = 8;
155 verifyManualRenderType(textSetRenderType, Text.NativeRendering);
156
157 units.gridUnit = 16;
158 verifyManualRenderType(textSetRenderType, Text.NativeRendering);
159 }
160
161 function test_colorGUPixelSize() {
162 units.gridUnit = 8;
163 textTestColorGUPixelSize.font.bold = true;
164 var pixelSizeAt8GU = textTestColorGUPixelSize.font.pixelSize;
165
166 units.gridUnit = 16;
167 textTestColorGUPixelSize.font.bold = false;
168 verify(textTestColorGUPixelSize.font.pixelSize > pixelSizeAt8GU);
169
170 units.gridUnit = 8;
171 textTestColorGUPixelSize.font.bold = true;
172 compare(textTestColorGUPixelSize.font.pixelSize, pixelSizeAt8GU);
173 }
174
175 Label {
176 id: textCustom
177 }
178 Label {
179 id: textFontSize
180 }
181
182 Label {
183 id: lightLabel
184 font.weight: Font.Light
185 }
186
187 Label {
188 id: lightLabel2
189 font.weight: Font.Light
190 font.bold: true
191 }
192
193 Label {
194 id: textSizeTest
195 }
196
197 Label {
198 id: textRenderTypeDefault
199 }
200
201 Label {
202 id: textRenderTypePreset
203 renderType: Text.QtRendering
204 }
205
206 Label {
207 id: textSetRenderType
208 }
209
210 Label {
211 id: textTestColorGUPixelSize
212 }
213 }