ukui-screensaver/ 0000775 0001750 0001750 00000000000 15172041106 012770 5 ustar feng feng ukui-screensaver/tests/ 0000775 0001750 0001750 00000000000 15172041106 014132 5 ustar feng feng ukui-screensaver/tests/unit_test_biometric_helper/ 0000775 0001750 0001750 00000000000 15172041106 021544 5 ustar feng feng ukui-screensaver/tests/unit_test_biometric_helper/CMakeLists.txt 0000664 0001750 0001750 00000003560 15172041106 024310 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/dbusifs/biometrichelper.cpp
../../src/common/biodefines.cpp
../../src/dbusifs/giodbus.cpp
unit_test_biometric_helper.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/common/biodefines.h
../../src/dbusifs/biometrichelper.h
../../src/dbusifs/giodbus.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${GLIB2_INCLUDE_DIRS}
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_biometric_helper ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_biometric_helper
Qt5::Core
Qt5::Gui
Qt5::DBus
)
# 链接 GTest 库
target_link_libraries(unit_test_biometric_helper
GTest::GTest
GTest::Main
Threads::Threads
${GLIB2_LIBRARIES}
)
ukui-screensaver/tests/unit_test_biometric_helper/main.cpp 0000664 0001750 0001750 00000001562 15172041035 023201 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_biometric_helper/unit_test_biometric_helper.cpp 0000664 0001750 0001750 00000007654 15172041035 027677 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include
#include
#include "../../src/dbusifs/biometrichelper.h"
#include "../../src/dbusifs/giodbus.h"
#include "stubext.h"
using namespace stub_ext;
class BiometricHelperTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pABiometricHelperDbus = new BiometricHelper();
}
static void TearDownTestSuite()
{
delete m_pABiometricHelperDbus;
m_pABiometricHelperDbus = nullptr;
}
static BiometricHelper *m_pABiometricHelperDbus;
};
BiometricHelper *BiometricHelperTest::m_pABiometricHelperDbus = nullptr;
TEST_F(BiometricHelperTest, Identify)
{
get_server_gvariant_stdout(-1);
QDBusPendingCall value = m_pABiometricHelperDbus->Identify(32, 1000, 0, -1);
ASSERT_EQ(value.isValid(), false);
}
TEST_F(BiometricHelperTest, UkeyIdentify)
{
QDBusPendingCall value = m_pABiometricHelperDbus->UkeyIdentify(100, 2, 1000);
ASSERT_EQ(value.isValid(), false);
}
TEST_F(BiometricHelperTest, GetHasUkeyFeature)
{
bool value = m_pABiometricHelperDbus->GetHasUkeyFeature(1000, 0, -1);
ASSERT_EQ(value, false);
}
TEST_F(BiometricHelperTest, GetFeatureCount)
{
bool value = m_pABiometricHelperDbus->GetFeatureCount(1000, 0, -1);
ASSERT_EQ(value, false);
}
TEST_F(BiometricHelperTest, SetExtraInfo)
{
int value = m_pABiometricHelperDbus->SetExtraInfo("extra_info", "extra_info");
ASSERT_EQ(value, 0);
}
TEST_F(BiometricHelperTest, StopOps)
{
int value = m_pABiometricHelperDbus->StopOps(32, 3000);
ASSERT_EQ(value, 0);
}
TEST_F(BiometricHelperTest, GetUserDevCount)
{
int value = m_pABiometricHelperDbus->GetUserDevCount(1000);
ASSERT_EQ(value, 0);
}
TEST_F(BiometricHelperTest, GetUserDevFeatureCount)
{
int value = m_pABiometricHelperDbus->GetUserDevFeatureCount(1000, 32);
ASSERT_EQ(value, 0);
}
TEST_F(BiometricHelperTest, GetDevList)
{
DeviceList value = m_pABiometricHelperDbus->GetDevList();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(BiometricHelperTest, GetUserFeatures)
{
FeatureMap value = m_pABiometricHelperDbus->GetUserFeatures(1000);
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BiometricHelperTest, GetDevCount)
{
int value = m_pABiometricHelperDbus->GetDevCount();
ASSERT_EQ(value, 0);
}
TEST_F(BiometricHelperTest, GetDevMesg)
{
QString value = m_pABiometricHelperDbus->GetDevMesg(32);
std::string str = value.toStdString();
const char* cstr = str.data();
ASSERT_EQ(cstr, "");
}
TEST_F(BiometricHelperTest, GetNotifyMesg)
{
QString value = m_pABiometricHelperDbus->GetNotifyMesg(32);
std::string str = value.toStdString();
const char* cstr = str.data();
ASSERT_EQ(cstr, "");
}
TEST_F(BiometricHelperTest, GetOpsMesg)
{
QString value = m_pABiometricHelperDbus->GetOpsMesg(32);
std::string str = value.toStdString();
const char* cstr = str.data();
ASSERT_EQ(cstr, "");
}
TEST_F(BiometricHelperTest, UpdateStatus)
{
StatusReslut status = m_pABiometricHelperDbus->UpdateStatus(32);
ASSERT_EQ(status.result , 0);
ASSERT_EQ(status.enable , 0);
ASSERT_EQ(status.devNum , 0);
ASSERT_EQ(status.devStatus , 0);
ASSERT_EQ(status.opsStatus , 0);
ASSERT_EQ(status.notifyMessageId , 0);
}
ukui-screensaver/tests/unit_test_session_helper/ 0000775 0001750 0001750 00000000000 15172041106 021252 5 ustar feng feng ukui-screensaver/tests/unit_test_session_helper/CMakeLists.txt 0000664 0001750 0001750 00000004200 15172041106 024006 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(QGS REQUIRED gsettings-qt)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control -fno-exceptions")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/dbusifs/sessionhelper.cpp
../../src/dbusifs/login1helper.cpp
../../src/dbusifs/dbusservermanager.cpp
../../src/userinfo.cpp
../../src/common/global_utils.cpp
../../src/lock-backend/gsettingshelper.cpp
unit_test_session_helper.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/common/definetypes.h
../../src/userinfo.h
../../src/common/global_utils.h
../../src/dbusifs/sessionhelper.h
../../src/dbusifs/login1helper.h
../../src/dbusifs/dbusservermanager.h
../../src/lock-backend/gsettingshelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${QGS_INCLUDE_DIRS}
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_session_helper ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_session_helper
Qt5::Core
Qt5::Gui
Qt5::DBus
${QGS_LIBRARIES}
)
# 链接 GTest 库
target_link_libraries(unit_test_session_helper
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_session_helper/main.cpp 0000664 0001750 0001750 00000001562 15172041035 022707 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_session_helper/unit_test_session_helper.cpp 0000664 0001750 0001750 00000005454 15172041035 027107 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include "../../src/dbusifs/sessionhelper.h"
#include "../../src/dbusifs/login1helper.h"
#include "stubext.h"
using namespace stub_ext;
class SessionHelperTest : public testing::Test, public QObject
{
protected:
static void SetUpTestSuite()
{
m_login1Helper = QSharedPointer(new Login1Helper(nullptr));
m_pSessionHelperDbus = new SessionHelper(m_login1Helper);
}
static void TearDownTestSuite()
{
delete m_pSessionHelperDbus;
m_pSessionHelperDbus = nullptr;
}
static SessionHelper *m_pSessionHelperDbus;
static QSharedPointer m_login1Helper;
};
SessionHelper *SessionHelperTest::m_pSessionHelperDbus = nullptr;
QSharedPointer SessionHelperTest::m_login1Helper = nullptr;
TEST_F(SessionHelperTest, canAction)
{
bool value = m_pSessionHelperDbus->canAction(PowerHibernate);
bool value1 = m_pSessionHelperDbus->canAction(PowerSuspend);
bool value2 = m_pSessionHelperDbus->canAction(PowerMonitorOff);
bool value3 = m_pSessionHelperDbus->canAction(PowerLogout);
bool value4 = m_pSessionHelperDbus->canAction(PowerReboot);
bool value5 = m_pSessionHelperDbus->canAction(PowerShutdown);
bool value6 = m_pSessionHelperDbus->canAction(PowerSwitchUser);
// bool value7 = m_pSessionHelperDbus->canAction(TestAction);
ASSERT_EQ(value, true);
ASSERT_EQ(value1, true);
ASSERT_EQ(value2, true);
ASSERT_EQ(value3, true);
ASSERT_EQ(value4, true);
ASSERT_EQ(value5, true);
ASSERT_EQ(value6, true);
}
TEST_F(SessionHelperTest, doAction)
{
bool value = m_pSessionHelperDbus->doAction("Suspend");
ASSERT_EQ(value, true);
}
TEST_F(SessionHelperTest, getLockCheckStatus)
{
QStringList value = m_pSessionHelperDbus->getLockCheckStatus("shutdown");
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(SessionHelperTest, playShutdownMusic)
{
bool value = m_pSessionHelperDbus->playShutdownMusic("Logout");
m_pSessionHelperDbus->playShutdownMusic("Reboot");
m_pSessionHelperDbus->playShutdownMusic("SwitchUser");
ASSERT_EQ(value, true);
}
ukui-screensaver/tests/unit_test_account_helper/ 0000775 0001750 0001750 00000000000 15172041106 021223 5 ustar feng feng ukui-screensaver/tests/unit_test_account_helper/unit_test_account_helper.cpp 0000664 0001750 0001750 00000004500 15172041035 027020 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include "../../src/dbusifs/accountshelper.h"
#include "stubext.h"
using namespace stub_ext;
class AccountsHelperTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pAccountsHelperDbus = new AccountsHelper();
}
static void TearDownTestSuite()
{
delete m_pAccountsHelperDbus;
m_pAccountsHelperDbus = nullptr;
}
static AccountsHelper *m_pAccountsHelperDbus;
};
AccountsHelper *AccountsHelperTest::m_pAccountsHelperDbus = nullptr;
TEST_F(AccountsHelperTest, UserLanguageByName)
{
QString value = m_pAccountsHelperDbus->getUserLanguageByName(getenv("USER"));
std::string str = value.toStdString();
const char* cstr = str.data();
ASSERT_STREQ(cstr, "zh_CN");
}
TEST_F(AccountsHelperTest, UserBackgroundByName)
{
QString value = m_pAccountsHelperDbus->getUserBackgroundByName(getenv("USER"));
std::string str = value.toStdString();
const char* cstr = str.data();
ASSERT_STREQ(cstr, "zh_CN");
}
TEST_F(AccountsHelperTest, UserSessionByName)
{
QString value = m_pAccountsHelperDbus->getUserSessionByName(getenv("USER"));
std::string str = value.toStdString();
const char* cstr = str.data();
ASSERT_STREQ(cstr, "zh_CN");
}
TEST_F(AccountsHelperTest, AccountBackground)
{
QString value = m_pAccountsHelperDbus->getAccountBackground(1000);
std::string str = value.toStdString();
const char* cstr = str.data();
ASSERT_STREQ(cstr, "zh_CN");
}
TEST_F(AccountsHelperTest, UserList)
{
QStringList value = m_pAccountsHelperDbus->getUserList();
ASSERT_EQ(value.isEmpty(), false);
}
ukui-screensaver/tests/unit_test_account_helper/CMakeLists.txt 0000664 0001750 0001750 00000003302 15172041106 023761 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/dbusifs/accountshelper.cpp
../../src/userinfo.cpp
../../src/common/global_utils.cpp
unit_test_account_helper.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/common/definetypes.h
../../src/userinfo.h
../../src/common/global_utils.h
../../src/dbusifs/accountshelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_account_helper ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_account_helper
Qt5::Core
Qt5::Gui
Qt5::DBus
)
# 链接 GTest 库
target_link_libraries(unit_test_account_helper
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_account_helper/main.cpp 0000664 0001750 0001750 00000001562 15172041035 022660 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/auto_test.sh 0000775 0001750 0001750 00000003035 15172041035 016502 0 ustar feng feng #!/bin/bash
# 设置退出脚本当命令失败时 (非零退出状态)
#set -e
# 函数:运行单元测试
run_unit_tests() {
local pattern="unit_test_*"
# 遍历所有匹配模式的目录
for dir in $pattern; do
if [ -d "$dir" ] && [ -x "$dir/$(basename "$dir")" ]; then
echo "Running tests in $dir..."
# 执行单元测试
(cd "$dir" && "./$(basename "$dir")")
# 收集代码覆盖率数据
echo "Collecting coverage data..."
(cd "$dir" && (find ./ -name '*.o' | xargs gcov --preserve-paths))
else
echo "Skipping non-existent or non-executable directory: $dir, $dir/$(basename "$dir")"
fi
done
}
# 上传 result.zip 到平台
URL=$1
upload_result() {
echo "current pwd : $(pwd)"
# 收集覆盖率信息
lcov -d . -c -o r.info
# 删除不需要的文件或路径
lcov -r r.info "$(pwd)/unit_test_*" "$(pwd)/../registeredSession/universalinterface.cpp" "/usr/include/*" "/opt/*" -o coverage.info
# 生成html覆盖率报告
genhtml "$(pwd)/coverage.info" -o result
# 打包
zip -r result.zip result
# 上传平台
curl --insecure -X POST -F "file=@/$(pwd)/result.zip" -F "package=ukui-control-center" -F "username=hesisheng" $URL
echo "all parameter : $@"
}
# 编译项目
echo "Compiling the project..."
cmake . && make
# 运行各个单元测试
echo "Running unit tests..."
run_unit_tests
# 上传到平台
#upload_result
echo "All tests have been run successfully, and coverage data has been collected."
ukui-screensaver/tests/unit_test_common/ 0000775 0001750 0001750 00000000000 15172041106 017520 5 ustar feng feng ukui-screensaver/tests/unit_test_common/CMakeLists.txt 0000664 0001750 0001750 00000004721 15172041106 022264 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui Widgets X11Extras Svg DBus REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(QGS REQUIRED gsettings-qt)
find_package(OpenSSL REQUIRED)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
find_package(X11 REQUIRED)
pkg_check_modules(GIOUNIX2 REQUIRED gio-unix-2.0)
pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/common/biodefines.cpp
../../src/common/commonfunc.cpp
../../src/common/configuration.cpp
../../src/common/global_utils.cpp
../../src/common/kyrsac.cpp
../../src/common/utils.cpp
../../src/lock-dialog/languagesetting.cpp
unit_test_common.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/common/definetypes.h
../../src/common/biodefines.h
../../src/common/commonfunc.h
../../src/common/configuration.h
../../src/common/global_utils.h
../../src/common/kyrsac.h
../../src/common/utils.h
../../src/lock-dialog/languagesetting.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${QGS_INCLUDE_DIRS}
${GIOUNIX2_INCLUDE_DIRS}
${X11_INCLUDE_DIRS}
)
qt5_add_resources(unit_test_common
assets.qrc
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_common ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_common
Qt5::Core
Qt5::Gui
Qt5::DBus
Qt5::Widgets
Qt5::Svg
Qt5::X11Extras
${QGS_LIBRARIES}
OpenSSL::Crypto
)
# 链接 GTest 库
target_link_libraries(unit_test_common
GTest::GTest
GTest::Main
Threads::Threads
${GIOUNIX2_LIBRARIES}
${X11_LIBRARIES}
)
ukui-screensaver/tests/unit_test_common/main.cpp 0000664 0001750 0001750 00000001562 15172041035 021155 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_common/unit_test_common.cpp 0000664 0001750 0001750 00000020362 15172041035 023616 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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 "../../src/common/definetypes.h"
#include "../../src/common/biodefines.h"
#include "../../src/common/commonfunc.h"
#include "../../src/common/configuration.h"
#include "../../src/common/global_utils.h"
#include "../../src/common/kyrsac.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "../../src/common/kyrsac.h"
#include "../../src/common/utils.h"
#include "../../src/lock-dialog/languagesetting.h"
#include "stubext.h"
using namespace stub_ext;
// 辅助函数,用于初始化OpenSSL库
void InitOpenSSL() {
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
}
// 辅助函数,用于清理OpenSSL库
void CleanupOpenSSL() {
EVP_cleanup();
ERR_free_strings();
}
class CommonTest : public testing::Test
{
protected:
void SetUp() override {
InitOpenSSL();
}
void TearDown() override {
CleanupOpenSSL();
}
KyRSAC rsac;
};
TEST_F(CommonTest, scaledPixmap)
{
setCursorCenter();
QPixmap pixmap = QIcon::fromTheme("view-refresh-symbolic").pixmap(48, 48);
QPixmap newPixmap = scaledPixmap(pixmap);
ASSERT_EQ(newPixmap.isNull(), false);
}
TEST_F(CommonTest, PixmapToRound)
{
QPixmap pixmap = QIcon::fromTheme("view-refresh-symbolic").pixmap(48, 48);
QPixmap newPixmap = PixmapToRound(pixmap, 4);
ASSERT_EQ(newPixmap.isNull(), false);
}
TEST_F(CommonTest, PixmapToRound2)
{
QPixmap pixmap = QIcon::fromTheme("view-refresh-symbolic").pixmap(48, 48);
QPixmap newPixmap = PixmapToRound(pixmap, 0, 0, 0, 0);
ASSERT_EQ(newPixmap.isNull(), false);
}
TEST_F(CommonTest, loadSvg)
{
QPixmap iconPixmap = loadSvg(":/image/assets/show-password.png", "white", 16);
ASSERT_EQ(iconPixmap.isNull(), false);
}
TEST_F(CommonTest, drawSymbolicColoredPixmap)
{
QPixmap retryIcon = QIcon::fromTheme("view-refresh-symbolic").pixmap(48, 48);
ASSERT_EQ(drawSymbolicColoredPixmap(retryIcon, "white").isNull(), false);
ASSERT_EQ(getLoadingIcon(16).width(), 16);
}
TEST_F(CommonTest, scaleBlurPixmap)
{
QPixmap *pixmap = new QPixmap(scaleBlurPixmap(16, 16, "/usr/share/background/house.png"));
ASSERT_EQ(pixmap->width(), 16);
}
TEST_F(CommonTest, blurPixmap)
{
QPixmap pixmap = QIcon::fromTheme("view-refresh-symbolic").pixmap(48, 48);
QPixmap newpixmap = blurPixmap(pixmap);
ASSERT_EQ(newpixmap.width(), 16);
}
TEST_F(CommonTest, getDeviceTypeTr)
{
getDeviceTypeTr(BioT_FingerVein);
getDeviceTypeTr(BioT_Iris);
getDeviceTypeTr(BioT_Face);
getDeviceTypeTr(BioT_VoicePrint);
getDeviceTypeTr(UniT_General_Ukey);
getDeviceTypeTr(UniT_Remote);
getDeviceTypeTr(-1);
ASSERT_EQ(getDeviceTypeTr(BioT_FingerPrint).isEmpty(), false);
}
TEST_F(CommonTest, getValue)
{
if (Configuration::instance()) {
QString color = Configuration::instance()->getValue("background-color").toString();
ASSERT_EQ(color.isEmpty(), false);
}
}
TEST_F(CommonTest, getCurrentUser)
{
if (Configuration::instance()) {
Configuration::instance()->getCurrentUser(getenv("USER"));
}
}
TEST_F(CommonTest, setValue)
{
if (Configuration::instance()) {
QString color = Configuration::instance()->getValue("backgroundPath").toString();
QString oldvalue = Configuration::instance()->getUserConfig("backgroundPath").toString();
Configuration::instance()->setValue("backgroundPath", oldvalue);
ASSERT_EQ(oldvalue.isEmpty(), false);
}
}
TEST_F(CommonTest, hasValue)
{
if (Configuration::instance()) {
bool value = Configuration::instance()->hasValue("backgroundPath");
ASSERT_EQ(value, false);
}
}
TEST_F(CommonTest, getIs990)
{
if (Configuration::instance()) {
bool value = Configuration::instance()->getIs990();
ASSERT_EQ(value, false);
}
}
TEST_F(CommonTest, getLastNumLock)
{
if (Configuration::instance()) {
bool value = Configuration::instance()->getLastNumLock();
Configuration::instance()->saveLastNumLock(value);
ASSERT_EQ(value, false);
}
}
TEST_F(CommonTest, getRootBackgroundOption)
{
if (Configuration::instance()) {
int value = Configuration::instance()->getRootBackgroundOption(getenv("USER"));
ASSERT_EQ(value, 1);
}
}
TEST_F(CommonTest, getDefaultBackgroundName)
{
if (Configuration::instance()) {
QString background = Configuration::instance()->getDefaultBackgroundName();
ASSERT_EQ(background.isEmpty(), false);
}
}
TEST_F(CommonTest, onLanguageChanged)
{
if (LanguageSetting::instance()) {
LanguageSetting::instance()->onLanguageChanged("zh_HK.UTF-8");
LanguageSetting::instance()->onLanguageChanged("zh_CN.UTF-8");
}
}
TEST_F(CommonTest, isCurUserSelf)
{
ASSERT_EQ(isCurUserSelf(getenv("USER")), true);
ASSERT_EQ(isCurUserSelf("lightdm"), false);
ASSERT_EQ(isCurUserSelf("test"), false);
}
TEST_F(CommonTest, checkCapsLockState)
{
checkIslivecd();
KillFocusOfKydroid();
ASSERT_EQ(checkCapsLockState(), false);
}
TEST_F(CommonTest, getDefaultFontSize)
{
ASSERT_EQ(getDefaultFontSize(), 14.0);
}
TEST_F(CommonTest, getUserFontSize)
{
ASSERT_EQ(getUserFontSize(getenv("USER")), 14.0);
}
TEST_F(CommonTest, getUserThemeColor)
{
ASSERT_EQ(getUserThemeColor(getenv("USER")), "test");
}
// 测试密钥生成并保存到文件
TEST_F(CommonTest, GenerateKeyPairToFile) {
QString priKeyFile = "test_private.pem";
QString pubKeyFile = "test_public.pem";
rsac.genKeyPair(priKeyFile, pubKeyFile, 1024);
// 这里可以添加额外的检查来验证文件是否成功生成且内容有效
// 例如,打开文件并读取内容,检查是否为有效的PEM格式密钥
// 但由于这是一个简单的测试示例,我们省略了这些步骤
}
// 测试密钥生成并保存到QByteArray
TEST_F(CommonTest, GenerateKeyPairToByteArray) {
QByteArray privateKey;
QByteArray publicKey;
rsac.genKeyPair(privateKey, publicKey, 1024);
// 检查生成的密钥是否非空
EXPECT_FALSE(privateKey.isEmpty());
EXPECT_FALSE(publicKey.isEmpty());
// 这里可以添加额外的检查来验证密钥的有效性
// 例如,使用OpenSSL函数解析生成的密钥并检查其属性
// 但由于这是一个简单的测试示例,我们省略了这些步骤
}
// 测试加密和解密
TEST_F(CommonTest, EncryptDecrypt) {
QByteArray privateKey;
QByteArray publicKey;
rsac.genKeyPair(privateKey, publicKey, 1024);
QByteArray plaintext = "Hello, RSA!";
QByteArray ciphertext;
QByteArray decryptedtext;
bool encryptResult = rsac.encryptData(plaintext, ciphertext, publicKey);
EXPECT_TRUE(encryptResult);
bool decryptResult = rsac.decryptData(ciphertext, decryptedtext, privateKey);
EXPECT_TRUE(decryptResult);
EXPECT_EQ(plaintext, decryptedtext);
}
// 测试签名和验签
TEST_F(CommonTest, SignVerify) {
QByteArray privateKey;
QByteArray publicKey;
rsac.genKeyPair(privateKey, publicKey, 1024);
QByteArray message = "This is a test message.";
QByteArray signature;
bool signResult = rsac.signData(message, signature, privateKey);
EXPECT_TRUE(signResult);
bool verifyResult = rsac.verifyData(message, signature, publicKey);
EXPECT_TRUE(verifyResult);
// 尝试使用错误的消息进行验签,应该失败
bool verifyWithWrongMessageResult = rsac.verifyData("Wrong message.", signature, publicKey);
EXPECT_FALSE(verifyWithWrongMessageResult);
}
ukui-screensaver/tests/unit_test_screensaver/ 0000775 0001750 0001750 00000000000 15172041106 020550 5 ustar feng feng ukui-screensaver/tests/unit_test_screensaver/unit_test_screensaver.cpp 0000664 0001750 0001750 00000013405 15172041035 025676 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include "../../src/ukccplugins/sessiondbus/screensaverinterface.h"
#include "../../src/lock-backend/lightdmhelper.h"
#include
#include "stubext.h"
using namespace stub_ext;
class ScreensaverInterfaceTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
StubExt st;
st.set_lamda(&LightDMHelper::connectToDaemonSync, []() { return true; });
st.set_lamda(&isGreeterMode, []() { return true; });
m_pDbusUpperInterfaceDbus = new DbusUpperInterface();
m_pDbusUpperInterfaceDbus->init();
m_pScreenSaverInterface = new ScreensaverInterface(m_pDbusUpperInterfaceDbus, m_pDbusUpperInterfaceDbus);
}
static void TearDownTestSuite()
{
if (m_pScreenSaverInterface) {
delete m_pScreenSaverInterface;
m_pScreenSaverInterface = nullptr;
}
delete m_pDbusUpperInterfaceDbus;
m_pDbusUpperInterfaceDbus = nullptr;
}
static ScreensaverInterface *m_pScreenSaverInterface;
static DbusUpperInterface *m_pDbusUpperInterfaceDbus;
};
DbusUpperInterface *ScreensaverInterfaceTest::m_pDbusUpperInterfaceDbus = nullptr;
ScreensaverInterface *ScreensaverInterfaceTest::m_pScreenSaverInterface = nullptr;
TEST_F(ScreensaverInterfaceTest, setPreentryTime)
{
int oldValue = m_pScreenSaverInterface->property("preentryTime").toInt();
m_pScreenSaverInterface->setPreentryTime(10);
int newValue = m_pScreenSaverInterface->property("preentryTime").toInt();
ASSERT_EQ(newValue, 10);
m_pScreenSaverInterface->setPreentryTime(oldValue);
}
TEST_F(ScreensaverInterfaceTest, setScreensaverType)
{
QGSettings gsetting("org.ukui.screensaver");
std::string oldValue = m_pScreenSaverInterface->property("screensaverType").toString().toStdString();
m_pScreenSaverInterface->setScreensaverType("ukui");
std::string newValue = gsetting.get("mode").toString().toStdString();
ASSERT_STREQ(newValue.c_str(), "default-ukui");
m_pScreenSaverInterface->setScreensaverType(oldValue.c_str());
}
TEST_F(ScreensaverInterfaceTest, setShowBreakTimeUkuiCustom)
{
bool oldValue = m_pScreenSaverInterface->property("showBreakTimeCustom").toBool();
m_pScreenSaverInterface->setShowBreakTimeCustom(true);
bool newValue = m_pScreenSaverInterface->property("showBreakTimeCustom").toBool();
ASSERT_EQ(newValue, true);
m_pScreenSaverInterface->setShowBreakTimeCustom(oldValue);
}
TEST_F(ScreensaverInterfaceTest, setShowBreakTimeUkui)
{
bool oldValue = m_pScreenSaverInterface->property("showBreakTimeUkui").toBool();
m_pScreenSaverInterface->setShowBreakTimeUkui(false);
bool newValue = m_pScreenSaverInterface->property("showBreakTimeUkui").toBool();
ASSERT_EQ(newValue, false);
m_pScreenSaverInterface->setShowBreakTimeUkui(oldValue);
}
TEST_F(ScreensaverInterfaceTest, setScreenLockEnabled)
{
bool oldValue = m_pScreenSaverInterface->property("screenLockEnabled").toBool();
m_pScreenSaverInterface->setScreenLockEnabled(false);
bool newValue = m_pScreenSaverInterface->property("screenLockEnabled").toBool();
ASSERT_EQ(newValue, false);
m_pScreenSaverInterface->setScreenLockEnabled(oldValue);
}
TEST_F(ScreensaverInterfaceTest, setCustomPath)
{
std::string oldValue = m_pScreenSaverInterface->property("customPath").toString().toStdString();
m_pScreenSaverInterface->setCustomPath("/test/path");
std::string newValue = m_pScreenSaverInterface->property("customPath").toString().toStdString();
ASSERT_STREQ(newValue.c_str(), "/test/path");
m_pScreenSaverInterface->setCustomPath(oldValue.c_str());
}
TEST_F(ScreensaverInterfaceTest, setSwitchRandom)
{
bool oldValue = m_pScreenSaverInterface->property("switchRandom").toBool();
m_pScreenSaverInterface->setSwitchRandom(false);
bool newValue = m_pScreenSaverInterface->property("switchRandom").toBool();
ASSERT_EQ(newValue, false);
m_pScreenSaverInterface->setSwitchRandom(oldValue);
}
TEST_F(ScreensaverInterfaceTest, setCycleTime)
{
int oldValue = m_pScreenSaverInterface->property("cycleTime").toInt();
m_pScreenSaverInterface->setCycleTime(60);
int newValue = m_pScreenSaverInterface->property("cycleTime").toInt();
ASSERT_EQ(newValue, 60);
m_pScreenSaverInterface->setCycleTime(oldValue);
}
TEST_F(ScreensaverInterfaceTest, setCustomText)
{
std::string oldValue = m_pScreenSaverInterface->property("customText").toString().toStdString();
m_pScreenSaverInterface->setCustomText("test custom text");
std::string newValue = m_pScreenSaverInterface->property("customText").toString().toStdString();
ASSERT_STREQ(newValue.c_str(), "test custom text");
m_pScreenSaverInterface->setCustomText(oldValue.c_str());
}
TEST_F(ScreensaverInterfaceTest, setCustomTextCentered)
{
bool oldValue = m_pScreenSaverInterface->property("customTextCentered").toBool();
m_pScreenSaverInterface->setCustomTextCentered(false);
bool newValue = m_pScreenSaverInterface->property("customTextCentered").toBool();
ASSERT_EQ(newValue, false);
m_pScreenSaverInterface->setCustomTextCentered(oldValue);
}
ukui-screensaver/tests/unit_test_screensaver/CMakeLists.txt 0000664 0001750 0001750 00000012251 15172041106 023311 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core DBus Network Test REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(PkgConfig REQUIRED)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
pkg_check_modules(GIOUNIX2 REQUIRED gio-unix-2.0)
pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0)
pkg_check_modules(QGS REQUIRED gsettings-qt)
pkg_check_modules(LIGHTDM-QT5-3 REQUIRED liblightdm-qt5-3)
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
# 查找pam动态库全路径并缓存到PAM_LIBRARIES变量
find_library(PAM_LIBRARIES pam)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/lock-backend/authpamthread.cpp
../../src/lock-backend/pamauthenticate.cpp
../../src/lock-backend/lightdmhelper.cpp
../../src/lock-backend/dbusupperinterface.cpp
../../src/lock-backend/gsettingshelper.cpp
../../src/lock-backend/bioauthenticate.cpp
../../src/lock-backend/switchuserutils.cpp
../../src/dbusifs/accountshelper.cpp
../../src/userinfo.cpp
../../src/common/global_utils.cpp
../../src/common/configuration.cpp
../../src/common/kyrsac.cpp
../../src/dbusifs/giodbus.cpp
../../src/dbusifs/uniauthservice.cpp
../../src/lock-backend/securityuser.cpp
../../src/dbusifs/freedesktophelper.cpp
../../src/dbusifs/login1helper.cpp
../../src/dbusifs/usdhelper.cpp
../../src/dbusifs/upowerhelper.cpp
../../src/dbusifs/sessionhelper.cpp
../../src/dbusifs/dbusservermanager.cpp
../../src/dbusifs/systemupgradehelper.cpp
../../src/lock-backend/sessionwatcher.cpp
../../src/dbusifs/kglobalaccelhelper.cpp
../../src/dbusifs/libinputswitchevent.cpp
../../src/lock-backend/personalizeddata.cpp
../../src/dbusifs/biometrichelper.cpp
../../src/dbusifs/device.cpp
../../src/dbusifs/machinemodel.cpp
../../src/dbusifs/enginedevice.cpp
../../src/common/biodefines.cpp
../../src/QtSingleApplication/qtlocalpeer.cpp
../kt-test-utils/cpp-stub-ext/stub-shadow.cpp
../../src/ukccplugins/sessiondbus/screensaverinterface.cpp
unit_test_screensaver.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/lock-backend/authpamthread.h
../../src/lock-backend/pamauthenticate.h
../../src/lock-backend/lightdmhelper.h
../../src/lock-backend/dbusupperinterface.h
../../src/lock-backend/gsettingshelper.h
../../src/lock-backend/bioauthenticate.h
../../src/lock-backend/switchuserutils.h
../../src/common/definetypes.h
../../src/userinfo.h
../../src/common/global_utils.h
../../src/common/configuration.h
../../src/common/kyrsac.h
../../src/dbusifs/giodbus.h
../../src/dbusifs/accountshelper.h
../../src/common/configuration.h
../../src/dbusifs/uniauthservice.h
../../src/lock-backend/securityuser.h
../../src/dbusifs/freedesktophelper.h
../../src/dbusifs/login1helper.h
../../src/dbusifs/usdhelper.h
../../src/dbusifs/upowerhelper.h
../../src/dbusifs/dbusservermanager.h
../../src/dbusifs/sessionhelper.h
../../src/dbusifs/systemupgradehelper.h
../../src/lock-backend/sessionwatcher.h
../../src/dbusifs/kglobalaccelhelper.h
../../src/dbusifs/libinputswitchevent.h
../../src/lock-backend/personalizeddata.h
../../src/dbusifs/biometrichelper.h
../../src/dbusifs/device.h
../../src/dbusifs/enginedevice.h
../../src/dbusifs/machinemodel.h
../../src/common/biodefines.h
../kt-test-utils/cpp-stub-ext/stubext.h
../kt-test-utils/cpp-stub-ext/stub-shadow.h
../../src/QtSingleApplication/qtlocalpeer.h
../../src/ukccplugins/sessiondbus/screensaverinterface.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${QGS_INCLUDE_DIRS}
${Qt5Test_INCLUDE_DIRS}
${LIGHTDM-QT5-3_INCLUDE_DIRS}
${LIBSYSTEMD_INCLUDE_DIRS}
${GIOUNIX2_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}../../src/QtSingleApplication/
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_screensaver ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_screensaver
Qt5::Core
Qt5::DBus
Qt5::Test
Qt5::Network
${QGS_LIBRARIES}
${PAM_LIBRARIES}
${LIGHTDM-QT5-3_LIBRARIES}
${LIBSYSTEMD_LIBRARIES}
OpenSSL::Crypto
-lukuiinputgatherclient
${GIOUNIX2_LIBRARIES}
)
# 链接 GTest 库
target_link_libraries(unit_test_screensaver
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_screensaver/main.cpp 0000664 0001750 0001750 00000001462 15172041035 022204 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_auth_pam/ 0000775 0001750 0001750 00000000000 15172041106 020026 5 ustar feng feng ukui-screensaver/tests/unit_test_auth_pam/unit_test_auth_pam.cpp 0000664 0001750 0001750 00000032717 15172041035 024441 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "../../src/dbusifs/accountshelper.h"
#include "../../src/lock-backend/authpamthread.h"
#include "../../src/lock-backend/pamauthenticate.h"
#include "../../src/lock-backend/lightdmhelper.h"
class AuthPamThreadTest : public ::testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pAuthPamThreadDbus = new AuthPamThread();
}
static void TearDownTestSuite()
{
delete m_pAuthPamThreadDbus;
m_pAuthPamThreadDbus = nullptr;
}
static AuthPamThread *m_pAuthPamThreadDbus;
// 辅助函数,模拟文件描述符操作
int createMockPipe()
{
int fds[2];
if (pipe(fds) == -1) {
return -1;
}
return fds[0];
}
// 辅助函数,模拟写入数据到文件描述符
void writeToFd(int fd, const char *data)
{
write(fd, data, strnlen(data, 1024));
}
// 辅助函数,从文件描述符读取数据
std::string readFromFd(int fd)
{
char buffer[1024];
ssize_t bytesRead = read(fd, buffer, sizeof(buffer) - 1);
if (bytesRead > 0) {
buffer[bytesRead] = '\0';
return buffer;
}
return "";
}
// 辅助函数,模拟 pam_start 的返回结果
int mockPamStart(pam_handle_t **pamh, const char *service, const char *user, const struct pam_conv *conv)
{
*pamh = reinterpret_cast(1);
return PAM_SUCCESS;
}
// 辅助函数,模拟 pam_authenticate 的返回结果
int mockPamAuthenticate(pam_handle_t *pamh, int flags)
{
return PAM_SUCCESS;
}
// 辅助函数,模拟 pam_acct_mgmt 的返回结果
int mockPamAcctMgmt(pam_handle_t *pamh, int flags)
{
return PAM_SUCCESS;
}
// 辅助函数,模拟 pam_get_item 的返回结果
int mockPamGetItem(pam_handle_t *pamh, int item_type, const void **item)
{
*item = nullptr;
return PAM_SUCCESS;
}
// 辅助函数,模拟 pam_strerror 的返回结果
const char *mockPamStrerror(pam_handle_t *pamh, int pam_err)
{
return "Mock Error";
}
// 辅助函数,模拟 pam_end 的行为
int mockPamEnd(pam_handle_t *pamh, int pam_status)
{
return PAM_SUCCESS;
}
};
AuthPamThread *AuthPamThreadTest::m_pAuthPamThreadDbus = nullptr;
// 测试 _authenticate 函数
TEST_F(AuthPamThreadTest, Authenticate)
{
m_pAuthPamThreadDbus->m_strUserName = getenv("USER");
qDebug() << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// 模拟 pam 函数
auto originalPamStart = pam_start;
auto originalPamAuthenticate = pam_authenticate;
auto originalPamAcctMgmt = pam_acct_mgmt;
auto originalPamGetItem = pam_get_item;
auto originalPamStrerror = pam_strerror;
auto originalPamEnd = pam_end;
// pam_start = mockPamStart;
// pam_authenticate = mockPamAuthenticate;
// pam_acct_mgmt = mockPamAcctMgmt;
// pam_get_item = mockPamGetItem;
// pam_strerror = mockPamStrerror;
// pam_end = mockPamEnd;
qDebug() << "??????????????????????????????????????";
// m_pAuthPamThreadDbus->_authenticate(m_pAuthPamThreadDbus->m_strUserName.toLocal8Bit().data());
// 恢复原始函数
// pam_start = originalPamStart;
// pam_authenticate = originalPamAuthenticate;
// pam_acct_mgmt = originalPamAcctMgmt;
// pam_get_item = originalPamGetItem;
// pam_strerror = originalPamStrerror;
// pam_end = originalPamEnd;
}
// 测试 startAuthPam 函数
TEST_F(AuthPamThreadTest, StartAuthPam)
{
qDebug() << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
int fdRead = createMockPipe();
int fdWrite = createMockPipe();
m_pAuthPamThreadDbus->startAuthPam(fdRead, fdWrite, getenv("USER"));
EXPECT_TRUE(m_pAuthPamThreadDbus->isRunning());
close(fdRead);
close(fdWrite);
}
// 测试 run 函数
TEST_F(AuthPamThreadTest, Run)
{
int fdRead = createMockPipe();
int fdWrite = createMockPipe();
m_pAuthPamThreadDbus->m_fdRead = fdRead;
m_pAuthPamThreadDbus->m_fdWrite = fdWrite;
m_pAuthPamThreadDbus->m_strUserName = getenv("USER");
// m_pAuthPamThreadDbus->run();
close(fdRead);
close(fdWrite);
}
// 测试 stopAuthPam 函数
TEST_F(AuthPamThreadTest, StopAuthPam)
{
m_pAuthPamThreadDbus->startAuthPam(0, 0, getenv("USER"));
m_pAuthPamThreadDbus->stopAuthPam();
EXPECT_FALSE(m_pAuthPamThreadDbus->isRunning());
}
// 测试 PamAuthenticate 类
class PamAuthenticateTest : public ::testing::Test
{
protected:
static AuthPamThread *m_pAuthPamThreadDbus;
QSharedPointer lightDMHelper;
QSharedPointer pamAuthenticate;
void SetUp() override
{
lightDMHelper = QSharedPointer(
new LightDMHelper(QSharedPointer(new AccountsHelper(nullptr)), nullptr));
pamAuthenticate = QSharedPointer(new PamAuthenticate(lightDMHelper));
}
void TearDown() override
{
pamAuthenticate.reset();
lightDMHelper.reset();
}
// 辅助函数,模拟 QSocketNotifier 的 activated 信号
void simulateSocketNotifierActivated(QSocketNotifier *socketNotifier)
{
// Q_EMIT socketNotifier->activated(socketNotifier->socket());
}
// 辅助函数,模拟管道操作
int createMockPipe()
{
int fds[2];
if (pipe(fds) == -1) {
return -1;
}
return fds[0];
}
// 辅助函数,模拟 AuthPamThread 的行为
class MockAuthPamThread : public AuthPamThread
{
public:
};
// 辅助函数,模拟 LightDMHelper 的行为
class MockLightDMHelper : public LightDMHelper
{
public:
MockLightDMHelper()
: LightDMHelper(QSharedPointer(new AccountsHelper(nullptr)), nullptr, nullptr)
{
}
};
};
// 测试 PamAuthenticate 构造函数
TEST_F(PamAuthenticateTest, Constructor)
{
// 检查信号和槽的连接
// EXPECT_TRUE(QObject::connect(lightDMHelper.get(), SIGNAL(showMessage(QString,
// QLightDM::Greeter::MessageType)),
// pamAuthenticate.get(), SLOT(onLDMShowMessage(QString, QLightDM::Greeter::MessageType)));
// EXPECT_TRUE(QObject::connect(lightDMHelper.get(), SIGNAL(showPrompt(QString, QLightDM::Greeter::PromptType)),
// pamAuthenticate.get(), SLOT(onLDMShowPrompt(QString, QLightDM::Greeter::PromptType)));
// EXPECT_TRUE(QObject::connect(lightDMHelper.get(), SIGNAL(authenticationComplete()),
// pamAuthenticate.get(), SIGNAL(authenticationComplete()));
}
// 测试 inAuthentication 函数
TEST_F(PamAuthenticateTest, InAuthentication)
{
// 测试 m_isOtherUser 为 false 时的情况
EXPECT_FALSE(pamAuthenticate->inAuthentication());
// 测试 m_isOtherUser 为 true 时的情况
pamAuthenticate->m_isOtherUser = true;
EXPECT_FALSE(pamAuthenticate->inAuthentication());
}
// 测试 isAuthenticated 函数
TEST_F(PamAuthenticateTest, IsAuthenticated)
{
// 测试 m_isOtherUser 为 false 时的情况
EXPECT_FALSE(pamAuthenticate->isAuthenticated());
// 测试 m_isOtherUser 为 true 时的情况
pamAuthenticate->m_isOtherUser = true;
EXPECT_FALSE(pamAuthenticate->isAuthenticated());
}
// 测试 authenticationUser 函数
TEST_F(PamAuthenticateTest, AuthenticationUser)
{
// 测试 m_isOtherUser 为 false 时的情况
EXPECT_EQ(pamAuthenticate->authenticationUser(), "");
// 测试 m_isOtherUser 为 true 时的情况
pamAuthenticate->m_isOtherUser = true;
EXPECT_EQ(pamAuthenticate->authenticationUser(), "");
}
// 测试 authenticate 函数
TEST_F(PamAuthenticateTest, Authenticate)
{
// 测试普通用户的情况
pamAuthenticate->authenticate("testuser");
EXPECT_EQ(pamAuthenticate->m_strUserName, "testuser");
EXPECT_NE(pamAuthenticate->m_threadAuthPam, nullptr);
EXPECT_NE(pamAuthenticate->m_socketNotifier, nullptr);
// 测试访客用户的情况
pamAuthenticate->authenticate("*guest");
// 测试 m_isOtherUser 为 true 的情况
pamAuthenticate->m_isOtherUser = true;
pamAuthenticate->authenticate("otheruser");
}
// 测试 respond 函数
TEST_F(PamAuthenticateTest, Respond)
{
// 测试正常响应的情况
pamAuthenticate->m_nPrompts = 1;
pamAuthenticate->respond("response");
EXPECT_EQ(pamAuthenticate->m_responseList.size(), 1);
// 测试 m_nPrompts 为 0 的情况
pamAuthenticate->m_nPrompts = 0;
pamAuthenticate->m_isOtherUser = false;
pamAuthenticate->respond("response");
EXPECT_EQ(pamAuthenticate->m_responseList.size(), 1);
}
// 测试 cancelAuthentication 函数
TEST_F(PamAuthenticateTest, CancelAuthentication)
{
// 模拟 AuthPamThread 和 QSocketNotifier
pamAuthenticate->m_threadAuthPam = new MockAuthPamThread();
pamAuthenticate->m_socketNotifier = new QSocketNotifier(0, QSocketNotifier::Read);
pamAuthenticate->m_isOtherUser = false;
pamAuthenticate->cancelAuthentication();
EXPECT_EQ(pamAuthenticate->m_threadAuthPam, nullptr);
EXPECT_EQ(pamAuthenticate->m_socketNotifier, nullptr);
EXPECT_FALSE(pamAuthenticate->m_isAuthenticated);
EXPECT_FALSE(pamAuthenticate->m_isInAuthentication);
EXPECT_EQ(pamAuthenticate->m_messageList.size(), 0);
EXPECT_EQ(pamAuthenticate->m_responseList.size(), 0);
EXPECT_EQ(pamAuthenticate->m_nPrompts, 0);
}
// 测试 onLDMShowMessage 函数
TEST_F(PamAuthenticateTest, OnLDMShowMessage)
{
pamAuthenticate->onLDMShowMessage("test",QLightDM::Greeter::MessageTypeInfo);
}
// 测试 onLDMShowPrompt 函数
TEST_F(PamAuthenticateTest, OnLDMShowPrompt)
{
pamAuthenticate->onLDMShowPrompt("",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("password",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("BIOMETRIC_PAM",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("{\n\t\"type\":\t0,\n\t\"binaryStr\":\t\"2fa_otp\"\n}",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("{\n\t\"type\":\t1,\n\t\"binaryInt\":\t\"2\"\n}",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("{\n\t\"type\":\t2,\n\t\"binaryStr\":\t\"test\"\n}",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("{\n\t\"type\":\t3,\n\t\"binaryStr\":\t\"test\"\n}",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("{\n\t\"type\":\t4,\n\t\"binaryStr\":\t\"otpauth\"\n}",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("{\n\t\"type\":\t5,\n\t\"binaryStr\":\t\"输入动态口令 \"\n}",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("{\n\t\"type\":\t6,\n\t\"binaryStr\":\t\"输入动态口令 \"\n}",QLightDM::Greeter::PromptTypeQuestion);
pamAuthenticate->onLDMShowPrompt("{\n\t\"type\":\t7,\n\t\"binaryStr\":\t\"输入动态口令 \"\n}",QLightDM::Greeter::PromptTypeQuestion);
}
// 测试 onSockRead 函数
TEST_F(PamAuthenticateTest, OnSockRead)
{
// 模拟管道
int fdToParent[2];
if (pipe(fdToParent) == -1) {
FAIL() << "Failed to create pipe";
}
pamAuthenticate->m_fdToParent[0] = fdToParent[0];
// 测试认证完成的情况
int authComplete = 1;
int authRet = PAM_SUCCESS;
write(pamAuthenticate->m_fdToParent[0], &authComplete, sizeof(authComplete));
write(pamAuthenticate->m_fdToParent[0], &authRet, sizeof(authRet));
QSignalSpy authenticationCompleteSpy(pamAuthenticate.get(), SIGNAL(authenticationComplete()));
simulateSocketNotifierActivated(pamAuthenticate->m_socketNotifier);
EXPECT_EQ(pamAuthenticate->m_isAuthenticated, true);
EXPECT_EQ(authenticationCompleteSpy.count(), 1);
// 测试消息接收的情况
authComplete = 0;
int msgLength = 1;
write(pamAuthenticate->m_fdToParent[0], &authComplete, sizeof(authComplete));
write(pamAuthenticate->m_fdToParent[0], &msgLength, sizeof(msgLength));
struct pam_message message;
message.msg_style = PAM_PROMPT_ECHO_OFF;
message.msg = "Enter password";
write(pamAuthenticate->m_fdToParent[0], &message.msg_style, sizeof(message.msg_style));
write(pamAuthenticate->m_fdToParent[0], message.msg, strnlen(message.msg, 1024) + 1);
QSignalSpy showPromptSpy(pamAuthenticate.get(), SIGNAL(showPrompt(QString, PamAuth::PromptType)));
simulateSocketNotifierActivated(pamAuthenticate->m_socketNotifier);
EXPECT_EQ(showPromptSpy.count(), 1);
close(fdToParent[0]);
close(fdToParent[1]);
}
ukui-screensaver/tests/unit_test_auth_pam/CMakeLists.txt 0000664 0001750 0001750 00000005305 15172041106 022571 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus Test REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(QGS REQUIRED gsettings-qt)
pkg_check_modules(LIGHTDM-QT5-3 REQUIRED liblightdm-qt5-3)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 查找pam动态库全路径并缓存到PAM_LIBRARIES变量
find_library(PAM_LIBRARIES pam)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/lock-backend/authpamthread.cpp
../../src/lock-backend/pamauthenticate.cpp
../../src/lock-backend/lightdmhelper.cpp
../../src/dbusifs/accountshelper.cpp
../../src/userinfo.cpp
../../src/common/global_utils.cpp
../../src/dbusifs/uniauthservice.cpp
../../src/lock-backend/securityuser.cpp
../../src/dbusifs/freedesktophelper.cpp
unit_test_auth_pam.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/lock-backend/authpamthread.h
../../src/lock-backend/pamauthenticate.h
../../src/lock-backend/lightdmhelper.h
../../src/common/definetypes.h
../../src/userinfo.h
../../src/common/global_utils.h
../../src/dbusifs/accountshelper.h
../../src/common/configuration.h
../../src/dbusifs/uniauthservice.h
../../src/lock-backend/securityuser.h
../../src/dbusifs/freedesktophelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${QGS_INCLUDE_DIRS}
${Qt5Test_INCLUDE_DIRS}
${LIGHTDM-QT5-3_INCLUDE_DIRS}
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_auth_pam ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_auth_pam
Qt5::Core
Qt5::Gui
Qt5::DBus
Qt5::Test
${QGS_LIBRARIES}
${PAM_LIBRARIES}
${LIGHTDM-QT5-3_LIBRARIES}
)
# 链接 GTest 库
target_link_libraries(unit_test_auth_pam
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_auth_pam/main.cpp 0000664 0001750 0001750 00000001562 15172041035 021463 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_usd_helper/ 0000775 0001750 0001750 00000000000 15172041106 020362 5 ustar feng feng ukui-screensaver/tests/unit_test_usd_helper/CMakeLists.txt 0000664 0001750 0001750 00000003066 15172041106 023127 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/dbusifs/usdhelper.cpp
unit_test_usd_helper.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/dbusifs/usdhelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_usd_helper ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_usd_helper
Qt5::Core
Qt5::Gui
Qt5::DBus
)
# 链接 GTest 库
target_link_libraries(unit_test_usd_helper
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_usd_helper/main.cpp 0000664 0001750 0001750 00000001562 15172041035 022017 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_usd_helper/unit_test_usd_helper.cpp 0000664 0001750 0001750 00000002470 15172041035 025322 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include "../../src/dbusifs/usdhelper.h"
#include "stubext.h"
using namespace stub_ext;
class UsdHelperTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pUsdHelperDbus = new UsdHelper();
}
static void TearDownTestSuite()
{
delete m_pUsdHelperDbus;
m_pUsdHelperDbus = nullptr;
}
static UsdHelper *m_pUsdHelperDbus;
};
UsdHelper *UsdHelperTest::m_pUsdHelperDbus = nullptr;
TEST_F(UsdHelperTest, usdExternalDoAction)
{
bool value = m_pUsdHelperDbus->usdExternalDoAction(-1);
ASSERT_EQ(value, false);
}
ukui-screensaver/tests/unit_test_dbus_interface/ 0000775 0001750 0001750 00000000000 15172041106 021205 5 ustar feng feng ukui-screensaver/tests/unit_test_dbus_interface/unit_test_dbus_interface.cpp 0000664 0001750 0001750 00000056442 15172041106 026777 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "../../src/lock-backend/authpamthread.h"
#include "../../src/lock-backend/pamauthenticate.h"
#include "../../src/lock-backend/lightdmhelper.h"
#include "../../src/lock-backend/dbusupperinterface.h"
#include "../../src/dbusifs/accountshelper.h"
#include "stubext.h"
using namespace stub_ext;
class DbusUpperInterfaceTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pAccountsHelperDbus = QSharedPointer(new AccountsHelper());
StubExt st;
st.set_lamda(&LightDMHelper::connectToDaemonSync, []() { return true; });
st.set_lamda(&isGreeterMode, []() { return true; });
m_pLightDMHelperDbus = new LightDMHelper(m_pAccountsHelperDbus, Configuration::instance());
m_pDbusUpperInterfaceDbus = new DbusUpperInterface();
m_pDbusUpperInterfaceDbus->init();
}
static void TearDownTestSuite()
{
delete m_pDbusUpperInterfaceDbus;
m_pDbusUpperInterfaceDbus = nullptr;
delete m_pLightDMHelperDbus;
m_pLightDMHelperDbus = nullptr;
m_pAccountsHelperDbus.reset();
}
static DbusUpperInterface *m_pDbusUpperInterfaceDbus;
static LightDMHelper *m_pLightDMHelperDbus;
static QSharedPointer m_pAccountsHelperDbus;
};
DbusUpperInterface *DbusUpperInterfaceTest::m_pDbusUpperInterfaceDbus = nullptr;
LightDMHelper *DbusUpperInterfaceTest::m_pLightDMHelperDbus = nullptr;
QSharedPointer DbusUpperInterfaceTest::m_pAccountsHelperDbus = nullptr;
TEST_F(DbusUpperInterfaceTest, GetSlpState)
{
m_pDbusUpperInterfaceDbus->onNameLost("test");
bool value = m_pDbusUpperInterfaceDbus->GetSlpState();
m_pLightDMHelperDbus->getLoginUserCount();
m_pLightDMHelperDbus->findUserByUid(getuid());
ASSERT_EQ(value, false);
}
TEST_F(DbusUpperInterfaceTest, GetBlankState)
{
bool value = m_pDbusUpperInterfaceDbus->GetBlankState();
ASSERT_EQ(value, false);
}
TEST_F(DbusUpperInterfaceTest, GetLockState)
{
bool value = m_pDbusUpperInterfaceDbus->GetLockState();
ASSERT_EQ(value, false);
}
TEST_F(DbusUpperInterfaceTest, CheckAppVersion)
{
bool value = m_pDbusUpperInterfaceDbus->CheckAppVersion();
ASSERT_EQ(value, false);
}
TEST_F(DbusUpperInterfaceTest, checkScreenDialogRunning)
{
m_pDbusUpperInterfaceDbus->LockStartupMode();
m_pDbusUpperInterfaceDbus->SessionTools();
m_pDbusUpperInterfaceDbus->Lock();
m_pDbusUpperInterfaceDbus->SwitchUser();
m_pDbusUpperInterfaceDbus->AppBlockWindow("Suspend");
m_pDbusUpperInterfaceDbus->MultiUserBlockWindow("Reboot");
m_pDbusUpperInterfaceDbus->onShowBlankScreensaver();
m_pDbusUpperInterfaceDbus->ShowScreensaver();
m_pDbusUpperInterfaceDbus->LockScreensaver();
// m_pDbusUpperInterfaceDbus->Suspend();
bool value = m_pDbusUpperInterfaceDbus->checkScreenDialogRunning();
ASSERT_EQ(value, false);
}
TEST_F(DbusUpperInterfaceTest, GenerateBatteryArgsList)
{
QJsonArray value = m_pDbusUpperInterfaceDbus->GenerateBatteryArgsList();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(DbusUpperInterfaceTest, getSleepLockCheck)
{
QJsonArray value = m_pDbusUpperInterfaceDbus->getSleepLockCheck();
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(DbusUpperInterfaceTest, getShutdownLockcheck)
{
QJsonArray value = m_pDbusUpperInterfaceDbus->getShutdownLockcheck();
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(DbusUpperInterfaceTest, getSaverTheme)
{
QJsonArray value = m_pDbusUpperInterfaceDbus->getSaverTheme();
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(DbusUpperInterfaceTest, getBatteryIconName)
{
QString value = m_pDbusUpperInterfaceDbus->getBatteryIconName();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(DbusUpperInterfaceTest, getIsBattery)
{
bool value = m_pDbusUpperInterfaceDbus->getIsBattery();
ASSERT_EQ(value, false);
}
TEST_F(DbusUpperInterfaceTest, GetDefaultAuthUser)
{
StubExt st;
st.set_lamda(&isGreeterMode, []() { return true; });
QString value = m_pDbusUpperInterfaceDbus->GetDefaultAuthUser();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(DbusUpperInterfaceTest, GetCurrentSession)
{
QString value = m_pDbusUpperInterfaceDbus->GetCurrentSession();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(DbusUpperInterfaceTest, GenerateSessionInfoList)
{
QJsonArray value = m_pDbusUpperInterfaceDbus->GenerateSessionInfoList();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(DbusUpperInterfaceTest, GetCurrentUser)
{
QString value = m_pDbusUpperInterfaceDbus->GetCurrentUser();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(DbusUpperInterfaceTest, getCurTabletMode)
{
bool value = m_pDbusUpperInterfaceDbus->getCurTabletMode();
ASSERT_EQ(value, false);
}
TEST_F(DbusUpperInterfaceTest, onPamShowMessage)
{
m_pDbusUpperInterfaceDbus->onPamShowMessage("",1);
}
TEST_F(DbusUpperInterfaceTest, onPamShowPrompt)
{
m_pDbusUpperInterfaceDbus->onPamShowPrompt("",1);
}
TEST_F(DbusUpperInterfaceTest, onPamShowBinaryPrompt)
{
m_pDbusUpperInterfaceDbus->onPamShowBinaryPrompt("",1);
}
TEST_F(DbusUpperInterfaceTest, onPamAuthCompleted)
{
m_pDbusUpperInterfaceDbus->onPamAuthCompleted();
}
TEST_F(DbusUpperInterfaceTest, onBioAuthShowMessage)
{
m_pDbusUpperInterfaceDbus->onBioAuthShowMessage("");
}
TEST_F(DbusUpperInterfaceTest, GenerateUserInfoList)
{
m_pDbusUpperInterfaceDbus->GenerateUserInfoList();
m_pDbusUpperInterfaceDbus->onUsersInfoChanged();
m_pDbusUpperInterfaceDbus->onLogin1ReqLock();
m_pDbusUpperInterfaceDbus->onLogin1ReqUnLock();
m_pDbusUpperInterfaceDbus->onLogin1PrepareForSleep(true);
m_pDbusUpperInterfaceDbus->onLogin1PrepareForSleep(false);
m_pDbusUpperInterfaceDbus->onLogin1SessionActiveChanged(true);
m_pDbusUpperInterfaceDbus->onBlockInhibitedChanged("ShutDown");
m_pDbusUpperInterfaceDbus->delayLockScreen();
m_pDbusUpperInterfaceDbus->stopDelayLockScreen();
m_pDbusUpperInterfaceDbus->onBatteryStatusChanged("test");
m_pDbusUpperInterfaceDbus->onSessionIdleReceived();
m_pDbusUpperInterfaceDbus->onSessionIdleExit();
m_pDbusUpperInterfaceDbus->onLockScreenTimeout();
m_pDbusUpperInterfaceDbus->onBatteryChanged(QStringList());
m_pDbusUpperInterfaceDbus->onLidStateChanged(false);
}
TEST_F(DbusUpperInterfaceTest, SendUpdateInfoSig)
{
QJsonObject getjsonCmd;
QJsonParseError jsonParseError;
QJsonObject objRes;
QVariant varValue;
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_LOCKSCREEN_CONF;
getjsonCmd["Key"] = KEY_IDLE_DELAY;
const QJsonDocument jsonDoc = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc.object();
varValue = objRes.value(KEY_IDLE_DELAY);
m_pDbusUpperInterfaceDbus->onLockScreenConfigChanged(KEY_IDLE_DELAY, varValue.toDouble());
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_SCREENSAVER_CONF;
getjsonCmd["Key"] = KEY_SHOW_REST_TIME;
const QJsonDocument jsonDoc1 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc1.object();
varValue = objRes.value(KEY_SHOW_REST_TIME);
m_pDbusUpperInterfaceDbus->onScreenSaverConfigChanged(KEY_SHOW_REST_TIME, varValue.toDouble());
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_POWERMANAGER_CONF;
getjsonCmd["Key"] = KEY_SLEEP_COMPUTER_AC;
const QJsonDocument jsonDoc2 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc2.object();
varValue = objRes.value(KEY_SLEEP_COMPUTER_AC);
m_pDbusUpperInterfaceDbus->onPowerManagerConfigChanged(KEY_SLEEP_COMPUTER_AC, varValue.toDouble());
// getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_MATEBG_CONF;
// getjsonCmd["Key"] = KEY_PICTURE_FILENAME;
// const QJsonDocument jsonDoc3 =
// QJsonDocument::fromJson(m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
// &jsonParseError); objRes = jsonDoc3.object(); varValue = objRes.value(KEY_PICTURE_FILENAME);
// m_pDbusUpperInterfaceDbus->onMateBgConfigChanged(KEY_PICTURE_FILENAME, varValue.toString());
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_UKCCPLUGINS_CONF;
getjsonCmd["Key"] = KEY_HOUR_SYSTEM;
const QJsonDocument jsonDoc4 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc4.object();
varValue = objRes.value(KEY_HOUR_SYSTEM);
m_pDbusUpperInterfaceDbus->onUkccPluginsConfigChanged(KEY_HOUR_SYSTEM, varValue.toDouble());
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_THEMESTYLE_CONF;
getjsonCmd["Key"] = KEY_SYSTEM_FONT_SIZE;
const QJsonDocument jsonDoc5 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc5.object();
varValue = objRes.value(KEY_SYSTEM_FONT_SIZE);
m_pDbusUpperInterfaceDbus->onThemeStyleConfigChanged(KEY_SYSTEM_FONT_SIZE, varValue.toDouble());
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_SESSION_CONF;
getjsonCmd["Key"] = KEY_SESSION_IDLE;
const QJsonDocument jsonDoc6 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc6.object();
varValue = objRes.value(KEY_SESSION_IDLE);
m_pDbusUpperInterfaceDbus->onSessionConfigChanged(KEY_SESSION_IDLE, varValue.toDouble());
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_KEYBOARD_CONF;
getjsonCmd["Key"] = KEY_CAPSLOCK_STATUS;
const QJsonDocument jsonDoc7 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc7.object();
varValue = objRes.value(KEY_CAPSLOCK_STATUS);
m_pDbusUpperInterfaceDbus->onKeyboardConfigChanged(KEY_CAPSLOCK_STATUS, varValue.toBool());
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_USD_MEDIAKEYS_CONF;
getjsonCmd["Key"] = KEY_AREA_SCREENSHOT;
const QJsonDocument jsonDoc8 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc8.object();
varValue = objRes.value(KEY_AREA_SCREENSHOT);
m_pDbusUpperInterfaceDbus->onUsdMediaKeysConfigChanged(KEY_AREA_SCREENSHOT, varValue.toString());
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_USD_MEDIA_STATE_KEYS_CONF;
getjsonCmd["Key"] = KEY_RFKILL_STATE;
const QJsonDocument jsonDoc9 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
objRes = jsonDoc9.object();
varValue = objRes.value(KEY_RFKILL_STATE);
m_pDbusUpperInterfaceDbus->onUsdMediaStateKeysConfigChanged(KEY_RFKILL_STATE, varValue.toDouble());
}
TEST_F(DbusUpperInterfaceTest, GetInformation)
{
// QList argumentList;
// argumentList << QVariant::fromValue(QString(QJsonDocument(jsonCmd).toJson()));
QList list{ /*LOCK_CMD_ID_GET_USERINFO_LIST, */ LOCK_CMD_ID_GET_DEFAULT_AUTH_USER,
LOCK_CMD_ID_GET_CURRENT_USER,
LOCK_CMD_ID_GET_SESSIONS_LIST,
LOCK_CMD_ID_GET_CURRENT_SESSION,
LOCK_CMD_ID_LOGIN1_IS_SESSION_ACTIVE,
LOCK_CMD_ID_GET_AGREEMENT,
LOCK_CMD_ID_GSETTINGS_GET_LOCKSCREEN_CONF,
LOCK_CMD_ID_GSETTINGS_GET_SCREENSAVER_CONF,
LOCK_CMD_ID_GSETTINGS_GET_POWERMANAGER_CONF,
/*LOCK_CMD_ID_GSETTINGS_GET_MATEBG_CONF,*/ LOCK_CMD_ID_GSETTINGS_GET_UKCCPLUGINS_CONF,
LOCK_CMD_ID_GSETTINGS_GET_THEMESTYLE_CONF,
LOCK_CMD_ID_GSETTINGS_GET_SESSION_CONF,
LOCK_CMD_ID_GSETTINGS_GET_KEYBOARD_CONF,
LOCK_CMD_ID_PAMAUTH_IS_AUTHENTICATED,
LOCK_CMD_ID_PAMAUTH_IS_INAUTHTICATION,
LOCK_CMD_ID_PAMAUTH_GET_AUTHUSER,
LOCK_CMD_ID_GSETTINGS_GET_USD_MEDIAKEYS_CONF,
LOCK_CMD_ID_GSETTINGS_GET_USD_MEDIA_STATE_KEYS_CONF,
LOCK_CMD_ID_LOGIN1_GET_POWER_MANAGER_CANHIBERNATE,
LOCK_CMD_ID_LOGIN1_GET_POWER_MANAGER_CANPOWEROFF,
LOCK_CMD_ID_LOGIN1_GET_POWER_MANAGER_CANREBOOT,
LOCK_CMD_ID_LOGIN1_GET_POWER_MANAGER_CANSUSPEND,
LOCK_CMD_ID_LOGIN1_GET_POWER_MANAGER_CANLOGOUT,
LOCK_CMD_ID_LOGIN1_GET_POWER_MANAGER_CANLOCKSCREEN,
LOCK_CMD_ID_SYSTEM_UPGRADE_CHECK,
LOCK_CMD_ID_UPOWER_BATTERY_STATUS,
LOCK_CMD_ID_UPOWER_IS_BATTERY,
LOCK_CMD_ID_UPOWER_BATTERY,
LOCK_CMD_ID_SESSION_GET_SLEEP_LOCKCHECK,
LOCK_CMD_ID_SESSION_GET_SHUTDOWN_LOCKCHECK,
LOCK_CMD_ID_LOCK_SCREEN_GET_THEMES,
LOCK_CMD_ID_BIOAUTH_GET_AVAILABLE_DEVICES,
LOCK_CMD_ID_BIOAUTH_GET_DISABLED_DEVICES,
LOCK_CMD_ID_BIOAUTH_GET_STATE,
LOCK_CMD_ID_BIOAUTH_GET_CURDEVICE,
LOCK_CMD_ID_BIOAUTH_FIND_DEVICE_BY_ID,
LOCK_CMD_ID_BIOAUTH_FIND_DEVICE_BY_NAME,
LOCK_CMD_ID_BIOAUTH_GET_DEFAULT_DEVICE,
LOCK_CMD_ID_GET_PUBLIC_KEY,
LOCK_CMD_ID_TABLET_MODE,
-1 };
for (int i = 0; i < list.count(); i++) {
QJsonObject jsonCmd;
jsonCmd["CmdId"] = list.at(i);
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(jsonCmd).toJson()));
}
}
TEST_F(DbusUpperInterfaceTest, SetInformation)
{
QJsonObject jsonCmd;
jsonCmd["CmdId"] = LOCK_CMD_ID_SET_USER;
jsonCmd["Content"] = getenv("USER");
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd).toJson()).toUtf8());
QJsonObject jsonCmd1;
jsonCmd1["CmdId"] = LOCK_CMD_ID_SWITCH_TO_USER;
jsonCmd1["Content"] = getenv("USER");
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd1).toJson()).toUtf8());
QJsonObject jsonCmd2;
jsonCmd2["CmdId"] = LOCK_CMD_ID_SET_SESSION;
jsonCmd2["Content"] = "testSession";
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd2).toJson()).toUtf8());
QJsonObject jsonCmd3;
jsonCmd3["CmdId"] = LOCK_CMD_ID_START_SESSION;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd3).toJson()).toUtf8());
QJsonObject getjsonCmd;
getjsonCmd["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_LOCKSCREEN_CONF;
getjsonCmd["Key"] = KEY_IDLE_DELAY;
QJsonParseError jsonParseError;
const QJsonDocument jsonDoc = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd).toJson())).toUtf8(),
&jsonParseError);
QJsonObject objRes = jsonDoc.object();
QVariant varValue = objRes.value(KEY_IDLE_DELAY);
QJsonObject jsonCmd4;
jsonCmd4["CmdId"] = LOCK_CMD_ID_GSETTINGS_SET_LOCKSCREEN_CONF;
jsonCmd4["Content"] = varValue.toDouble();
jsonCmd4["Key"] = KEY_IDLE_DELAY;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd4).toJson()).toUtf8());
QJsonObject getjsonCmd5;
getjsonCmd5["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_SCREENSAVER_CONF;
getjsonCmd5["Key"] = KEY_VIDEO_SIZE;
QJsonParseError jsonParseError5;
const QJsonDocument jsonDoc5 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd5).toJson())).toUtf8(),
&jsonParseError5);
QJsonObject objRes5 = jsonDoc5.object();
QVariant varValue5 = objRes5.value(KEY_VIDEO_SIZE);
QJsonObject jsonCmd5;
jsonCmd5["CmdId"] = LOCK_CMD_ID_GSETTINGS_SET_SCREENSAVER_CONF;
jsonCmd5["Content"] = varValue5.toDouble();
jsonCmd5["Key"] = KEY_VIDEO_SIZE;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd5).toJson()).toUtf8());
QJsonObject getjsonCmd6;
getjsonCmd6["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_POWERMANAGER_CONF;
getjsonCmd6["Key"] = KEY_SLEEP_COMPUTER_AC;
QJsonParseError jsonParseError6;
const QJsonDocument jsonDoc6 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd6).toJson())).toUtf8(),
&jsonParseError6);
QJsonObject objRes6 = jsonDoc6.object();
QVariant varValue6 = objRes6.value(KEY_SLEEP_COMPUTER_AC);
QJsonObject jsonCmd6;
jsonCmd6["CmdId"] = LOCK_CMD_ID_GSETTINGS_SET_POWERMANAGER_CONF;
jsonCmd6["Content"] = varValue6.toDouble();
jsonCmd6["Key"] = KEY_SLEEP_COMPUTER_AC;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd6).toJson()).toUtf8());
QJsonObject getjsonCmd7;
getjsonCmd7["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_UKCCPLUGINS_CONF;
getjsonCmd7["Key"] = KEY_HOUR_SYSTEM;
QJsonParseError jsonParseError7;
const QJsonDocument jsonDoc7 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd7).toJson())).toUtf8(),
&jsonParseError7);
QJsonObject objRes7 = jsonDoc7.object();
QVariant varValue7 = objRes7.value(KEY_HOUR_SYSTEM);
QJsonObject jsonCmd7;
jsonCmd7["CmdId"] = LOCK_CMD_ID_GSETTINGS_SET_UKCCPLUGINS_CONF;
jsonCmd7["Content"] = varValue7.toDouble();
jsonCmd7["Key"] = KEY_HOUR_SYSTEM;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd7).toJson()).toUtf8());
QJsonObject getjsonCmd8;
getjsonCmd8["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_THEMESTYLE_CONF;
getjsonCmd8["Key"] = KEY_SYSTEM_FONT_SIZE;
QJsonParseError jsonParseError8;
const QJsonDocument jsonDoc8 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd8).toJson())).toUtf8(),
&jsonParseError8);
QJsonObject objRes8 = jsonDoc8.object();
QVariant varValue8 = objRes8.value(KEY_SYSTEM_FONT_SIZE);
QJsonObject jsonCmd8;
jsonCmd8["CmdId"] = LOCK_CMD_ID_GSETTINGS_SET_THEMESTYLE_CONF;
jsonCmd8["Content"] = varValue8.toDouble();
jsonCmd8["Key"] = KEY_SYSTEM_FONT_SIZE;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd8).toJson()).toUtf8());
QJsonObject getjsonCmd9;
getjsonCmd9["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_SESSION_CONF;
getjsonCmd9["Key"] = KEY_SESSION_IDLE;
QJsonParseError jsonParseError9;
const QJsonDocument jsonDoc9 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd9).toJson())).toUtf8(),
&jsonParseError9);
QJsonObject objRes9 = jsonDoc9.object();
QVariant varValue9 = objRes9.value(KEY_SESSION_IDLE);
QJsonObject jsonCmd9;
jsonCmd9["CmdId"] = LOCK_CMD_ID_GSETTINGS_SET_SESSION_CONF;
jsonCmd9["Content"] = varValue9.toDouble();
jsonCmd9["Key"] = KEY_SESSION_IDLE;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd9).toJson()).toUtf8());
QJsonObject jsonCmd10;
jsonCmd10["CmdId"] = LOCK_CMD_ID_PAMAUTH_AUTHENTICATE;
jsonCmd10["Content"] = getenv("USER");
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd10).toJson()).toUtf8());
QJsonObject jsonCmd11;
jsonCmd11["CmdId"] = LOCK_CMD_ID_PAMAUTH_RESPOND;
jsonCmd11["Content"] = "test";
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd11).toJson()).toUtf8());
QJsonObject jsonCmd12;
jsonCmd12["CmdId"] = LOCK_CMD_ID_PAMAUTH_AUTHENTICATE_CANCEL;
// jsonCmd12["Content"] = "test";
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd12).toJson()).toUtf8());
QJsonObject jsonCmd13;
jsonCmd13["CmdId"] = LOCK_CMD_ID_USD_MEDIAKEYS;
jsonCmd13["Content"] = VOLUME_DOWN_KEY;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd13).toJson()).toUtf8());
QJsonObject jsonCmd14;
jsonCmd14["CmdId"] = LOCK_CMD_ID_LOGIN1_SET_POWER_MANAGER;
jsonCmd14["Content"] = "LockScreen";
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd14).toJson()).toUtf8());
QJsonObject jsonCmd15;
jsonCmd15["CmdId"] = LOCK_CMD_ID_LOCK_STATE_CHANGED;
jsonCmd15["Content"] = false;
jsonCmd15["SessionTools"] = false;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd15).toJson()).toUtf8());
QJsonObject jsonCmd16;
jsonCmd16["CmdId"] = LOCK_CMD_ID_BIOAUTH_STARTAUTH;
jsonCmd16["UserId"] = 1000;
jsonCmd16["DevId"] = 101;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd16).toJson()).toUtf8());
QJsonObject jsonCmd17;
jsonCmd17["CmdId"] = LOCK_CMD_ID_BIOAUTH_STOPAUTH;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd17).toJson()).toUtf8());
QJsonObject jsonCmd18;
jsonCmd18["CmdId"] = LOCK_CMD_ID_KWIN_BLOCK_SHORTCUT;
jsonCmd18["Content"] = true;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd18).toJson()).toUtf8());
QJsonObject jsonCmd19;
jsonCmd19["CmdId"] = LOCK_CMD_ID_KWIN_BLOCK_SHORTCUT;
jsonCmd19["Content"] = false;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd19).toJson()).toUtf8());
QJsonObject getjsonCmd20;
getjsonCmd20["CmdId"] = LOCK_CMD_ID_GSETTINGS_GET_USD_MEDIA_STATE_KEYS_CONF;
getjsonCmd20["Key"] = KEY_RFKILL_STATE;
QJsonParseError jsonParseError20;
const QJsonDocument jsonDoc20 = QJsonDocument::fromJson(
m_pDbusUpperInterfaceDbus->GetInformation(QString(QJsonDocument(getjsonCmd20).toJson())).toUtf8(),
&jsonParseError20);
QJsonObject objRes20 = jsonDoc20.object();
QVariant varValue20 = objRes20.value(KEY_RFKILL_STATE);
QJsonObject jsonCmd20;
jsonCmd20["CmdId"] = LOCK_CMD_ID_GSETTINGS_SET_USD_MEDIA_STATE_KEYS_CONF;
jsonCmd20["Content"] = varValue20.toDouble();
jsonCmd20["Key"] = KEY_RFKILL_STATE;
m_pDbusUpperInterfaceDbus->SetInformation(QString(QJsonDocument(jsonCmd20).toJson()).toUtf8());
}
ukui-screensaver/tests/unit_test_dbus_interface/CMakeLists.txt 0000664 0001750 0001750 00000012330 15172041106 023744 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus Network Test REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GIOUNIX2 REQUIRED gio-unix-2.0)
pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0)
pkg_check_modules(QGS REQUIRED gsettings-qt)
pkg_check_modules(LIGHTDM-QT5-3 REQUIRED liblightdm-qt5-3)
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 查找pam动态库全路径并缓存到PAM_LIBRARIES变量
find_library(PAM_LIBRARIES pam)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/lock-backend/authpamthread.cpp
../../src/lock-backend/pamauthenticate.cpp
../../src/lock-backend/lightdmhelper.cpp
../../src/lock-backend/dbusupperinterface.cpp
../../src/lock-backend/gsettingshelper.cpp
../../src/lock-backend/bioauthenticate.cpp
../../src/lock-backend/switchuserutils.cpp
../../src/dbusifs/accountshelper.cpp
../../src/userinfo.cpp
../../src/common/global_utils.cpp
../../src/common/configuration.cpp
../../src/common/kyrsac.cpp
../../src/dbusifs/giodbus.cpp
../../src/dbusifs/uniauthservice.cpp
../../src/lock-backend/securityuser.cpp
../../src/dbusifs/freedesktophelper.cpp
../../src/dbusifs/login1helper.cpp
../../src/dbusifs/usdhelper.cpp
../../src/dbusifs/upowerhelper.cpp
../../src/dbusifs/sessionhelper.cpp
../../src/dbusifs/dbusservermanager.cpp
../../src/dbusifs/systemupgradehelper.cpp
../../src/lock-backend/sessionwatcher.cpp
../../src/dbusifs/kglobalaccelhelper.cpp
../../src/dbusifs/libinputswitchevent.cpp
../../src/lock-backend/personalizeddata.cpp
../../src/dbusifs/biometrichelper.cpp
../../src/dbusifs/device.cpp
../../src/dbusifs/machinemodel.cpp
../../src/dbusifs/enginedevice.cpp
../../src/common/biodefines.cpp
../../src/QtSingleApplication/qtlocalpeer.cpp
../kt-test-utils/cpp-stub-ext/stub-shadow.cpp
unit_test_dbus_interface.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/lock-backend/authpamthread.h
../../src/lock-backend/pamauthenticate.h
../../src/lock-backend/lightdmhelper.h
../../src/lock-backend/dbusupperinterface.h
../../src/lock-backend/gsettingshelper.h
../../src/lock-backend/bioauthenticate.h
../../src/lock-backend/switchuserutils.h
../../src/common/definetypes.h
../../src/userinfo.h
../../src/common/global_utils.h
../../src/common/configuration.h
../../src/common/kyrsac.h
../../src/dbusifs/giodbus.h
../../src/dbusifs/accountshelper.h
../../src/common/configuration.h
../../src/dbusifs/uniauthservice.h
../../src/lock-backend/securityuser.h
../../src/dbusifs/freedesktophelper.h
../../src/dbusifs/login1helper.h
../../src/dbusifs/usdhelper.h
../../src/dbusifs/upowerhelper.h
../../src/dbusifs/dbusservermanager.h
../../src/dbusifs/sessionhelper.h
../../src/dbusifs/systemupgradehelper.h
../../src/lock-backend/sessionwatcher.h
../../src/dbusifs/kglobalaccelhelper.h
../../src/dbusifs/libinputswitchevent.h
../../src/lock-backend/personalizeddata.h
../../src/dbusifs/biometrichelper.h
../../src/dbusifs/device.h
../../src/dbusifs/enginedevice.h
../../src/dbusifs/machinemodel.h
../../src/common/biodefines.h
../kt-test-utils/cpp-stub-ext/stubext.h
../kt-test-utils/cpp-stub-ext/stub-shadow.h
../../src/QtSingleApplication/qtlocalpeer.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${QGS_INCLUDE_DIRS}
${Qt5Test_INCLUDE_DIRS}
${LIGHTDM-QT5-3_INCLUDE_DIRS}
${LIBSYSTEMD_INCLUDE_DIRS}
${GIOUNIX2_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}../../src/QtSingleApplication/
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_dbus_interface ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_dbus_interface
Qt5::Core
Qt5::Gui
Qt5::DBus
Qt5::Test
Qt5::Network
${QGS_LIBRARIES}
${PAM_LIBRARIES}
${LIGHTDM-QT5-3_LIBRARIES}
${LIBSYSTEMD_LIBRARIES}
OpenSSL::Crypto
-lukuiinputgatherclient
${GIOUNIX2_LIBRARIES}
)
# 链接 GTest 库
target_link_libraries(unit_test_dbus_interface
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_dbus_interface/main.cpp 0000664 0001750 0001750 00000001562 15172041035 022642 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_backend_dbus/ 0000775 0001750 0001750 00000000000 15172041106 020634 5 ustar feng feng ukui-screensaver/tests/unit_test_backend_dbus/CMakeLists.txt 0000664 0001750 0001750 00000003620 15172041106 023375 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/lock-dialog/backenddbushelper.cpp
../../src/userinfo.cpp
../../src/agreementinfo.cpp
../../src/common/biodefines.cpp
../../src/common/global_utils.cpp
../../src/dbusifs/freedesktophelper.cpp
unit_test_backend_dbus.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/lock-dialog/backenddbushelper.h
../../src/common/definetypes.h
../../src/common/biodefines.h
../../src/userinfo.h
../../src/agreementinfo.h
../../src/common/global_utils.h
../../src/dbusifs/freedesktophelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_backend_dbus ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_backend_dbus
Qt5::Core
Qt5::Gui
Qt5::DBus
# 链接 GTest 库
target_link_libraries(unit_test_backend_dbus
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_backend_dbus/main.cpp 0000664 0001750 0001750 00000001562 15172041035 022271 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_backend_dbus/unit_test_backend_dbus.cpp 0000664 0001750 0001750 00000035174 15172041035 026055 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include "../../src/lock-dialog/backenddbushelper.h"
#include "../../src/common/definetypes.h"
#include "../../src/agreementinfo.h"
#include "stubext.h"
using namespace stub_ext;
class BackendDbusHelperTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
QString displayNum = QString(qgetenv("DISPLAY")).replace(":", "").replace(".", "_");
QString sessionDbus = QString("%1%2").arg(QString(SS_DBUS_SERVICE)).arg(displayNum);
m_pBackendDbusHelperDbus = new BackendDbusHelper(sessionDbus, SS_DBUS_PATH, QDBusConnection::sessionBus());
if (!m_pBackendDbusHelperDbus->isValid()) {
delete m_pBackendDbusHelperDbus;
m_pBackendDbusHelperDbus = new BackendDbusHelper(SS_DBUS_SERVICE, SS_DBUS_PATH, QDBusConnection::sessionBus());
}
}
static void TearDownTestSuite()
{
delete m_pBackendDbusHelperDbus;
m_pBackendDbusHelperDbus = nullptr;
}
static BackendDbusHelper *m_pBackendDbusHelperDbus;
};
BackendDbusHelper *BackendDbusHelperTest::m_pBackendDbusHelperDbus = nullptr;
TEST_F(BackendDbusHelperTest, getUsersInfo)
{
QList value = m_pBackendDbusHelperDbus->getUsersInfo();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(BackendDbusHelperTest, getAgreementInfo)
{
AgreementInfoPtr value = m_pBackendDbusHelperDbus->getAgreementInfo();
// ASSERT_EQ(value, NULL);
}
TEST_F(BackendDbusHelperTest, getSessionsInfo)
{
QList value = m_pBackendDbusHelperDbus->getSessionsInfo();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(BackendDbusHelperTest, getBatteryArgs)
{
QStringList value = m_pBackendDbusHelperDbus->getBatteryArgs();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(BackendDbusHelperTest, getSleepLockcheck)
{
QStringList value = m_pBackendDbusHelperDbus->getSleepLockcheck();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(BackendDbusHelperTest, isSessionActive)
{
bool value = m_pBackendDbusHelperDbus->isSessionActive();
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, switchToUser)
{
int value = m_pBackendDbusHelperDbus->switchToUser(getenv("USER"));
ASSERT_EQ(value, 0);
}
TEST_F(BackendDbusHelperTest, setCurrentUser)
{
bool value = m_pBackendDbusHelperDbus->setCurrentUser(getenv("USER"));
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, setPowerManager)
{
bool value = m_pBackendDbusHelperDbus->setPowerManager(false, "LockScreen");
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, sendPassword)
{
QByteArray decryptText;
bool value = m_pBackendDbusHelperDbus->sendPassword(getenv("USER"), decryptText);
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, getBatteryIconName)
{
QString value = m_pBackendDbusHelperDbus->getBatteryIconName();
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BackendDbusHelperTest, getIsBattery)
{
bool value = m_pBackendDbusHelperDbus->getIsBattery();
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, getCurTabletMode)
{
bool value = m_pBackendDbusHelperDbus->getCurTabletMode();
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, lockStateChanged)
{
bool value = m_pBackendDbusHelperDbus->lockStateChanged(false, false);
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, pamIsInAuthentication)
{
m_pBackendDbusHelperDbus->startSession();
m_pBackendDbusHelperDbus->pamAuthenticate(getenv("USER"));
m_pBackendDbusHelperDbus->bioStartAuth(getuid(), 32);
m_pBackendDbusHelperDbus->bioStopAuth();
m_pBackendDbusHelperDbus->pamRespond("");
m_pBackendDbusHelperDbus->pamAuthenticateCancel();
bool value = m_pBackendDbusHelperDbus->pamIsInAuthentication();
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, pamIsAuthenticated)
{
bool value = m_pBackendDbusHelperDbus->pamIsAuthenticated();
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, pamAuthenticateUser)
{
QString value = m_pBackendDbusHelperDbus->pamAuthenticateUser();
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BackendDbusHelperTest, bioGetAvailableDevices)
{
QList value = m_pBackendDbusHelperDbus->bioGetAvailableDevices(101);
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BackendDbusHelperTest, bioGetDisabledDevices)
{
QList value = m_pBackendDbusHelperDbus->bioGetDisabledDevices(101);
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BackendDbusHelperTest, bioGetBioAuthState)
{
int value = m_pBackendDbusHelperDbus->bioGetBioAuthState();
ASSERT_EQ(value, 0);
}
TEST_F(BackendDbusHelperTest, bioGetCurBioInfo)
{
DeviceInfo bioValue1 = m_pBackendDbusHelperDbus->bioGetCurBioInfo();
DeviceInfo bioValue2 = m_pBackendDbusHelperDbus->bioFindDeviceById(getuid(), 101);
DeviceInfo bioValue3 = m_pBackendDbusHelperDbus->bioFindDeviceByName(getuid(), "uru4000");
QString value = m_pBackendDbusHelperDbus->bioGetDefaultDevice(getuid(), getenv("USER"));
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BackendDbusHelperTest, getCurrentSession)
{
QString value = m_pBackendDbusHelperDbus->getCurrentSession();
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BackendDbusHelperTest, setCurrentSession)
{
bool value = m_pBackendDbusHelperDbus->setCurrentSession("testSession");
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, onUpdateInformation)
{
QList list{LOCK_CMD_ID_USERINFO_CHANGED, LOCK_CMD_ID_CURRENT_USER_CHANGED,
LOCK_CMD_ID_CURRENT_SESSION_CHANGED, LOCK_CMD_ID_LOGIN1_REQ_LOCK,
LOCK_CMD_ID_LOGIN1_REQ_UNLOCK, LOCK_CMD_ID_LOGIN1_PREPAREFORSLEEP,
LOCK_CMD_ID_LOGIN1_SESSION_ACTIVE_CHANGED, LOCK_CMD_ID_GSETTINGS_LOCKSCREEN_CONF_CHANGED,
LOCK_CMD_ID_GSETTINGS_SCREENSAVER_CONF_CHANGED, LOCK_CMD_ID_GSETTINGS_POWERMANAGER_CONF_CHANGED,
LOCK_CMD_ID_GSETTINGS_MATEBG_CONF_CHANGED, LOCK_CMD_ID_GSETTINGS_UKCCPLUGINS_CONF_CHANGED,
LOCK_CMD_ID_GSETTINGS_THEMESTYLE_CONF_CHANGED, LOCK_CMD_ID_GSETTINGS_SESSION_CONF_CHANGED,
LOCK_CMD_ID_LOGIN1_BLOCKINHIBITED_CHANGED, LOCK_CMD_ID_GSETTINGS_KEYBOARD_CONF_CHANGED,
LOCK_CMD_ID_PAMAUTH_SHOWMESSAGE, LOCK_CMD_ID_PAMAUTH_SHOWPROMPT, LOCK_CMD_ID_PAMAUTH_AUTH_COMPLETED,
LOCK_CMD_ID_GSETTINGS_USD_MEDIAKEYS_CONF_CHANGED, LOCK_CMD_ID_GSETTINGS_USD_MEDIA_STATE_KEYS_CONF_CHANGED,
LOCK_CMD_ID_UPOWER_BATTERY_STATUS, LOCK_CMD_ID_UPOWER_BATTERY, LOCK_CMD_ID_BIOAUTH_SERVICE_STATUS_CHANGED,
LOCK_CMD_ID_BIOAUTH_DEVICE_CHANGED, LOCK_CMD_ID_BIOAUTH_SHOW_MESSAGE, LOCK_CMD_ID_BIOAUTH_AUTHSTATE_CHANGED,
LOCK_CMD_ID_BIOAUTH_FRAME_DATA, LOCK_CMD_ID_BIOAUTH_COMPLETE, LOCK_CMD_ID_TABLET_MODE_CHANGED};
for (int i = 0; i < list.count(); i++) {
QJsonObject retObj;
retObj["CmdId"] = list.at(i);
m_pBackendDbusHelperDbus->onUpdateInformation(QString(QJsonDocument(retObj).toJson()));
}
}
TEST_F(BackendDbusHelperTest, usdExternalDoAction)
{
bool value = m_pBackendDbusHelperDbus->usdExternalDoAction(VOLUME_DOWN_KEY);
m_pBackendDbusHelperDbus->usdExternalDoAction(VOLUME_UP_KEY);
ASSERT_EQ(value, true);
}
TEST_F(BackendDbusHelperTest, getDefaultAuthUser)
{
QString value = m_pBackendDbusHelperDbus->getDefaultAuthUser();
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BackendDbusHelperTest, getCurrentUser)
{
QString value = m_pBackendDbusHelperDbus->getCurrentUser();
ASSERT_EQ(value.isEmpty(), true);
}
TEST_F(BackendDbusHelperTest, getScreenSaverConf)
{
bool value = m_pBackendDbusHelperDbus->getScreenSaverConf(KEY_AUTOMATIC_SWITCHING_ENABLE).toBool();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, setScreenSaverConf)
{
bool oldvalue = m_pBackendDbusHelperDbus->getScreenSaverConf(KEY_AUTOMATIC_SWITCHING_ENABLE).toBool();
bool value = m_pBackendDbusHelperDbus->setScreenSaverConf(KEY_AUTOMATIC_SWITCHING_ENABLE, !oldvalue);
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setScreenSaverConf(KEY_AUTOMATIC_SWITCHING_ENABLE, oldvalue);
}
TEST_F(BackendDbusHelperTest, getLockScreenConf)
{
bool value = m_pBackendDbusHelperDbus->getLockScreenConf(KEY_LOCK_ENABLED).toBool();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, setLockScreenConf)
{
bool oldvalue = m_pBackendDbusHelperDbus->getLockScreenConf(KEY_LOCK_ENABLED).toBool();
bool value = m_pBackendDbusHelperDbus->setLockScreenConf(KEY_LOCK_ENABLED, !oldvalue);
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setLockScreenConf(KEY_LOCK_ENABLED, oldvalue);
}
TEST_F(BackendDbusHelperTest, getShutdownLockcheck)
{
QStringList value = m_pBackendDbusHelperDbus->getShutdownLockcheck();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(BackendDbusHelperTest, getSaverThemes)
{
QStringList value = m_pBackendDbusHelperDbus->getSaverThemes();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(BackendDbusHelperTest, getPowerManagerConf)
{
bool value = m_pBackendDbusHelperDbus->getPowerManagerConf(KEY_LOCK_BLANKSCREEN).toBool();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, setPowerManagerConf)
{
bool oldvalue = m_pBackendDbusHelperDbus->getPowerManagerConf(KEY_LOCK_BLANKSCREEN).toBool();
bool value = m_pBackendDbusHelperDbus->setPowerManagerConf(KEY_LOCK_BLANKSCREEN, !oldvalue);
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setPowerManagerConf(KEY_LOCK_BLANKSCREEN, oldvalue);
}
TEST_F(BackendDbusHelperTest, getMateBgConf)
{
QString value = m_pBackendDbusHelperDbus->getMateBgConf(KEY_PICTURE_FILENAME).toString();
ASSERT_EQ(value.isEmpty(), false);
}
TEST_F(BackendDbusHelperTest, setMateBgConf)
{
QString oldvalue = m_pBackendDbusHelperDbus->getMateBgConf(KEY_PICTURE_FILENAME).toString();
return ;
bool value = m_pBackendDbusHelperDbus->setMateBgConf("picture-filename", "sss");
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setMateBgConf("picture-filename", oldvalue);
}
TEST_F(BackendDbusHelperTest, getUkccPluginsConf)
{
QString value = m_pBackendDbusHelperDbus->getUkccPluginsConf(KEY_DATE).toString();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, setUkccPluginsConf)
{
QString oldvalue = m_pBackendDbusHelperDbus->getUkccPluginsConf(KEY_DATE).toString();
bool value = m_pBackendDbusHelperDbus->setUkccPluginsConf(KEY_DATE, "sss");
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setUkccPluginsConf(KEY_DATE, oldvalue);
}
TEST_F(BackendDbusHelperTest, getThemeStyleConf)
{
QString value = m_pBackendDbusHelperDbus->getThemeStyleConf(KEY_THEME_COLOR).toString();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, setThemeStyleConf)
{
QString oldvalue = m_pBackendDbusHelperDbus->getThemeStyleConf(KEY_THEME_COLOR).toString();
bool value = m_pBackendDbusHelperDbus->setThemeStyleConf(KEY_THEME_COLOR, "sss");
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setThemeStyleConf(KEY_THEME_COLOR, oldvalue);
}
TEST_F(BackendDbusHelperTest, getSessionConf)
{
int value = m_pBackendDbusHelperDbus->getSessionConf(KEY_SESSION_IDLE).toInt();
ASSERT_EQ(value, 60);
}
TEST_F(BackendDbusHelperTest, setSessionConf)
{
int oldvalue = m_pBackendDbusHelperDbus->getSessionConf(KEY_SESSION_IDLE).toInt();
bool value = m_pBackendDbusHelperDbus->setSessionConf(KEY_SESSION_IDLE, 30);
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setSessionConf(KEY_SESSION_IDLE, oldvalue);
}
TEST_F(BackendDbusHelperTest, getKeyboardConf)
{
bool value = m_pBackendDbusHelperDbus->getKeyboardConf(KEY_CAPSLOCK_STATUS).toBool();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, setKeyboardConf)
{
bool oldvalue = m_pBackendDbusHelperDbus->getKeyboardConf(KEY_CAPSLOCK_STATUS).toBool();
bool value = m_pBackendDbusHelperDbus->setKeyboardConf(KEY_CAPSLOCK_STATUS, !oldvalue);
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setKeyboardConf(KEY_CAPSLOCK_STATUS, oldvalue);
}
TEST_F(BackendDbusHelperTest, getUsdMediaStateKeys)
{
int value = m_pBackendDbusHelperDbus->getUsdMediaStateKeys(KEY_RFKILL_STATE).toInt();
ASSERT_EQ(value, 60);
}
TEST_F(BackendDbusHelperTest, setUsdMediaStateKeys)
{
int oldvalue = m_pBackendDbusHelperDbus->getUsdMediaStateKeys(KEY_RFKILL_STATE).toInt();
bool value = m_pBackendDbusHelperDbus->setUsdMediaStateKeys(KEY_RFKILL_STATE, 0);
ASSERT_EQ(value, false);
m_pBackendDbusHelperDbus->setUsdMediaStateKeys(KEY_RFKILL_STATE, oldvalue);
}
TEST_F(BackendDbusHelperTest, getUsdMediaKeys)
{
QString value = m_pBackendDbusHelperDbus->getUsdMediaKeys(KEY_WINDOW_SCREENSHOT).toString();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, getPowerManagerCanSuspend)
{
bool value = m_pBackendDbusHelperDbus->getPowerManagerCanSuspend();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, getPowerManagerCanReboot)
{
bool value = m_pBackendDbusHelperDbus->getPowerManagerCanReboot();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, getPowerManagerCanPowerOff)
{
bool value = m_pBackendDbusHelperDbus->getPowerManagerCanPowerOff();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, getPowerManagerCanSwitchUser)
{
bool value = m_pBackendDbusHelperDbus->getPowerManagerCanSwitchUser();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, getPowerManagerCanHibernate)
{
bool value = m_pBackendDbusHelperDbus->getPowerManagerCanHibernate();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, getPowerManagerCanLogout)
{
bool value = m_pBackendDbusHelperDbus->getPowerManagerCanLogout();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, getPowerManagerCanLockScreen)
{
bool value = m_pBackendDbusHelperDbus->getPowerManagerCanLockScreen();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, checkSystemUpgrade)
{
bool value = m_pBackendDbusHelperDbus->checkSystemUpgrade();
ASSERT_EQ(value, false);
}
TEST_F(BackendDbusHelperTest, getPublicEncrypt)
{
QString value = m_pBackendDbusHelperDbus->getPublicEncrypt();
ASSERT_EQ(value.isEmpty(), false);
}
ukui-screensaver/tests/unit_test_gsettings_helper/ 0000775 0001750 0001750 00000000000 15172041106 021576 5 ustar feng feng ukui-screensaver/tests/unit_test_gsettings_helper/CMakeLists.txt 0000664 0001750 0001750 00000003302 15172041106 024334 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(QGS REQUIRED gsettings-qt)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/lock-backend/gsettingshelper.cpp
unit_test_gsettings_helper.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/common/definetypes.h
../../src/lock-backend/gsettingshelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${QGS_INCLUDE_DIRS}
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_gsettings_helper ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_gsettings_helper
Qt5::Core
Qt5::Gui
Qt5::DBus
${QGS_LIBRARIES}
)
# 链接 GTest 库
target_link_libraries(unit_test_gsettings_helper
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_gsettings_helper/unit_test_gsettings_helper.cpp 0000664 0001750 0001750 00000042141 15172041035 027751 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include "../../src/lock-backend/gsettingshelper.h"
#include "../../src/common/definetypes.h"
#include "stubext.h"
using namespace stub_ext;
class GSettingsHelperTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pGSettingsHelperDbus = new GSettingsHelper();
}
static void TearDownTestSuite()
{
delete m_pGSettingsHelperDbus;
m_pGSettingsHelperDbus = nullptr;
}
static GSettingsHelper *m_pGSettingsHelperDbus;
};
GSettingsHelper *GSettingsHelperTest::m_pGSettingsHelperDbus = nullptr;
TEST_F(GSettingsHelperTest, GetScreenSaverConf)
{
QVariant result1 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_SHOW_REST_TIME);
bool value1 = result1.toBool();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_SHOW_REST_TIME);
QVariant result2 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_SHOW_CUSTOM_REST_TIME);
bool value2 = result2.toBool();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_SHOW_CUSTOM_REST_TIME);
QVariant result3 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_SHOW_UKUI_REST_TIME);
bool value3 = result3.toBool();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_SHOW_UKUI_REST_TIME);
QVariant result4 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_CYCLE_TIME);
int value4 = result4.toInt();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_CYCLE_TIME);
QVariant result5 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_AUTOMATIC_SWITCHING_ENABLE);
bool value5 = result5.toBool();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_AUTOMATIC_SWITCHING_ENABLE);
QVariant result6 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_BACKGROUND_PATH);
QString value6 = result6.toString();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_BACKGROUND_PATH);
QVariant result7 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_MYTEXT);
QString value7 = result7.toString();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_MYTEXT);
QVariant result8 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_TEXT_IS_CENTER);
bool value8 = result8.toBool();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_TEXT_IS_CENTER);
QVariant result9 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_SHOW_MESSAGE_ENABLED);
bool value9 = result9.toBool();
QVariant result10 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_MESSAGE_NUMBER);
int value10 = result10.toInt();
QVariant result11 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_VIDEO_FORMAT);
QString value11 = result11.toString();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_VIDEO_FORMAT);
QVariant result12 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_VIDEO_PATH);
QString value12 = result12.toString();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_VIDEO_PATH);
QVariant result13 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_VIDEO_SIZE);
int value13 = result13.toInt();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_VIDEO_SIZE);
QVariant result14 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_VIDEO_WIDTH);
int value14 = result14.toInt();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_VIDEO_WIDTH);
QVariant result15 = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_VIDEO_HEIGHT);
int value15 = result15.toInt();
m_pGSettingsHelperDbus->onScreenSaverConfigChanged(KEY_VIDEO_HEIGHT);
ASSERT_EQ(value1, true);
ASSERT_EQ(value2, true);
ASSERT_EQ(value3, true);
ASSERT_EQ(value4, 300);
ASSERT_EQ(value5, false);
ASSERT_EQ(value6.isEmpty(), false);
ASSERT_EQ(value7.isEmpty(), true);
ASSERT_EQ(value8, true);
ASSERT_EQ(value9, false);
ASSERT_EQ(value10, 0);
ASSERT_EQ(value11.isEmpty(), false);
ASSERT_EQ(value12.isEmpty(), false);
ASSERT_EQ(value13, 100);
ASSERT_EQ(value14, 1920);
ASSERT_EQ(value15, 1080);
}
TEST_F(GSettingsHelperTest, SetScreenSaverConf)
{
QVariant result = m_pGSettingsHelperDbus->GetScreenSaverConf(KEY_SHOW_REST_TIME);
bool oldValue = result.toBool();
bool value = m_pGSettingsHelperDbus->SetScreenSaverConf(KEY_SHOW_REST_TIME, true);
m_pGSettingsHelperDbus->SetScreenSaverConf(KEY_SHOW_REST_TIME, oldValue);
ASSERT_EQ(value, true);
}
TEST_F(GSettingsHelperTest, GetLockScreenConf)
{
QVariant result1 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IDLE_DELAY);
int value1 = result1.toInt();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_IDLE_DELAY);
QVariant result2 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IDLE_LOCK);
int value2 = result2.toInt();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_IDLE_LOCK);
QVariant result3 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IDLE_LOCK);
bool value3 = result3.toBool();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_IDLE_LOCK);
QVariant result4 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IDLE_LOCK);
bool value4 = result4.toBool();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_IDLE_LOCK);
QVariant result5 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IDLE_LOCK);
int value5 = result5.toInt();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_IDLE_LOCK);
QVariant result6 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IDLE_LOCK);
bool value6 = result6.toBool();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_IDLE_LOCK);
QVariant result7 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_SLEEP_ACTIVATION_ENABLED);
bool value7 = result7.toBool();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_SLEEP_ACTIVATION_ENABLED);
QVariant result8 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_LOCK_ENABLED);
bool value8 = result8.toBool();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_LOCK_ENABLED);
QVariant result9 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_BACKGROUND);
QString value9 = result9.toString();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_BACKGROUND);
QVariant result10 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_MODE);
QString value10 = result10.toString();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_MODE);
QVariant result11 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_THEMES);
QStringList value11 = result11.toStringList();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_THEMES);
QVariant result12 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IMAGE_TRANSITION_EFFECT);
int value12 = result12.toInt();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_IMAGE_TRANSITION_EFFECT);
QVariant result13 = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IMAGE_SWITCH_INTERVAL);
int value13 = result13.toInt();
m_pGSettingsHelperDbus->onLockScreenConfigChanged(KEY_IMAGE_SWITCH_INTERVAL);
ASSERT_EQ(value1, 5);
ASSERT_EQ(value2, -1);
ASSERT_EQ(value3, true);
ASSERT_EQ(value4, true);
ASSERT_EQ(value5, 10);
ASSERT_EQ(value6, true);
ASSERT_EQ(value7, true);
ASSERT_EQ(value8, true);
ASSERT_EQ(value9.isEmpty(), false);
ASSERT_EQ(value10.isEmpty(), false);
ASSERT_EQ(value11.isEmpty(), false);
ASSERT_EQ(value12, 0);
ASSERT_EQ(value13, 60);
}
TEST_F(GSettingsHelperTest, SetLockScreenConf)
{
QVariant result = m_pGSettingsHelperDbus->GetLockScreenConf(KEY_IDLE_DELAY);
int oldValue = result.toInt();
bool value = m_pGSettingsHelperDbus->SetLockScreenConf(KEY_IDLE_DELAY, 1);
m_pGSettingsHelperDbus->SetLockScreenConf(KEY_IDLE_DELAY, oldValue);
ASSERT_EQ(value, true);
}
TEST_F(GSettingsHelperTest, GetPowerManagerConf)
{
QVariant result1 = m_pGSettingsHelperDbus->GetPowerManagerConf(KEY_LOCK_SUSPEND);
bool value1 = result1.toBool();
m_pGSettingsHelperDbus->onPowerManagerConfigChanged(KEY_LOCK_SUSPEND);
QVariant result2 = m_pGSettingsHelperDbus->GetPowerManagerConf(KEY_LOCK_HIBERNATE);
bool value2 = result2.toBool();
m_pGSettingsHelperDbus->onPowerManagerConfigChanged(KEY_LOCK_HIBERNATE);
QVariant result3 = m_pGSettingsHelperDbus->GetPowerManagerConf(KEY_LOCK_BLANKSCREEN);
bool value3 = result3.toBool();
m_pGSettingsHelperDbus->onPowerManagerConfigChanged(KEY_LOCK_BLANKSCREEN);
QVariant result4 = m_pGSettingsHelperDbus->GetPowerManagerConf(KEY_SLEEP_COMPUTER_AC);
int value4 = result4.toInt();
m_pGSettingsHelperDbus->onPowerManagerConfigChanged(KEY_SLEEP_COMPUTER_AC);
QVariant result5 = m_pGSettingsHelperDbus->GetPowerManagerConf(KEY_SLEEP_DISPLAY_AC);
int value5 = result5.toInt();
m_pGSettingsHelperDbus->onPowerManagerConfigChanged(KEY_SLEEP_DISPLAY_AC);
QVariant result6 = m_pGSettingsHelperDbus->GetPowerManagerConf(KEY_BUTTON_LID_AC);
int value6 = result6.toInt();
m_pGSettingsHelperDbus->onPowerManagerConfigChanged(KEY_BUTTON_LID_AC);
ASSERT_EQ(value1, false);
ASSERT_EQ(value2, false);
ASSERT_EQ(value3, true);
ASSERT_EQ(value4, -1);
ASSERT_EQ(value5, -1);
ASSERT_EQ(value6, 0);
}
TEST_F(GSettingsHelperTest, SetPowerManagerConf)
{
QVariant result = m_pGSettingsHelperDbus->GetPowerManagerConf(KEY_LOCK_SUSPEND);
bool oldValue = result.toBool();
bool value = m_pGSettingsHelperDbus->SetPowerManagerConf(KEY_LOCK_SUSPEND, false);
m_pGSettingsHelperDbus->SetPowerManagerConf(KEY_LOCK_SUSPEND, oldValue);
ASSERT_EQ(value, true);
}
TEST_F(GSettingsHelperTest, GetMateBgConf)
{
QVariant result1 = m_pGSettingsHelperDbus->GetMateBgConf(KEY_PICTURE_FILENAME);
QString value1 = result1.toString();
// m_pGSettingsHelperDbus->onMateBgConfigChanged(KEY_PICTURE_FILENAME);
QVariant result2 = m_pGSettingsHelperDbus->GetMateBgConf(KEY_PICTURE_OPTIONS);
QString value2 = result2.toString();
// m_pGSettingsHelperDbus->onMateBgConfigChanged(KEY_PICTURE_OPTIONS);
QVariant result3 = m_pGSettingsHelperDbus->GetMateBgConf(KEY_PRIMARY_COLOR);
QString value3 = result3.toString();
// m_pGSettingsHelperDbus->onMateBgConfigChanged(KEY_PRIMARY_COLOR);
ASSERT_EQ(value1.isEmpty(), false);
ASSERT_EQ(value2.isEmpty(), false);
ASSERT_EQ(value3.isEmpty(), false);
}
TEST_F(GSettingsHelperTest, SetMateBgConf)
{
QVariant result = m_pGSettingsHelperDbus->GetMateBgConf(KEY_PICTURE_FILENAME);
QString oldValue = result.toString();
bool value = m_pGSettingsHelperDbus->SetMateBgConf(KEY_PICTURE_FILENAME, "ssss");
m_pGSettingsHelperDbus->SetMateBgConf(KEY_PICTURE_FILENAME, oldValue);
ASSERT_EQ(value, true);
}
TEST_F(GSettingsHelperTest, GetUkccPluginsConf)
{
QVariant result1 = m_pGSettingsHelperDbus->GetUkccPluginsConf(KEY_HOUR_SYSTEM);
int value1 = result1.toInt();
m_pGSettingsHelperDbus->onUkccPluginsConfigChanged(KEY_HOUR_SYSTEM);
QVariant result2 = m_pGSettingsHelperDbus->GetUkccPluginsConf(KEY_DATE);
QString value2 = result2.toString();
m_pGSettingsHelperDbus->onUkccPluginsConfigChanged(KEY_DATE);
ASSERT_EQ(value1, 24);
ASSERT_EQ(value2.isEmpty(), false);
}
TEST_F(GSettingsHelperTest, SetUkccPluginsConf)
{
QVariant result = m_pGSettingsHelperDbus->GetUkccPluginsConf(KEY_HOUR_SYSTEM);
int oldValue = result.toInt();
bool value = m_pGSettingsHelperDbus->SetUkccPluginsConf(KEY_HOUR_SYSTEM, 100);
m_pGSettingsHelperDbus->SetUkccPluginsConf(KEY_HOUR_SYSTEM, oldValue);
ASSERT_EQ(value, true);
}
TEST_F(GSettingsHelperTest, GetThemeStyleConf)
{
QVariant result1 = m_pGSettingsHelperDbus->GetThemeStyleConf(KEY_SYSTEM_FONT_SIZE);
double value1 = result1.toDouble();
m_pGSettingsHelperDbus->onThemeStyleConfigChanged(KEY_SYSTEM_FONT_SIZE);
QVariant result2 = m_pGSettingsHelperDbus->GetThemeStyleConf(KEY_THEME_COLOR);
QString value2 = result2.toString();
m_pGSettingsHelperDbus->onThemeStyleConfigChanged(KEY_THEME_COLOR);
QVariant result3 = m_pGSettingsHelperDbus->GetThemeStyleConf(KEY_MENU_TRANSPARENCY);
int value3 = result3.toInt();
m_pGSettingsHelperDbus->onThemeStyleConfigChanged(KEY_MENU_TRANSPARENCY);
QVariant result4 = m_pGSettingsHelperDbus->GetThemeStyleConf(KEY_STYLE_NAME);
QString value4 = result4.toString();
m_pGSettingsHelperDbus->onThemeStyleConfigChanged(KEY_STYLE_NAME);
QVariant result5 = m_pGSettingsHelperDbus->GetThemeStyleConf(KEY_SYSTEM_FONT);
QString value5 = result5.toString();
m_pGSettingsHelperDbus->onThemeStyleConfigChanged(KEY_SYSTEM_FONT);
ASSERT_EQ(value1, 11);
ASSERT_EQ(value2.isEmpty(), false);
ASSERT_EQ(value3, 35);
ASSERT_EQ(value4.isEmpty(), false);
ASSERT_EQ(value5.isEmpty(), false);
}
TEST_F(GSettingsHelperTest, SetThemeStyleConf)
{
QVariant result = m_pGSettingsHelperDbus->GetThemeStyleConf(KEY_SYSTEM_FONT_SIZE);
int oldValue = result.toInt();
bool value = m_pGSettingsHelperDbus->SetThemeStyleConf(KEY_SYSTEM_FONT_SIZE, 14);
m_pGSettingsHelperDbus->SetThemeStyleConf(KEY_SYSTEM_FONT_SIZE, oldValue);
ASSERT_EQ(value, true);
}
TEST_F(GSettingsHelperTest, GetSessionConf)
{
QVariant result1 = m_pGSettingsHelperDbus->GetSessionConf(KEY_SESSION_IDLE);
int value1 = result1.toInt();
m_pGSettingsHelperDbus->onSessionConfigChanged(KEY_SESSION_IDLE);
QVariant result2 = m_pGSettingsHelperDbus->GetSessionConf(KEY_SESSION_LOGOUT_MUSIC);
bool value2 = result2.toBool();
m_pGSettingsHelperDbus->onSessionConfigChanged(KEY_SESSION_LOGOUT_MUSIC);
QVariant result3 = m_pGSettingsHelperDbus->GetSessionConf(KEY_SESSION_POWEROFF_MUSIC);
bool value3 = result3.toBool();
m_pGSettingsHelperDbus->onSessionConfigChanged(KEY_SESSION_POWEROFF_MUSIC);
ASSERT_EQ(value1, 1);
ASSERT_EQ(value2, false);
ASSERT_EQ(value3, false);
}
TEST_F(GSettingsHelperTest, SetSessionConf)
{
QVariant result = m_pGSettingsHelperDbus->GetSessionConf(KEY_SESSION_LOGOUT_MUSIC);
bool oldValue = result.toBool();
bool value = m_pGSettingsHelperDbus->SetSessionConf(KEY_SESSION_LOGOUT_MUSIC, false);
m_pGSettingsHelperDbus->SetSessionConf(KEY_SESSION_LOGOUT_MUSIC, oldValue);
ASSERT_EQ(value, true);
}
TEST_F(GSettingsHelperTest, GetKeyboardConf)
{
QVariant result1 = m_pGSettingsHelperDbus->GetKeyboardConf(KEY_CAPSLOCK_STATUS);
bool value1 = result1.toBool();
m_pGSettingsHelperDbus->onKeyboardConfigChanged(KEY_CAPSLOCK_STATUS);
ASSERT_EQ(value1, false);
}
TEST_F(GSettingsHelperTest, SetKeyboardConf)
{
QVariant result = m_pGSettingsHelperDbus->GetKeyboardConf(KEY_CAPSLOCK_STATUS);
bool oldValue = result.toBool();
bool value = m_pGSettingsHelperDbus->SetKeyboardConf(KEY_CAPSLOCK_STATUS, false);
m_pGSettingsHelperDbus->SetKeyboardConf(KEY_CAPSLOCK_STATUS, oldValue);
ASSERT_EQ(value, true);
}
TEST_F(GSettingsHelperTest, GetUsdMediaKeys)
{
QVariant result1 = m_pGSettingsHelperDbus->GetUsdMediaKeys(KEY_AREA_SCREENSHOT);
QString value1 = result1.toString();
m_pGSettingsHelperDbus->onUsdMediaKeysConfigChanged(KEY_AREA_SCREENSHOT);
QVariant result2 = m_pGSettingsHelperDbus->GetUsdMediaKeys(KEY_AREA_SCREENSHOT2);
QString value2 = result2.toString();
m_pGSettingsHelperDbus->onUsdMediaKeysConfigChanged(KEY_AREA_SCREENSHOT2);
QVariant result3 = m_pGSettingsHelperDbus->GetUsdMediaKeys(KEY_SCREEN_SHOT);
QString value3 = result3.toString();
m_pGSettingsHelperDbus->onUsdMediaKeysConfigChanged(KEY_SCREEN_SHOT);
QVariant result4 = m_pGSettingsHelperDbus->GetUsdMediaKeys(KEY_SCREEN_SHOT2);
QString value4 = result4.toString();
m_pGSettingsHelperDbus->onUsdMediaKeysConfigChanged(KEY_SCREEN_SHOT2);
QVariant result5 = m_pGSettingsHelperDbus->GetUsdMediaKeys(KEY_WINDOW_SCREENSHOT);
QString value5 = result5.toString();
m_pGSettingsHelperDbus->onUsdMediaKeysConfigChanged(KEY_WINDOW_SCREENSHOT);
ASSERT_EQ(value1.isEmpty(), false);
ASSERT_EQ(value2.isEmpty(), false);
ASSERT_EQ(value3.isEmpty(), false);
ASSERT_EQ(value4.isEmpty(), false);
ASSERT_EQ(value5.isEmpty(), false);
}
TEST_F(GSettingsHelperTest, GetUsdMediaStateKeys)
{
QVariant result1 = m_pGSettingsHelperDbus->GetUsdMediaStateKeys(KEY_RFKILL_STATE);
bool value1 = result1.toBool();
m_pGSettingsHelperDbus->onUsdMediaStateKeysConfigChanged(KEY_RFKILL_STATE);
ASSERT_EQ(value1, false);
}
TEST_F(GSettingsHelperTest, SetUsdMediaStateKeys)
{
QVariant result = m_pGSettingsHelperDbus->GetUsdMediaStateKeys(KEY_RFKILL_STATE);
bool oldValue = result.toBool();
bool value = m_pGSettingsHelperDbus->SetUsdMediaStateKeys(KEY_RFKILL_STATE, false);
m_pGSettingsHelperDbus->SetUsdMediaStateKeys(KEY_RFKILL_STATE, oldValue);
ASSERT_EQ(value, true);
}
ukui-screensaver/tests/unit_test_gsettings_helper/main.cpp 0000664 0001750 0001750 00000001562 15172041035 023233 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_session_watcher/ 0000775 0001750 0001750 00000000000 15172041106 021430 5 ustar feng feng ukui-screensaver/tests/unit_test_session_watcher/CMakeLists.txt 0000664 0001750 0001750 00000004263 15172041106 024175 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus X11Extras REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(QGS REQUIRED gsettings-qt)
pkg_check_modules(GIOUNIX2 REQUIRED gio-unix-2.0)
pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
find_package(X11 REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/lock-backend/sessionwatcher.cpp
../../src/common/utils.cpp
../../src/common/global_utils.cpp
../../src/lock-backend/gsettingshelper.cpp
unit_test_session_watcher.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/common/definetypes.h
../../src/common/utils.h
../../src/common/global_utils.h
../../src/lock-backend/sessionwatcher.h
../../src/lock-backend/gsettingshelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${QGS_INCLUDE_DIRS}
${GIOUNIX2_INCLUDE_DIRS}
${X11_INCLUDE_DIRS}
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_session_watcher ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_session_watcher
Qt5::Core
Qt5::Gui
Qt5::DBus
Qt5::X11Extras
${QGS_LIBRARIES}
${GIOUNIX2_LIBRARIES}
${X11_LIBRARIES}
)
# 链接 GTest 库
target_link_libraries(unit_test_session_watcher
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_session_watcher/main.cpp 0000664 0001750 0001750 00000001562 15172041035 023065 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_session_watcher/unit_test_session_watcher.cpp 0000664 0001750 0001750 00000003157 15172041035 027441 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include
#include "../../src/lock-backend/sessionwatcher.h"
#include "stubext.h"
using namespace stub_ext;
class SessionWatcherTest : public testing::Test
{
protected:
QSharedPointer m_pGSettingsHelperDbus;
QSharedPointer m_pSessionWatcherDbus;
void SetUp() override
{
m_pGSettingsHelperDbus = QSharedPointer(new GSettingsHelper());
m_pSessionWatcherDbus = QSharedPointer(new SessionWatcher(m_pGSettingsHelperDbus));
}
void TearDown() override
{
m_pSessionWatcherDbus.reset();
m_pGSettingsHelperDbus.reset();
}
};
TEST_F(SessionWatcherTest, GetCurUserName)
{
m_pSessionWatcherDbus->onStatusChanged(0);
m_pSessionWatcherDbus->onStatusChanged(1);
m_pSessionWatcherDbus->onStatusChanged(2);
m_pSessionWatcherDbus->onStatusChanged(3);
}
ukui-screensaver/tests/unit_test_kglobalaccel_helper/ 0000775 0001750 0001750 00000000000 15172041106 022172 5 ustar feng feng ukui-screensaver/tests/unit_test_kglobalaccel_helper/unit_test_kglobalaccel_helper.cpp 0000664 0001750 0001750 00000003016 15172041035 030737 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include "../../src/dbusifs/kglobalaccelhelper.h"
#include "stubext.h"
using namespace stub_ext;
class KglobalAccelHelperTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pKglobalAccelHelperDbus = new KglobalAccelHelper();
}
static void TearDownTestSuite()
{
delete m_pKglobalAccelHelperDbus;
m_pKglobalAccelHelperDbus = nullptr;
}
static KglobalAccelHelper *m_pKglobalAccelHelperDbus;
};
KglobalAccelHelper *KglobalAccelHelperTest::m_pKglobalAccelHelperDbus = nullptr;
TEST_F(KglobalAccelHelperTest, blockShortcut)
{
bool oldValue = m_pKglobalAccelHelperDbus->blockShortcut(true);
ASSERT_EQ(oldValue, true);
bool newValue = m_pKglobalAccelHelperDbus->blockShortcut(false);
ASSERT_EQ(newValue, true);
}
ukui-screensaver/tests/unit_test_kglobalaccel_helper/CMakeLists.txt 0000664 0001750 0001750 00000003154 15172041106 024735 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/dbusifs/kglobalaccelhelper.cpp
unit_test_kglobalaccel_helper.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/dbusifs/kglobalaccelhelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_kglobalaccel_helper ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_kglobalaccel_helper
Qt5::Core
Qt5::Gui
Qt5::DBus
)
# 链接 GTest 库
target_link_libraries(unit_test_kglobalaccel_helper
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_kglobalaccel_helper/main.cpp 0000664 0001750 0001750 00000001562 15172041035 023627 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_display_service/ 0000775 0001750 0001750 00000000000 15172041106 021415 5 ustar feng feng ukui-screensaver/tests/unit_test_display_service/unit_test_display_service.cpp 0000664 0001750 0001750 00000005010 15172041035 027401 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include "../../src/common/displayservice.h"
class DisplayServiceTest : public testing::Test
{
protected:
// static void SetUpTestSuite()
// {
// m_pGSettingsHelperDbus = new GSettingsHelper();
// }
// static void TearDownTestSuite()
// {
// delete m_pGSettingsHelperDbus;
// m_pGSettingsHelperDbus = nullptr;
// }
// static GSettingsHelper *m_pGSettingsHelperDbus;
};
//GSettingsHelper *DisplayServiceTest::m_pGSettingsHelperDbus = nullptr;
// 测试 switchDisplayMode 函数
TEST_F(DisplayServiceTest, SwitchDisplayMode) {
// 测试 DISPLAY_MODE_ORI
bool value = DisplayService::instance()->switchDisplayMode(DISPLAY_MODE_ORI);
EXPECT_EQ(value, false);
// 测试 DISPLAY_MODE_CLONE
bool value1 = DisplayService::instance()->switchDisplayMode(DISPLAY_MODE_CLONE);
EXPECT_EQ(value1, false);
// 测试 DISPLAY_MODE_EXTEND
bool value2 = DisplayService::instance()->switchDisplayMode(DISPLAY_MODE_EXTEND);
EXPECT_EQ(value2, false);
// 测试 DISPLAY_MODE_ONLY_OUT
bool value3 = DisplayService::instance()->switchDisplayMode(DISPLAY_MODE_ONLY_OUT);
EXPECT_EQ(value3, false);
}
// 测试 setOneDisplayMode 函数
TEST_F(DisplayServiceTest, SetOneDisplayMode) {
// 测试使用 xrandr
DisplayService::instance()->setOneDisplayMode();
}
// 测试 setCurUserName 函数
TEST_F(DisplayServiceTest, SetCurUserName) {
DisplayService::instance()->setCurUserName(getenv("USER"));
}
// 测试 isSaveParamInUsed 函数
TEST_F(DisplayServiceTest, IsSaveParamInUsed) {
EXPECT_TRUE(DisplayService::instance()->isSaveParamInUsed());
EXPECT_FALSE(DisplayService::instance()->isSaveParamInUsed());
}
// 测试 isJJW7200 函数
TEST_F(DisplayServiceTest, IsJJW7200) {
int value = DisplayService::instance()->isJJW7200();
EXPECT_EQ(value, 0);
}
ukui-screensaver/tests/unit_test_display_service/CMakeLists.txt 0000664 0001750 0001750 00000003027 15172041106 024157 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/common/displayservice.cpp
unit_test_display_service.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/common/displayservice.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_display_service ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_display_service
Qt5::Core
Qt5::Gui
Qt5::DBus
)
# 链接 GTest 库
target_link_libraries(unit_test_display_service
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_display_service/main.cpp 0000664 0001750 0001750 00000001562 15172041035 023052 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_switch_user/ 0000775 0001750 0001750 00000000000 15172041106 020567 5 ustar feng feng ukui-screensaver/tests/unit_test_switch_user/CMakeLists.txt 0000664 0001750 0001750 00000003621 15172041106 023331 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0)
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/lock-backend/switchuserutils.cpp
../../src/common/global_utils.cpp
unit_test_switch_user.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/lock-backend/switchuserutils.h
../../src/common/global_utils.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
${GLIB2_INCLUDE_DIRS}
${LIBSYSTEMD_INCLUDE_DIRS}
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_switch_user ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_switch_user
Qt5::Core
Qt5::Gui
Qt5::DBus
${LIBSYSTEMD_LIBRARIES}
)
# 链接 GTest 库
target_link_libraries(unit_test_switch_user
GTest::GTest
GTest::Main
Threads::Threads
${GLIB2_LIBRARIES}
)
ukui-screensaver/tests/unit_test_switch_user/main.cpp 0000664 0001750 0001750 00000001562 15172041035 022224 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/unit_test_switch_user/unit_test_switch_user.cpp 0000664 0001750 0001750 00000005317 15172041035 025737 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include
#include "../../src/common/global_utils.h"
#include "../../src/lock-backend/switchuserutils.h"
#include "stubext.h"
using namespace stub_ext;
class SwitchUserUtilsTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pSwitchUserUtilsDbus = new SwitchUserUtils();
}
static void TearDownTestSuite()
{
delete m_pSwitchUserUtilsDbus;
m_pSwitchUserUtilsDbus = nullptr;
}
static SwitchUserUtils *m_pSwitchUserUtilsDbus;
};
SwitchUserUtils *SwitchUserUtilsTest::m_pSwitchUserUtilsDbus = nullptr;
// 测试 GetCurUserName 函数
TEST_F(SwitchUserUtilsTest, GetCurUserName) {
QString userName = m_pSwitchUserUtilsDbus->GetCurUserName();
EXPECT_EQ(userName, "testuser");
}
// 测试 GetUidByName 函数
TEST_F(SwitchUserUtilsTest, GetUidByName) {
int uid = m_pSwitchUserUtilsDbus->GetUidByName(getenv("USER"));
EXPECT_EQ(uid, 1000);
}
// 测试 GetUserUDII 函数
TEST_F(SwitchUserUtilsTest, GetUserUDII) {
UserDisplayIfInfo userDisplayIfInfo = m_pSwitchUserUtilsDbus->GetUserUDII(getenv("USER"));
EXPECT_EQ(userDisplayIfInfo.strSeatPath, "/org/freedesktop/DisplayManager/Seat1");
EXPECT_EQ(userDisplayIfInfo.strUserName, "testuser");
EXPECT_EQ(userDisplayIfInfo.strSessionPath, "/org/freedesktop/DisplayManager/Session1");
}
// 测试 SwitchToUserSession 函数
TEST_F(SwitchUserUtilsTest, SwitchToUserSession) {
UserDisplayIfInfo userDisplayIfInfo;
userDisplayIfInfo.strSeatPath = "/org/freedesktop/DisplayManager/Seat1";
userDisplayIfInfo.strUserName = "testuser";
userDisplayIfInfo.strSessionPath = "/org/freedesktop/DisplayManager/Session1";
int result = m_pSwitchUserUtilsDbus->SwitchToUserSession("/org/freedesktop/DisplayManager/Seat1", userDisplayIfInfo);
EXPECT_EQ(result, 0);
}
// 测试 SwitchToUserLock 函数
TEST_F(SwitchUserUtilsTest, SwitchToUserLock) {
bool result = m_pSwitchUserUtilsDbus->SwitchToUserLock();
EXPECT_TRUE(result);
}
ukui-screensaver/tests/unit_test_freedesktop_helper/ 0000775 0001750 0001750 00000000000 15172041106 022102 5 ustar feng feng ukui-screensaver/tests/unit_test_freedesktop_helper/unit_test_freedesktop_helper.cpp 0000664 0001750 0001750 00000003122 15172041035 030555 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
#include "../../src/dbusifs/freedesktophelper.h"
#include "stubext.h"
using namespace stub_ext;
class FreedesktopHelperTest : public testing::Test
{
protected:
static void SetUpTestSuite()
{
m_pFreedesktopHelperDbus = new FreedesktopHelper();
}
static void TearDownTestSuite()
{
delete m_pFreedesktopHelperDbus;
m_pFreedesktopHelperDbus = nullptr;
}
static FreedesktopHelper *m_pFreedesktopHelperDbus;
};
FreedesktopHelper *FreedesktopHelperTest::m_pFreedesktopHelperDbus = nullptr;
TEST_F(FreedesktopHelperTest, NameHasOwner)
{
bool value = m_pFreedesktopHelperDbus->NameHasOwner("org.ukui.Biometric");
ASSERT_EQ(value, false);
}
TEST_F(FreedesktopHelperTest, isServiceActivable)
{
bool value = m_pFreedesktopHelperDbus->isServiceActivable("org.ukui.UniauthBackend");
ASSERT_EQ(value, false);
}
ukui-screensaver/tests/unit_test_freedesktop_helper/CMakeLists.txt 0000664 0001750 0001750 00000003215 15172041106 024643 0 ustar feng feng # CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)
find_package(Qt5 COMPONENTS Core Gui DBus REQUIRED)
# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 开启代码覆盖率相关编译选项(对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-access-control")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
# 定义源文件列表,对应原来的SOURCES变量
set(SOURCES
../../src/dbusifs/freedesktophelper.cpp
unit_test_freedesktop_helper.cpp
main.cpp
)
# 定义头文件列表,对应原来的HEADERS变量
set(HEADERS
../../src/common/definetypes.h
../../src/dbusifs/freedesktophelper.h
)
# 包含头文件的路径设置,对应原来的INCLUDEPATH变量
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
)
# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
# 添加可执行文件或库目标,将元对象代码源文件一起添加进去
add_executable(unit_test_freedesktop_helper ${SOURCES} ${MOC_SOURCES})
# 链接Qt相关的库
target_link_libraries(unit_test_freedesktop_helper
Qt5::Core
Qt5::Gui
Qt5::DBus
)
# 链接 GTest 库
target_link_libraries(unit_test_freedesktop_helper
GTest::GTest
GTest::Main
Threads::Threads
)
ukui-screensaver/tests/unit_test_freedesktop_helper/main.cpp 0000664 0001750 0001750 00000001562 15172041035 023537 0 ustar feng feng /*
* Copyright (C) 2025 KylinSoft Co., Ltd.
*
* 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 3, 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
#include
int main(int argc, char **argv)
{
QGuiApplication a(argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
ukui-screensaver/tests/kt-test-utils/ 0000775 0001750 0001750 00000000000 15172041035 016664 5 ustar feng feng ukui-screensaver/tests/kt-test-utils/cpp-stub-ext/ 0000775 0001750 0001750 00000000000 15172041035 021217 5 ustar feng feng ukui-screensaver/tests/kt-test-utils/cpp-stub-ext/stub-shadow.cpp 0000664 0001750 0001750 00000003147 15172041035 024170 0 ustar feng feng /*
* Author: Zhang Yu
* Maintainer: Zhang Yu
*
* MIT License
*
* Copyright (c) 2020 Zhang Yu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "stub-shadow.h"
namespace stub_ext {
WrapperMap stub_wrappers;
Wrapper::Wrapper()
{
}
Wrapper::~Wrapper()
{
}
void freeWrapper(Wrapper *wrapper)
{
if (!wrapper)
return;
for (auto iter = stub_wrappers.begin(); iter != stub_wrappers.end();) {
if (iter->second == wrapper)
iter = stub_wrappers.erase(iter);
else
++iter;
}
delete wrapper;
}
}
ukui-screensaver/tests/kt-test-utils/cpp-stub-ext/stubext.h 0000664 0001750 0001750 00000007341 15172041035 023073 0 ustar feng feng
#ifndef STUBEXT_H
#define STUBEXT_H
/*
* Author: Zhang Yu
* Maintainer: Zhang Yu
*
* MIT License
*
* Copyright (c) 2020 Zhang Yu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
//需修改Stub的私用成员函数和成员变量为保护类型
#include "stub.h"
#include "stub-shadow.h"
#ifdef DEBUG_STUB_INVOKE
// use to make sure the stub function is invoked.
# define __DBG_STUB_INVOKE__ printf("stub at %s:%d is invoked.\n", __FILE__, __LINE__);
#else
# define __DBG_STUB_INVOKE__
#endif
#define VADDR(CLASS_NAME, MEMBER_NAME) (typename stub_ext::VFLocator::Func)(&CLASS_NAME::MEMBER_NAME)
namespace stub_ext {
class StubExt : public Stub
{
public:
StubExt()
: Stub() { }
template
bool set_lamda(T addr, Lamda lamda)
{
char *fn = addrof(addr);
if (m_result.find(fn) != m_result.end())
reset(addr);
Wrapper *wrapper = nullptr;
auto addr_stub = depictShadow(&wrapper, addr, lamda);
if (set(addr, addr_stub)) {
m_wrappers.insert(std::make_pair(fn, wrapper));
return true;
} else {
freeWrapper(wrapper);
}
return false;
}
template
void reset(T addr)
{
Stub::reset(addr);
char *fn = addrof(addr);
auto iter = m_wrappers.find(fn);
if (iter != m_wrappers.end()) {
freeWrapper(iter->second);
m_wrappers.erase(iter);
}
}
~StubExt()
{
clear();
}
void clear() override
{
Stub::clear();
for (auto iter = m_wrappers.begin(); iter != m_wrappers.end(); ++iter) {
freeWrapper(iter->second);
}
m_wrappers.clear();
}
template
static void *get_ctor_addr(bool start = true)
{
// the start vairable must be true, or the compiler will optimize out.
if (start) goto Start;
Call_Constructor:
// This line of code will not be executed.
// The purpose of the code is to allow the compiler to generate the assembly code that calls the constructor.
T();
Start:
// The address of the line of code T() obtained by assembly
char *p = (char *)&&Call_Constructor; // https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
// CALL rel32
void *ret = 0;
char pos;
char call = 0xe8;
do {
pos = *p;
if (pos == call) {
ret = p + 5 + (*(int *)(p + 1));
}
} while (!ret && (++p));
return ret;
}
protected:
std::map m_wrappers;
};
}
#endif // STUBEXT_H
ukui-screensaver/tests/kt-test-utils/cpp-stub-ext/stub-shadow.h 0000664 0001750 0001750 00000011434 15172041035 023633 0 ustar feng feng
#ifndef STUBSHADOW_H
#define STUBSHADOW_H
/*
* Author: Zhang Yu
* Maintainer: Zhang Yu
*
* MIT License
*
* Copyright (c) 2020 Zhang Yu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include
#include
namespace stub_ext {
#define LAMDA_FUNCTION_TYPE decltype(&Lamda::operator())
class Wrapper
{
public:
Wrapper();
virtual ~Wrapper();
};
typedef std::unordered_map WrapperMap;
extern WrapperMap stub_wrappers;
template
class LamdaWrapper : public Wrapper
{
public:
LamdaWrapper(Lamda func): Wrapper(),_func(func){}
~LamdaWrapper(){}
Lamda _func;
};
template
struct VFLocator
{
};
template
struct VFLocator
{
typedef Ret (*Func)(Obj*, Args...);
};
template
struct VFLocator
{
typedef Ret (*Func)(Obj*, Args...);
};
template
struct LamdaCaller
{
};
template
struct LamdaCaller
{
template
static Ret call(LamdaWrapper *wrapper, OrgArgs&&... args)
{
return wrapper->_func(std::forward(args)...);
}
};
template
struct LamdaCaller
{
template
static Ret call(LamdaWrapper *wrapper, OrgArgs&&... args)
{
return wrapper->_func();
}
};
template
struct FuncShadow
{
};
template
struct FuncShadow
{
typedef Ret (*Shadow)(Args...);
typedef Ret RetType;
static Ret call(Args ...args)
{
Shadow shadow = &call;
long id = (long)shadow;
auto iter = stub_wrappers.find(id);
assert(stub_wrappers.find(id) != stub_wrappers.end());
LamdaWrapper *wrapper = dynamic_cast *>(iter->second);
return LamdaCaller::call(wrapper, args...);
}
};
template
struct FuncShadow
{
typedef Ret (*Shadow)(Obj *,Args...);
typedef Ret RetType;
static Ret call(Obj *obj, Args ...args)
{
Shadow shadow = &call;
long id = (long)shadow;
auto iter = stub_wrappers.find(id);
assert(stub_wrappers.find(id) != stub_wrappers.end());
LamdaWrapper *wrapper = dynamic_cast *>(iter->second);
return LamdaCaller::call(wrapper, obj, args...);
}
};
template
struct FuncShadow
{
typedef Ret (*Shadow)(Obj *,Args...);
typedef Ret RetType;
static Ret call(Obj *obj, Args ...args)
{
Shadow shadow = &call;
long id = (long)shadow;
auto iter = stub_wrappers.find(id);
assert(stub_wrappers.find(id) != stub_wrappers.end());
LamdaWrapper *wrapper = dynamic_cast *>(iter->second);
return LamdaCaller::call(wrapper, obj, args...);
}
};
template
typename FuncShadow::Shadow depictShadow(Wrapper **wrapper, Func func, Lamda lamda)
{
*wrapper = new LamdaWrapper(lamda);
typename FuncShadow::Shadow shadow = &FuncShadow::call;
long id = (long)shadow;
assert(stub_wrappers.find(id) == stub_wrappers.end());
stub_wrappers.insert(std::make_pair(id,*wrapper));
return shadow;
}
void freeWrapper(Wrapper *wrapper);
}
#endif // STUBSHADOW_H
ukui-screensaver/tests/kt-test-utils/cpp-stub/ 0000775 0001750 0001750 00000000000 15172041035 020421 5 ustar feng feng ukui-screensaver/tests/kt-test-utils/cpp-stub/stub.h 0000664 0001750 0001750 00000023417 15172041035 021556 0 ustar feng feng #ifndef __STUB_H__
#define __STUB_H__
#ifdef _WIN32
//windows
#include
#include
#else
//linux
#include
#include
#include
#endif
//c
#include
#include
//c++
#include