Skip to content

Commit

Permalink
Add lockscreen call to system API, add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Dec 8, 2023
1 parent 9c54aef commit b944a75
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 10 deletions.
2 changes: 0 additions & 2 deletions applications/system-service/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ void Application::uninterruptApplication(){
button_flood[i++] = createEvent(EV_SYN, SYN_REPORT, 1);
button_flood[i++] = createEvent(EV_SYN, SYN_REPORT, 0);
}
buttonDevice.open();
wacomDevice.open();
}
O_INFO("Writing event floods");
touchHandler->write(input_flood, flood_size);
Expand Down
17 changes: 12 additions & 5 deletions applications/system-service/systemapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,16 @@ void SystemAPI::suspend(){
O_DEBUG("Suspend requested.");
}

void SystemAPI::lockscreen(){
auto lockscreenApp = appsAPI->getApplication(appsAPI->lockscreenApplication());
if(lockscreenApp != nullptr){
O_DEBUG("Switching to lock screen application");
lockscreenApp->resumeNoSecurityCheck();
}else{
O_DEBUG("No lock screen application found");
}
}

void SystemAPI::powerOff() {
if(powerOffInhibited()){
O_WARNING("Unable to power off. Action is currently inhibited.");
Expand Down Expand Up @@ -703,11 +713,8 @@ void SystemAPI::suspendTimeout(){
}
void SystemAPI::lockTimeout(){
if(autoLock()){
auto lockscreenApp = appsAPI->getApplication(appsAPI->lockscreenApplication());
if(lockscreenApp != nullptr){
O_INFO("Automatic lock due to inactivity...");
lockscreenApp->resumeNoSecurityCheck();
}
O_INFO("Automatic lock due to inactivity...");
lockscreen();
}
}

Expand Down
1 change: 1 addition & 0 deletions applications/system-service/systemapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class SystemAPI : public APIBase {

public slots:
void suspend();
void lockscreen();
void powerOff();
void reboot();
void activity();
Expand Down
2 changes: 2 additions & 0 deletions interfaces/systemapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
</signal>
<method name="suspend">
</method>
<method name="lockscreen">
</method>
<method name="powerOff">
</method>
<method name="reboot">
Expand Down
4 changes: 2 additions & 2 deletions shared/liboxide/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace Oxide {
return !(QStringList() << "0" << "n" << "no" << "false").contains(env.toLower());
}

std::string getAppName(){
if(!QCoreApplication::startingUp()){
std::string getAppName(bool ignoreQApp){
if(!ignoreQApp && !QCoreApplication::startingUp()){
return qApp->applicationName().toStdString().c_str();
}
static std::string name;
Expand Down
3 changes: 2 additions & 1 deletion shared/liboxide/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ namespace Oxide {
LIBOXIDE_EXPORT bool debugEnabled();
/*!
* \brief Get the name of the application
* \param Don't use qApp's application name
* \return The name of the application
*/
LIBOXIDE_EXPORT std::string getAppName();
LIBOXIDE_EXPORT std::string getAppName(bool ignoreQApp = false);
/*!
* \brief Print the current backtrace
*/
Expand Down
1 change: 1 addition & 0 deletions shared/liboxide/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QVariant>
#include <QJsonArray>
#include <QDBusArgument>
#include <QJsonDocument>
/*!
* \brief The JSON namespace
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/liboxide/liboxide.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ TEMPLATE = app
SOURCES += \
main.cpp \
test_Debug.cpp \
test_Event_Device.cpp \
test_Json.cpp \
test_Math.cpp \
test_QByteArray.cpp \
test_Threading.cpp
Expand All @@ -25,6 +27,8 @@ include(../../qmake/liboxide.pri)
HEADERS += \
autotest.h \
test_Debug.h \
test_Event_Device.h \
test_Json.h \
test_Math.h \
test_QByteArray.h \
test_Threading.h
42 changes: 42 additions & 0 deletions tests/liboxide/test_Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,48 @@
test_Debug::test_Debug(){ }
test_Debug::~test_Debug(){ }

void test_Debug::test_getDebugApplicationInfo(){
QCOMPARE(
QString::fromStdString(Oxide::getDebugApplicationInfo()),
QString("[%1:%2:%3 liboxide]")
.arg(::getpgrp())
.arg(::getpid())
.arg(::gettid())
);
}

void test_Debug::test_getDebugLocation(){
QCOMPARE(QString::fromStdString(Oxide::getDebugLocation("file", 0, "function")), "(file:0, function)");
QCOMPARE(QString::fromStdString(Oxide::getDebugLocation("file", 1, "function")), "(file:1, function)");
}

void test_Debug::test_debugEnabled(){
unsetenv("DEBUG");
QVERIFY(!Oxide::debugEnabled());
::setenv("DEBUG", "0", true);
QVERIFY(!Oxide::debugEnabled());
::setenv("DEBUG", "n", true);
QVERIFY(!Oxide::debugEnabled());
::setenv("DEBUG", "no", true);
QVERIFY(!Oxide::debugEnabled());
::setenv("DEBUG", "false", true);
QVERIFY(!Oxide::debugEnabled());
::setenv("DEBUG", "1", true);
QVERIFY(Oxide::debugEnabled());
}

void test_Debug::test_getAppName(){
QCOMPARE(QString::fromStdString(Oxide::getAppName()), QString("liboxide"));
qApp->setApplicationName("liboxide-test");
QCOMPARE(QString::fromStdString(Oxide::getAppName()), QString("liboxide-test"));
qApp->setApplicationName("liboxide");
QCOMPARE(QString::fromStdString(Oxide::getAppName()), QString("liboxide"));
QCOMPARE(QString::fromStdString(Oxide::getAppName(true)), QString("liboxide"));
// TODO - test /proc/self/comm changing
// TODO - test /proc/self/exe changing
// TODO - test /proc/self/{comm,exe} both being null
}

void test_Debug::test_backtrace(){
auto trace = Oxide::backtrace(2);
QCOMPARE(trace.size(), 1);
Expand Down
4 changes: 4 additions & 0 deletions tests/liboxide/test_Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ class test_Debug : public QObject{
~test_Debug();

private slots:
void test_getDebugApplicationInfo();
void test_getDebugLocation();
void test_debugEnabled();
void test_getAppName();
void test_backtrace();
};
39 changes: 39 additions & 0 deletions tests/liboxide/test_Event_Device.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "test_Event_Device.h"

#include <liboxide/event_device.h>

test_Event_Device::test_Event_Device(){ }
test_Event_Device::~test_Event_Device(){ }

void test_Event_Device::test_create_device(){
auto ev = Oxide::event_device::create_event(0, 0, 0);
QCOMPARE(ev.type, 0);
QCOMPARE(ev.code, 0);
QCOMPARE(ev.value, 0);
ev = Oxide::event_device::create_event(1, 1, 1);
QCOMPARE(ev.type, 1);
QCOMPARE(ev.code, 1);
QCOMPARE(ev.value, 1);
}

void test_Event_Device::test_event_device(){
Oxide::event_device event0("/dev/input/event0", O_RDWR);
QCOMPARE(event0.device, "/dev/input/event0");
QVERIFY(!event0.locked);
event0.lock();
QVERIFY(event0.locked);
event0.unlock();
QVERIFY(!event0.locked);
QVERIFY(event0.fd > 0);
input_absinfo absInfo;
memset(&absInfo, 0, sizeof(input_absinfo));
ioctl(event0.fd, EVIOCGABS(ABS_MT_POSITION_X), &absInfo);
QCOMPARE(event0.abs_info(ABS_MT_POSITION_X).maximum, absInfo.maximum);
// TODO - test ev_syn
// TODO - test ev_dropped
// TODO - test write
event0.close();
QCOMPARE(event0.fd, 0);
}

DECLARE_TEST(test_Event_Device)
16 changes: 16 additions & 0 deletions tests/liboxide/test_Event_Device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#pragma once
#include "autotest.h"

class test_Event_Device : public QObject{
Q_OBJECT

public:
test_Event_Device();
~test_Event_Device();

private slots:
void test_create_device();
void test_event_device();
};
73 changes: 73 additions & 0 deletions tests/liboxide/test_Json.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "test_Json.h"

#include <liboxide/json.h>
#include <QJsonObject>

test_Json::test_Json(){ }
test_Json::~test_Json(){ }

void test_Json::test_decodeDBusArgument(){
// TODO - Oxide::JSON::decodeDBusArgument();
}

void test_Json::test_sanitizeForJson(){
// TODO - Oxide::JSON::sanitizeForJson();
}

void test_Json::test_toJson(){
QCOMPARE(Oxide::JSON::toJson(QVariant()), "null");
QCOMPARE(Oxide::JSON::toJson(true), "true");
QCOMPARE(Oxide::JSON::toJson(false), "false");
QCOMPARE(Oxide::JSON::toJson(10), "10");
QCOMPARE(Oxide::JSON::toJson(10.1), "10.1");
QCOMPARE(Oxide::JSON::toJson("10"), "\"10\"");
QJsonObject obj;
obj.insert("value", 10);
QCOMPARE(Oxide::JSON::toJson(obj), "{\"value\":10}");
QCOMPARE(Oxide::JSON::toJson(obj, QJsonDocument::Indented), "{\n \"value\": 10\n}\n");
QJsonArray arr;
arr.append(10);
arr.append("10");
QCOMPARE(Oxide::JSON::toJson(arr), "[10,\"10\"]");
QCOMPARE(Oxide::JSON::toJson(arr, QJsonDocument::Indented), "[\n 10,\n \"10\"\n]\n");
}

void test_Json::test_fromJson(){
QVariant variant = Oxide::JSON::fromJson("null");
QVERIFY(variant.isNull());
variant = Oxide::JSON::fromJson("true");
QVERIFY(variant.isValid());
QVERIFY(!variant.isNull());
QCOMPARE(variant.toBool(), true);
variant = Oxide::JSON::fromJson("false");
QVERIFY(variant.isValid());
QVERIFY(!variant.isNull());
QCOMPARE(variant.toBool(), false);
variant = Oxide::JSON::fromJson("1");
QVERIFY(variant.isValid());
QVERIFY(!variant.isNull());
QCOMPARE(variant.toInt(), 1);
variant = Oxide::JSON::fromJson("\"1\"");
QVERIFY(variant.isValid());
QVERIFY(!variant.isNull());
QCOMPARE(variant.toString(), "1");
variant = Oxide::JSON::fromJson("{\"value\": 10}");
QVERIFY(variant.isValid());
QVERIFY(!variant.isNull());
QJsonObject obj = variant.toJsonObject();
QVERIFY(obj.keys().contains("value"));
QCOMPARE(obj.value("value"), 10);
variant = Oxide::JSON::fromJson("[10, \"10\"]");
QVERIFY(variant.isValid());
QVERIFY(!variant.isNull());
QJsonArray arr = variant.toJsonArray();
QCOMPARE(arr.count(), 2);
QJsonValue value = arr.first();
QVERIFY(value.isDouble());
QCOMPARE(value.toDouble(), 10);
value = arr.last();
QVERIFY(value.isString());
QCOMPARE(value.toString(), "10");
}

DECLARE_TEST(test_Json)
18 changes: 18 additions & 0 deletions tests/liboxide/test_Json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#pragma once
#include "autotest.h"

class test_Json : public QObject{
Q_OBJECT

public:
test_Json();
~test_Json();

private slots:
void test_decodeDBusArgument();
void test_sanitizeForJson();
void test_toJson();
void test_fromJson();
};

0 comments on commit b944a75

Please sign in to comment.