aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-10-16 16:45:15 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2018-11-02 16:46:04 +0000
commit936d31179d44220571ded15840bedeccb581c83b (patch)
treed7c38d2bed038e6206dc9291109508fb665be0ea
parent953fbac6131823e4fce0eb4707a854469c4c04ff (diff)
tst_qquickmenu: add a test for MenuItems before and after a Repeaterv5.12.0-beta4
Just to verify that it works, as a similar test was added for Instantiator in another patch. Change-Id: I1ab55d98a3726bff1a2984db0d81ae444e05d630 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--tests/auto/qquickmenu/data/repeaterWithItemsBeforeAndAfter.qml88
-rw-r--r--tests/auto/qquickmenu/tst_qquickmenu.cpp32
2 files changed, 119 insertions, 1 deletions
diff --git a/tests/auto/qquickmenu/data/repeaterWithItemsBeforeAndAfter.qml b/tests/auto/qquickmenu/data/repeaterWithItemsBeforeAndAfter.qml
new file mode 100644
index 00000000..46ed8856
--- /dev/null
+++ b/tests/auto/qquickmenu/data/repeaterWithItemsBeforeAndAfter.qml
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 QtQml 2.11
+import QtQuick 2.11
+import QtQuick.Controls 2.4
+
+ApplicationWindow {
+ width: 200
+ height: 200
+
+ property alias menu: menu
+
+ Menu {
+ id: menu
+
+ MenuItem {
+ objectName: text
+ text: "Before"
+ }
+
+ Repeater {
+ model: ["Repeater Item #1", "Repeater Item #2"]
+
+ MenuItem {
+ objectName: text
+ text: modelData
+ }
+
+ // We want our items to be added after the "Before" MenuItem,
+ // so we have to insert items at the index after it.
+ onItemAdded: menu.insertItem(1 + index, item)
+ onItemRemoved: menu.removeItem(item)
+ }
+
+ MenuItem {
+ objectName: text
+ text: "After"
+ }
+ }
+}
diff --git a/tests/auto/qquickmenu/tst_qquickmenu.cpp b/tests/auto/qquickmenu/tst_qquickmenu.cpp
index 2ba9363b..2f6d5049 100644
--- a/tests/auto/qquickmenu/tst_qquickmenu.cpp
+++ b/tests/auto/qquickmenu/tst_qquickmenu.cpp
@@ -75,6 +75,7 @@ private slots:
void addItem();
void menuSeparator();
void repeater();
+ void repeaterWithItemsBeforeAndAfter();
void order();
void popup();
void actions();
@@ -591,7 +592,7 @@ void tst_QQuickMenu::repeater()
for (int i = 0; i < count; ++i) {
QQuickItem *item = menu->itemAt(i);
- QVERIFY(item);
+ QVERIFY2(item, qPrintable(QString::fromLatin1("Expected item to be at index %1").arg(i)));
QCOMPARE(item->property("idx").toInt(), i);
QQuickItem *repeaterItem = nullptr;
@@ -615,6 +616,35 @@ void tst_QQuickMenu::repeater()
}
}
+void tst_QQuickMenu::repeaterWithItemsBeforeAndAfter()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("repeaterWithItemsBeforeAndAfter.qml"));
+
+ QQuickApplicationWindow *window = helper.appWindow;
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QGuiApplication::focusWindow() == window);
+ centerOnScreen(window);
+ moveMouseAway(window);
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
+ menu->open();
+ QVERIFY(menu->isVisible());
+ waitForMenuListViewPolish(menu);
+
+ QStringList expectedItemTexts;
+ expectedItemTexts << QLatin1String("Before") << QLatin1String("Repeater Item #1")
+ << QLatin1String("Repeater Item #2") << QLatin1String("After");
+
+ for (int i = 0; i < expectedItemTexts.size(); ++i) {
+ const QString expectedText = expectedItemTexts.at(i);
+ QQuickMenuItem *menuItem = qobject_cast<QQuickMenuItem*>(menu->itemAt(i));
+ QVERIFY(menuItem);
+ QCOMPARE(menuItem->text(), expectedText);
+ }
+}
+
void tst_QQuickMenu::order()
{
QQuickApplicationHelper helper(this, QLatin1String("order.qml"));