2024-10-10 12:34:03 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtTest 1.15
|
2023-04-14 08:18:56 +00:00
|
|
|
|
2022-04-19 17:47:30 +00:00
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.TestHelpers 0.1
|
|
|
|
|
|
|
|
Item {
|
2022-05-03 12:16:22 +00:00
|
|
|
id: root
|
2022-04-19 17:47:30 +00:00
|
|
|
width: 400
|
|
|
|
height: 300
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: noSourceComponent
|
|
|
|
|
|
|
|
StatusImageCropPanel {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
windowStyle: StatusImageCrop.WindowStyle.Rounded
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 12:16:22 +00:00
|
|
|
property url testImageUrl: `${Qt.resolvedUrl(".")}../../sandbox/demoapp/data/logo-test-image.png`
|
|
|
|
|
2022-04-19 17:47:30 +00:00
|
|
|
Component {
|
|
|
|
id: withSourceComponent
|
|
|
|
|
|
|
|
StatusImageCropPanel {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
// TODO: generate test image and break the sandbox dependency
|
2022-05-03 12:16:22 +00:00
|
|
|
source: root.testImageUrl
|
2022-04-19 17:47:30 +00:00
|
|
|
windowStyle: StatusImageCrop.WindowStyle.Rectangular
|
|
|
|
Component.onCompleted: setCropRect(Qt.rect(10, 0, sourceSize.width - 20, sourceSize.height))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: testLoader
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
active: false
|
|
|
|
}
|
|
|
|
|
|
|
|
TestCase {
|
|
|
|
id: qmlWarningsTest
|
|
|
|
|
2022-05-03 12:16:22 +00:00
|
|
|
name: "StatusImageCropPanel"
|
2022-04-19 17:47:30 +00:00
|
|
|
|
|
|
|
when: windowShown
|
|
|
|
|
|
|
|
//
|
|
|
|
// Test guards
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
qtOuput.restartCapturing()
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
testLoader.active = false
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tests
|
|
|
|
|
|
|
|
function test_no_source_initialization() {
|
|
|
|
testLoader.sourceComponent = noSourceComponent
|
|
|
|
testLoader.active = true
|
|
|
|
verify(waitForRendering(testLoader.item))
|
|
|
|
testLoader.active = false
|
|
|
|
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_with_source_initialization() {
|
|
|
|
testLoader.sourceComponent = withSourceComponent
|
|
|
|
testLoader.active = true
|
|
|
|
verify(waitForRendering(testLoader.item))
|
|
|
|
testLoader.active = false
|
2022-05-03 12:16:22 +00:00
|
|
|
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_setCrop_error_if_no_source_regression() {
|
|
|
|
testLoader.sourceComponent = noSourceComponent
|
|
|
|
testLoader.active = true
|
|
|
|
verify(waitForRendering(testLoader.item))
|
|
|
|
testLoader.item.setCropRect(Qt.rect(10, 10, 300, 300))
|
|
|
|
verify(qtOuput.qtOuput().length !== 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
|
|
|
|
qtOuput.restartCapturing()
|
|
|
|
testLoader.item.source = root.testImageUrl
|
|
|
|
verify(waitForRendering(testLoader.item))
|
|
|
|
testLoader.active = false
|
2022-04-19 17:47:30 +00:00
|
|
|
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MonitorQtOutput {
|
|
|
|
id: qtOuput
|
|
|
|
}
|
|
|
|
}
|