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,173 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// 覆盖率缺口补全:DeviceManager 模块下多个 Device* 类的 vendor() 等 getter
// 此前未被任何用例调用,函数覆盖率为 0。本文件对各设备类做默认构造并调用其
// 未覆盖的 getter:
// - vendor() 等为 const 成员 getter,默认构造未填充硬件数据,返回空串;
// 用例主要保证 getter 可被安全调用(函数覆盖),并验证默认语义。
// - DeviceNetwork::canDisable/isWireless/hwAddress 与 DeviceStorage::getManfName/
// getOemName 含可判定的默认逻辑或查表逻辑,使用确定性断言。

#include "DeviceAudio.h"

Check warning on line 13 in deepin-devicemanager/tests/src/DeviceManager/ut_device_getters_covgap.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceAudio.h" not found.
#include "DeviceBios.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceBios.h" not found.
#include "DeviceBluetooth.h"

Check warning on line 15 in deepin-devicemanager/tests/src/DeviceManager/ut_device_getters_covgap.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceBluetooth.h" not found.
#include "DeviceCdrom.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceCdrom.h" not found.
#include "DeviceComputer.h"

Check warning on line 17 in deepin-devicemanager/tests/src/DeviceManager/ut_device_getters_covgap.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceComputer.h" not found.
#include "DeviceGpu.h"

Check warning on line 18 in deepin-devicemanager/tests/src/DeviceManager/ut_device_getters_covgap.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceGpu.h" not found.
#include "DeviceImage.h"

Check warning on line 19 in deepin-devicemanager/tests/src/DeviceManager/ut_device_getters_covgap.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceImage.h" not found.
#include "DeviceInput.h"

Check warning on line 20 in deepin-devicemanager/tests/src/DeviceManager/ut_device_getters_covgap.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceInput.h" not found.
#include "DeviceMemory.h"

Check warning on line 21 in deepin-devicemanager/tests/src/DeviceManager/ut_device_getters_covgap.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceMemory.h" not found.
#include "DeviceMonitor.h"

Check warning on line 22 in deepin-devicemanager/tests/src/DeviceManager/ut_device_getters_covgap.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DeviceMonitor.h" not found.
#include "DeviceNetwork.h"
#include "DeviceOtherPCI.h"
#include "DeviceOthers.h"
#include "DevicePower.h"
#include "DevicePrint.h"
#include "DeviceStorage.h"
#include "DeviceInfo.h"
#include "MacroDefinition.h"

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

#include <gtest/gtest.h>

