From e9e68baf652eca70c6a4c080ed9e49c70c8c9984 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 22 May 2016 19:04:03 +0200 Subject: Platform menus Change-Id: Ifbca41ef384ca8fe8afefc61869f85c17db0f8c7 Reviewed-by: Mitch Curtis --- tests/auto/platform/data/tst_menu.qml | 235 +++++++++++++++ tests/auto/platform/data/tst_menubar.qml | 229 +++++++++++++++ tests/auto/platform/data/tst_menuitem.qml | 107 +++++++ tests/auto/platform/data/tst_menuitemgroup.qml | 380 +++++++++++++++++++++++++ 4 files changed, 951 insertions(+) create mode 100644 tests/auto/platform/data/tst_menu.qml create mode 100644 tests/auto/platform/data/tst_menubar.qml create mode 100644 tests/auto/platform/data/tst_menuitem.qml create mode 100644 tests/auto/platform/data/tst_menuitemgroup.qml (limited to 'tests/auto/platform') diff --git a/tests/auto/platform/data/tst_menu.qml b/tests/auto/platform/data/tst_menu.qml new file mode 100644 index 00000000..cc846d99 --- /dev/null +++ b/tests/auto/platform/data/tst_menu.qml @@ -0,0 +1,235 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $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." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import Qt.labs.platform 1.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "Menu" + + Component { + id: item + MenuItem { } + } + + Component { + id: menu + Menu { } + } + + SignalSpy { + id: itemsSpy + signalName: "itemsChanged" + } + + function init() { + verify(!itemsSpy.target) + compare(itemsSpy.count, 0) + } + + function cleanup() { + itemsSpy.target = null + itemsSpy.clear() + } + + function test_addRemove() { + var control = menu.createObject(testCase) + + itemsSpy.target = control + verify(itemsSpy.valid) + + control.addItem(item.createObject(control, {text: "1"})) + compare(control.items.length, 1) + compare(control.items[0].text, "1") + compare(itemsSpy.count, 1) + + control.addItem(item.createObject(control, {text: "2"})) + compare(control.items.length, 2) + compare(control.items[0].text, "1") + compare(control.items[1].text, "2") + compare(itemsSpy.count, 2) + + control.insertItem(1, item.createObject(control, {text: "3"})) + compare(control.items.length, 3) + compare(control.items[0].text, "1") + compare(control.items[1].text, "3") + compare(control.items[2].text, "2") + compare(itemsSpy.count, 3) + + control.insertItem(0, item.createObject(control, {text: "4"})) + compare(control.items.length, 4) + compare(control.items[0].text, "4") + compare(control.items[1].text, "1") + compare(control.items[2].text, "3") + compare(control.items[3].text, "2") + compare(itemsSpy.count, 4) + + control.insertItem(control.items.length, item.createObject(control, {text: "5"})) + compare(control.items.length, 5) + compare(control.items[0].text, "4") + compare(control.items[1].text, "1") + compare(control.items[2].text, "3") + compare(control.items[3].text, "2") + compare(control.items[4].text, "5") + compare(itemsSpy.count, 5) + + control.removeItem(control.items[4]) + compare(control.items.length, 4) + compare(control.items[0].text, "4") + compare(control.items[1].text, "1") + compare(control.items[2].text, "3") + compare(control.items[3].text, "2") + compare(itemsSpy.count, 6) + + control.removeItem(control.items[0]) + compare(control.items.length, 3) + compare(control.items[0].text, "1") + compare(control.items[1].text, "3") + compare(control.items[2].text, "2") + compare(itemsSpy.count, 7) + + control.removeItem(control.items[1]) + compare(control.items.length, 2) + compare(control.items[0].text, "1") + compare(control.items[1].text, "2") + compare(itemsSpy.count, 8) + + control.removeItem(control.items[1]) + compare(control.items.length, 1) + compare(control.items[0].text, "1") + compare(itemsSpy.count, 9) + + control.removeItem(control.items[0]) + compare(control.items.length, 0) + compare(itemsSpy.count, 10) + + control.destroy() + } + + Component { + id: contentMenu + Menu { + QtObject { objectName: "object" } + MenuItem { objectName: "item1" } + Timer { objectName: "timer" } + MenuItem { objectName: "item2" } + Component { MenuItem { } } + } + } + + function test_content() { + var control = contentMenu.createObject(testCase) + + function compareObjectNames(content, names) { + if (content.length !== names.length) + return false + for (var i = 0; i < names.length; ++i) { + if (content[i].objectName !== names[i]) + return false + } + return true + } + + itemsSpy.target = control + verify(itemsSpy.valid) + + verify(compareObjectNames(control.data, ["object", "item1", "timer", "item2", ""])) + verify(compareObjectNames(control.items, ["item1", "item2"])) + + control.addItem(item.createObject(control, {objectName: "item3"})) + verify(compareObjectNames(control.data, ["object", "item1", "timer", "item2", "", "item3"])) + verify(compareObjectNames(control.items, ["item1", "item2", "item3"])) + compare(itemsSpy.count, 1) + + control.insertItem(0, item.createObject(control, {objectName: "item4"})) + verify(compareObjectNames(control.data, ["object", "item1", "timer", "item2", "", "item3", "item4"])) + verify(compareObjectNames(control.items, ["item4", "item1", "item2", "item3"])) + compare(itemsSpy.count, 2) + + control.removeItem(control.items[1]) + verify(compareObjectNames(control.data, ["object", "timer", "item2", "", "item3", "item4"])) + verify(compareObjectNames(control.items, ["item4", "item2", "item3"])) + compare(itemsSpy.count, 3) + + control.destroy() + } + + Component { + id: dynamicMenu + Menu { + id: dmenu + MenuItem { text: "static" } + Component.onCompleted: { + addItem(item.createObject(dmenu, {text: "added"})) + insertItem(0, item.createObject(dmenu, {text: "inserted"})) + } + } + } + + function test_dynamic() { + var control = dynamicMenu.createObject(testCase) + + // insertItem(), addItem(), and static MenuItem {} + compare(control.items.length, 3) + compare(control.items[0].text, "inserted") + + var dying = item.createObject(control, {text: "dying"}) + control.addItem(dying) + compare(control.items.length, 4) + compare(control.items[3].text, "dying") + dying.destroy() + wait(0) + compare(control.items.length, 3) + + control.destroy() + } + + function test_type() { + // Q_ENUMS(QPlatformMenu::MenuType) + compare(Menu.DefaultMenu, 0) + compare(Menu.EditMenu, 1) + } +} diff --git a/tests/auto/platform/data/tst_menubar.qml b/tests/auto/platform/data/tst_menubar.qml new file mode 100644 index 00000000..6c29f164 --- /dev/null +++ b/tests/auto/platform/data/tst_menubar.qml @@ -0,0 +1,229 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $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." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import Qt.labs.platform 1.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "MenuBar" + + Component { + id: menu + Menu { } + } + + Component { + id: menuBar + MenuBar { } + } + + SignalSpy { + id: menusSpy + signalName: "menusChanged" + } + + function init() { + verify(!menusSpy.target) + compare(menusSpy.count, 0) + } + + function cleanup() { + menusSpy.target = null + menusSpy.clear() + } + + function test_addRemove() { + var control = menuBar.createObject(testCase) + + menusSpy.target = control + verify(menusSpy.valid) + + control.addMenu(menu.createObject(control, {title: "1"})) + compare(control.menus.length, 1) + compare(control.menus[0].title, "1") + compare(menusSpy.count, 1) + + control.addMenu(menu.createObject(control, {title: "2"})) + compare(control.menus.length, 2) + compare(control.menus[0].title, "1") + compare(control.menus[1].title, "2") + compare(menusSpy.count, 2) + + control.insertMenu(1, menu.createObject(control, {title: "3"})) + compare(control.menus.length, 3) + compare(control.menus[0].title, "1") + compare(control.menus[1].title, "3") + compare(control.menus[2].title, "2") + compare(menusSpy.count, 3) + + control.insertMenu(0, menu.createObject(control, {title: "4"})) + compare(control.menus.length, 4) + compare(control.menus[0].title, "4") + compare(control.menus[1].title, "1") + compare(control.menus[2].title, "3") + compare(control.menus[3].title, "2") + compare(menusSpy.count, 4) + + control.insertMenu(control.menus.length, menu.createObject(control, {title: "5"})) + compare(control.menus.length, 5) + compare(control.menus[0].title, "4") + compare(control.menus[1].title, "1") + compare(control.menus[2].title, "3") + compare(control.menus[3].title, "2") + compare(control.menus[4].title, "5") + compare(menusSpy.count, 5) + + control.removeMenu(control.menus[4]) + compare(control.menus.length, 4) + compare(control.menus[0].title, "4") + compare(control.menus[1].title, "1") + compare(control.menus[2].title, "3") + compare(control.menus[3].title, "2") + compare(menusSpy.count, 6) + + control.removeMenu(control.menus[0]) + compare(control.menus.length, 3) + compare(control.menus[0].title, "1") + compare(control.menus[1].title, "3") + compare(control.menus[2].title, "2") + compare(menusSpy.count, 7) + + control.removeMenu(control.menus[1]) + compare(control.menus.length, 2) + compare(control.menus[0].title, "1") + compare(control.menus[1].title, "2") + compare(menusSpy.count, 8) + + control.removeMenu(control.menus[1]) + compare(control.menus.length, 1) + compare(control.menus[0].title, "1") + compare(menusSpy.count, 9) + + control.removeMenu(control.menus[0]) + compare(control.menus.length, 0) + compare(menusSpy.count, 10) + + control.destroy() + } + + Component { + id: contentBar + MenuBar { + QtObject { objectName: "object" } + Menu { objectName: "menu1" } + Timer { objectName: "timer" } + Menu { objectName: "menu2" } + Component { Menu { } } + } + } + + function test_content() { + var control = contentBar.createObject(testCase) + + function compareObjectNames(content, names) { + if (content.length !== names.length) + return false + for (var i = 0; i < names.length; ++i) { + if (content[i].objectName !== names[i]) + return false + } + return true + } + + menusSpy.target = control + verify(menusSpy.valid) + + verify(compareObjectNames(control.data, ["object", "menu1", "timer", "menu2", ""])) + verify(compareObjectNames(control.menus, ["menu1", "menu2"])) + + control.addMenu(menu.createObject(control, {objectName: "menu3"})) + verify(compareObjectNames(control.data, ["object", "menu1", "timer", "menu2", "", "menu3"])) + verify(compareObjectNames(control.menus, ["menu1", "menu2", "menu3"])) + compare(menusSpy.count, 1) + + control.insertMenu(0, menu.createObject(control, {objectName: "menu4"})) + verify(compareObjectNames(control.data, ["object", "menu1", "timer", "menu2", "", "menu3", "menu4"])) + verify(compareObjectNames(control.menus, ["menu4", "menu1", "menu2", "menu3"])) + compare(menusSpy.count, 2) + + control.removeMenu(control.menus[1]) + verify(compareObjectNames(control.data, ["object", "timer", "menu2", "", "menu3", "menu4"])) + verify(compareObjectNames(control.menus, ["menu4", "menu2", "menu3"])) + compare(menusSpy.count, 3) + + control.destroy() + } + + Component { + id: dynamicBar + MenuBar { + id: dbar + Menu { title: "static" } + Component.onCompleted: { + addMenu(menu.createObject(dbar, {title: "added"})) + insertMenu(0, menu.createObject(dbar, {title: "inserted"})) + } + } + } + + function test_dynamic() { + var control = dynamicBar.createObject(testCase) + + // insertMenu(), addMenu(), and static Menu {} + compare(control.menus.length, 3) + compare(control.menus[0].title, "inserted") + + var dying = menu.createObject(control, {title: "dying"}) + control.addMenu(dying) + compare(control.menus.length, 4) + compare(control.menus[3].title, "dying") + dying.destroy() + wait(0) + compare(control.menus.length, 3) + + control.destroy() + } +} diff --git a/tests/auto/platform/data/tst_menuitem.qml b/tests/auto/platform/data/tst_menuitem.qml new file mode 100644 index 00000000..7c2dd8f5 --- /dev/null +++ b/tests/auto/platform/data/tst_menuitem.qml @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $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." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import Qt.labs.platform 1.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "MenuItem" + + Component { + id: menuItem + MenuItem { } + } + + SignalSpy { + id: spy + } + + function test_properties_data() { + return [ + {tag: "enabled", signal: "enabledChanged", init: true, value: false}, + {tag: "visible", signal: "visibleChanged", init: true, value: false}, + {tag: "separator", signal: "separatorChanged", init: false, value: true}, + {tag: "checkable", signal: "checkableChanged", init: false, value: true}, + {tag: "checked", signal: "checkedChanged", init: false, value: true}, + {tag: "role", signal: "roleChanged", init: MenuItem.TextHeuristicRole, value: MenuItem.AboutRole}, + {tag: "text", signal: "textChanged", init: "", value: "text"}, + {tag: "iconSource", signal: "iconSourceChanged", init: "", value: "qrc:/undo.png"}, + {tag: "iconName", signal: "iconNameChanged", init: "", value: "edit-undo"}, + {tag: "shortcut", signal: "shortcutChanged", init: undefined, value: StandardKey.Undo} + ] + } + + function test_properties(data) { + var item = menuItem.createObject(testCase) + verify(item) + + spy.target = item + spy.signalName = data.signal + verify(spy.valid) + + compare(item[data.tag], data.init) + item[data.tag] = data.value + compare(spy.count, 1) + compare(item[data.tag], data.value) + + item[data.tag] = data.value + compare(spy.count, 1) + + spy.clear() + item.destroy() + } + + function test_role() { + // Q_ENUMS(QPlatformMenuItem::MenuRole) + compare(MenuItem.NoRole, 0) + compare(MenuItem.TextHeuristicRole, 1) + compare(MenuItem.ApplicationSpecificRole, 2) + compare(MenuItem.AboutQtRole, 3) + compare(MenuItem.AboutRole, 4) + compare(MenuItem.PreferencesRole, 5) + compare(MenuItem.QuitRole, 6) + } +} diff --git a/tests/auto/platform/data/tst_menuitemgroup.qml b/tests/auto/platform/data/tst_menuitemgroup.qml new file mode 100644 index 00000000..31fc18b1 --- /dev/null +++ b/tests/auto/platform/data/tst_menuitemgroup.qml @@ -0,0 +1,380 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $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." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import Qt.labs.platform 1.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "MenuItemGroup" + + Component { + id: menuItemGroup + MenuItemGroup { } + } + + SignalSpy { + id: checkedItemSpy + signalName: "checkedItemChanged" + } + + SignalSpy { + id: itemsSpy + signalName: "itemsChanged" + } + + function init() { + verify(!checkedItemSpy.target) + compare(checkedItemSpy.count, 0) + + verify(!itemsSpy.target) + compare(itemsSpy.count, 0) + } + + function cleanup() { + checkedItemSpy.target = null + checkedItemSpy.clear() + + itemsSpy.target = null + itemsSpy.clear() + } + + function test_null() { + var group = menuItemGroup.createObject(testCase) + verify(group) + + group.addItem(null) + group.removeItem(null) + + group.destroy() + } + + Component { + id: item + MenuItem { } + } + + function test_exclusive() { + var group = menuItemGroup.createObject(testCase) + verify(group) + + compare(group.exclusive, true) + + checkedItemSpy.target = group + verify(checkedItemSpy.valid) + verify(!group.checkedItem) + + var item1 = item.createObject(testCase, {checked: true}) + var item2 = item.createObject(testCase, {checked: false}) + var item3 = item.createObject(testCase, {checked: true}) + + // add checked + group.addItem(item1) + compare(group.checkedItem, item1) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, true) + compare(checkedItemSpy.count, 1) + + // add non-checked + group.addItem(item2) + compare(group.checkedItem, item1) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, true) + compare(checkedItemSpy.count, 1) + + // add checked + group.addItem(item3) + compare(group.checkedItem, item3) + compare(item1.checked, false) + compare(item2.checked, false) + compare(item3.checked, true) + compare(checkedItemSpy.count, 2) + + // change checked + group.checkedItem = item2 + compare(group.checkedItem, item2) + compare(item1.checked, false) + compare(item2.checked, true) + compare(item3.checked, false) + compare(checkedItemSpy.count, 3) + + // check + item1.checked = true + compare(group.checkedItem, item1) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, false) + compare(checkedItemSpy.count, 4) + + // remove non-checked + group.removeItem(item2) + compare(group.checkedItem, item1) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, false) + compare(checkedItemSpy.count, 4) + + // remove checked + group.removeItem(item1) + compare(group.checkedItem, null) + compare(item1.checked, false) + compare(item2.checked, false) + compare(item3.checked, false) + compare(checkedItemSpy.count, 5) + + group.destroy() + } + + function test_nonExclusive() { + var group = menuItemGroup.createObject(testCase, {exclusive: false}) + verify(group) + + compare(group.exclusive, false) + + checkedItemSpy.target = group + verify(checkedItemSpy.valid) + verify(!group.checkedItem) + + var item1 = item.createObject(testCase, {checked: true}) + var item2 = item.createObject(testCase, {checked: false}) + var item3 = item.createObject(testCase, {checked: true}) + + // add checked + group.addItem(item1) + compare(group.checkedItem, null) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, true) + compare(checkedItemSpy.count, 0) + + // add non-checked + group.addItem(item2) + compare(group.checkedItem, null) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, true) + compare(checkedItemSpy.count, 0) + + // add checked + group.addItem(item3) + compare(group.checkedItem, null) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, true) + compare(checkedItemSpy.count, 0) + + // change checked + group.checkedItem = item2 + compare(group.checkedItem, item2) + compare(item1.checked, true) + compare(item2.checked, true) + compare(item3.checked, true) + compare(checkedItemSpy.count, 1) + + // check + item1.checked = false + item1.checked = true + compare(group.checkedItem, item2) + compare(item1.checked, true) + compare(item2.checked, true) + compare(item3.checked, true) + compare(checkedItemSpy.count, 1) + + // remove checked + group.removeItem(item2) + compare(group.checkedItem, null) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, true) + compare(checkedItemSpy.count, 2) + + // remove non-checked + group.removeItem(item1) + compare(group.checkedItem, null) + compare(item1.checked, true) + compare(item2.checked, false) + compare(item3.checked, true) + compare(checkedItemSpy.count, 2) + + group.destroy() + } + + function test_items() { + var group = menuItemGroup.createObject(testCase) + verify(group) + + itemsSpy.target = group + verify(itemsSpy.valid) + + compare(group.items.length, 0) + compare(group.checkedItem, null) + + var item1 = item.createObject(testCase, {checked: true}) + var item2 = item.createObject(testCase, {checked: false}) + + group.items = [item1, item2] + compare(group.items.length, 2) + compare(group.items[0], item1) + compare(group.items[1], item2) + compare(group.checkedItem, item1) + compare(itemsSpy.count, 2) + + var item3 = item.createObject(testCase, {checked: true}) + + group.addItem(item3) + compare(group.items.length, 3) + compare(group.items[0], item1) + compare(group.items[1], item2) + compare(group.items[2], item3) + compare(group.checkedItem, item3) + compare(itemsSpy.count, 3) + + group.removeItem(item1) + compare(group.items.length, 2) + compare(group.items[0], item2) + compare(group.items[1], item3) + compare(group.checkedItem, item3) + compare(itemsSpy.count, 4) + + group.items = [] + compare(group.items.length, 0) + compare(group.checkedItem, null) + compare(itemsSpy.count, 5) + + group.destroy() + } + + function test_itemDestroyed() { + var group = menuItemGroup.createObject(testCase) + verify(group) + + itemsSpy.target = group + verify(itemsSpy.valid) + + var item1 = item.createObject(testCase, {checked: true}) + + group.addItem(item1) + compare(group.items.length, 1) + compare(group.items[0], item1) + compare(group.checkedItem, item1) + compare(itemsSpy.count, 1) + + item1.destroy() + wait(0) + compare(group.items.length, 0) + compare(group.checkedItem, null) + compare(itemsSpy.count, 2) + + group.destroy() + } + + function test_visible() { + var group = menuItemGroup.createObject(testCase) + verify(group) + + compare(group.visible, true) + + for (var i = 0; i < 3; ++i) { + group.addItem(item.createObject(testCase)) + compare(group.items[i].visible, true) + } + + group.visible = false + compare(group.visible, false) + + for (i = 0; i < 3; ++i) + compare(group.items[i].visible, false) + + group.items[1].visible = true + compare(group.items[1].visible, false) + + group.items[1].visible = false + compare(group.items[1].visible, false) + + group.visible = true + compare(group.visible, true) + + compare(group.items[0].visible, true) + compare(group.items[1].visible, false) + compare(group.items[2].visible, true) + + group.destroy() + } + + function test_enabled() { + var group = menuItemGroup.createObject(testCase) + verify(group) + + compare(group.enabled, true) + + for (var i = 0; i < 3; ++i) { + group.addItem(item.createObject(testCase)) + compare(group.items[i].enabled, true) + } + + group.enabled = false + compare(group.enabled, false) + + for (i = 0; i < 3; ++i) + compare(group.items[i].enabled, false) + + group.items[1].enabled = true + compare(group.items[1].enabled, false) + + group.items[1].enabled = false + compare(group.items[1].enabled, false) + + group.enabled = true + compare(group.enabled, true) + + compare(group.items[0].enabled, true) + compare(group.items[1].enabled, false) + compare(group.items[2].enabled, true) + + group.destroy() + } +} -- cgit v1.2.3