diff --git a/config-kscreenlocker.h.cmake b/config-kscreenlocker.h.cmake --- a/config-kscreenlocker.h.cmake +++ b/config-kscreenlocker.h.cmake @@ -1,7 +1,9 @@ -#ifndef KSCREENLOCKER_UNIT_TEST -#define KCHECKPASS_BIN "${CMAKE_INSTALL_FULL_LIBEXECDIR}/kcheckpass" -#else +#ifdef KSCREENLOCKER_TEST_APPS +#define KCHECKPASS_BIN "${CMAKE_BINARY_DIR}/kcheckpass/kcheckpass" +#elif defined(KSCREENLOCKER_UNIT_TEST) #define KCHECKPASS_BIN "${CMAKE_CURRENT_BINARY_DIR}/greeter/autotests/fakekcheckpass" +#else +#define KCHECKPASS_BIN "${CMAKE_INSTALL_FULL_LIBEXECDIR}/kcheckpass" #endif #define KSCREENLOCKER_GREET_BIN "${CMAKE_INSTALL_FULL_LIBEXECDIR}/kscreenlocker_greet" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,3 +6,10 @@ add_executable(powermanagment_test powermanagementtest.cpp ../powermanagement.cpp) target_link_libraries(powermanagment_test Qt5::Gui Qt5::DBus Qt5::Quick) ecm_mark_as_test(powermanagment_test) + +include_directories(../kcheckpass/) +add_definitions(-DQML_FILE="${CMAKE_CURRENT_SOURCE_DIR}/kcheckpass_test.qml") +add_definitions(-DKSCREENLOCKER_TEST_APPS) +add_executable(kcheckpass_test kcheckpass_test.cpp ../greeter/authenticator.cpp) +target_link_libraries(kcheckpass_test Qt5::Gui Qt5::Quick) +ecm_mark_as_test(kcheckpass_test) diff --git a/tests/kcheckpass_test.cpp b/tests/kcheckpass_test.cpp new file mode 100644 --- /dev/null +++ b/tests/kcheckpass_test.cpp @@ -0,0 +1,36 @@ +/******************************************************************** + KSld - the KDE Screenlocker Daemon + This file is part of the KDE project. + +Copyright (C) 2017 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#include "../greeter/authenticator.h" +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + Authenticator authenticator; + + QQuickView view; + view.rootContext()->setContextProperty("authenticator", &authenticator); + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setSource(QUrl::fromLocalFile(QStringLiteral(QML_FILE))); + view.show(); + return app.exec(); +} diff --git a/tests/kcheckpass_test.qml b/tests/kcheckpass_test.qml new file mode 100644 --- /dev/null +++ b/tests/kcheckpass_test.qml @@ -0,0 +1,55 @@ +/******************************************************************** + KSld - the KDE Screenlocker Daemon + This file is part of the KDE project. + +Copyright (C) 2017 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +import QtQuick 2.1 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.3 + +Item { + ColumnLayout { + anchors.fill: parent + Label { + id: message + Connections { + target: authenticator + onFailed: { + message.text = "Authentication failed"; + } + onSucceeded: { + message.text = "Authentication succeeded"; + } + onGraceLockedChanged: { + message.text = "" + } + } + } + TextField { + id: password + enabled: !authenticator.graceLocked + echoMode: TextInput.Password + } + Button { + text: "Authenticate" + enabled: !authenticator.graceLocked + onClicked: { + authenticator.tryUnlock(password.text) + } + } + } +}