tst_gridlayout.qml: convert to a proper data-driven test

Change-Id: I9f2ccd3d4e6933d68b03d82c2c319aa2e8951e78
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Mitch Curtis 2019-09-11 14:20:19 +02:00
parent d52e92469d
commit b1b284e3ce
1 changed files with 26 additions and 13 deletions

View File

@ -60,8 +60,8 @@ Item {
id: testCase id: testCase
name: "Tests_GridLayout" name: "Tests_GridLayout"
when: windowShown when: windowShown
width: 200 width: parent.width
height: 200 height: parent.height
Component { Component {
id: layout_flow_Component id: layout_flow_Component
@ -851,24 +851,37 @@ Item {
} }
} }
function test_spacings() function test_spacings_data()
{
let data = [
{ spacing: Number.NaN },
{ spacing: 0 },
{ spacing: 10 },
{ spacing: -5 },
{ spacing: -19 }
]
for (let i = 0; i < data.length; ++i) {
data[i].tag = data[i].spacing.toString()
}
return data
}
function test_spacings(data)
{ {
var layout = layout_spacings_Component.createObject(container); var layout = layout_spacings_Component.createObject(container);
// breaks down below -19. This is acceptable, since it means that the implicit size of the layout is negative // breaks down below -19. This is acceptable, since it means that the implicit size of the layout is negative
var testSpacings = [Number.NaN, 0, 10, -5, -19] var testSpacings = [Number.NaN, 0, 10, -5, -19]
layout.rowSpacing = 0 layout.rowSpacing = 0
for (var i = 0; i < testSpacings.length; ++i) { var spacing = data.spacing
var sp = testSpacings[i] if (isNaN(spacing)) {
if (isNaN(sp)) { spacing = 5 // Test defaults
sp = 5 // Test defaults } else {
} else { layout.columnSpacing = spacing
layout.columnSpacing = sp
}
tryCompare(layout.children[0], "itemRect", [ 0, 0, 10, 10])
tryCompare(layout.children[1], "itemRect", [10 + sp, 0, 10, 10])
compare(layout.implicitWidth, 20 + sp)
} }
tryCompare(layout.children[0], "itemRect", [ 0, 0, 10, 10])
tryCompare(layout.children[1], "itemRect", [10 + spacing, 0, 10, 10])
compare(layout.implicitWidth, 20 + spacing)
// do not crash // do not crash
layout.columnSpacing = -100 layout.columnSpacing = -100