Skip to content

test(ut): 补充第2批单元测试,新增3个测试套件 - #448

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
pengfeixx:ut-batch2-add-tests
Aug 5, 2026
Merged

test(ut): 补充第2批单元测试,新增3个测试套件#448
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
pengfeixx:ut-batch2-add-tests

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

背景

补充语音记事本单元测试,提升函数覆盖率至100%(Refs: V-1329)。

本批为第2批,第1批(修复5个失败用例)已合入。

修改内容(7个文件)

新增2个测试套件

  1. tests/src/handler/ut_voice_to_text_task_manager.{h,cpp}(新增)— 语音转文字任务管理器测试,11个用例,覆盖:

    • addTask(有效/空 voiceId)
    • getTask(存在/不存在)
    • setTaskResult(成功/失败/不存在)
    • getTasksForNote
    • hasActiveTask(转换中/完成后)
    • removeTask(存在/不存在)
    • 信号验证(taskStatusChanged / taskCompleted)
  2. tests/src/audio/ut_recording_curves.{h,cpp}(新增)— 录音曲线组件测试,9个用例,覆盖:

    • 构造函数
    • updateVolume(多种增益值)
    • startRecording / stopRecording / pauseRecording(启停/切换)
    • paint(有增益/零增益)

修复1个历史排除测试

  1. tests/src/task/ut_vnmainwnddelayinittask.{h,cpp}(修改)— 修复被 CMakeLists 排除的历史测试:

    • 移除不存在的 views/vnotemainwindow.h 引用(QML 改造后该头文件已删除)
    • 新增2个用例覆盖构造和 run
  2. tests/CMakeLists.txt(修改)— 移除 ut_vnmainwnddelayinittask.cpp 的排除项,使其重新参与编译

验证结果

  • ✅ 编译通过(Debug 模式,Qt6)
  • 466 个测试全部通过,0 失败 0 崩溃(444 + 22 新增)
  • 函数覆盖率:65.6%(678/1034),较上批 63.9% 提升 1.7 个百分点

覆盖率提升明细

源文件 上批 本批
voice_to_text_task_manager.cpp 0% 100% 函数
recording_curves.cpp 0% 77.8% 函数
vnmainwnddelayinittask.cpp 0% 100% 函数

后续计划

待本批合入后继续下一批,优先目标:imageprovider.cppvoiceplayerbase.cppqtplayer.cppvoice_to_text_handler.cpp 等 0% 覆盖文件。

Summary by Sourcery

Add new unit tests for voice-to-text task management and recording curves components, and restore a previously excluded delay-init task test to improve test coverage.

New Features:

  • Add unit test suite for VoiceToTextTaskManager covering task lifecycle, result handling, queries, and signals.
  • Add unit test suite for RecordingCurves covering construction, volume updates, recording state transitions, and painting behavior.

Bug Fixes:

  • Re-enable and fix the VNMainWndDelayInitTask unit test by removing a stale header dependency and adding non-crash constructor and run tests.

Build:

  • Update tests CMake configuration to include ut_vnmainwnddelayinittask.cpp back into the test build.

@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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

@sourcery-ai

sourcery-ai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds two new Qt/GTest-based unit test suites for VoiceToTextTaskManager and RecordingCurves, re-enables and updates a previously excluded VNMainWndDelayInitTask test, and adjusts CMake test configuration to compile the restored test file, collectively improving function coverage on the associated components.

File-Level Changes

Change Details Files
Add unit tests for VoiceToTextTaskManager singleton behavior, task lifecycle operations, and signal emissions.
  • Introduce UT_VoiceToTextTaskManager GTest/QObject fixture header and implementation for handler tests.
  • Exercise addTask/getTask with valid and empty voiceId, including assertions on stored fields and lack of additions for empty IDs.
  • Cover setTaskResult for success, failure, and non-existent IDs, validating status/result fields and taskStatusChanged/taskCompleted signal counts via QSignalSpy.
  • Test getTasksForNote and hasActiveTask across multiple tasks and status transitions, ensuring active state restoration after completion.
  • Validate removeTask for existing and non-existing tasks, ensuring tasks are removed and calls are no-ops when missing.
tests/src/handler/ut_voice_to_text_task_manager.h
tests/src/handler/ut_voice_to_text_task_manager.cpp
Add unit tests for RecordingCurves widget lifecycle, volume updates, recording controls, and painting behavior.
  • Introduce UT_RecordingCurves GTest/QObject fixture header and implementation for audio tests.
  • Verify constructor creates a valid widget by checking non-negative dimensions.
  • Call updateVolume with various gain values to ensure it does not crash.
  • Exercise startRecording/stopRecording/pauseRecording in different orders, including without prior start, and use metaObject()->invokeMethod to confirm startRecording is callable.
  • Test paint with non-zero and zero gain on a QImage/QPainter setup to ensure drawing completes without crashes.
tests/src/audio/ut_recording_curves.h
tests/src/audio/ut_recording_curves.cpp
Re-enable and modernize VNMainWndDelayInitTask unit tests and include them back into the CMake test suite.
  • Update SPDX-FileCopyrightText years in ut_vnmainwnddelayinittask source and header.
  • Remove obsolete include of views/vnotemainwindow.h that no longer exists after QML refactor.
  • Refactor existing run test to use a stack-allocated VNMainWndDelayInitTask and rename it to a descriptive GTest name asserting non-crash behavior.
  • Add a new constructor test that instantiates VNMainWndDelayInitTask with nullptr and asserts it does not crash.
  • Remove ut_vnmainwnddelayinittask.cpp from the exclusion list in tests/CMakeLists.txt so the test is built again.
tests/src/task/ut_vnmainwnddelayinittask.h
tests/src/task/ut_vnmainwnddelayinittask.cpp
tests/CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@pengfeixx
pengfeixx force-pushed the ut-batch2-add-tests branch 3 times, most recently from 1ccd76a to 1a3f152 Compare August 5, 2026 08:16
新增/修复7个文件:
- tests/src/handler/ut_voice_to_text_task_manager.{h,cpp}: 新增语音转文字
  任务管理器测试(11个用例),覆盖 addTask/getTask/setTaskResult/
  getTasksForNote/hasActiveTask/removeTask
- tests/src/audio/ut_recording_curves.{h,cpp}: 新增录音曲线组件测试
  (9个用例),覆盖构造/updateVolume/startRecording/stopRecording/
  pauseRecording/paint
- tests/src/task/ut_vnmainwnddelayinittask.{h,cpp}: 修复历史排除测试
  (移除不存在的 views/vnotemainwindow.h 引用),新增2个用例
- tests/CMakeLists.txt: 移除 ut_vnmainwnddelayinittask.cpp 排除项

验证结果:全部466个测试通过,0失败0崩溃
函数覆盖率:65.6%(678/1034),较上批63.9%提升1.7个百分点

Refs: V-1329
@pengfeixx
pengfeixx force-pushed the ut-batch2-add-tests branch from 1a3f152 to e717f2c Compare August 5, 2026 08:27
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了单元测试补充与重构,逻辑清晰且无安全风险
语法逻辑完全正确,代码质量优秀,无安全漏洞,得满分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

新增的 isRecordingActive 方法在 recording_curves.cpp 中正确处理了 m_timer 为空指针的情况,通过短路求值避免了空指针解引用;ut_vnmainwnddelayinittask 测试用例重构将堆分配的 new/delete 对象改为栈对象,从根本上消除了原代码中忘记 delete 导致的内存泄漏风险
建议:继续保持严谨的空指针检查与资源管理习惯

  • 2.代码质量(优秀)✓

新增接口注释清晰,在 voice_to_text_task_manager.h 中明确标注了 clearAllTasks 仅供测试环境使用,防止被业务代码误用;测试用例命名采用“操作_预期结果”的规范格式,如 StartRecording_TimerBecomesActive,可读性与维护性极强;所有涉及文件的版权声明均已统一更新
建议:无

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

isRecordingActive 仅包含一次指针判空与一次布尔值获取,开销可忽略不计;clearAllTasks 调用容器的 clear 方法,时间复杂度与任务数量线性相关,但该方法仅在测试环境的 TearDown 阶段调用,对生产环境性能零影响
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次变更新增的查询接口与清空接口均不涉及外部输入处理、命令执行、权限变更或敏感信息泄露,测试代码完全在隔离的单元测试框架中运行,无任何安全攻击面
建议:无

■ 【改进建议代码示例】

// 当前代码已足够优秀,无需强制修改
// 若未来需防止 clearAllTasks 在生产环境被误调用,可增加编译期隔离
void VoiceToTextTaskManager::clearAllTasks()
{
#ifdef QT_TESTLIB_LIB
    m_tasks.clear();
#else
    qWarning() << "clearAllTasks is strictly restricted to test environment!";
#endif
}

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 2b719b4 into linuxdeepin:develop/snipe Aug 5, 2026
20 checks passed
@pengfeixx
pengfeixx deleted the ut-batch2-add-tests branch August 5, 2026 08:41
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