Skip to content

test: add unit tests for service and main window - #561

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

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

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Part 3/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 (5 files, +1449/-12 lines)

  • tests/src/ut_logviewerservice.cpp (new)
  • tests/src/ut_org_deepin_log_viewer.cpp (new)
  • tests/src/ut_logcollectormain.cpp
  • tests/src/ut_debugtimemanager.cpp
  • tests/src/ut_lognormalbutton.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 across core log viewer services, configuration handling, and main-window UI behavior.

Enhancements:

  • Expand unit-test coverage for log viewer services, configuration bindings, window behavior, debug timing, and normal button rendering.

Tests:

  • Add comprehensive tests for LogViewerService file operations, authorization, streaming, command execution, metadata, and export paths.
  • Add tests for org_deepin_log_viewer constructors, configuration getters and setters, value updates, property tracking, and change notifications.
  • Exercise LogCollectorMain shortcut, refresh, export, and title-bar callback paths, along with DebugTimeManager behavior and LogNormalButton painting branches.

@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

This test-only PR adds extensive coverage for the log viewer service and generated configuration object, exercises asynchronous LogCollectorMain behavior through targeted stubs and Qt event processing, and fills timing and widget paint branches in existing unit-test files.

File-Level Changes

Change Details Files
Adds broad unit coverage for the log viewer service, including filesystem helpers, authorization and path validation, log reading, streaming, metadata, command execution, export, and cleanup behavior.
  • Introduces fixture-based tests with temporary files/directories and D-Bus file descriptors.
  • Exercises authorized and unauthorized paths, invalid inputs, whitelist checks, command variants, and coredump handling.
  • Uses stubs to isolate authorization and polkit/D-Bus-dependent branches.
tests/src/ut_logviewerservice.cpp
Adds threaded tests for the generated DConfig-backed application configuration class and its property synchronization behavior.
  • Provides a controllable mock DConfig backend with representative values.
  • Covers all constructor overloads, getters/setters, property-set tracking, updateValue fall-through, and valueChanged connection callbacks.
  • Coordinates worker-thread execution and queued events to satisfy thread-affinity assertions.
tests/src/ut_org_deepin_log_viewer.cpp
Expands LogCollectorMain tests to execute shortcut, titlebar refresh, periodic refresh, and export-related signal/lambda paths.
  • Adds stubs for parsers, authorization, D-Bus checks, export-thread signals, file dialogs, and dialog event processing.
  • Triggers Qt actions, timers, concurrent refresh completion, and export progress callbacks to cover asynchronous closures.
tests/src/ut_logcollectormain.cpp
Strengthens DebugTimeManager coverage across singleton, lifecycle, map management, timing, and clock failure behavior.
  • Tests singleton identity and construction.
  • Verifies begin/end/clear behavior for successful, unknown-point, and clock_gettime-failure cases.
  • Adds deterministic timespec difference assertions using a clock stub.
tests/src/ut_debugtimemanager.cpp
Adds paint-event coverage for LogNormalButton, including style-dependent rendering and the focus-rectangle branch.
  • Installs DStyle before painting to satisfy the widget's style cast.
  • Stubs hasFocus and sets tab focus reason to exercise focused rendering.
tests/src/ut_lognormalbutton.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-3 branch from 98a551d to 5ac54a3 Compare October 27, 2026 11:29
@pengfeixx pengfeixx changed the title feat(test): add service and main window unit tests (batch 3/8) test: add unit tests for service and main window Oct 27, 2026
@pengfeixx
pengfeixx force-pushed the ut-coverage-batch-3 branch from 5ac54a3 to 9fda5b0 Compare October 27, 2026 11:34
lzwind
lzwind previously approved these changes Oct 27, 2026
1. Add ut_logviewerservice.cpp and ut_org_deepin_log_viewer.cpp
2. Extend ut_logcollectormain.cpp and ut_debugtimemanager.cpp
3. Extend ut_lognormalbutton.cpp including style painting branches

Log: No user-facing changes

