Skip to content

test(libdmusic): raise line coverage above 80%#718

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/libdmusic-coverage
Jul 20, 2026
Merged

test(libdmusic): raise line coverage above 80%#718
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/libdmusic-coverage

Conversation

@pengfeixx

Copy link
Copy Markdown
Contributor

Add 19 tests covering PlayerEngine playable-meta cache, list mutations, manual navigation branches, fade switch animations, and Utils DBus property call. Closes the gap from 79.1% to 80.1% line coverage.

新增 19 个用例,覆盖 PlayerEngine 可播放 meta 缓存、列表变更、
手动切歌各分支、淡入淡出动画路径及 Utils DBus 属性调用。
行覆盖率从 79.1% 提升至 80.1%。

Log: 提升单元测试覆盖率到 80% 以上
Influence: 覆盖率提升后回归测试更充分,便于后续重构与缺陷定位。

Add 19 tests covering PlayerEngine playable-meta cache, list mutations,
manual navigation branches, fade switch animations, and Utils DBus
property call. Closes the gap from 79.1% to 80.1% line coverage.

新增 19 个用例,覆盖 PlayerEngine 可播放 meta 缓存、列表变更、
手动切歌各分支、淡入淡出动画路径及 Utils DBus 属性调用。
行覆盖率从 79.1% 提升至 80.1%。

Log: 提升单元测试覆盖率到 80% 以上
Influence: 覆盖率提升后回归测试更充分,便于后续重构与缺陷定位。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @pengfeixx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码为播放器引擎和工具函数补充了详尽的单元测试,覆盖了多种播放列表操作和淡入淡出动画路径
逻辑正确且无安全漏洞,仅因部分测试等待时间较长可能影响整体测试执行效率扣少量分数

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

测试代码使用 Google Test 框架结合 Qt 的 QTest::qWait 进行异步逻辑测试,语法正确。在 test_playerengine.cpp 中,针对各种播放列表状态和播放模式(如 RepeatAll, RepeatSingle)进行了状态注入和断言验证,逻辑严密。test_utils.cpp 中对 readDBusProperty 的测试正确处理了返回的 QVariant 状态。
潜在问题:部分测试依赖固定的时间等待(如 QTest::qWait(2000)),若在不同性能的机器上运行,可能导致测试不稳定。
建议:考虑使用 QSignalSpy 监听特定信号来替代固定时间的 QTest::qWait,提高测试的稳定性和执行速度。

  • 2.代码质量(良好)✓

测试命名规范,能清晰表达测试意图,如 middleMetaHasBothNextAndPrevious。每个测试块前都有详细的注释说明覆盖的分支和触发条件,提高了代码的可读性和可维护性。
潜在问题:无
建议:保持当前的注释和命名规范。

  • 3.代码性能(无性能问题)✓

测试代码主要针对功能覆盖,使用了部分 QTest::qWait 进行延时等待动画完成,这在测试 Qt 动画和异步操作时是标准做法。
潜在问题:累计的等待时间(如 600+700+2000 毫秒等)会增加单次测试套件的运行总时长。
建议:在可能的情况下,通过 mock 对象直接触发 finished 信号,而不是等待真实时间流逝。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次提交为纯测试代码,未引入任何用户输入处理或外部数据解析逻辑,不存在命令注入、缓冲区溢出等安全风险。test_utils.cpp 中调用的不存在的 DBus 服务也是安全的内部测试行为。

  • 建议:无需安全修复。

■ 【改进建议代码示例】

// 建议使用 QSignalSpy 替代固定等待时间,以提升测试稳定性和性能
// 以 test_playerengine.cpp 中的 fadeSwitchWithFadeOutAndFadeInPath 为例:

TEST(PlayerEngineFadeSwitchTest, fadeSwitchWithFadeOutAndFadeInPathOptimized)
{
    InjectedEngine env;
    env.engine->setPlaybackMode(DmGlobal::RepeatAll);
    env.engine->setFadeInOut(true);
    DMusic::MediaMeta m1 = makePlayableCda("fs1");
    DMusic::MediaMeta m2 = makePlayableCda("fs2");
    env.engine->addMetasToPlayList({m1, m2});
    env.engine->setMediaMeta(m1);
    env.fake->m_fakeState = DmGlobal::Playing;
    
    int before = env.fake->setMediaCallCount;
    
    // 假设 engine 有 metaChanged 信号可用于监听切换完成
    QSignalSpy spy(env.engine, &PlayerEngine::metaChanged);
    
    env.engine->playNextMeta(false);
    
    // 等待信号触发,超时时间设为 1000ms 作为兜底
    QVERIFY(spy.wait(1000));
    
    EXPECT_GT(env.fake->setMediaCallCount, before);
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit bff3e4d into linuxdeepin:master Jul 20, 2026
20 checks passed
@pengfeixx
pengfeixx deleted the test/libdmusic-coverage branch July 20, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants