Skip to content

Commit fbcd35e

Browse files
committed
[tests] Add test application for lockscreen testing
1 parent 05d79b2 commit fbcd35e

9 files changed

Lines changed: 215 additions & 0 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include(GNUInstallDirs)
1717

1818
option(USE_SYSTEMD "Use systemd services" ON)
1919
option(USE_GEOCLUE2 "Use geoclue2 location service. If no use classic geoclue" OFF)
20+
option(BUILD_TESTS "Build tests" OFF)
2021

2122
set(QT_MIN_VERSION "6.2.0")
2223
set(CMAKE_INSTALL_PREFIX /usr)
@@ -49,6 +50,11 @@ if(USE_SYSTEMD)
4950
install(FILES data/lipstick.service DESTINATION /usr/lib/systemd/user)
5051
endif()
5152

53+
if(BUILD_TESTS)
54+
find_package(Glacier 1.1 COMPONENTS App REQUIRED)
55+
add_subdirectory(tests)
56+
endif()
57+
5258
install(FILES data/nemovars.conf
5359
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/glacier-home)
5460
install(FILES

‎tests/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(lockscreen_preview)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(PROJECT lockscreen_preview)
2+
add_executable(${PROJECT}
3+
main.cpp
4+
../stubs/lipsticksettings_stub.cpp
5+
../stubs/lipsticksettings_stub.h
6+
../stubs/wallclock_stub.cpp
7+
../stubs/wallclock_stub.h)
8+
9+
add_compile_definitions("SOURCE_ROOT=\"${CMAKE_SOURCE_DIR}\"")
10+
11+
target_link_libraries(${PROJECT} PUBLIC
12+
Qt6::Gui
13+
Qt6::Qml
14+
Qt6::Quick
15+
Glacier::App)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/****************************************************************************************
2+
**
3+
** Copyright (C) 2025 Chupligin Sergey <neochapay@gmail.com>
4+
** All rights reserved.
5+
**
6+
** You may use this file under the terms of BSD license as follows:
7+
**
8+
** Redistribution and use in source and binary forms, with or without
9+
** modification, are permitted provided that the following conditions are met:
10+
** * Redistributions of source code must retain the above copyright
11+
** notice, this list of conditions and the following disclaimer.
12+
** * Redistributions in binary form must reproduce the above copyright
13+
** notice, this list of conditions and the following disclaimer in the
14+
** documentation and/or other materials provided with the distribution.
15+
** * Neither the name of the author nor the
16+
** names of its contributors may be used to endorse or promote products
17+
** derived from this software without specific prior written permission.
18+
**
19+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
23+
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26+
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
**
30+
****************************************************************************************/
31+
32+
import QtQuick
33+
import QtQuick.Controls
34+
35+
ApplicationWindow {
36+
id: root
37+
38+
Component.onCompleted: {
39+
var lockScreen = Qt.createComponent(sourceDir + "/src/qml/Lockscreen.qml");
40+
if (lockScreen.status == Component.Ready) {
41+
lockScreen.createObject(root, {x: 0, y: 0});
42+
}
43+
}
44+
}

‎tests/lockscreen_preview/main.cpp‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/****************************************************************************************
2+
**
3+
** Copyright (C) 2025 Chupligin Sergey <neochapay@gmail.com>
4+
** All rights reserved.
5+
**
6+
** You may use this file under the terms of BSD license as follows:
7+
**
8+
** Redistribution and use in source and binary forms, with or without
9+
** modification, are permitted provided that the following conditions are met:
10+
** * Redistributions of source code must retain the above copyright
11+
** notice, this list of conditions and the following disclaimer.
12+
** * Redistributions in binary form must reproduce the above copyright
13+
** notice, this list of conditions and the following disclaimer in the
14+
** documentation and/or other materials provided with the distribution.
15+
** * Neither the name of the author nor the
16+
** names of its contributors may be used to endorse or promote products
17+
** derived from this software without specific prior written permission.
18+
**
19+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
23+
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26+
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
**
30+
****************************************************************************************/
31+
32+
#include <QGuiApplication>
33+
#include <QQmlApplicationEngine>
34+
#include <QQuickWindow>
35+
36+
#include <glacierapp.h>
37+
38+
#include "../stubs/lipsticksettings_stub.h"
39+
#include "../stubs/wallclock_stub.h"
40+
#include "qqmlcontext.h"
41+
42+
#ifndef SOURCE_ROOT
43+
#error "Source dir not deffined"
44+
#endif
45+
46+
47+
int main(int argc, char** argv)
48+
{
49+
QGuiApplication* app = GlacierApp::app(argc, argv);
50+
QQmlApplicationEngine* engine = GlacierApp::engine(app);
51+
52+
QString sourceDir = QString(SOURCE_ROOT);
53+
LipstickSettingsStub lipstickSettings;
54+
WallClockStub wallClock;
55+
56+
57+
engine->rootContext()->setContextProperty("LipstickSettings", &lipstickSettings);
58+
engine->rootContext()->setContextProperty("wallClock", &wallClock);
59+
engine->rootContext()->setContextProperty("sourceDir", sourceDir);
60+
61+
QQuickWindow* window = GlacierApp::showWindow(sourceDir+"/tests/lockscreen_preview/LocscreenTestWindow.qml");
62+
window->setTitle(QObject::tr("Lockscreen test"));
63+
64+
return app->exec();
65+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "lipsticksettings_stub.h"
2+
3+
LipstickSettingsStub::LipstickSettingsStub(QObject* parent)
4+
: QObject { parent }
5+
, m_lockscreenVisible(true)
6+
{
7+
}
8+
9+
bool LipstickSettingsStub::lockscreenVisible() const
10+
{
11+
return m_lockscreenVisible;
12+
}
13+
14+
void LipstickSettingsStub::setLockscreenVisible(bool newLockscreenVisible)
15+
{
16+
if (m_lockscreenVisible == newLockscreenVisible)
17+
return;
18+
m_lockscreenVisible = newLockscreenVisible;
19+
emit lockscreenVisibleChanged();
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef LIPSTICKSETTINGS_STUB_H
2+
#define LIPSTICKSETTINGS_STUB_H
3+
4+
#include <QObject>
5+
6+
class LipstickSettingsStub : public QObject {
7+
Q_OBJECT
8+
Q_PROPERTY(bool lockscreenVisible READ lockscreenVisible WRITE setLockscreenVisible NOTIFY lockscreenVisibleChanged FINAL)
9+
10+
public:
11+
explicit LipstickSettingsStub(QObject* parent = nullptr);
12+
13+
bool lockscreenVisible() const;
14+
void setLockscreenVisible(bool newLockscreenVisible);
15+
16+
signals:
17+
void lockscreenVisibleChanged();
18+
private:
19+
bool m_lockscreenVisible;
20+
};
21+
22+
#endif // LIPSTICKSETTINGS_STUB_H

‎tests/stubs/wallclock_stub.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "wallclock_stub.h"
2+
3+
WallClockStub::WallClockStub(QObject *parent)
4+
: QObject { parent }
5+
, m_time(QDateTime::currentDateTime())
6+
{
7+
}
8+
9+
QDateTime WallClockStub::time() const
10+
{
11+
return m_time;
12+
}
13+
14+
void WallClockStub::setTime(const QDateTime &newTime)
15+
{
16+
if (m_time == newTime)
17+
return;
18+
m_time = newTime;
19+
emit timeChanged();
20+
}

‎tests/stubs/wallclock_stub.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef WALLCLOCK_STUB_H
2+
#define WALLCLOCK_STUB_H
3+
4+
#include <QDateTime>
5+
#include <QObject>
6+
7+
class WallClockStub : public QObject {
8+
Q_OBJECT
9+
Q_PROPERTY(QDateTime time READ time WRITE setTime NOTIFY timeChanged FINAL)
10+
public:
11+
explicit WallClockStub(QObject* parent = nullptr);
12+
QDateTime time() const;
13+
void setTime(const QDateTime &newTime);
14+
15+
signals:
16+
void timeChanged();
17+
18+
private:
19+
QDateTime m_time;
20+
};
21+
22+
#endif // WALLCLOCK_STUB_H

0 commit comments

Comments
 (0)