2015-01-30 19:57:40 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2015-03-04 15:54:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
|
|
|
** You may use this file under the terms of the BSD license as follows:
|
|
|
|
**
|
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
|
|
|
** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
|
** contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
2015-01-30 19:57:40 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
import QtQuick 2.2
|
|
|
|
import QtTest 1.0
|
2015-09-30 15:47:36 +00:00
|
|
|
import Qt.labs.controls 1.0
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
TestCase {
|
|
|
|
id: testCase
|
|
|
|
width: 200
|
|
|
|
height: 200
|
|
|
|
visible: true
|
|
|
|
when: windowShown
|
|
|
|
name: "StackView"
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
Item { id: item }
|
2015-01-30 19:57:40 +00:00
|
|
|
TextField { id: textField }
|
|
|
|
Component { id: component; Item { } }
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: stackView
|
|
|
|
StackView { }
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_initialItem() {
|
2015-06-29 17:14:55 +00:00
|
|
|
var control1 = stackView.createObject(testCase)
|
|
|
|
verify(control1)
|
|
|
|
compare(control1.currentItem, null)
|
2015-01-30 19:57:40 +00:00
|
|
|
control1.destroy()
|
|
|
|
|
2015-06-29 17:14:55 +00:00
|
|
|
var control2 = stackView.createObject(testCase, {initialItem: item})
|
|
|
|
verify(control2)
|
|
|
|
compare(control2.currentItem, item)
|
2015-01-30 19:57:40 +00:00
|
|
|
control2.destroy()
|
2015-06-29 17:14:55 +00:00
|
|
|
|
|
|
|
var control3 = stackView.createObject(testCase, {initialItem: component})
|
|
|
|
verify(control3)
|
|
|
|
verify(control3.currentItem)
|
|
|
|
control3.destroy()
|
2015-01-30 19:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_currentItem() {
|
|
|
|
var control = stackView.createObject(testCase, {initialItem: item})
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.currentItem, item)
|
|
|
|
control.push(component)
|
|
|
|
verify(control.currentItem !== item)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.pop(StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.currentItem, item)
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_busy() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.busy, false)
|
|
|
|
control.push(component)
|
|
|
|
compare(control.busy, false)
|
|
|
|
control.push(component)
|
|
|
|
compare(control.busy, true)
|
|
|
|
tryCompare(control, "busy", false)
|
|
|
|
control.pop()
|
|
|
|
compare(control.busy, true)
|
|
|
|
tryCompare(control, "busy", false)
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_status() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
var item1 = component.createObject(control)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item1.StackView.status, StackView.Inactive)
|
2015-01-30 19:57:40 +00:00
|
|
|
control.push(item1)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item1.StackView.status, StackView.Active)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
var item2 = component.createObject(control)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.status, StackView.Inactive)
|
2015-01-30 19:57:40 +00:00
|
|
|
control.push(item2)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.status, StackView.Activating)
|
|
|
|
compare(item1.StackView.status, StackView.Deactivating)
|
|
|
|
tryCompare(item2.StackView, "status", StackView.Active)
|
|
|
|
tryCompare(item1.StackView, "status", StackView.Inactive)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
control.pop()
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.status, StackView.Deactivating)
|
|
|
|
compare(item1.StackView.status, StackView.Activating)
|
|
|
|
tryCompare(item2.StackView, "status", StackView.Inactive)
|
|
|
|
tryCompare(item1.StackView, "status", StackView.Active)
|
2015-03-28 20:51:10 +00:00
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_index() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-03-28 20:51:10 +00:00
|
|
|
|
|
|
|
var item1 = component.createObject(control)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item1.StackView.index, -1)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(item1, StackView.Immediate)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item1.StackView.index, 0)
|
2015-03-28 20:51:10 +00:00
|
|
|
|
|
|
|
var item2 = component.createObject(control)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.index, -1)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(item2, StackView.Immediate)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.index, 1)
|
|
|
|
compare(item1.StackView.index, 0)
|
2015-03-28 20:51:10 +00:00
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
control.pop(StackView.Immediate)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.index, -1)
|
|
|
|
compare(item1.StackView.index, 0)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
2015-06-30 11:39:43 +00:00
|
|
|
function test_view() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-06-30 11:39:43 +00:00
|
|
|
|
|
|
|
var item1 = component.createObject(control)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item1.StackView.view, null)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(item1, StackView.Immediate)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item1.StackView.view, control)
|
2015-06-30 11:39:43 +00:00
|
|
|
|
|
|
|
var item2 = component.createObject(control)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.view, null)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(item2, StackView.Immediate)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.view, control)
|
|
|
|
compare(item1.StackView.view, control)
|
2015-06-30 11:39:43 +00:00
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
control.pop(StackView.Immediate)
|
2015-09-14 21:53:12 +00:00
|
|
|
compare(item2.StackView.view, null)
|
|
|
|
compare(item1.StackView.view, control)
|
2015-06-30 11:39:43 +00:00
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:57:40 +00:00
|
|
|
function test_depth() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 0)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(item, StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 1)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(item, StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 2)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.pop(StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 1)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(component, StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 2)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.pop(StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 1)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.pop(StackView.Immediate) // ignored
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 1)
|
|
|
|
control.clear()
|
|
|
|
compare(control.depth, 0)
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_size() {
|
|
|
|
var container = component.createObject(testCase, {width: 200, height: 200})
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(container)
|
2015-01-30 19:57:40 +00:00
|
|
|
var control = stackView.createObject(container, {width: 100, height: 100})
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
container.width += 10
|
|
|
|
container.height += 20
|
|
|
|
compare(control.width, 100)
|
|
|
|
compare(control.height, 100)
|
|
|
|
container.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_focus() {
|
|
|
|
var control = stackView.createObject(testCase, {initialItem: item, width: 200, height: 200})
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
control.forceActiveFocus()
|
|
|
|
verify(control.activeFocus)
|
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(textField, StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.currentItem, textField)
|
|
|
|
textField.forceActiveFocus()
|
|
|
|
verify(textField.activeFocus)
|
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
control.pop(StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.currentItem, item)
|
|
|
|
verify(control.activeFocus)
|
|
|
|
verify(!textField.activeFocus)
|
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_find() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
var item1 = component.createObject(control, {objectName: "1"})
|
|
|
|
var item2 = component.createObject(control, {objectName: "2"})
|
|
|
|
var item3 = component.createObject(control, {objectName: "3"})
|
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(item1, StackView.Immediate)
|
|
|
|
control.push(item2, StackView.Immediate)
|
|
|
|
control.push(item3, StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
compare(control.find(function(item, index) { return index === 0 }), item1)
|
|
|
|
compare(control.find(function(item) { return item.objectName === "1" }), item1)
|
|
|
|
|
|
|
|
compare(control.find(function(item, index) { return index === 1 }), item2)
|
|
|
|
compare(control.find(function(item) { return item.objectName === "2" }), item2)
|
|
|
|
|
|
|
|
compare(control.find(function(item, index) { return index === 2 }), item3)
|
|
|
|
compare(control.find(function(item) { return item.objectName === "3" }), item3)
|
|
|
|
|
|
|
|
compare(control.find(function() { return false }), null)
|
|
|
|
compare(control.find(function() { return true }), item3)
|
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_get() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push([item, component, component], StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
verify(control.get(0, StackView.DontLoad))
|
|
|
|
compare(control.get(0, StackView.ForceLoad), item)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
verify(!control.get(1, StackView.DontLoad))
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
verify(control.get(2, StackView.DontLoad))
|
|
|
|
verify(control.get(2, StackView.ForceLoad))
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
function test_push() {
|
2015-01-30 19:57:40 +00:00
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-07-06 21:57:23 +00:00
|
|
|
// missing arguments
|
2015-09-14 21:53:12 +00:00
|
|
|
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":59:9: QML StackView: push: missing arguments")
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.push(), null)
|
|
|
|
|
2015-07-06 21:57:23 +00:00
|
|
|
// nothing to push
|
2015-09-14 21:53:12 +00:00
|
|
|
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":59:9: QML StackView: push: nothing to push")
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.push(StackView.Immediate), null)
|
2015-03-28 20:51:10 +00:00
|
|
|
|
|
|
|
// push(item)
|
2015-01-30 19:57:40 +00:00
|
|
|
var item1 = component.createObject(control, {objectName:"1"})
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.push(item1, StackView.Immediate), item1)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 1)
|
|
|
|
compare(control.currentItem, item1)
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// push([item])
|
2015-01-30 19:57:40 +00:00
|
|
|
var item2 = component.createObject(control, {objectName:"2"})
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.push([item2], StackView.Immediate), item2)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 2)
|
|
|
|
compare(control.currentItem, item2)
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// push(item, {properties})
|
|
|
|
var item3 = component.createObject(control)
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.push(item3, {objectName:"3"}, StackView.Immediate), item3)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(item3.objectName, "3")
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 3)
|
|
|
|
compare(control.currentItem, item3)
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// push([item, {properties}])
|
|
|
|
var item4 = component.createObject(control)
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.push([item4, {objectName:"4"}], StackView.Immediate), item4)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(item4.objectName, "4")
|
|
|
|
compare(control.depth, 4)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.currentItem, item4)
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// push(component, {properties})
|
2015-09-14 14:27:24 +00:00
|
|
|
var item5 = control.push(component, {objectName:"5"}, StackView.Immediate)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(item5.objectName, "5")
|
|
|
|
compare(control.depth, 5)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.currentItem, item5)
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// push([component, {properties}])
|
2015-09-14 14:27:24 +00:00
|
|
|
var item6 = control.push([component, {objectName:"6"}], StackView.Immediate)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(item6.objectName, "6")
|
|
|
|
compare(control.depth, 6)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.currentItem, item6)
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_pop() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
var items = []
|
|
|
|
for (var i = 0; i < 7; ++i)
|
|
|
|
items.push(component.createObject(control, {objectName:i}))
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(items, StackView.Immediate)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-09-14 21:53:12 +00:00
|
|
|
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":59:9: QML StackView: pop: too many arguments")
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.pop(1, 2, 3), null)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// pop the top most item
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.pop(StackView.Immediate), items[6])
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.depth, 6)
|
|
|
|
compare(control.currentItem, items[5])
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// pop down to (but not including) the Nth item
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.pop(items[3], StackView.Immediate), items[5])
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.depth, 4)
|
|
|
|
compare(control.currentItem, items[3])
|
|
|
|
|
|
|
|
// pop the top most item
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.pop(undefined, StackView.Immediate), items[3])
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 3)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.currentItem, items[2])
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// don't pop non-existent item
|
2015-09-14 21:53:12 +00:00
|
|
|
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":59:9: QML StackView: pop: unknown argument: " + testCase)
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.pop(testCase, StackView.Immediate), null)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.depth, 3)
|
|
|
|
compare(control.currentItem, items[2])
|
|
|
|
|
|
|
|
// pop all items down to (but not including) the 1st item
|
2015-09-14 14:27:24 +00:00
|
|
|
control.pop(null, StackView.Immediate)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.depth, 1)
|
|
|
|
compare(control.currentItem, items[0])
|
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_replace() {
|
|
|
|
var control = stackView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-03-28 20:51:10 +00:00
|
|
|
|
2015-07-06 21:57:23 +00:00
|
|
|
// missing arguments
|
2015-09-14 21:53:12 +00:00
|
|
|
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":59:9: QML StackView: replace: missing arguments")
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.replace(), null)
|
|
|
|
|
2015-07-06 21:57:23 +00:00
|
|
|
// nothing to push
|
2015-09-14 21:53:12 +00:00
|
|
|
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":59:9: QML StackView: replace: nothing to push")
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.replace(StackView.Immediate), null)
|
2015-03-28 20:51:10 +00:00
|
|
|
|
|
|
|
// replace(item)
|
|
|
|
var item1 = component.createObject(control, {objectName:"1"})
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.replace(item1, StackView.Immediate), item1)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.depth, 1)
|
|
|
|
compare(control.currentItem, item1)
|
|
|
|
|
2015-03-28 20:51:10 +00:00
|
|
|
// replace([item])
|
|
|
|
var item2 = component.createObject(control, {objectName:"2"})
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.replace([item2], StackView.Immediate), item2)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(control.depth, 1)
|
|
|
|
compare(control.currentItem, item2)
|
|
|
|
|
|
|
|
// replace(item, {properties})
|
|
|
|
var item3 = component.createObject(control)
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.replace(item3, {objectName:"3"}, StackView.Immediate), item3)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(item3.objectName, "3")
|
|
|
|
compare(control.depth, 1)
|
|
|
|
compare(control.currentItem, item3)
|
|
|
|
|
|
|
|
// replace([item, {properties}])
|
|
|
|
var item4 = component.createObject(control)
|
2015-09-14 14:27:24 +00:00
|
|
|
compare(control.replace([item4, {objectName:"4"}], StackView.Immediate), item4)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(item4.objectName, "4")
|
|
|
|
compare(control.depth, 1)
|
|
|
|
compare(control.currentItem, item4)
|
|
|
|
|
|
|
|
// replace(component, {properties})
|
2015-09-14 14:27:24 +00:00
|
|
|
var item5 = control.replace(component, {objectName:"5"}, StackView.Immediate)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(item5.objectName, "5")
|
|
|
|
compare(control.depth, 1)
|
|
|
|
compare(control.currentItem, item5)
|
|
|
|
|
|
|
|
// replace([component, {properties}])
|
2015-09-14 14:27:24 +00:00
|
|
|
var item6 = control.replace([component, {objectName:"6"}], StackView.Immediate)
|
2015-03-28 20:51:10 +00:00
|
|
|
compare(item6.objectName, "6")
|
|
|
|
compare(control.depth, 1)
|
|
|
|
compare(control.currentItem, item6)
|
|
|
|
|
2015-01-30 19:57:40 +00:00
|
|
|
control.destroy()
|
|
|
|
}
|
2015-08-26 13:14:23 +00:00
|
|
|
|
|
|
|
function test_visibility_data() {
|
|
|
|
return [
|
|
|
|
{tag:"default transitions", properties: {}},
|
|
|
|
{tag:"null transitions", properties: {pushEnter: null, pushExit: null, popEnter: null, popExit: null}}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_visibility(data) {
|
|
|
|
var control = stackView.createObject(testCase, data.properties)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-08-26 13:14:23 +00:00
|
|
|
|
|
|
|
var item1 = component.createObject(control)
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(item1, StackView.Immediate)
|
2015-08-26 13:14:23 +00:00
|
|
|
verify(item1.visible)
|
|
|
|
|
|
|
|
var item2 = component.createObject(control)
|
|
|
|
control.push(item2)
|
|
|
|
tryCompare(item1, "visible", false)
|
|
|
|
verify(item2.visible)
|
|
|
|
|
|
|
|
control.pop()
|
|
|
|
verify(item1.visible)
|
|
|
|
tryCompare(item2, "visible", false)
|
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
2015-08-26 15:53:41 +00:00
|
|
|
|
|
|
|
Component {
|
|
|
|
id: transitionView
|
|
|
|
StackView {
|
|
|
|
property int popEnterRuns
|
|
|
|
property int popExitRuns
|
|
|
|
property int pushEnterRuns
|
|
|
|
property int pushExitRuns
|
|
|
|
popEnter: Transition {
|
|
|
|
PauseAnimation { duration: 1 }
|
|
|
|
onRunningChanged: if (!running) ++popEnterRuns
|
|
|
|
}
|
|
|
|
popExit: Transition {
|
|
|
|
PauseAnimation { duration: 1 }
|
|
|
|
onRunningChanged: if (!running) ++popExitRuns
|
|
|
|
}
|
|
|
|
pushEnter: Transition {
|
|
|
|
PauseAnimation { duration: 1 }
|
|
|
|
onRunningChanged: if (!running) ++pushEnterRuns
|
|
|
|
}
|
|
|
|
pushExit: Transition {
|
|
|
|
PauseAnimation { duration: 1 }
|
|
|
|
onRunningChanged: if (!running) ++pushExitRuns
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_transitions() {
|
|
|
|
var control = transitionView.createObject(testCase)
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-08-26 15:53:41 +00:00
|
|
|
|
|
|
|
control.push(component)
|
|
|
|
verify(!control.busy)
|
|
|
|
compare(control.pushEnterRuns, 0)
|
|
|
|
compare(control.pushExitRuns, 0)
|
|
|
|
|
|
|
|
control.push(component)
|
|
|
|
tryCompare(control, "busy", false)
|
|
|
|
compare(control.pushEnterRuns, 1)
|
|
|
|
compare(control.pushExitRuns, 1)
|
|
|
|
|
|
|
|
control.pop()
|
|
|
|
tryCompare(control, "busy", false)
|
|
|
|
compare(control.popEnterRuns, 1)
|
|
|
|
compare(control.popExitRuns, 1)
|
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
2015-08-28 11:35:19 +00:00
|
|
|
|
|
|
|
TestItem {
|
|
|
|
id: indestructibleItem
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: destructibleComponent
|
|
|
|
TestItem { }
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_ownership_data() {
|
|
|
|
return [
|
2015-09-14 14:27:24 +00:00
|
|
|
{tag:"item, transition", arg: indestructibleItem, operation: StackView.Transition, destroyed: false},
|
|
|
|
{tag:"item, immediate", arg: indestructibleItem, operation: StackView.Immediate, destroyed: false},
|
|
|
|
{tag:"component, transition", arg: destructibleComponent, operation: StackView.Transition, destroyed: true},
|
|
|
|
{tag:"component, immediate", arg: destructibleComponent, operation: StackView.Immediate, destroyed: true},
|
|
|
|
{tag:"url, transition", arg: Qt.resolvedUrl("TestItem.qml"), operation: StackView.Transition, destroyed: true},
|
|
|
|
{tag:"url, immediate", arg: Qt.resolvedUrl("TestItem.qml"), operation: StackView.Immediate, destroyed: true}
|
2015-08-28 11:35:19 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_ownership(data) {
|
|
|
|
var control = transitionView.createObject(testCase, {initialItem: component})
|
2015-08-28 12:13:02 +00:00
|
|
|
verify(control)
|
2015-08-28 11:35:19 +00:00
|
|
|
|
|
|
|
// push-pop
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(data.arg, StackView.Immediate)
|
2015-08-28 11:35:19 +00:00
|
|
|
verify(control.currentItem)
|
|
|
|
verify(control.currentItem.hasOwnProperty("destroyedCallback"))
|
|
|
|
var destroyed = false
|
|
|
|
control.currentItem.destroyedCallback = function() { destroyed = true }
|
|
|
|
control.pop(data.operation)
|
|
|
|
tryCompare(control, "busy", false)
|
|
|
|
wait(0) // deferred delete
|
|
|
|
compare(destroyed, data.destroyed)
|
|
|
|
|
|
|
|
// push-replace
|
2015-09-14 14:27:24 +00:00
|
|
|
control.push(data.arg, StackView.Immediate)
|
2015-08-28 11:35:19 +00:00
|
|
|
verify(control.currentItem)
|
|
|
|
verify(control.currentItem.hasOwnProperty("destroyedCallback"))
|
|
|
|
destroyed = false
|
|
|
|
control.currentItem.destroyedCallback = function() { destroyed = true }
|
|
|
|
control.replace(component, data.operation)
|
|
|
|
tryCompare(control, "busy", false)
|
|
|
|
wait(0) // deferred delete
|
|
|
|
compare(destroyed, data.destroyed)
|
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
2015-10-10 22:04:55 +00:00
|
|
|
|
|
|
|
Component {
|
|
|
|
id: attachedItem
|
|
|
|
Item {
|
|
|
|
property int index: StackView.index
|
|
|
|
property StackView view: StackView.view
|
|
|
|
property int status: StackView.status
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_attached() {
|
|
|
|
var control = stackView.createObject(testCase, {initialItem: attachedItem})
|
|
|
|
|
|
|
|
compare(control.get(0).index, 0)
|
|
|
|
compare(control.get(0).view, control)
|
|
|
|
compare(control.get(0).status, StackView.Active)
|
|
|
|
|
|
|
|
control.push(attachedItem, StackView.Immediate)
|
|
|
|
|
|
|
|
compare(control.get(0).index, 0)
|
|
|
|
compare(control.get(0).view, control)
|
|
|
|
compare(control.get(0).status, StackView.Inactive)
|
|
|
|
|
|
|
|
compare(control.get(1).index, 1)
|
|
|
|
compare(control.get(1).view, control)
|
|
|
|
compare(control.get(1).status, StackView.Active)
|
|
|
|
|
|
|
|
control.pop(StackView.Immediate)
|
|
|
|
|
|
|
|
compare(control.get(0).index, 0)
|
|
|
|
compare(control.get(0).view, control)
|
|
|
|
compare(control.get(0).status, StackView.Active)
|
|
|
|
|
|
|
|
control.destroy()
|
|
|
|
}
|
2015-01-30 19:57:40 +00:00
|
|
|
}
|