Skip to content

test: add unit tests for utils, threads and entries - #562

Merged
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:ut-coverage-batch-4
Oct 27, 2026
Merged

pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:ut-coverage-batch-4

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Part 4/8 of the deepin-log-viewer unit-test coverage series (single-commit PR; all 8 PRs touch disjoint file sets and are mutually independent).

Files in this PR (7 files, +1295/-176 lines)

  • tests/src/ut_utils_extra.cpp (new)
  • tests/src/ut_logtreeview.cpp
  • tests/src/ut_logapplicationparsethread.cpp
  • tests/src/ut_cliapplicationhelper.cpp (new)
  • tests/src/ut_logviewer_auth_main.cpp (new)
  • tests/src/ut_logtableview.cpp (new)
  • tests/src/ut_journalwork.cpp

Notes

  • Test-only change: no production source code is modified.
  • New test files live in tests/src/ / tests/dbusproxy/ / tests/ut_logviewerplugin/, globbed automatically by tests/CMakeLists.txt (re-run cmake after pulling).
  • Each file was compiled and executed individually (GTest + lcov) in its generating task; whole-branch build verification recommended in CI.
  • Series goal: function coverage toward 100% (baseline: 690 passing cases, 68.2% function / 58.5% line coverage).

Summary by Sourcery

Increase unit-test coverage for utilities, journal workers, log views, single-instance support, and authentication startup paths.

Enhancements:

  • Expand unit-test coverage across utility functions, journal parsing, log views, single-instance handling, and authentication entry points.
  • Exercise success, failure, filtering, event-handling, process-control, filesystem, authorization, and command-execution paths using focused test fixtures and stubs.

Tests:

  • Add comprehensive tests for utility behavior, including file handling, user and system information, authorization, coredump processing, command execution, log export, and path expansion.
  • Add coverage for journal parsing and worker execution, including journal errors, filters, stopping, and process cleanup.
  • Add tests for LogTreeView and LogTableView construction, rendering, keyboard, focus, mouse, and touch interactions.
  • Add tests for CLI single-instance lifecycle and socket handlers, plus log viewer authentication main-path behavior.

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Sorry @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 45 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

Test-only batch 4/8 expansion adds 1,295 lines of unit coverage across utilities, journal parsing and workers, single-instance/authentication helpers, and Qt view event/rendering paths, using stubs, temporary resources, and child processes to isolate external dependencies.

File-Level Changes

Change Details Files
Adds broad unit coverage for utility behavior, filesystem/process helpers, authorization, coredump handling, and optional logger-rule configuration.
  • Exercise common and edge-case utility paths using temporary files/directories and command execution.
  • Stub polkit and D-Bus dependencies to test authorization and coredump aggregation deterministically.
  • Cover user/account lookup, path expansion, log export, audit mapping, and conversion helpers.
  • Conditionally test LoggerRules initialization, configuration callbacks, and rule updates.
tests/src/ut_utils_extra.cpp
Expands journal parsing thread coverage with stubbed systemd-journal and D-Bus interactions.
  • Test timestamp and integer conversion helpers plus map initialization.
  • Cover journal open failure, no-match, app/filter/level paths, and stop conditions.
  • Exercise thread run, journal doWork dispatch, and process shutdown behavior.
tests/src/ut_logapplicationparsethread.cpp
Adds tests for single-instance application coordination and its local-socket callbacks.
  • Verify singleton creation, cleanup/recreation, construction, wait-time state, and all scope modes.
  • Exercise repeated-key behavior and new-connection/ready-read socket handlers through an event loop.
tests/src/ut_cliapplicationhelper.cpp
Adds isolated tests for the log viewer authentication entry point and journal worker execution.
  • Run authentication main with empty and populated argument sets in forked child processes while stubbing Qt process/shared-memory operations.
  • Invoke journalWork::run with journal/color-format dependencies stubbed.
tests/src/ut_logviewer_auth_main.cpp
tests/src/ut_journalwork.cpp
Strengthens LogTreeView tests across rendering, keyboard, touch, mouse, focus, and model-dependent branches.
  • Validate constructor UI state and row-height behavior for null, empty, and populated models.
  • Exercise selected/invalid row painting with style stubs.
  • Verify key signal behavior, touch state transitions, mouse pressed/unpressed paths, and focus reasons.
tests/src/ut_logtreeview.cpp
Adds basic lifecycle and focus-event coverage for LogTableView.
  • Test construction with and without a parent.
  • Invoke focus-in and focus-out handlers.
tests/src/ut_logtableview.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 ut-coverage-batch-4 branch from 508db69 to 64ba7f0 Compare October 27, 2026 11:29
@pengfeixx pengfeixx changed the title feat(test): add unit tests for utils, parse threads and standalone entries (batch 4/8) test: add unit tests for utils, threads and entries Oct 27, 2026
@pengfeixx
pengfeixx force-pushed the ut-coverage-batch-4 branch from 64ba7f0 to f1fd1b2 Compare October 27, 2026 11:34
lzwind
lzwind previously approved these changes Oct 27, 2026
1. Add ut_utils_extra, ut_cliapplicationhelper, ut_logtableview and
   ut_logviewer_auth_main test files
2. Rewrite ut_logtreeview.cpp with stricter assertions
3. Extend ut_logapplicationparsethread.cpp and ut_journalwork.cpp

Log: No user-facing changes

Influence:
1. Run deepin-log-viewer-test with --gtest_filter='*Utils*;*TreeView*'
2. Verify full suite passes with ASAN_OPTIONS=detect_leaks=0
3. Check lcov function coverage of utils and parse threads

test: 新增工具类、解析线程与入口单元测试

1. 新增 ut_utils_extra、ut_cliapplicationhelper、ut_logtableview
   与 ut_logviewer_auth_main 测试文件
2. 重写 ut_logtreeview.cpp,断言更严格
3. 扩展 ut_logapplicationparsethread.cpp 与 ut_journalwork.cpp

Log: 无用户可见变化

Influence:
1. 运行 deepin-log-viewer-test 过滤 Utils/TreeView 套件
2. 以 ASAN_OPTIONS=detect_leaks=0 验证全量用例通过
3. 用 lcov 检查 utils 与解析线程函数覆盖率
@deepin-bot

deepin-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.5.43
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #567

@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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 97 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 deepin-log-viewer 项目新增和扩展单元测试代码,涵盖 CliApplicationHelper、 journalWork、LogApplicationParseThread、LogTableView、LogTreeView、logViewerAuth main、 Utils 等模块。全部变更均位于 tests/src/ 目录,不涉及生产代码。四维度分析结果: 语法逻辑正确(25/25),代码质量良好(22/25,存在1处恒真断言和.cpp直接包含的测试技巧), 代码性能合理(20/20),代码安全无漏洞(30/30)。OCR 因浅克隆缺少基准提交未能完成, 但基于 AI 四维度深度分析,未发现安全漏洞,代码审查通过。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无需修改,语法逻辑正确。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['将 UT_GetDateTimeFromStamp_002 的恒真断言改为具体预期值检查,或添加注释说明为覆盖率测试', '在 ut_logviewer_auth_main.cpp 顶部补充注释,说明直接包含 .cpp 文件是为覆盖率测试的必要做法', '考虑将公共 stub 函数提取到 tests/src/stubs/ 目录下的公共头文件中']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无需修改,测试性能合理。']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无需修改,测试代码无安全风险。']


💡 改进建议代码示例

// 建议:将 UT_GetDateTimeFromStamp_002 中的恒真断言改为有意义的验证 TEST_F(LogApplicationParseThread_UT, UT_GetDateTimeFromStamp_002) {
    // 空字符串应返回空结果或特定默认值,根据实际实现确定预期
    QString result = m_logAppThread->getDateTimeFromStamp("");
    EXPECT_TRUE(result.isEmpty()) << "Empty timestamp should return empty string";
}

本报告由 AI 代码审查工具自动生成

@pengfeixx
pengfeixx merged commit f48055c into linuxdeepin:master Oct 27, 2026
14 of 15 checks passed
@pengfeixx
pengfeixx deleted the ut-coverage-batch-4 branch October 27, 2026 13:01
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