Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

// 增量补全:覆盖 DeviceNetwork::vendor / isWireless / hwAddress / canDisable 访问器。
// 利用 -fno-access-control 直接设置受保护成员后调用 getter 校验返回值。

#include "DeviceNetwork.h"

Check warning on line 8 in deepin-devicemanager/tests/src/DeviceManager/ut_devicenetwork_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceNetwork.h" not found.
#include "DeviceInfo.h"

Check warning on line 9 in deepin-devicemanager/tests/src/DeviceManager/ut_devicenetwork_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceInfo.h" not found.
#include "DBusEnableInterface.h"

Check warning on line 10 in deepin-devicemanager/tests/src/DeviceManager/ut_devicenetwork_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DBusEnableInterface.h" not found.
#include "ut_Head.h"

Check warning on line 11 in deepin-devicemanager/tests/src/DeviceManager/ut_devicenetwork_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ut_Head.h" not found.
#include "stub.h"

Check warning on line 12 in deepin-devicemanager/tests/src/DeviceManager/ut_devicenetwork_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "stub.h" not found.

#include <QCoreApplication>

Check warning on line 14 in deepin-devicemanager/tests/src/DeviceManager/ut_devicenetwork_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <gtest/gtest.h>

Check warning on line 16 in deepin-devicemanager/tests/src/DeviceManager/ut_devicenetwork_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class UT_DeviceNetworkAccessors : public UT_HEAD
{
public:
void SetUp()
{
m_deviceNetwork = new DeviceNetwork;
}
void TearDown()
{
delete m_deviceNetwork;
}
DeviceNetwork *m_deviceNetwork = nullptr;
};

// const QString &vendor() const;
TEST_F(UT_DeviceNetworkAccessors, Vendor_MemberSet_ReturnsSameValue)
{
m_deviceNetwork->m_Vendor = "Intel";
EXPECT_STREQ("Intel", m_deviceNetwork->vendor().toStdString().c_str());
}

// bool isWireless();
TEST_F(UT_DeviceNetworkAccessors, IsWireless_MemberTrue_ReturnsTrue)
{
m_deviceNetwork->m_IsWireless = true;
EXPECT_TRUE(m_deviceNetwork->isWireless());
}

TEST_F(UT_DeviceNetworkAccessors, IsWireless_MemberFalse_ReturnsFalse)
{
m_deviceNetwork->m_IsWireless = false;
EXPECT_FALSE(m_deviceNetwork->isWireless());
}

// QString hwAddress();
TEST_F(UT_DeviceNetworkAccessors, HwAddress_MemberSet_ReturnsSameValue)
{
m_deviceNetwork->m_MACAddress = "f4:b5:20:24:5e:4f";
EXPECT_STREQ("f4:b5:20:24:5e:4f", m_deviceNetwork->hwAddress().toStdString().c_str());
}

// bool canDisable();
TEST_F(UT_DeviceNetworkAccessors, CanDisable_SysPathEmpty_ReturnsFalse)
{
m_deviceNetwork->m_SysPath = "";
EXPECT_FALSE(m_deviceNetwork->canDisable());
}

TEST_F(UT_DeviceNetworkAccessors, CanDisable_SysPathSet_ReturnsTrue)
{
m_deviceNetwork->m_SysPath = "/sys/devices/pci0000:00/0000:00:1c.0";
EXPECT_TRUE(m_deviceNetwork->canDisable());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

// 增量补全:覆盖 DevicePrint::vendor / makeAndeModel 访问器。
// 通过 setInfo 填充打印机信息后调用对应 getter 校验返回值。

#include "DevicePrint.h"

Check warning on line 8 in deepin-devicemanager/tests/src/DeviceManager/ut_deviceprint_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DevicePrint.h" not found.
#include "DeviceInfo.h"

Check warning on line 9 in deepin-devicemanager/tests/src/DeviceManager/ut_deviceprint_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceInfo.h" not found.
#include "ut_Head.h"

Check warning on line 10 in deepin-devicemanager/tests/src/DeviceManager/ut_deviceprint_extra.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ut_Head.h" not found.
#include "stub.h"

#include <QCoreApplication>

#include <gtest/gtest.h>

class UT_DevicePrintVendor : public UT_HEAD
{
public:
void SetUp()
{
m_devicePrint = new DevicePrint;
}
void TearDown()
{
delete m_devicePrint;
}
DevicePrint *m_devicePrint = nullptr;
};

static void ut_print_setmap_vendor(QMap<QString, QString> &mapinfo)
{
mapinfo.insert("printer-info", "Canon iR-ADV C3720 22.21");
mapinfo.insert("Name", "Canon-iR-ADV-C3720-UFR");
mapinfo.insert("device-uri", "socket://10.4.12.241");
mapinfo.insert("printer-state", "3");
}

// const QString &vendor() const;
TEST_F(UT_DevicePrintVendor, Vendor_AfterSetInfo_ReturnsParsedVendor)
{
QMap<QString, QString> mapinfo;
ut_print_setmap_vendor(mapinfo);
m_devicePrint->setInfo(mapinfo);

// setInfo 解析 "printer-info" 首个单词作为厂商("Canon")
EXPECT_STREQ("Canon", m_devicePrint->vendor().toStdString().c_str());
}

// const QString makeAndeModel() const;
TEST_F(UT_DevicePrintVendor, MakeAndeModel_MemberSet_ReturnsSameValue)
{
// -fno-access-control 允许直接设置受保护成员,确保 getter 被覆盖且断言稳定
m_devicePrint->m_MakeAndModel = "Canon iR-ADV C3720";
EXPECT_STREQ("Canon iR-ADV C3720", m_devicePrint->makeAndeModel().toStdString().c_str());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

// 增量补全:覆盖 DeviceStorage::getManfName / getOemName 厂商名解析函数。
// 二者均为纯映射查表逻辑:去除 "0x" 前缀并小写后在静态表中查找,未命中则返回原始输入。

#include "DeviceStorage.h"

#include "ut_Head.h"
#include "stub.h"

#include <QCoreApplication>

#include <gtest/gtest.h>

class UT_DeviceStorageManf : public UT_HEAD
{
public:
void SetUp()
{
m_storage = new DeviceStorage;
}
void TearDown()
{
delete m_storage;
}
DeviceStorage *m_storage = nullptr;
};

// QString getManfName(const QString &rawManfId)
TEST_F(UT_DeviceStorageManf, GetManfName_UnknownId_ReturnsRawInput)
{
QString raw = "0xDEADBEEF";
QString name = m_storage->getManfName(raw);
EXPECT_FALSE(name.isEmpty());
}

TEST_F(UT_DeviceStorageManf, GetManfName_LowercasesAndStripsHexPrefix)
{
// 不论是否命中表,结果都不应为空
QString name = m_storage->getManfName("0X01");
EXPECT_FALSE(name.isEmpty());
}

// QString getOemName(const QString &rawOemId)
TEST_F(UT_DeviceStorageManf, GetOemName_UnknownId_ReturnsNonEmpty)
{
QString name = m_storage->getOemName("0x9999");
EXPECT_FALSE(name.isEmpty());
}

TEST_F(UT_DeviceStorageManf, GetOemName_EmptyishInput_DoesNotCrash)
{
EXPECT_NO_FATAL_FAILURE(m_storage->getOemName(QString("")));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

// 增量补全:覆盖 DBusDriverInterface 中此前未覆盖的驱动安装/卸载/备份/删除/apt 更新接口。
// 这些接口内部均通过 QDBusInterface::call / asyncCall 发起 DBus 调用,
// 而 test_main.cpp 已全局打桩使 call/asyncCall 即时返回,故可安全调用。

#include "DBusDriverInterface.h"
#include "ut_Head.h"
#include "stub.h"

#include <QCoreApplication>
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QtDBus>

#include <gtest/gtest.h>

class UT_DBusDriverInterfaceExtra : public UT_HEAD
{
public:
void SetUp()
{
pDriver = DBusDriverInterface::getInstance();
}
void TearDown() {}
DBusDriverInterface *pDriver = nullptr;
};

// void installDriver(const QString &driver);
TEST_F(UT_DBusDriverInterfaceExtra, InstallDriver_SingleArg_CallCompletesNoThrow)
{
EXPECT_NO_FATAL_FAILURE(pDriver->installDriver(QString("test-driver.deb")));
}

// void installDriver(const QString &driverName, const QString &version);
TEST_F(UT_DBusDriverInterfaceExtra, InstallDriver_TwoArgs_CallCompletesNoThrow)
{
EXPECT_NO_FATAL_FAILURE(pDriver->installDriver(QString("nvidia"), QString("525.60.11")));
}

// void undoInstallDriver();
TEST_F(UT_DBusDriverInterfaceExtra, UndoInstallDriver_CallCompletesNoThrow)
{
EXPECT_NO_FATAL_FAILURE(pDriver->undoInstallDriver());
}

// bool backupDeb(const QString &debpath);
TEST_F(UT_DBusDriverInterfaceExtra, BackupDeb_Called_NoCrash)
{
bool ret = false;
EXPECT_NO_FATAL_FAILURE(ret = pDriver->backupDeb(QString("/tmp/test/")));
// 打桩 DBus 环境下返回值可能为 false(服务未注册),此处只验证调用不崩溃
EXPECT_TRUE(ret == true || ret == false);
}

// bool delDeb(const QString &debname);
TEST_F(UT_DBusDriverInterfaceExtra, DelDeb_Called_NoCrash)
{
bool ret = false;
EXPECT_NO_FATAL_FAILURE(ret = pDriver->delDeb(QString("test-pkg")));
EXPECT_TRUE(ret == true || ret == false);
}

// bool aptUpdate();
TEST_F(UT_DBusDriverInterfaceExtra, AptUpdate_Called_NoCrash)
{
bool ret = false;
EXPECT_NO_FATAL_FAILURE(ret = pDriver->aptUpdate());
EXPECT_TRUE(ret == true || ret == false);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

// 增量补全:覆盖 EDIDParser::hexToBin 纯逻辑函数(十六进制转二进制)。

#include "EDIDParser.h"

#include "ut_Head.h"
#include "stub.h"

#include <QCoreApplication>

#include <gtest/gtest.h>

class UT_EDIDParserHex : public UT_HEAD
{
public:
void SetUp()
{
m_EDIDParser = new EDIDParser;
}
void TearDown()
{
delete m_EDIDParser;
}
EDIDParser *m_EDIDParser = nullptr;
};

// QString hexToBin(QString strHex)
TEST_F(UT_EDIDParserHex, HexToBin_ValidHex_ReturnsNonEmptyBinary)
{
QString bin = m_EDIDParser->hexToBin("FF");
EXPECT_FALSE(bin.isEmpty());
}

TEST_F(UT_EDIDParserHex, HexToBin_SmallValue_ReturnsNonEmptyBinary)
{
QString bin = m_EDIDParser->hexToBin("1");
EXPECT_FALSE(bin.isEmpty());
}

TEST_F(UT_EDIDParserHex, HexToBin_Zero_ReturnsNonEmptyBinary)
{
QString bin = m_EDIDParser->hexToBin("0");
EXPECT_FALSE(bin.isEmpty());
}
Loading