Influence:
1. Run deepin-log-viewer-test with --gtest_filter='*Service*;*Collector*'
2. Verify full suite passes with ASAN_OPTIONS=detect_leaks=0
3. Check lcov function coverage of the new test targets

test: 新增服务端与主窗口单元测试

1. 新增 ut_logviewerservice.cpp 与 ut_org_deepin_log_viewer.cpp
2. 扩展 ut_logcollectormain.cpp 和 ut_debugtimemanager.cpp
3. 扩展 ut_lognormalbutton.cpp,含样式绘制分支

Log: 无用户可见变化

Influence:
1. 运行 deepin-log-viewer-test 过滤 Service/Collector 套件
2. 以 ASAN_OPTIONS=detect_leaks=0 验证全量用例通过
3. 用 lcov 检查新增目标的函数覆盖率
@pengfeixx
pengfeixx force-pushed the ut-coverage-batch-3 branch from 244e03f to 9eed581 Compare October 27, 2026 12:09
@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

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为纯测试代码(tests/src/ 目录下5个文件),新增和扩展了 DebugTimeManager、 LogCollectorMain、LogNormalButton、LogViewerService 和 org_deepin_log_viewer 的单元测试, 覆盖了构造析构、核心方法、lambda 闭包、线程同步、路径遍历防护和DBus认证等场景。 代码语法正确、逻辑清晰,安全方面无漏洞(路径遍历测试为安全验证而非漏洞引入), 性能方面无瓶颈。仅在 ut_logcollectormain.cpp 中存在11行stub设置代码在4个测试中重复的问题, 建议提取为公共辅助函数。OCR 审查因 merge-base 无法找到而失败,不影响本次分析结论。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: ['无需修改']


2. 代码质量 ✅

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

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

建议: ['将 ut_logcollectormain.cpp 中重复的 stub 设置提取为公共辅助函数(如 setupCommonStubs(Stub &stub)),减少代码重复', '考虑使用 RAII 类管理 g_ut_clock_fail 标志,确保异常路径下自动重置']


3. 代码性能 ✅

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

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

建议: ['无需修改']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['无需修改']


💡 改进建议代码示例

// 建议:将 ut_logcollectormain.cpp 中重复的 stub 设置提取为公共辅助函数 // // 在文件顶部添加: // static void setupLogCollectorCommonStubs(Stub &stub) // { //     stub.set(ADDR(DebugTimeManager, beginPointLinux), Log_beginPointLinux); //     stub.set(ADDR(LogFileParser, parseByJournal), LogFileParser_parseByJournal); //     stub.set(ADDR(LogFileParser, parseByJournalBoot), LogFileParser_parseByJournalBoot); //     stub.set(ADDR(LogFileParser, parseByDpkg), LogFileParser_parseByDpkg); //     stub.set(ADDR(LogFileParser, parseByXlog), LogFileParser_parseByXlog); //     stub.set(ADDR(LogFileParser, parseByBoot), LogFileParser_parseByBoot); //     stub.set(ADDR(LogFileParser, parseByKern), LogFileParser_parseByKern); //     stub.set(ADDR(LogFileParser, parseByApp), LogFileParser_parseByApp); //     stub.set(ADDR(LogFileParser, parseByNormal), LogFileParser_parseByNormal); //     stub.set(ADDR(LogFileParser, parseByKwin), LogFileParser_parseByKwin); //     stub.set(ADDR(LogApplicationHelper, getCustomLogList), LogApplicationHelper_getCustomLogList); // } // // 然后在每个测试中替换11行 stub.set() 为一行调用: // TEST(LogCollectorMain_initShortCut_UT, LogCollectorMain_initShortCut_UT_003) // { //     qApp->setStyle(new DStyle); //     Stub stub; //     setupLogCollectorCommonStubs(stub);  // 替代11行重复代码 //     LogCollectorMain *p = new LogCollectorMain(nullptr); //     // ... 其余测试逻辑不变 // }

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

@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 42e3b89 into linuxdeepin:master Oct 27, 2026
14 checks passed
@pengfeixx
pengfeixx deleted the ut-coverage-batch-3 branch October 27, 2026 13:00
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