Dialog auto tests
Add a test that checks all dialog flags are set when a dialog becomes visible. Renamed existing dialog test for clarity Change-Id: I3677816877860cab3303122e81f9ee30fc563e39
This commit is contained in:
parent
87e3240f72
commit
9bafdb6ed6
@ -37,6 +37,7 @@ MACRO(PLASMA_UNIT_TESTS)
|
||||
ENDMACRO(PLASMA_UNIT_TESTS)
|
||||
|
||||
PLASMA_UNIT_TESTS(
|
||||
dialogqmltest
|
||||
fallbackpackagetest
|
||||
packagestructuretest
|
||||
packageurlinterceptortest
|
||||
@ -48,7 +49,7 @@ PLASMA_UNIT_TESTS(
|
||||
add_executable(storagetest storagetest.cpp ../src/plasma/private/storage.cpp ../src/plasma/private/storagethread.cpp)
|
||||
target_link_libraries(storagetest Qt5::Gui Qt5::Test Qt5::Sql KF5::KIOCore KF5::Plasma KF5::CoreAddons)
|
||||
|
||||
set(dialogtest_srcs dialogtest.cpp)
|
||||
set(dialogtest_srcs dialognativetest.cpp)
|
||||
ecm_add_test(${dialogtest_srcs} TEST_NAME dialogtest LINK_LIBRARIES Qt5::Gui Qt5::Test Qt5::Qml Qt5::Quick KF5::WindowSystem KF5::Plasma KF5::PlasmaQuick)
|
||||
|
||||
set(coronatest_srcs coronatest.cpp)
|
||||
|
@ -17,11 +17,11 @@
|
||||
* Boston, MA 02110-1301, USA. *
|
||||
*********************************************************************************/
|
||||
|
||||
#include "dialogtest.h"
|
||||
#include "dialognativetest.h"
|
||||
#include <KWindowSystem>
|
||||
|
||||
|
||||
void DialogTest::initTestCase()
|
||||
void DialogNativeTest::initTestCase()
|
||||
{
|
||||
m_dialog = new PlasmaQuick::Dialog;
|
||||
|
||||
@ -45,14 +45,14 @@ void DialogTest::initTestCase()
|
||||
m_dialog->show();
|
||||
}
|
||||
|
||||
void DialogTest::cleanupTestCase()
|
||||
void DialogNativeTest::cleanupTestCase()
|
||||
{
|
||||
delete m_dialog;
|
||||
delete m_panel;
|
||||
delete m_panel2;
|
||||
}
|
||||
|
||||
void DialogTest::position()
|
||||
void DialogNativeTest::position()
|
||||
{
|
||||
QTest::qWaitForWindowExposed(m_dialog);
|
||||
|
||||
@ -64,4 +64,4 @@ void DialogTest::position()
|
||||
QCOMPARE(m_dialog->y(), 49);
|
||||
}
|
||||
|
||||
QTEST_MAIN(DialogTest)
|
||||
QTEST_MAIN(DialogNativeTest)
|
@ -27,7 +27,7 @@
|
||||
|
||||
|
||||
|
||||
class DialogTest : public QObject
|
||||
class DialogNativeTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
90
autotests/dialogqmltest.cpp
Normal file
90
autotests/dialogqmltest.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
/********************************************************************************
|
||||
* Copyright 2014 David Edmundson <davidedmundson@kde.org> *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public License *
|
||||
* along with this library; see the file COPYING.LIB. If not, write to *
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
||||
* Boston, MA 02110-1301, USA. *
|
||||
*********************************************************************************/
|
||||
|
||||
#include "dialogqmltest.h"
|
||||
|
||||
#include "plasmaquick/dialog.h"
|
||||
#include <plasma.h>
|
||||
|
||||
#include <QQmlEngine>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <QtTest/QSignalSpy>
|
||||
|
||||
|
||||
//this test checks that we don't set visible to true until after we set the window flags
|
||||
void DialogQmlTest::loadAndShow()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
|
||||
QByteArray dialogQml =
|
||||
"import QtQuick 2.0\n"
|
||||
"import org.kde.plasma.core 2.0 as PlasmaCore\n"
|
||||
"\n"
|
||||
"PlasmaCore.Dialog {\n"
|
||||
" id: root\n"
|
||||
"\n"
|
||||
" location: true && PlasmaCore.Types.TopEdge\n"
|
||||
" visible: true && true\n"
|
||||
" type: true && PlasmaCore.Dialog.Notification\n"
|
||||
"\n"
|
||||
" mainItem: Rectangle {\n"
|
||||
" width: 200\n"
|
||||
" height: 200\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
//we use true && Value to force it to be a complex binding, which won't be evaluated in
|
||||
//component.beginCreate
|
||||
//the bug still appears without this, but we need to delay it in this test
|
||||
//so we can connect to the visibleChanged signal
|
||||
|
||||
|
||||
QQmlComponent component(&engine);
|
||||
|
||||
QSignalSpy spy(&component, SIGNAL(statusChanged(QQmlComponent::Status)));
|
||||
component.setData(dialogQml, QUrl("test://dialogTest"));
|
||||
spy.wait();
|
||||
|
||||
PlasmaQuick::Dialog *dialog = qobject_cast< PlasmaQuick::Dialog* >(component.beginCreate(engine.rootContext()));
|
||||
qDebug() << component.errorString();
|
||||
Q_ASSERT(dialog);
|
||||
|
||||
m_dialogShown = false;
|
||||
|
||||
//this will be called during component.completeCreate
|
||||
auto c = connect(dialog, &QWindow::visibleChanged, [=]() {
|
||||
m_dialogShown = true;
|
||||
QCOMPARE(dialog->type(), PlasmaQuick::Dialog::Notification);
|
||||
QCOMPARE(dialog->location(), Plasma::Types::TopEdge);
|
||||
});
|
||||
|
||||
component.completeCreate();
|
||||
QCOMPARE(m_dialogShown, true);
|
||||
|
||||
//disconnect on visible changed before we delete the dialog
|
||||
disconnect(c);
|
||||
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QTEST_MAIN(DialogQmlTest)
|
40
autotests/dialogqmltest.h
Normal file
40
autotests/dialogqmltest.h
Normal file
@ -0,0 +1,40 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2014 Marco Martin <mart@kde.org> *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public License *
|
||||
* along with this library; see the file COPYING.LIB. If not, write to *
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
||||
* Boston, MA 02110-1301, USA. *
|
||||
*******************************************************************************/
|
||||
#ifndef DIALOLOADGTEST_H
|
||||
#define DIALOLOADGTEST_H
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include "plasmaquick/dialog.h"
|
||||
|
||||
|
||||
|
||||
class DialogQmlTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void loadAndShow();
|
||||
private:
|
||||
bool m_dialogShown;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user