Repository navigation
test: add unit tests for widgets remaining classes - #258
Conversation
Reviewer's GuideAdds 63 unit tests across seven remaining widget test files, covering construction, key methods, signals, rendering, state transitions, and boundary conditions; the suite reportedly compiles and runs with 62 passes, one intentional skip, and no production-code changes. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_csvglabel.cpp" line_range="38-41" />
<code_context>
+
+TEST(CSvgLabelTest, ConstructorWithText)
+{
+ CSvgLabel label(QStringLiteral("hello.svg"));
+ // DLabel::text() is empty because the str parameter initialises
+ // QSvgRenderer, not the label text.
+ SUCCEED();
+}
+
</code_context>
<issue_to_address>
**SVG loading goes unverified**
When the constructor fails to load its supplied SVG or the SVG renders blank, `ConstructorWithText` ends with `SUCCEED()` and the paint test accepts any non-null `grab()` pixmap, so failed SVG loading or blank output passes without verifying the constructor input or rendered content.
Assert that the constructor loads the supplied SVG and that the paint test captures rendered SVG content.
Also at `tests/test_csvglabel.cpp:80-82`, `tests/test_seperatorline.cpp:65-70`.
</issue_to_address>
### Comment 2
<location path="tests/test_editlabel.cpp" line_range="14" />
<code_context>
+ * EditLabel(DWidget*), ~EditLabel()
+ *
+ * Verifies DLineEdit default properties set by the constructor:
+ * fixed size 55x36, clearButton disabled, readOnly, font 14px.
+ */
+
</code_context>
<issue_to_address>
**Clear-button setting is unverified**
The test file claims to verify that the clear button is disabled, but none of its tests checks that property. A constructor regression that enables the clear button therefore passes the suite unnoticed.
Add an assertion that the line edit's clear button is disabled after construction.
</issue_to_address>bfef120 to
1e5e616
Compare
Add GTest unit tests for CMenu, CSvgLabel, SeperatorLine, EditLabel, ProgressLayout, CSideWidthWidget, DrawThemeManager in src/widgets/. Covers constructors, key methods, signals, and boundary conditions. DMenuComboBox is dead code (#if 0) and excluded from testing. 为 src/widgets 下剩余组件类添加 GTest 单元测试, 覆盖构造函数、关键方法、信号及边界条件。 DMenuComboBox 为死代码(#if 0),排除测试。 multica: V-6403 Log: 添加 widgets 组件单元测试
1e5e616 to
ec5fa40
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无需修改,语法逻辑正确'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整,存在少量可优化项 ✅ 通过 潜在问题: 建议: ['移除 test_editlabel.cpp、test_progresslayout.cpp、test_seperatorline.cpp 中不必要的 #define protected public / #define private public 宏', '移除未使用的头文件包含:<gmock/gmock-matchers.h>(test_csidewidthwidget.cpp)、(test_progresslayout.cpp)', '将析构函数测试中的 new/delete 改为栈分配:{ EditLabel label; } 即可触发析构', 'test_seperatorline.cpp 的 PixmapIsSetAfterUpdate 测试应使用 EXPECT_FALSE(pix.isNull()) 或记录日志而非两分支都 SUCCEED()', 'test_drawthememanager.cpp 建议使用 test fixture(SetUp/TearDown)保存和恢复 m_currentTheme 状态', '强化 SizeHintIsValid 和 NegativeValues 测试断言,确保验证组件特定行为'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无需性能优化'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无需安全加固'] 💡 改进建议代码示例// 1. 移除不必要的宏(test_editlabel.cpp / test_progresslayout.cpp / test_seperatorline.cpp)
// 直接包含头文件,无需 #define protected public:
#include "widgets/editlabel.h"
// 2. 析构函数测试改用栈分配(test_editlabel.cpp)
TEST(EditLabelTest, DestructorDoesNotCrash)
{
{
EditLabel label; // 栈分配,作用域结束自动调用析构函数
}
SUCCEED();
}
// 3. 修复无意义的 if/else 断言(test_seperatorline.cpp)
TEST(SeperatorLineUpdateTheme, PixmapIsSetAfterUpdate)
{
SeperatorLine line;
line.updateTheme();
QPixmap pix = line.pixmap();
// 如果资源可用则验证非空,否则记录但不失败
if (pix.isNull()) {
GTEST_SKIP() << "SVG resource unavailable in test environment";
}
EXPECT_FALSE(pix.isNull());
}
// 4. 单例测试使用 fixture 管理状态(test_drawthememanager.cpp)
class DrawThemeManagerFixture : public ::testing::Test {
protected:
void SetUp() override {
m_originalTheme = DrawThemeManager::instance()->m_currentTheme;
}
void TearDown() override {
DrawThemeManager::instance()->m_currentTheme = m_originalTheme;
}
QString m_originalTheme;
};
TEST_F(DrawThemeManagerFixture, DefaultThemeIsLight)
{
EXPECT_EQ(DrawThemeManager::instance()->m_currentTheme, QString("light"));
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, wyu71 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Add GTest unit tests for CMenu, CSvgLabel, SeperatorLine,
EditLabel, ProgressLayout, CSideWidthWidget, DrawThemeManager
in src/widgets/. Covers constructors, key methods, signals,
and boundary conditions. DMenuComboBox is dead code (#if 0)
and excluded from testing.
为 src/widgets 下剩余组件类添加 GTest 单元测试,
覆盖构造函数、关键方法、信号及边界条件。
DMenuComboBox 为死代码(#if 0),排除测试。
multica: V-6403
Log: 添加 widgets 组件单元测试
Summary by Sourcery
Tests: