Skip to content

test(common): extend existing tests for better coverage - #503

Merged
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
pengfeixx:test/ut-common-controls-ext
Aug 3, 2026
Merged

test(common): extend existing tests for better coverage#503
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
pengfeixx:test/ut-common-controls-ext

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Add test cases for CSyntaxHighlighter, Settings, Utils, FindBar, JumpLineBar, LineBar and Tabbar.

Log: 扩充common和controls模块现有测试用例
Influence: 提升Settings、Utils、Tabbar等类的函数覆盖率

Summary by Sourcery

Extend unit test coverage for common utilities, settings, syntax highlighting, and controls components.

Tests:

  • Add coverage for multiple Utils functions including DLL loading, hashing, library path resolution, share-dir checks, text wrapping, and floating message display.
  • Expand Tabbar tests to cover navigation, tab visibility actions, context menu event filtering, size-mode change handling, and translation strings.
  • Increase Settings tests to exercise the custom backend lifecycle, save-path configuration, widget-creation lambdas, and key-sequence handling dialog logic.
  • Augment CSyntaxHighlighter tests to verify invalid-character highlighting configuration paths.
  • Add FindBar tests for switching to the replace bar and retrieving the current search text.
  • Add LineBar and JumpLineBar tests to cover size-mode change reactions and line-count management.

@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

@sourcery-ai

sourcery-ai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR extends unit test coverage for several common and controls components (Utils, Tabbar, Settings, CSyntaxHighlighter, FindBar, LineBar, JumpLineBar) by deleting obsolete commented‑out tests and adding new, executable tests that exercise previously uncovered branches, lambdas, and helper functions without changing production code.

File-Level Changes

Change Details Files
Expand Utils unit tests to cover previously untested helper functions and edge paths.
  • Remove legacy, commented-out tests for detectEncode, codecConfidenceForData, and isShareDirAndReadOnly to reduce noise.
  • Add executable tests for loadCustomDLL, getStringMD5Hash, libPath, and isShareDirAndReadOnly that validate behavior without relying on stubs.
  • Add multiple lineFeed tests to cover single-row, multi-row, and negative-row branches.
  • Add sendFloatMessageFixedFont test that exercises DFloatingMessage creation and the internal count_if lambda over repeated calls.
tests/src/common/ut_utils.cpp
Increase Tabbar test coverage, focusing on navigation, context-menu lambdas, constructor connections, and translation paths.
  • Remove old commented-out tests for openFilesInWindow, addTabWithIndex, updateTab, previousTab, and eventFilter.
  • Add previousTab test that exercises index decrement and wrap-around behavior.
  • Add showTabs test that checks enabling/disabling of close-left/right actions based on current index and tab count.
  • Add eventFilter test that stubs tabAt and QMenu::exec to build the tab context menu, verify actions, and trigger all connected lambdas.
  • Add constructor lambda test by toggling DGuiApplicationHelper::sizeMode and ensuring Tabbar reacts without crashing.
  • Add explicit tr() tests to exercise Q_OBJECT-generated translations for common strings.
tests/src/controls/ut_tabbar.cpp
Extend Settings-related tests to cover CustemBackend, Settings lifecycle, and UI-handler lambdas for several options.
  • Add CustemBackend test that constructs a backend with a temporary config file, writes with doSetOption, flushes with doSync, queries keys, and reads via getOption, then deletes the backend.
  • Add round-trip tests for Settings::setSavePathId and getSavePathId.
  • Add explicit Settings destructor test via new/delete to cover non-singleton destruction path.
  • Add createSavingPathWgt test that obtains a real DSettingsOption, builds the widget, and triggers the option valueChanged lambda.
  • Add createFontComBoBoxHandle test that builds a combo box for a DSettingsOption and triggers both the option valueChanged lambda and the comboBox currentTextChanged lambda.
  • Introduce NoLoopDDialog subclass plus stubbing for Settings::createDialog and add createKeySequenceEditHandle test that emits KeySequenceEdit::editingFinished to exercise its lambda without running a nested event loop.
tests/src/common/ut_setting.cpp
Add CSyntaxHighlighter tests to exercise invalid-character highlighting toggles.
  • Extend fixture tests to call setInvalidCharHighlight(true) and verify m_bInvalidCharHighlight and m_bHighlight are set.
  • Add a complementary test with setInvalidCharHighlight(false) to confirm flags are cleared appropriately.
tests/src/common/ut_csyntaxhighlighter.cpp
Improve FindBar coverage for switch-to-replace behavior and current search text retrieval.
  • Add handleSwitchToReplace test that connects to sigSwitchToReplaceBar, invokes the handler, and asserts the signal is emitted.
  • Add getCurrentSearchText test that checks the default empty state and then sets text in m_editLine->lineEdit to verify correct retrieval.
tests/src/controls/ut_findbar.cpp
Extend LineBar and JumpLineBar tests to cover size-mode reaction and line-count tracking.
  • Add LineBar constructor lambda test that toggles DGuiApplicationHelper::sizeMode to exercise the connected sizeModeChanged handler.
  • Add JumpLineBar getLineCount test that calls activeInput and verifies the stored line count via getLineCount.
tests/src/controls/ut_linebar.cpp
tests/src/controls/ut_jumplinebar.cpp

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 test/ut-common-controls-ext branch from 97b31f8 to a3d54a1 Compare August 3, 2026 02:30
Add test cases for CSyntaxHighlighter, Settings, Utils, FindBar,
JumpLineBar, LineBar and Tabbar.

Log: 扩充common和controls模块现有测试用例
Influence: 提升Settings、Utils、Tabbar等类的函数覆盖率
@pengfeixx
pengfeixx force-pushed the test/ut-common-controls-ext branch from a3d54a1 to 9a1595a Compare August 3, 2026 02:33
Log: 更新已修改文件的SPDX版权头年份范围
Influence: 无
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:90分

■ 【总体评价】

代码新增了大量单元测试以提升覆盖率,但存在少量复制粘贴错误和脚本健壮性问题。
逻辑基本正确且无安全漏洞,因重复宏定义和rm命令缺乏容错各扣5分。

■ 【详细分析】

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

代码整体语法正确,能够正常编译。新增的测试用例逻辑清晰,如 ut_setting.cpp 中通过重写 DDialog::exec() 避免事件循环崩溃的设计很巧妙。但 test-prj-running.sh 中取消了 rm -r 命令的注释,如果目录不存在会导致脚本报错并可能中断执行。
潜在问题:test-prj-running.sh 中的 rm -r $builddir 在首次运行或目录被清理后再次运行时,会因为目录不存在而执行失败。
建议:将 rm -r 修改为 rm -rf 以增加脚本的健壮性。

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

测试代码整体结构清晰,注释完整,命名规范。但在 ut_linebar.cpp 中,DGUI_USE_NAMESPACE 宏被连续定义了三次,这明显是复制粘贴引入的冗余代码。
潜在问题:ut_linebar.cpp 中存在重复的宏定义,影响代码整洁度。
建议:删除 ut_linebar.cpp 中多余的 DGUI_USE_NAMESPACE 宏,保留一个即可。

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

测试代码主要关注功能覆盖,不涉及高并发或复杂算法,性能表现良好。test-prj-running.sh 中的 make -j8 充分利用了多核编译,符合常规构建流程。
建议:无需特别优化。

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次提交为单元测试和构建脚本的更新,未引入任何安全漏洞。虽然 test-prj-running.sh 中使用了 rm 命令,但由于操作的是固定的相对路径目录且在测试环境中运行,不构成安全威胁。

  • 建议:无需修复。

■ 【改进建议代码示例】

diff --git a/tests/src/controls/ut_linebar.cpp b/tests/src/controls/ut_linebar.cpp
index 8c690e35..8ea3969e 100644
--- a/tests/src/controls/ut_linebar.cpp
+++ b/tests/src/controls/ut_linebar.cpp
@@ -6,9 +6,7 @@
 #include "../../src/controls/linebar.h"
 #include <QFocusEvent>
 #include <QEvent>
 #include <DGuiApplicationHelper>
 DGUI_USE_NAMESPACE
-DGUI_USE_NAMESPACE
-DGUI_USE_NAMESPACE
 
 test_linebar::test_linebar()
 {
diff --git a/tests/test-prj-running.sh b/tests/test-prj-running.sh
index fc2c3531..ce79da3c 100644
--- a/tests/test-prj-running.sh
+++ b/tests/test-prj-running.sh
@@ -1,15 +1,15 @@
 #!/bin/bash
 builddir=build
 reportdir=build-ut
-# rm -r $builddir
-# rm -r ../$builddir
-# rm -r $reportdir
-# rm -r ../$reportdir
-# mkdir ../$builddir
-# mkdir ../$reportdir
+rm -rf $builddir
+rm -rf ../$builddir
+rm -rf $reportdir
+rm -rf ../$reportdir
+mkdir ../$builddir
+mkdir ../$reportdir
 cd ../$builddir
 #编译
-# cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_ON" ..
+cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_ON" ..
 make -j8
 #生成asan日志和ut测试xml结果
 export ASAN_OPTIONS=abort_on_error=0:detect_leaks=0

@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 4d27c52 into linuxdeepin:master Aug 3, 2026
20 checks passed
@pengfeixx
pengfeixx deleted the test/ut-common-controls-ext branch August 3, 2026 02:46
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