Skip to content

test(common): add unit tests for common and encodes modules - #505

Merged
pengfeixx merged 2 commits into
linuxdeepin:masterfrom
pengfeixx:test/ut-common-new
Aug 3, 2026
Merged

test(common): add unit tests for common and encodes modules#505
pengfeixx merged 2 commits into
linuxdeepin:masterfrom
pengfeixx:test/ut-common-new

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Add tests for Config, Eventlogutils, IflytekAiAssistant, TextFileSaver and detectcode helper functions.

Log: 新增common和encodes模块的单元测试
Influence: 覆盖Config、Eventlogutils等类的未覆盖函数

Summary by Sourcery

Add unit tests to cover previously untested functionality in the common and encodes modules.

Tests:

  • Add unit tests for UTF-8 and GB18030 encoding helper functions in the encodes module.
  • Add unit tests for IflytekAiAssistant private and singleton behaviors, including DBus-related paths and destructor.
  • Add unit tests for Config singleton lifecycle, configuration getters, and value-changed handling.
  • Add unit tests for TextFileSaver saveAs success and failure paths.
  • Add unit tests for Eventlogutils singleton access and log writing behavior with various JSON inputs.

@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

Add new GoogleTest-based unit tests for previously uncovered functionality in the common and encodes modules, targeting private/internal methods and file-scope helper functions via -fno-access-control and direct declarations.

File-Level Changes

Change Details Files
Add unit tests for detectcode.cpp file-scope helper functions to validate UTF-8 multi-byte counting and GB18030/UTF-8 error handling paths.
  • Declare utf8MultiByteCount, checkGB18030ToUtf8Error, and checkUTF8ToGB18030Error as extern functions to access file-scope helpers from detectcode.cpp.
  • Add tests covering ASCII, valid multi-byte prefixes, continuation-byte sequences, and invalid leading bits for utf8MultiByteCount, including the internal lambda path.
  • Add tests for checkGB18030ToUtf8Error that cover short buffers, non-matching 4-byte sequences, and a PUA mapping hit with replacement length and appendChar assertions.
  • Add tests for checkUTF8ToGB18030Error for short buffers, PUA mapping hits from UTF-8 to GB18030, mapping of known 2005 error codes, and non-matching sequences with default replacement behavior.
tests/src/encodes/ut_detectcode_helpers.cpp
Add unit tests for IflytekAiAssistant to exercise private static and instance methods, status transitions, and destructor behavior.
  • Test launchCopilotChat with a QDBusInterface pointing at the copilot service, asserting the returned CallStatus is one of the known enum values regardless of DBus environment.
  • Test stopTtsDirectlyInternal when the assistant is not enabled, confirming it returns the current status immediately.
  • Force m_status to Enable and verify stopTtsDirectlyInternal follows the DBus success path and returns Success, then restore the previous status.
  • Create and delete a standalone IflytekAiAssistant instance to cover the private defaulted destructor.
tests/src/common/ut_iflytek_ai_assistant.cpp
Add unit tests for Config singleton behavior, constructor/destructor coverage, configuration getters, and the DConfig valueChanged lambda.
  • Create and delete a Config instance via the private constructor to cover constructor and destructor using -fno-access-control.
  • Verify Config::instance returns a non-null singleton and is stable across repeated calls.
  • Exercise configuration getters such as defaultEncoding to ensure they return non-empty values.
  • Conditionally invoke the DConfig valueChanged signal via QMetaObject on relevant keys to cover the lambda that updates internal state when DConfig is valid.
tests/src/common/ut_config.cpp
Add unit tests for TextFileSaver that cover both successful and failing saveAs paths, including error string handling.
  • Use a QTextDocument and QTemporaryDir to save content to a real temporary file via saveAs, asserting success and file existence.
  • Set an initial file path, then call saveAs with an unwritable/nonexistent directory path to verify failure, restoration of original path semantics, and a non-empty errorString.
tests/src/common/ut_textfilesaver.cpp
Add unit tests for Eventlogutils singleton and writeLogs behavior with and without payload data.
  • Verify Eventlogutils::GetInstance returns a singleton instance and that repeated calls return the same pointer.
  • Call writeLogs with a populated QJsonObject containing a StartUp tid and message, confirming the function executes regardless of writeEventLogFunc availability.
  • Call writeLogs with an empty QJsonObject to ensure the early-return path is covered without errors.
tests/src/common/ut_eventlogutils.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

Add tests for Config, Eventlogutils, IflytekAiAssistant, TextFileSaver
and detectcode helper functions.

Log: 新增common和encodes模块的单元测试
Influence: 覆盖Config、Eventlogutils等类的未覆盖函数
Log: 修正新增测试文件的SPDX版权头年份
Influence: 无
@pengfeixx
pengfeixx force-pushed the test/ut-common-new branch from f5e1bac to c89c4ab Compare August 3, 2026 05:54
@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
pengfeixx merged commit 6d634a4 into linuxdeepin:master Aug 3, 2026
15 of 18 checks passed
@pengfeixx
pengfeixx deleted the test/ut-common-new branch August 3, 2026 06:27
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