File: tst_label13.qml

package info (click to toggle)
lomiri-ui-toolkit 1.3.5110%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,436 kB
  • sloc: cpp: 85,830; python: 5,537; sh: 1,344; javascript: 919; ansic: 573; makefile: 204
file content (213 lines) | stat: -rw-r--r-- 6,615 bytes parent folder | download | duplicates (2)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * Copyright 2015 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import QtTest 1.0
import Lomiri.Components 1.3

TestCase {
    name: "Label13API"

    function cleanup() {
        textCustom.fontSize = "medium";
        textCustom.font.weight = Font.Light;
    }

    function initTestCase() {
        compare(textCustom.font.family, "Noto Sans", "Default font family");
        compare(textCustom.font.weight, Font.Light, "Default font weight");
        compare(textCustom.fontSize, "medium", "fontSize is 'medium' by default")
        compare(textCustom.textSize, Label.Medium, "fontSize is 'medium' by default")
    }

    function test_fontSize_data() {
        return [
            {tag: "xx-small"},
            {tag: "x-small"},
            {tag: "small"},
            {tag: "medium"},
            {tag: "large"},
            {tag: "x-large"},
        ];
    }
    function test_fontSize(data) {
        textCustom.fontSize = data.tag;
        compare(textCustom.fontSize, data.tag, "Can set/get " + data.tag)
    }

    function test_textSize_data() {
        return [
            {tag: "XxSmall", size: Label.XxSmall},
            {tag: "XSmall", size: Label.XSmall},
            {tag: "Small", size: Label.Small},
            {tag: "Medium", size: Label.Medium},
            {tag: "Large", size: Label.Large},
            {tag: "XLarge", size: Label.XLarge},
        ];
    }
    function test_textSize(data) {
        textCustom.textSize = data.tag;
        compare(textCustom.textSize, data.size, "Can set/get " + data.tag)
    }

    // this must be executed on a Label which is tested only by this function
    function test_textSize_suppresses_fontSize() {
        textSizeTest.textSize = Label.XLarge;
        textSizeTest.fontSize = "xx-small";
        compare(textSizeTest.textSize, Label.XLarge, "fontSize overruled textSize!");
    }

    function test_fontSize_equals_textSize_data() {
        return [
            {tag: "xx-small", size: Label.XxSmall},
            {tag: "x-small", size: Label.XSmall},
            {tag: "small", size: Label.Small},
            {tag: "medium", size: Label.Medium},
            {tag: "large", size: Label.Large},
            {tag: "x-large", size: Label.XLarge},
        ];
    }
    function test_fontSize_equals_textSize(data) {
        textFontSize.textSize = data.size;
        fuzzyCompare(textFontSize.font.pixelSize, FontUtils.sizeToPixels(data.tag), 0.999, "pixelSize differs for " + data.tag);
    }

    function test_fontWeight_data() {
        return [
            {tag: "Light", weight: Font.Light},
            {tag: "Normal", weight: Font.Normal},
            {tag: "DemiBold", weight: Font.DemiBold},
            {tag: "Bold", weight: Font.Bold},
            {tag: "Black", weight: Font.Black},
        ];
    }
    function test_fontWeight(data) {
        textCustom.font.weight = data.weight
        compare(textCustom.font.weight, data.weight, "can set/get " + data.weight);
    }

    function test_boldWeightConflict() {
        compare(lightLabel.font.weight, Font.Light, "font.weight is not overriden by font.bold")
    }

    function test_weightPrecedence() {
        compare(lightLabel2.font.weight, Font.Light, "font.weight takes precedence over font.bold")
    }


    function verifyAutomaticRenderType(label) {
        if (units.gridUnit <= 10) {
            compare(label.renderType, Text.NativeRendering,
                    "On low dpi screen renderType is Text.NativeRendering by default");
        } else {
            compare(label.renderType, Text.QtRendering,
                    "On high dpi screen renderType is Text.QtRendering by default");
        }
    }

    function verifyManualRenderType(label, renderType) {
        compare(label.renderType, renderType,
                "renderType was set manually, no automatic change should happen to it");
    }

    function test_renderTypeDefault_data() {
        return [
            {tag: "Default", gridUnit: 8.0},
            {tag: "HighDPI", gridUnit: 16.0},
            {tag: "LowDPI", gridUnit: 10.0},
        ];
    }

    function test_renderTypeDefault(data) {
        verifyAutomaticRenderType(textRenderTypeDefault);
        units.gridUnit = data.gridUnit;
        verifyAutomaticRenderType(textRenderTypeDefault);
    }

    function test_presetRenderType_data() {
        return test_renderTypeDefault_data();
    }

    function test_setRenderType() {
        units.gridUnit = 8;
        verifyAutomaticRenderType(textSetRenderType);
        units.gridUnit = 16;
        verifyAutomaticRenderType(textSetRenderType);

        // set renderType manually
        textSetRenderType.renderType = Text.NativeRendering;
        verifyManualRenderType(textSetRenderType, Text.NativeRendering);

        units.gridUnit = 8;
        verifyManualRenderType(textSetRenderType, Text.NativeRendering);

        units.gridUnit = 16;
        verifyManualRenderType(textSetRenderType, Text.NativeRendering);
    }

    function test_colorGUPixelSize() {
        units.gridUnit = 8;
        textTestColorGUPixelSize.font.bold = true;
        var pixelSizeAt8GU = textTestColorGUPixelSize.font.pixelSize;

        units.gridUnit = 16;
        textTestColorGUPixelSize.font.bold = false;
        verify(textTestColorGUPixelSize.font.pixelSize > pixelSizeAt8GU);

        units.gridUnit = 8;
        textTestColorGUPixelSize.font.bold = true;
        compare(textTestColorGUPixelSize.font.pixelSize, pixelSizeAt8GU);
    }

    Label {
        id: textCustom
    }
    Label {
        id: textFontSize
    }

    Label {
        id: lightLabel
        font.weight: Font.Light
    }

    Label {
        id: lightLabel2
        font.weight: Font.Light
        font.bold: true
    }

    Label {
        id: textSizeTest
    }

    Label {
        id: textRenderTypeDefault
    }

    Label {
        id: textRenderTypePreset
        renderType: Text.QtRendering
    }

    Label {
        id: textSetRenderType
    }

    Label {
        id: textTestColorGUPixelSize
    }
}