// ---- vendor() getter 集群:默认构造后调用,验证不崩溃且返回 QString ----
TEST(UT_Device_GettersCovGap, DeviceAudio_Vendor_DefaultCtorNoCrash)
{
DeviceAudio device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceBluetooth_Vendor_DefaultCtorNoCrash)
{
DeviceBluetooth device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceCdrom_Vendor_DefaultCtorNoCrash)
{
DeviceCdrom device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceComputer_Vendor_DefaultCtorNoCrash)
{
DeviceComputer device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceGpu_Vendor_DefaultCtorNoCrash)
{
DeviceGpu device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceImage_Vendor_DefaultCtorNoCrash)
{
DeviceImage device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceInput_Vendor_DefaultCtorNoCrash)
{
DeviceInput device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceMemory_Vendor_DefaultCtorNoCrash)
{
DeviceMemory device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceMonitor_Vendor_DefaultCtorNoCrash)
{
DeviceMonitor device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceOtherPCI_Vendor_DefaultCtorNoCrash)
{
DeviceOtherPCI device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DeviceOthers_Vendor_DefaultCtorNoCrash)
{
DeviceOthers device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DevicePower_Vendor_DefaultCtorNoCrash)
{
DevicePower device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

TEST(UT_Device_GettersCovGap, DevicePrint_Vendor_DefaultCtorNoCrash)
{
DevicePrint device;
EXPECT_NO_FATAL_FAILURE(device.vendor());
}

// ---- 非 vendor 的确定性 getter ----

TEST(UT_Device_GettersCovGap, DeviceBios_Tomlname_DefaultCtorReturnsEmpty)
{
DeviceBios device;
EXPECT_TRUE(device.tomlname().isEmpty());
}

TEST(UT_Device_GettersCovGap, DevicePrint_MakeAndModel_DefaultCtorReturnsEmpty)
{
DevicePrint device;
EXPECT_TRUE(device.makeAndeModel().isEmpty());
}

TEST(UT_Device_GettersCovGap, DeviceNetwork_Vendor_DefaultCtorReturnsEmpty)
{
DeviceNetwork device;
EXPECT_TRUE(device.vendor().isEmpty());
}

TEST(UT_Device_GettersCovGap, DeviceNetwork_IsWireless_DefaultCtorReturnsFalse)
{
DeviceNetwork device;
EXPECT_FALSE(device.isWireless());
}

TEST(UT_Device_GettersCovGap, DeviceNetwork_HwAddress_DefaultCtorReturnsEmpty)
{
DeviceNetwork device;
EXPECT_TRUE(device.hwAddress().isEmpty());
}

TEST(UT_Device_GettersCovGap, DeviceNetwork_CanDisable_EmptySysPathReturnsFalse)
{
// canDisable: m_SysPath 为空时返回 false
DeviceNetwork device;
EXPECT_FALSE(device.canDisable());
}

TEST(UT_Device_GettersCovGap, DeviceStorage_GetManfName_KnownIdReturnsMappedVendor)
{
DeviceStorage device;
// MANFID_TABLE 中 000001 -> Panasonic
EXPECT_EQ(device.getManfName("000001"), "Panasonic");
}

TEST(UT_Device_GettersCovGap, DeviceStorage_GetManfName_UnknownIdReturnsRawInput)
{
DeviceStorage device;
// 查表未命中时返回原始输入
EXPECT_EQ(device.getManfName("zzz-unknown-manf"), "zzz-unknown-manf");
}

TEST(UT_Device_GettersCovGap, DeviceStorage_GetOemName_UnknownIdReturnsRawInput)
{
DeviceStorage device;
EXPECT_EQ(device.getOemName("zzz-unknown-oem"), "zzz-unknown-oem");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// 覆盖率缺口补全:EDIDParser::hexToBin 此前未被任何用例调用,函数覆盖率为 0。
// 本文件补全该函数的用例,覆盖合法十六进制输入与边界输入。

#include "EDIDParser.h"

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

#include <gtest/gtest.h>

// hexToBin 内部依次调用 hexToDec 与 decTobin,最终结果按 4 位对齐补零。
TEST(UT_EDIDParser_HexToBin, HexToBin_TwoFF_ReturnsEightOnes)
{
EDIDParser parser;
EXPECT_EQ(parser.hexToBin("FF"), "11111111");
}

TEST(UT_EDIDParser_HexToBin, HexToBin_SingleZero_ReturnsFourZeros)
{
EDIDParser parser;
EXPECT_EQ(parser.hexToBin("0"), "0000");
}

TEST(UT_EDIDParser_HexToBin, HexToBin_SingleOne_ReturnsPaddedOne)
{
EDIDParser parser;
EXPECT_EQ(parser.hexToBin("1"), "0001");
}

TEST(UT_EDIDParser_HexToBin, HexToBin_SingleA_ReturnsBinary1010)
{
EDIDParser parser;
EXPECT_EQ(parser.hexToBin("A"), "1010");
}

TEST(UT_EDIDParser_HexToBin, HexToBin_EmptyInput_ReturnsFourZeros)
{
EDIDParser parser;
EXPECT_EQ(parser.hexToBin(""), "0000");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// 覆盖率缺口补全:PageInfo::packageHasInstalled 此前未被用例调用。
// 该函数通过 `dpkg -s <pkg>` 判断包是否安装:已安装包 stdout 含 "installed",
// 不存在的包 stdout 为空(提示信息走 stderr)。PageInfo 为抽象基类,通过其派生类
// PageMultiInfo 实例化后调用。

#include "PageInfo.h"
#include "PageMultiInfo.h"

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

#include <gtest/gtest.h>

TEST(UT_PageInfo_PackageHasInstalled, InstalledDpkgPackage_ReturnsTrue)
{
PageMultiInfo *p = new PageMultiInfo;
PageInfo *info = dynamic_cast<PageInfo *>(p);
// dpkg 自身必然已安装
EXPECT_TRUE(info->packageHasInstalled("dpkg"));
delete p;
}

TEST(UT_PageInfo_PackageHasInstalled, NonExistentPackage_ReturnsFalse)
{
PageMultiInfo *p = new PageMultiInfo;
PageInfo *info = dynamic_cast<PageInfo *>(p);
EXPECT_FALSE(info->packageHasInstalled("zzz-not-a-real-package-20260811"));
delete p;
}
36 changes: 36 additions & 0 deletions deepin-devicemanager/tests/src/Tool/ut_commontools_feedback.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// 覆盖率缺口补全:CommonTools 的构造函数与静态 feedback() 此前未被用例调用。
// - 构造函数仅做日志输出,构造对象即可覆盖。
// - feedback() 内部构造 QDBusInterface 调用服务支持 DBus;测试环境无会话总线,
// QDBusInterface 无效、QDBusReply::isValid() 为 false,走 else 分支,函数体完整执行
// 且不会阻塞或崩溃,因此可直接调用覆盖。

#include "commontools.h"

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

#include <gtest/gtest.h>

TEST(UT_CommonTools_Feedback, Constructor_WithNullParent_ObjectCreated)
{
CommonTools tools(nullptr);
EXPECT_NE(nullptr, &tools);
}

TEST(UT_CommonTools_Feedback, Constructor_WithParent_ObjectCreated)
{
QObject parent;
CommonTools tools(&parent);
EXPECT_EQ(&parent, tools.parent());
}

TEST(UT_CommonTools_Feedback, Feedback_NoSessionBus_CompletesWithoutCrash)
{
// 无 DBus 会话总线时,feedback 内部 DBus 调用即时返回无效应答,
// 函数走 false 分支正常结束。此处验证其可被安全调用。
EXPECT_NO_FATAL_FAILURE(CommonTools::feedback());
}
52 changes: 52 additions & 0 deletions deepin-devicemanager/tests/src/ut_driverinfo_getters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// 覆盖率缺口补全:MacroDefinition.h 中 DriverInfo 结构的 backupFileName/modelName/
// driverName/vendorName 四个内联 getter 此前未被调用,函数覆盖率为 0。
// 本文件通过构造 DriverInfo 并回写成员,验证 getter 取值正确。

#include "MacroDefinition.h"

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

#include <gtest/gtest.h>

TEST(UT_DriverInfo_Getters, BackupFileName_SetValue_ReturnsSameValue)
{
DriverInfo info;
info.m_BackupFileName = "nvidia-525-backup.deb";
EXPECT_EQ(info.backupFileName(), "nvidia-525-backup.deb");
}

TEST(UT_DriverInfo_Getters, ModelName_SetValue_ReturnsSameValue)
{
DriverInfo info;
info.m_ModelName = "GeForce RTX 3060";
EXPECT_EQ(info.modelName(), "GeForce RTX 3060");
}

TEST(UT_DriverInfo_Getters, DriverName_SetValue_ReturnsSameValue)
{
DriverInfo info;
info.m_DriverName = "nvidia-driver-525";
EXPECT_EQ(info.driverName(), "nvidia-driver-525");
}

TEST(UT_DriverInfo_Getters, VendorName_SetValue_ReturnsSameValue)
{
DriverInfo info;
info.m_VendorName = "NVIDIA Corporation";
EXPECT_EQ(info.vendorName(), "NVIDIA Corporation");
}

// 默认构造后各 getter 应返回空串,验证默认值语义
TEST(UT_DriverInfo_Getters, DefaultCtor_GettersReturnEmptyString)
{
DriverInfo info;
EXPECT_TRUE(info.backupFileName().isEmpty());
EXPECT_TRUE(info.modelName().isEmpty());
EXPECT_TRUE(info.driverName().isEmpty());
EXPECT_TRUE(info.vendorName().isEmpty());
}
Loading